We have a simple custom shader for drawing lines on a flat map. Each line layer has a different fixed Y value, so that it’ll appear “on top” of other layers (this is how we z-order). So we want to set the “Y” position value inside of a Uniform value.
The Uniform Value can be read just fine from the Pixel Shader, but from the Vertex Shader, it’s treated the value as “always default/zero”.
Here is our HLSL:
#include “Uniforms.hlsl”
#include “Transform.hlsl”
uniform float cYPos;
void VS(float4 iPos : POSITION,
out float4 oPos : OUTPOSITION)
{
iPos.y = cYPos; // <<<<<<<<<<<<<< THIS IS ALWAYS ZERO!!!
float4x3 modelMatrix = iModelMatrix;
float3 worldPos = GetWorldPos(modelMatrix);
oPos = GetClipPos(worldPos);
}
void PS(
out float4 oColor : OUTCOLOR0)
{
float color = 0.05 * cYPos; // <<<<<<<<<<<<< Here it reads YPos just fine
oColor = float4(color, color, color, 1.0);
}
==
We are using UrhoSharp, to set the Shader parameter as follows:
float yPos = 1f;
foreach (var layer in _lineLayers.Values)
{
layer.Material.SetShaderParameter("YPos", yPos);
yPos += 1f;
}
I have tried reading the YPos, and it is always Zero within the VertexShader, while works fine for the PixelShader.
The Urho Samples do not have any examples where a Vertex Shader accesses the Uniforms (that I can find), to prove that this works.
Help would be greatly appreciated here. Has anyone else gotten Vertex Shaders to access the Uniform values?