Page 1 of 1

[SOLVED] timer uniform in custom post processing shader

PostPosted: Tue Apr 03, 2018 3:42 pm
by hg82
Hey everybody,

I went out to add some nice post processing shaders to GzDoom. Right now I'm working on a vignette shader and I try to animate the vignette.
As far as I understand the wiki I should be able to use a timer uniform through just defining it at the top of my shader.

But the mentioned
Code: Select allExpand view
uniform float timer;
doesn't do anything. It seams to always be 0...

Is the timer not working for post processing shaders or am I missing something? Could someone please point me in the right direction?
I spent hours to get this working without results...

Any help is much appreciated.

Cheers
HG

Re: timer uniform in custom post processing shader

PostPosted: Tue Apr 03, 2018 6:01 pm
by Pixel Eater
In your Zscript file you'll need to add the line:

Code: Select allExpand view
Shader.SetUniform1f( p, "Shader Name", "timer", ( gametic + e.FracTic ) * 1 / 35 ) ;

I'm not good with terminology but it should go in the "event block?"

Re: timer uniform in custom post processing shader

PostPosted: Mon Apr 09, 2018 4:06 am
by hg82
Thanks Pixel Eater!

I could figure it out.

You need to have something like this in your ZSCRIPT lump:
Code: Select allExpand view
class ShaderTimer : EventHandler
{
   override void RenderOverlay(RenderEvent e)
   {
      // thanks to Pixel Eater from the ZDoom Forums!!!
      float timer = (gametic +  e.FracTic) * 1 / 35;
      // set timer uniforms for the shaders
      Shader.SetUniform1f(players[consoleplayer], "PostVignette", "timer", timer);
      Shader.SetUniform1f(players[consoleplayer], "PostNoise", "timer", timer);
   }
}


Then you need to add your event handler class in the "gameinfo" block inside your "mapinfo" lump
Code: Select allExpand view
gameinfo
{
   AddEventHandlers = "ShaderTimer"
}


Again: Thank you very much... Couldn't have figured it out without your help.

Re: [SOLVED] timer uniform in custom post processing shader

PostPosted: Wed Apr 11, 2018 4:03 pm
by Pixel Eater
I'm glad it worked despite my shoddy explanation :wink: