在DirectX11 Vertex和像素着色器之间交换

时间:2017-01-05 19:06:33

标签: c++ render draw directx-11

所以我一直在关注Frank Luna的一本教程" 3D游戏编程与DirectX11"并且一直在研究Sky-box。除了纹理所需的小调整之外,这个天空盒正确渲染。我为Sky Box创建了一个单独的顶点和像素着色器,因为它在.fx文件中不需要那么多工作。当我绘制我的对象时,它们都会绘制,但是当我使用正常的顶点和像素着色器时,我的对象显示为黑色(我认为它们无法从着色器中获取颜色)。

_pImmediateContext->RSSetState(_solidFrame);
_pImmediateContext->VSSetShader(_pSkyVertexShader, nullptr, 0);
_pImmediateContext->PSSetShaderResources(3, 1, &_pTextureSkyMap);
_pImmediateContext->PSSetShaderResources(0, 1, &_pTextureRV);
_pImmediateContext->PSSetShaderResources(1, 1, &_pSpecTextureRV);
_pImmediateContext->PSSetShaderResources(2, 1, &_pNormTextureRV);
_pImmediateContext->PSSetSamplers(0, 1, &_pSamplerLinear);
_pImmediateContext->PSSetShader(_pSkyPixelShader, nullptr, 0);

//Imported Sky
world = XMLoadFloat4x4(&_sky.GetWorld());
cb.mWorld = XMMatrixTranspose(world);
_pImmediateContext->UpdateSubresource(_pConstantBuffer, 0, nullptr, &cb, 0, 0); //Copies the constant buffer to the shaders.
//Draw the Pitch
_sky.Draw(_pd3dDevice, _pImmediateContext);

_pImmediateContext->VSSetShader(_pVertexShader, nullptr, 0);
_pImmediateContext->VSSetConstantBuffers(0, 1, &_pConstantBuffer);
_pImmediateContext->PSSetConstantBuffers(0, 1, &_pConstantBuffer);
_pImmediateContext->PSSetShaderResources(0, 1, &_pTextureMetalRV);
_pImmediateContext->PSSetShaderResources(1, 1, &_pSpecTextureRV);
_pImmediateContext->PSSetShaderResources(2, 1, &_pNormTextureRV);
_pImmediateContext->PSSetSamplers(0, 1, &_pSamplerLinear);
_pImmediateContext->PSSetShader(_pPixelShader, nullptr, 0);

//Floor
// Render opaque objects //
// Set vertex buffer for the Floor
_pImmediateContext->IASetVertexBuffers(0, 1, &_pVertexBufferFloor, &stride, &offset);
// Set index buffer
_pImmediateContext->IASetIndexBuffer(_pIndexBufferFloor, DXGI_FORMAT_R16_UINT, 0);
world = XMLoadFloat4x4(&_worldFloor);
cb.mWorld = XMMatrixTranspose(world);
_pImmediateContext->UpdateSubresource(_pConstantBuffer, 0, nullptr, &cb, 0, 0); //Copies the constant buffer to the shaders.
_pImmediateContext->DrawIndexed(96, 0, 0);

//Imported Pitch
world = XMLoadFloat4x4(&_pitch.GetWorld());
cb.mWorld = XMMatrixTranspose(world);
_pImmediateContext->UpdateSubresource(_pConstantBuffer, 0, nullptr, &cb, 0, 0); //Copies the constant buffer to the shaders.
//Draw the Pitch
_pitch.Draw(_pd3dDevice, _pImmediateContext);

_pImmediateContext->PSSetShaderResources(0, 1, &_pTextureMetalRV);
_pImmediateContext->PSSetShaderResources(1, 1, &_pSpecTextureMetalRV);
_pImmediateContext->PSSetShaderResources(2, 1, &_pNormTextureMetalRV);

我是否错过了一行代码来清除更改着色器之间的某些内容而不使用错误的数据?

1 个答案:

答案 0 :(得分:0)

对.fx文件进行小编辑是一个问题,我没有注意到。现在通过恢复该文件来修复。