# 龙书D3D11章节习题答案(第九章)

504人阅读 评论(0)

Chapter 9 : Blending

1. Modify the “Transparent Water” demo by using the following line before drawing the water:

md3dImmediateContext->OMSetBlendState(TransparentBS, blendFactors, 0xfffffffe);

This turns off the first bit which disables the first sample. Because we are not using multisampling (which is like using multisampling with one sample), this prevents the water pixels from being drawn.

	// Use 4X MSAA?
if( mEnable4xMsaa )
{
sd.SampleDesc.Count   = 4;
sd.SampleDesc.Quality = m4xMsaaQuality-1;
}
// No MSAA
else
{
sd.SampleDesc.Count   = 1;
sd.SampleDesc.Quality = 0;
}

	md3dImmediateContext->OMSetBlendState(RenderStates::TransparentBS, blendFactor, 0x00000000); //同0xfffffffe

2. Experiment with different blend operations and blend factor combinations.

3. Modify the “Blend” demo by drawing the water first. Explain the results.

4. Suppose fogStart = 10 and fogRange = 200. Compute foggedColor for when
(a) dist(p, E) = 160
(b) dist(p, E) = 110
(c) dist(p, E) = 60
(d) dist(p, E) = 30

(a) s = (160-10)/200 = 0.75, foggedColor = 0.75*fogColor + (1-0.75)*litColor.

5. Verify the effect techniques with gAlphaClip=false which do not have a discard instruction, and the techniques with gAlphaClip=true which do, by looking at the generated shader assembly. The discard instruction corresponds to the HLSL clip instruction.

HLSL:

		if(gAlphaClip)
{
// Discard pixel if texture alpha < 0.1.  Note that we do this
// test as soon as possible so that we can potentially exit the shader
// early, thereby skipping the rest of the shader code.
clip(texColor.a - 0.1f);
}

fxc编译为汇编代码如下: (fxc编译时需要指定选项/Fc以生成.cod汇编文件)

                add r1.x, r0.w, l(-0.100000)
lt r1.x, r1.x, l(0.000000)
and r1.x, r1.x, l(-1)
discard r1.x

6. Modify the “Blend” demo by creating and applying a blend render state that disables color writes to the red and green color channels.

	transparentDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALPHA | D3D11_COLOR_WRITE_ENABLE_BLUE;

1
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：20320次
• 积分：436
• 等级：
• 排名：千里之外
• 原创：19篇
• 转载：3篇
• 译文：1篇
• 评论：10条
文章分类
评论排行
最新评论