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

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;

• 本文已收录于以下专栏：

举报原因： 您举报文章：龙书D3D11章节习题答案(第九章) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)