- Home /
Allow shaders with 'time' variable to update in editor
Hi all,
I am have a shader that uses the _Time unity passed in value and I would like to see this material change and update in the editor (for example I might have a water texture and want to change settings without running the game to examine the changes).
I have tried attaching a script to the gameobject with the [ExecuteInEditMode] flag. but this only calls that script, it does not tick the shader time.
I have looked in the shader settings but could not find a way to do this.
I have also tried setting the global time variable like so:
var time = (float)EditorApplication.timeSinceStartup;
Vector4 vTime = new Vector4( time / 20, time, time*2, time*3);
Shader.SetGlobalVector( "_Time", vTime );
and also setting it straight in shader, but it can not be found:
if( editorMaterial.HasProperty( "_Time" ) )
{
Debug.Log( "has time" ); //This is never printed
}
Has anyone done this before? It seems like it should be something quite simple that I am missing.
Answer by Bristar · Oct 11, 2011 at 08:43 PM
Instead of setting time to shader, create new parameter (like _Phase("_Phase", Float) = 0
). And then set time value directly to this parameter.
var time = Application.isEditor?(float)EditorApplication.timeSinceStartup:Time.time;
Shader.SetFloat("_Phase", time );
or
var time = Application.isEditor?(float)EditorApplication.timeSinceStartup:Time.time;
Vector4 vTime = new Vector4( time / 20, time, time*2, time*3);
Shader.SetVector("_Phase", time );
This may help.
http://forum.unity3d.com/threads/61653-Get-_Time-from-shader-for-script
I agreed with @Ev_genus, define your own timervalue may be a better way.
Your answer
Follow this Question
Related Questions
How to change editor highlighting behavior? 0 Answers
Shader works in Editor Mode, breaks when running. 2 Answers
Editor Script, Index Out of Range Exception after Play 1 Answer
Failed to initialize unity graphics - dxdiag is fine and opengl fails 1 Answer
Do I need to use SetDirty in my editors if I'm using SerializedProperties? 1 Answer