Hello, I just wanted to try a shader that updates according the time. In The Book of Shaders something called u_time is used, but in Defold such a variable won’t work. Following the book, I wrote at the beginning part of the code:
uniform float u_time;
And I got the following warning:
WARNING:RENDER: Type for uniform u_time is not supported (6)
Perhaps a little silly - but why did this happen? How can I import some variable telling the running time (and the cursor position, and so on)? Do I need to firstly add a “Fragment Constant” in the material editing interface, and use a Lua script to get the time and transport it to that “constant”?
Besides, since it’s a shader inside Defold there’re definitely specific usages, but I can’t find out where to learn such things systematically. Are there some recommended tutorials and documents?
CONSTANT_TYPE_USER
A vector4 constant that you can use for any custom data you want to pass into your shader programs. You can set the initial value of the constant in the constant definition, but it is mutable through the functions [go.set()](https://defold.com/ref/stable/go/#go.set) / [go.animate()](https://defold.com/ref/stable/go/#go.animate). You can also retrieve the value with [go.get()](https://defold.com/ref/stable/go/#go.get). Changing a material constant of a single component instance [breaks render batching and will result in additional draw calls](https://defold.com/manuals/render/#draw-calls-and-batching).
Example: ```lua go.set(“#sprite”, “tint”, vmath.vector4(1,0,0,1))
Uniforms in Defold can only be described as vectors of 4 elements, as Matthias mentioned above. This means, if you want to pass something that represents time you will need to add such value in 1 of the 4 places in the vector, for example:
local time = vmath.vector4(0)
function update(self, dt)
time.x = time.x + 1
go.set("#sprite", "u_time", time)
end
This plus assumgin you hav the uniform set properly in your material should allow you to have a increasing with every update time value in your fragment program
You can check out “blink_effect_trigger” uniform rm setup in my tutorial
Regarding the differences between shaders - what are your impressions up to now and what could be your expectations from a tutorial that could fill the gap?
Guys thanks a lot! In fact I knew how the uniform work (although I ignored the type problem), I just wanted to ask whether people get time information inside the shader program or by using uniforms. Seems like the latter is the right way! (Also, thank you for the tutorials)
Time should be increased by frame’s dt for the effect to look fitted to the updating frames, so yes, I think it is the best to increase it via a uniform
Also, depending on your setup, you could either increase it in some game object’s script’s update function (for example for individual sprites) or in render script’s update function (for example for drawing textures on quads)