[help] loop through array

Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
User avatar
zrrion the insect
Posts: 2397
Joined: Thu Jun 25, 2009 1:58 pm
Location: Time Station 1: Moon of Glendale

[help] loop through array

Post by zrrion the insect »

I have a shader:

Code: Select all

void main()
	vec3 colour = texture(InputTexture, TexCoord).rgb;
	vec3 cyan = vec3(0.0, 1.0, 1.0);
	vec3 rainbow[6] = {	vec3(0.93, 0.75, 0.60), vec3(1.00, 0.59, 0.23, vec3(0.97, 0.94, 0.30), vec3(0.75, 0.89, 0.30), vec3(0.72, 0.82, 0.93), vec3(0.92, 0.51, 0.90) };

	if (colour == cyan)	
		FragColor = vec4(rainbow[int(timer/35) % 6], 0.0);
		FragColor = vec4(colour, 1.0);
and in gldefs I have:

Code: Select all

HardwareShader PostProcess Screen
	Name "CyanShader"
	Shader "shaders/PostProcess/CYAN.fp" 330
	Uniform float timer
I am trying to get it to recolor all cyan on the screen to the colours in the array. Idealy it should switch colours after 6 tics.
Presently it will recolor cyan, but it does not cycle through the array. Could someone point me in the right direction?
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: [help] loop through array

Post by Pixel Eater »

Do you already have the timer being sent from ZScript? Something like:

Code: Select all

class "Your Event Handler" : EventHandler
   override void RenderOverlay( RenderEvent e )
      Shader.SetUniform1f( players[ consoleplayer ], "Your Shader Name", "timer", gametic + e.FracTic );
Edit: Actually if you're going by ticks you could possibly use 'override void WorldTick()' instead of the RenderOverlay() stuff and leave off '+ e.FracTic'.

Return to “Shaders”