DirectX11 With Windows SDK--13 动手实现一个简易Effects框架、阴影效果绘制 (5)

BasicEffect::SetRenderDefault方法使用了默认的3D像素着色器和顶点着色器,并且其余各状态都保留使用默认状态:

void BasicEffect::SetRenderDefault(ID3D11DeviceContext * deviceContext) { deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); deviceContext->IASetInputLayout(pImpl->m_pVertexLayout3D.Get()); deviceContext->VSSetShader(pImpl->m_pVertexShader3D.Get(), nullptr, 0); deviceContext->RSSetState(nullptr); deviceContext->PSSetShader(pImpl->m_pPixelShader3D.Get(), nullptr, 0); deviceContext->PSSetSamplers(0, 1, RenderStates::SSLinearWrap.GetAddressOf()); deviceContext->OMSetDepthStencilState(nullptr, 0); deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFFF); } BasicEffect::SetRenderAlphaBlend方法--Alpha透明混合渲染

该绘制模式关闭了光栅化裁剪,并采用透明混合方式。

void BasicEffect::SetRenderAlphaBlend(ID3D11DeviceContext * deviceContext) { deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); deviceContext->IASetInputLayout(pImpl->m_pVertexLayout3D.Get()); deviceContext->VSSetShader(pImpl->m_pVertexShader3D.Get(), nullptr, 0); deviceContext->RSSetState(RenderStates::RSNoCull.Get()); deviceContext->PSSetShader(pImpl->m_pPixelShader3D.Get(), nullptr, 0); deviceContext->PSSetSamplers(0, 1, RenderStates::SSLinearWrap.GetAddressOf()); deviceContext->OMSetDepthStencilState(nullptr, 0); deviceContext->OMSetBlendState(RenderStates::BSTransparent.Get(), nullptr, 0xFFFFFFFF); } BasicEffect::SetRenderNoDoubleBlend方法--无重复混合(单次混合)

该绘制模式用于绘制阴影,防止过度混合。需要指定绘制区域的模板值。

void BasicEffect::SetRenderNoDoubleBlend(ID3D11DeviceContext * deviceContext, UINT stencilRef) { deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); deviceContext->IASetInputLayout(pImpl->m_pVertexLayout3D.Get()); deviceContext->VSSetShader(pImpl->m_pVertexShader3D.Get(), nullptr, 0); deviceContext->RSSetState(RenderStates::RSNoCull.Get()); deviceContext->PSSetShader(pImpl->m_pPixelShader3D.Get(), nullptr, 0); deviceContext->PSSetSamplers(0, 1, RenderStates::SSLinearWrap.GetAddressOf()); deviceContext->OMSetDepthStencilState(RenderStates::DSSNoDoubleBlend.Get(), stencilRef); deviceContext->OMSetBlendState(RenderStates::BSTransparent.Get(), nullptr, 0xFFFFFFFF); } BasicEffect::SetWriteStencilOnly方法--仅写入模板值

该模式用于向模板缓冲区写入用户指定的模板值,并且不写入到深度缓冲区和后备缓冲区。

void BasicEffect::SetWriteStencilOnly(ID3D11DeviceContext * deviceContext, UINT stencilRef) { deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); deviceContext->IASetInputLayout(pImpl->m_pVertexLayout3D.Get()); deviceContext->VSSetShader(pImpl->m_pVertexShader3D.Get(), nullptr, 0); deviceContext->RSSetState(nullptr); deviceContext->PSSetShader(pImpl->m_pPixelShader3D.Get(), nullptr, 0); deviceContext->PSSetSamplers(0, 1, RenderStates::SSLinearWrap.GetAddressOf()); deviceContext->OMSetDepthStencilState(RenderStates::DSSWriteStencil.Get(), stencilRef); deviceContext->OMSetBlendState(RenderStates::BSNoColorWrite.Get(), nullptr, 0xFFFFFFFF); } BasicEffect::SetRenderDefaultWithStencil方法--对指定模板值区域进行常规绘制

该模式下,仅对模板缓冲区的模板值和用户指定的相等的区域进行常规绘制。

void BasicEffect::SetRenderDefaultWithStencil(ID3D11DeviceContext * deviceContext, UINT stencilRef) { deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); deviceContext->IASetInputLayout(pImpl->m_pVertexLayout3D.Get()); deviceContext->VSSetShader(pImpl->m_pVertexShader3D.Get(), nullptr, 0); deviceContext->RSSetState(RenderStates::RSCullClockWise.Get()); deviceContext->PSSetShader(pImpl->m_pPixelShader3D.Get(), nullptr, 0); deviceContext->PSSetSamplers(0, 1, RenderStates::SSLinearWrap.GetAddressOf()); deviceContext->OMSetDepthStencilState(RenderStates::DSSDrawWithStencil.Get(), stencilRef); deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFFF); } BasicEffect::SetRenderAlphaBlendWithStencil方法--对指定模板值区域进行Alpha透明混合绘制

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzjgjd.html