I have a problem wherein I'm trying to set two simple float variables in my shader. I have a dozen other shaders in this project where it works fine, but for some reason, I've got a bug in this one that I just can't spot.
Here's what I'm doing; I'll edit it down for brevity but try to stay complete. Any suggestions are very welcome!
First, I store the video width and height in the class that represents my shader, and then call functions that set the variables.
_hVideoWidth = _ptrEffect->GetParameterByName(0, "videoWidth");
_hVideoHeight = _ptrEffect->GetParameterByName(0, "videoHeight");
pShader->_videoWidth = pCameraManager->_backBufferWidth;
pShader->_videoHeight = pCameraManager->_backBufferHeight;
pShader->SetActive();
_ptrEffect->SetFloat(_hVideoWidth, _videoWidth);
_ptrEffect->SetFloat(_hVideoHeight, _videoHeight);
Then I do my drawing:
UINT cPasses;
pShader->GetEffect()->Begin(&cPasses, 0);
// Drawing code here
pShader->GetEffect()->End();
My shader will use the videoHeight/Width in order to scale it to the viewport. If I hardcode the width and height, it all works perfectly.
cbuffer VideoData : register(b0)
{
float videoWidth;
float videoHeight;
}
VertexShaderOutput UILineVertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
output.Position = input.Position;
// Convert pixel coords to (-1, +1)
output.Position.x = output.Position.x / videoWidth * 2.0f - 1.0f;
output.Position.y = output.Position.y / videoHeight * 2.0f - 1.0f;
output.Color = input.Color;
return output;
}
The mystery, however, is that at this point the shader has videoWidth and videoHeight still as zero. If I just hardcode those two expressions to 1280 and 1024 respectively, it works perfectly.
So, there's SOMETHING about the way I'm setting the videoWidth and videoHeight. I've confirmed that at the point I call SetFloat() they are in fact passing in the right values, but they just never seem to make it to the shader variables.
Any suggestions or anything obvious? Even a guess would help, I've been looking at this one for a while!
Thanks, Dave