Jump to content

Rotating Shader Help


reepblue
 Share

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.

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

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.

  • Upvote 2

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

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.

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

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

  • Upvote 2

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

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.

  • Upvote 1

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...