Examples Please

I have been watching the Unite 2016 Shader Course and a few others online but I’m guessing few really get to this level because there are a lot of obscure references.
New to Shaders but I’m catching on pretty quick.
So I’m playing with the basic water shader in the standard assets. Which is perfect for what I’m trying to do. For reference…

In the above image I want to modify the code to have a day and night time reflective color but there are no examples that ive seen YET to modify these colors based on my gametime script.

I played around with the code to set up (2) reflective colors.


To get this

I want to SWITCH between these 2 colors based on my game time and I have not seen any good examples yet. But putting this into search parameters have left me on a witch hunt most not even pertaining to Unity which is why it seems not many users get to this level. It doesn’t seem hard but I cant really move forward without primers and good examples.

Here is an example of my test scene and what I mean by time. Just in case that needs explaining.

One is a shader file and I need to know how to either manipulate it through C# script or create resources that can be accessed by the shader through the C# script file.

The advanced WaterShader sort of gets into this but there is a lot of unused code and other parameters not even used. I can follow it… but it might be faster to just ask here.

Thanks in advance




I found a work around changing the material of the object but Id be really interested if I could change it in code versus (2) prefabs
Just dabbling and having fun later all

You just need to set the values directly on the material: Unity - Scripting API: Material

Look at the material.SetXXX() methods.

1 Like

There are many ways to do it. The simplest would be to use two materials and swap between them. You can either have two objects you swap between or you can swap the renderer component’s shared material from script.

However if what you really want is to blend from one to the other smoothly rather than swap instantly from one to the other, you’ll need to add a float parameter to the shader that lerps between the two textures and then set that value on the material.

Or you can set it globally.

In the shader you’ll want to do something like this.

// Properties
_NightToDay (“Night to Day”, Range(0, 1)) = 1 // 0 = night, 1 = day

// In the CGPROGRAM block, but outside of a function
float _NightToDay;

// In the frag function
fixed4 controlA = tex2D(_ColorControlA, uv); // day
fixed4 controlB = tex2D(_ColorControlB, uv); // night
fixed4 control = lerp(controlB, controlA, _NightToDay); // lerp between night and day colors

2 Likes