[SOLVED] timer uniform in custom post processing shader

Ask about editing graphics, sounds, models, music, etc here!
Shaders (GLSL) and SNDINFO questions also go here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
User avatar
hg82
Posts: 13
Joined: Thu Mar 22, 2018 11:40 am

[SOLVED] timer uniform in custom post processing shader

Post 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 all

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
Last edited by hg82 on Mon Apr 09, 2018 3:06 am, edited 1 time in total.
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: timer uniform in custom post processing shader

Post by Pixel Eater »

In your Zscript file you'll need to add the line:

Code: Select all

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?"
User avatar
hg82
Posts: 13
Joined: Thu Mar 22, 2018 11:40 am

Re: timer uniform in custom post processing shader

Post by hg82 »

Thanks Pixel Eater!

I could figure it out.

You need to have something like this in your ZSCRIPT lump:

Code: Select all

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 all

gameinfo
{
	AddEventHandlers = "ShaderTimer"
}
Again: Thank you very much... Couldn't have figured it out without your help.
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

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

Post by Pixel Eater »

I'm glad it worked despite my shoddy explanation :wink:

Return to “Assets (and other stuff)”