Original Post
Hi guys,
I''m having a problem creating a pixel shader. The following code initializes a shader and returns it. I added the last 3 lines in to step through and see if I was getting valid handles to my constants. It is returning null for two of the samplers, and "0x0000001" for the other one, which in the debugger is flagged with a "" remark. Do I have to do something to register these samplers? Also some places I''ve read that one must declare the textures inside the shader and bind them to the samplers, but I''ve seen a lot of shaders which don''t do this. Is there something I''m missing here?
Here''s the initialization code...
HRESULT hrErr;
CPixelShader* tempShader = new CPixelShader();
LPD3DXBUFFER pCode, pErrors;
hrErr = D3DXCompileShaderFromFile(name.c_str(),NULL,NULL,"PShade","ps_2_0",0,&pCode,&pErrors,&tempShader->m_pPixelConstants);
if(FAILED(hrErr))
{
assert(false && "pixel shader creation failed");
}
hrErr = device->CreatePixelShader((DWORD*)pCode->GetBufferPointer(),&tempShader->m_pPixelShader);
if(FAILED(hrErr))
{
assert(false && "pixel shader creation failed");
}
pCode->Release();
if(rm)
{
rm->registerResource(tempShader, PIXEL_SHADER);
}
D3DXHANDLE handle;
handle = tempShader->m_pPixelConstants->GetConstantByName(NULL,"grassSampler");
handle = tempShader->m_pPixelConstants->GetConstantByName(NULL,"groundSampler");
handle = tempShader->m_pPixelConstants->GetConstantByName(NULL,"snowSampler");
return tempShader;
[source]
And here is the shader
[source]
struct VS_OUTPUT
{
float4 Pos : POSITION;
float2 Tex0 : TEXCOORD0;
float2 Tex1 : TEXCOORD1;
float2 Tex2 : TEXCOORD2;
};
sampler grassSampler;
sampler snowSampler;
sampler groundSampler;
struct PS_OUTPUT
{
float4 Color : COLOR;
};
////////////////////////////////////////
PS_OUTPUT PShade(VS_OUTPUT In)
{
PS_OUTPUT Out = (PS_OUTPUT) 0;
Out.Color = tex2D(groundSampler,In.Tex0); + tex2D(grassSampler,In.Tex1) + tex2D(snowSampler,In.Tex2);
return Out;
}