Jump to content

[SOLVED]How to get Time and Resolution in shader?


photo

Recommended Posts

I am trying to use the uniform variable Time and viewport Resolution in fragment shader, something like the _Time & _ScreenParams in UNITY shader, iResolution & iGlobalTime in Shadertoy.com, What are the built-in variable for UNIGINE if they exit. If they don't exit, how to implement such variable? Anyone knows?

I appreciated for reading this post. THX

Link to comment

Actually I think Time is NOT available as some Unigine default  shader variable. Therefore just must extend some Unigine material and provide time as an additional parameter to your shader code.  

Link to comment

Hi Cinetec!

 

We don't have built-in uniform for time so you have to declare and modify it by yourself or you can define an expression parameter and use built-in "time" variable in that expression so it'll be filled automatically:

<parameter name="custom_time_uniform" type="expression">time</parameter>
  • Like 1
Link to comment

Thank you so much Unclebob, you are awesome! The problem has been solved by using your method, but to make it work, I must pass the built-in "time" variable inside a vec4. Something like:

 

<parameter name="custom_time_uniform" type="expression">vec4(time,0,0,0)</parameter>

Link to comment

yup exactly unclebob's suggestion is the solution, you basically get the time parameter of the system functions and straight pass it on a float, works for me... the vec4 or vec3 solution i use for the mouse input (used in some of these shaders), since there is not vec2 in unigine script... i would use also app width and height for resolution (????).... i have actually imported most of the fragment shaders and raymarchers from the glsl sandbox and shadertoy into Unigine....

since we are on the topic though i have noticed a significant drop on FPS between the same shaders from shadertoy and 'glsl hacker', when i import them into Unigine... the same shader could run in 60-70 fps and then drop down to 20-25 when importing them into Unigine... whould an explanation on that be possible...? (i do have in mind that all of these shaders are case studies and fun experiments and usually not at all optimised for performance, but still.....)..... 

Link to comment

Hey Marinos,

 

As Cinetec mentioned earlier, you can use s_viewport in order to get resolution information.

 

I need more information about how exactly you ported your shader from shadertoy into Unigine, because there are many reasons why your shader is not working as fast as it's working on shadertoy. For example, it could be rendered couple of times per frame if you set this shader for multiple passes in one material or there might be other post-process materials or the app resolution is different than on shadertoy.

  • Like 1
Link to comment

ok i will post more info really soon then... thanks unclebob..... :)

 

"the app resolution is different than on shadertoy", obviously this one is one i do have in mind.... i ll post info since there might be one of the other reasons you are mentioning....

Link to comment
×
×
  • Create New...