Shader.SetGlobal* only works for last uniform per type

Hi,

I added a '.hlsl’ file with some common functions. I also wanted to get some global parameters in there to later set them with Shader.SetGlobal method calls.

HLSL globals:

uniform float _gWaterPlaneY = 405.9467;
uniform float _gFogDistance = 4;
uniform float _gDirectSunlightMaxDepth = 160;
uniform float3 _gTurbidityColor = float3(0.0999, 0.203, 0.22);
uniform float3 _gAbsorptionColor = float3(1, 0.8, 0.7);

C# Update code:

        private static readonly int WaterPlaneY = Shader.PropertyToID("_gWaterPlaneY");
        private static readonly int DirectSunlightMaxDepth = Shader.PropertyToID("_gDirectSunlightMaxDepth");
        private static readonly int FogDistance = Shader.PropertyToID("_gFogDistance");
        private static readonly int TurbidityColor = Shader.PropertyToID("_gTurbidityColor");
        private static readonly int AbsorptionColor = Shader.PropertyToID("_gAbsorptionColor");

            Shader.SetGlobalFloat(WaterPlaneY, _waterPlaneY);
            Shader.SetGlobalFloat(DirectSunlightMaxDepth, _directSunlightMaxDepth);
            Shader.SetGlobalFloat(FogDistance, _fogDistance);
            Shader.SetGlobalColor(TurbidityColor, _turbidityColor);
            Shader.SetGlobalColor(AbsorptionColor, _absorptionColor);

However, only last ‘float’ parameter works, same applies with ‘float3’ params.

When I simply switch last two float params in HLSL code, then again, the last one works while the previous one that used to be the first and was working, stops working.

What the heck? :smile:

Hi!
Do you have these properties declared in your shader?

No I don’t. What I did is that I moved HDRP package to my packages folder and removed @version_number from the HDRP package folder name.
I wanted to modify how directional lights are calculated (I did that in LightEvaluation.hlsl). That works, but for the love of me, I can’t change the parameter values (I added the problematic parameters into the same hlsl file).

When I played with it more yesterday, I managed to get almost all parameters to work. Without changing the code really. It is so weird. Just by rebuilding a few times. I have introduced all the parameters at the same time and none of them collide with any other globals (by having the same name). There is some weird issue. I will investigate further.