Jump to content
reepblue

Rotating Shader Help

Recommended Posts

Tonight I've been looking for a way to rotate a texture 360 degrees from the center so I can use it on a model sheet. I've only found ex_texcoords0 which pans the texture on the face, but I can't seem to find any values or clues on how I would rotate the texture on the face. Any pointers in the right direction would be appreciated.

Share this post


Link to post

You can apply a 2x2 rotation matrix to the texcoords, something like this would rotate the texture :

 

		    float sinx = sin ( 0.0001 * currenttime );
	    float cosx = cos ( 0.0001 * currenttime );
	    float siny = sin ( 0.0001 * currenttime );
           mat2 rotmatrix =  mat2( cosx, -sinx, siny, cosx);
           vec2 rotuv = rotmatrix*ex_texcoords0;

 

Then use rotuv instead of ex_texcoords0 when you lookup the texture.

Share this post


Link to post

if you just need a fast 90 degree or 180 rotation, you can switch ex_texoords0.xy with yx and -xy -yx etc..

Share this post


Link to post

Thanks, now I just need to figure out how to make it spin from the center for the plane/texture than the front corner. I kind of want to do a spinning animation on my cubes in Vectronic.

 

Edit: No luck so far, I just keep getting effects that reminds me of the Giygas boss battle from EarthBound. I guess I still need help.

Share this post


Link to post

Like this :

 

 //find center
vec2 uv = (ex_texcoords0-0.5);

//rotate
float sinx = sin ( 0.001 * currenttime );
float cosx = cos ( 0.001 * currenttime );
float siny = sin ( 0.001 * currenttime );
mat2 rotmatrix = mat2( cosx, -sinx, siny, cosx);

//apply matrix and restore uv (0.5)
vec2 rotuv = rotmatrix*uv+0.5;

//fetch texture using new uv coordinates
outcolor *= texture(texture0,rotuv);

post-747-0-83439800-1437640370.jpg

Share this post


Link to post

How cool. This will suit my 'Click-To-Go' marker perfectly. Was just wondering how to solve that and here is a solution like sent from heaven. :)

Share this post


Link to post

Shadmar, you're a hero. Just a tip, make sure that the texture file is Clamped to X and Y to remove the duplicate textures you see in the corners while it's rotating. Now to test my idea with this. Thanks again.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...