 1. ## Squeeze & Rotation Shaders

These are three shaders I've created that anyone is free to use for any purposes, no credit needed at all.

#1: PT_Rotate
This is a simple 'optimized' edited versions of Sphax's rotation pixel shader. It uses a sin/cos pseudo matrix instead of polar coordinates, which makes it run much faster- I use it on a 512x512 image at 50 FPS as a core part of one of my games, and the original rotate shader was not efficient enough.

Parameters:
fAngle: The angle, in degrees, by which the image is rotated counter-clockwise.

Code:
```// Pixel shader input structure
struct PS_INPUT
{
float4 Position   : POSITION;
float2 Texture    : TEXCOORD0;
};

struct PS_OUTPUT
{
float4 Color   : COLOR0;
};

// Global variables
sampler2D Tex0;

float fAngle, Temp, Tcos, Tsin;

PS_OUTPUT ps_main( in PS_INPUT In )
{
// Output pixel
PS_OUTPUT Out;
In.Texture.x = In.Texture.x-0.5;
In.Texture.y = In.Texture.y-0.5;
Tcos = cos(fAngle);
Tsin = sin(fAngle);
Temp = In.Texture.x * Tcos - In.Texture.y * Tsin + 0.5;
In.Texture.y = In.Texture.y * Tcos + In.Texture.x * Tsin + 0.5;
In.Texture.x = Temp;
Out.Color = tex2D(Tex0, In.Texture.xy);

return Out;
}

// Effect technique
technique tech_main
{
pass P0
{
}
}```
#2: Squeeze
This creates a 'black hole' effect, pulling all pixels in towards the center of the object, as pictured below. Optionally can have a little rotation around the center as it pulls inwards.

Parameters:
fCoeff: Float, given from 0.0 to 1.0, which determines how much to squeeze an image inwards. At 1.0, there will be no distortion. At 0.0, the particles are infinitely squeezed inwards from the edges. For smooth transitions, values should decreased logarithmically (1.0 -> 0.5 -> 0.25 -> 0.125)
fAngle: Angle, in degrees, which determines how much to rotate an image inwards as it approaches the center. The amount of rotations increases direction with this value; 360 =/= 0. Each 360 degrees will cause one full spiral

Code:
```// Pixel shader input structure
struct PS_INPUT
{
float4 Position   : POSITION;
float2 Texture    : TEXCOORD0;
};

struct PS_OUTPUT
{
float4 Color   : COLOR0;
};

// Global variables
sampler2D Tex0;
float fCoeff, fAngle, Angle, Dist;

PS_OUTPUT ps_main( in PS_INPUT In )
{
// Output pixel
PS_OUTPUT Out;
Dist = distance(In.Texture.xy, float2(0.5,0.5)) * 2;
if (Dist < 1.0){
Angle = atan2(In.Texture.y - 0.5, In.Texture.x - 0.5) + pow(1 - Dist,2) * fAngle;
Dist = (pow(Dist,fCoeff)) / 2;
In.Texture.x = cos(Angle) * Dist + 0.5;
In.Texture.y = sin(Angle) * Dist + 0.5;
}
Out.Color = tex2D(Tex0, In.Texture.xy);

return Out;
}

// Effect technique
technique tech_main
{
pass P0
{
}
}``` #3: Squeeze Filter
This is the same as the above, except works as a filter on the background instead of on an object- an object using this will use its X/Y bounds to create an ellipsoidal (circle) transformation of the background. You can overlay your black hole on top of the screen, as pictured:

Parameters:
fCoeff: Float, given from 0.0 to 1.0, which determines how much to squeeze an image inwards. At 1.0, there will be no distortion. At 0.0, the particles are infinitely squeezed inwards from the edges. For smooth transitions, values should decreased logarithmically (1.0 -> 0.5 -> 0.25 -> 0.125)
fAngle: Angle, in degrees, which determines how much to rotate an image inwards as it approaches the center. The amount of rotations increases direction with this value; 360 =/= 0. Each 360 degrees will cause one full spiral

Code:
```sampler2D bg : register(s1);
float fCoeff, fAngle, Angle, Dist;

float4 ps_main(in float2 In : TEXCOORD0) : COLOR0
{
Dist = distance(In.xy, float2(0.5,0.5)) * 2;
if (Dist < 1.0){
Angle = atan2(In.y - 0.5, In.x - 0.5) + pow(1 - Dist,2) * fAngle;
Dist = (pow(Dist,fCoeff)) / 2;
In.x = cos(Angle) * Dist + 0.5;
In.y = sin(Angle) * Dist + 0.5;
}
return tex2D(bg,In.xy);
}

technique tech_main { pass P0 { PixelShader  = compile ps_2_0 ps_main(); }}```  #### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•