- Home /
Question by
pyjamaslug · Mar 01, 2018 at 12:04 AM ·
scripting problemshaderscgreplacement shaderglobal variables
setGlobalFloat() doesn't initialise my shader parameters
I have a very simple shader that I am using as a replacement shader but I still want to pass some parameters into it. Since there is no material to access, I tried declaring some parameters in the shader and setting them globally. I actually do some other stuff in the fragment shader but even if I pare it down to what is here, I get a maximum value green pixel showing that the global has not been set by my script (and in fact the shader compiler complains that the output variable has not been fully initialised, either).
CGPROGRAM
//pragmas and includes snipped out
float _range;
//varyings structs snipped out
// vertex shader snipped out
fixed4 frag (v2f i) : SV_TARGET{
return fixed4 (0, 0, _range, 1);
}
ENDCG
there is no properties block, and I set the global parameter from the inspector using
public float range = 0.1f;
void update(){
Shader.setGlobalFloat("_range", range);
}
The code inspector shows the parameter showing up in the $global buffer but it never gets set to anything.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612153657im_/https://answers.unity.com/themes/thub/images/avi.jpg)