DX12-6th

6th Capture

6.13.7

Q: Merge the vertices of a box and pyramid (Exercise 4) into one large vertex buffer. Also merge the indices of the box and pyramid into one large index buffer (but do not update the index values). Then draw the box and pyramid one-by-one using the parameters of ID3D12CommandList::DrawIndexedInstanced. Use the world transformation matrix so that the box and pyramid are disjoint in world space

image-20220305213358594

只要配置两个 submesh 以及在 drawIndexInstanced 的时候注意,遗憾的是我在分开两个的时候我是直接把他们坐标该改一下的。不大好

virtual void STDMETHODCALLTYPE DrawIndexedInstanced( 
    _In_  UINT IndexCountPerInstance,
    _In_  UINT InstanceCount,
    _In_  UINT StartIndexLocation,
    _In_  INT BaseVertexLocation,
    _In_  UINT StartInstanceLocation) = 0;

6.13.8-6.13.9

Q: Modify the Box demo by rendering the cube in wireframe mode
Q: Modify the Box demo by disabling backface culling (D3D12_CULL_NONE); also try culling front faces instead of back faces (D3D12_CULL_FRONT). Output your results in wireframe mode so that you can more easily see the difference.

线框(WIREFRAME)在光栅化的描述中选择。

psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
psoDesc.RasterizerState.FillMode = D3D12_FILL_MODE_WIREFRAME;
//psoDesc.RasterizerState.CullMode = D3D12_CULL_NONE;
//psoDesc.RasterizerState.CullMode = D3D12_CULL_MODE_FRONT;
/*
enum D3D12_CULL_MODE
    {
        D3D12_CULL_MODE_NONE	= 1,
        D3D12_CULL_MODE_FRONT	= 2,
        D3D12_CULL_MODE_BACK	= 3
    } 	D3D12_CULL_MODE;
*/

D3D12_CULL_MODE_FRONTimage-20220305215313716

D3D12_CULL_MODE_NONEimage-20220305215505408

6.13.10

Q:改变Color的数据类型

改用 XMCOLOR 作为颜色类型 , 需要修改几处数据。image-202203052210530556.13.11

vertex 相关的数据结构中,调换顺序会不会有什么影响

(a)恰当的,只要 D3D12_INPUT_ELEMENT_DESC 中的 AlignedByteOffset 用于判断输入的位于结构体中的哪个偏移
(b)恰当的。这个应该是由于 desc 中第一个字符串描述的来判断是否是对应项。

6.13.12

正常视口
image-20220305225030326

左半边视口
image-20220305225111429

6.13.13

image-20220307144654889

6.13.14

float4 PS(VertexOut pin) : SV_Target
{
    return abs(pin.Color*sin(gTime));
}

6.13.15

clip ( pin.Color.r - 0.5f )
把颜色值小于 0.5f 的裁掉了。

6.13.16

这里有坑,不知道为什么。

//可行
struct ObjectConstants
{
    XMFLOAT4X4 WorldViewProj = MathHelper::Identity4x4();
    XMFLOAT4 gPulseColor;
    float gTime;
};
//不行,gPulseColor 可能是对齐的问题
struct ObjectConstants
{
    XMFLOAT4X4 WorldViewProj = MathHelper::Identity4x4();
    float gTime;
    XMFLOAT4 gPulseColor;
};

6.13.17

略,书上源代码清清楚楚的