An example of rotating a texture 0-360 degrees in a pixelshader.

Just playing around mainly, but planning to use it to some extent in a different shader.

Maybe it will be useful to somebody.

Texture Rotation in Pixelshader



Code:
BMAP* tex = "stone.tga";

MATERIAL* mtlEffect = 


{

skin1 = tex;
	
effect = " 

//-------------------------------------
// non-tweakables
//-------------------------------------
float4x4 	matWorldViewProj;


//-------------------------------------
// tweakables
//-------------------------------------
float vecSkill1; // pass angle in degrees

//-------------------------------------
// textures
//-------------------------------------

texture mtlSkin1;
sampler sTex = sampler_state
{
   Texture = <mtlSkin1>;
   MinFilter = Linear;
   MagFilter = Linear;
   MipFilter = Linear;   
   AddressU  = wrap;  
   AddressV  = wrap;  
};


//-------------------------------------
// structs 
//-------------------------------------
struct VS_INPUT
{
    float4 Position		: 	POSITION;
    float2 TexCoord0 	: 	TEXCOORD0;
};

struct VS_OUTPUT
{
    float4 PosWorld		: POSITION;    
    float2 TexCoord0		: TEXCOORD0;    
   
};

// ----------------------------------------------------------------
//  vertexshader 
// ----------------------------------------------------------------
VS_OUTPUT vs_main( VS_INPUT In ) 
{
    VS_OUTPUT Out;

    float4 Position = mul(In.Position,  matWorldViewProj);
    Out.PosWorld = Position;
    Out.TexCoord0 =  In.TexCoord0.xy;
        
    return Out;
}



// ----------------------------------------------------------------
//  pixelshader 
// ----------------------------------------------------------------
float4 ps_main(VS_OUTPUT In) : COLOR
{
    
    float s = sin(radians(vecSkill1.x)); // input in degrees
    float c = cos(radians(vecSkill1.x));
    
    float2x2 rotMatrix = float2x2(c,-s,s,c);
    
    float2 rotated_tex = In.TexCoord0 -=0.5;
    rotated_tex = mul(In.TexCoord0.xy ,rotMatrix);
    rotated_tex += 0.5;
       
    float4 oTexture = tex2D(sTex, rotated_tex * 2 ); 
       
    return oTexture;
   
}


// ----------------------------------------------------------------
//  Technique
// ----------------------------------------------------------------
Technique tech1 
{
    Pass One
      {
      	vertexshader = compile vs_2_0 vs_main();
         pixelshader = compile ps_2_0 ps_main();
      }

     
}


";

}

action mtl_texrot () {
	
	my.material = mtlEffect;
   
}