Page 1 of 1

[Shader] interactive sprite rotation

Posted: Fri Nov 18, 2016 10:28 am
by kodi
This is a silly trick where the alpha channel of a sprite, texture, hudmessage-printed graphic or anything else is hijacked as an argument for rotation. This means you can make smoothly turning clocks, compasses, rolling cacodemons etc.

Credits: based on the static rotation shader found in a beta of WolfenDoom: Blade of Agony. Edit: No longer applies.
Note: Does not work in GZDoom's GL renderer.

GLDEFS:

Code: Select all

hardwareshader [texture/sprite/graphic] SomeTextureNameHere
{
shader arot.txt
}
arot.txt:

Code: Select all

uniform float timer;
 
vec4 Process(vec4 color)
{
vec2 tex_coord = gl_TexCoord[0].st;
	

	float angle = color.a*6.283; // turns to radians :^)
	float x = tex_coord.x;
	float y = tex_coord.y;


    float output_x = cos(angle) * (x-0.5) - sin(angle) * (y-0.5) +0.5 ; 
    float output_y = sin(angle) * (x-0.5) + cos(angle) * (y-0.5) +0.5;
    
	color.a = 1.0;
	return getTexel(vec2(output_x, output_y)) * color;
}

Re: [Shader] interactive sprite rotation

Posted: Fri Nov 18, 2016 6:38 pm
by Ænima
Will use, thanks!

(will credit you and wolfendoom)

Re: [Shader] interactive sprite rotation

Posted: Sat Nov 19, 2016 8:43 am
by Tormentor667
Would have been cool if you asked for permisson though before using it

Re: [Shader] interactive sprite rotation

Posted: Sat Nov 19, 2016 10:40 am
by kodi
Terribly sorry torm - I sometimes forget other people don't have as careless an attitude to their own code as I do. I rewrote the entire shader in the OP from scratch out of courtesy, using a different method but producing identical results.