I’m a total beginner to HLSL and have got some sample code that renders a flat triangle. If I try to replace the PShader function from one that returns an explicit color to one that references a global variable (mycol) below, then it no longer renders the triangle in color but in black.
float4 mycol = float4(1.0f, 1.0f, 0.0f, 1.0f);
float4 VShader(float4 position : POSITION) : SV_POSITION
{
return position;
}
float4 PShader(float4 position : SV_POSITION) : SV_Target
{
return mycol; // float4(1.0f, 0.0f, 1.0f, 1.0f);
}
I’ve tried reading the HLSL specs but feel I’m probably missing something obvious?
any help appreciated,
GMan
I believe you can only pass global values using constant buffers in directx. You need to initiate the constant buffer in the c++ code:
Then in your rendering code:
and in your shader: