I know it is possible to access a float variable called, say “MyFloat” from a script by using material.SetFloat(). However, a Replaced shader is called without a material, so one is tempted to create a material with the Replaced shader, assign it in the inspector and then do something along these lines in the script that’s attached to the camera:
// C# Script excerpt:
public Material MyMaterial;
public float MyfloatVariable;
void OnPreCull() {
MyMaterial.SetFloat("_MyFloat", MyfloatVariable);
var cam = shaderCamera.camera;
cam.RenderWithShader (MyMaterial.shader, "");
}
// Displacement Shader Script excerpt
Properties {
_MyFloat ("MyFloater", float) = 1;
}
uniform float _Myfloat;
However, this doesn’t work. The variable is indeed changed on the material, but has no effect on the shader attached to the camera it seems. I have yet to find a way to access replacement shader variables from a C# script. Any help would be appreciated, because all my attempts so far have failed. Perhaps I’m missing something simple?
Here are some images at different times showing how the shader is affecting a bunch of spheres lying on a grid at y=0, as well as some other meshes. The colored inset is another camera that renders the scene without the shader replacement. The cylinder in the center of the spheres is supposed to be the source, but at the moment I cannot move the source via script, because I’m unable to access the cylinder’s position from within the replacement shader itself… The source position is hardcoded into the shader and is not connected to the cylinder’s transform.position. How can I access it dynamically from the C# script?