Game Development Reference
In-Depth Information
protected:
ID3D11PixelShader* m_pPixelShader;
ID3D11Buffer*
m_pcbPSMaterial;
std::string
m_textureResource;
};
The class definition is somewhat similar to the one you saw for the vertex shader, just
simpler. The differences include an additional ID3D11Buffer * member, since this
shader accepts two constant buffers: one for the material definition and the other for
lighting. It also defines the string used to grab the texture from the resource cache
and a Boolean that controls whether the lights are active. The constructor and
destructor are fairly trivial and similar to the vertex shader class:
GameCode4_Hlsl_PixelShader::GameCode4_Hlsl_PixelShader(
std::string textureResource)
{
m_textureResource = textureResource;
m_pPixelShader = NULL;
m_pcbPSMaterial = NULL;
}
GameCode4_Hlsl_PixelShader::~GameCode4_Hlsl_PixelShader()
{
SAFE_RELEASE(m_pPixelShader);
SAFE_RELEASE(m_pcbPSMaterial);
}
As before, the shader is set up and is very similar to the vertex shader, with the one
difference that there are two constant buffers to create:
HRESULT GameCode4_Hlsl_PixelShader::OnRestore(Scene *pScene)
{
HRESULT hr;
SAFE_RELEASE(m_pPixelShader);
SAFE_RELEASE(m_pcbPSMaterial);
//============================================================
// Set up the pixel shader and related constant buffers
ID3DBlob* pPixelShaderBuffer = NULL;
std::string hlslFileName =
Effects\\GameCode4_PS.hlsl
;
Resource resource(hlslFileName.c_str());
shared_ptr<ResHandle> pResourceHandle =
g_pApp->m_ResCache->GetHandle(&resource);
if ( FAILED (CompileShader(pResourceHandle->Buffer(),
Search WWH ::




Custom Search