summaryrefslogtreecommitdiffstats
path: root/Studio/Content/Effect Library/Distortion Spiral.effect
blob: a5a9697188a3735e08a4e063765fde2ee33f13b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?xml version="1.0" encoding="UTF-8" ?>
<Effect>
	<MetaData>
		<!--Distorts the image in a spiraling way.-->
		<Property name="radius" formalName="Radius" min="0" max="1" 	default=".3" 		description="Adjusts the distorted area."/>
		<Property name="spiral" formalName="Spiral" min="-10" max="10" 	default="1.0" 		description="Adjusts the spiraling amount."/>
		<Property name="center" formalName="Center" type="Float2" 		default="0.5 0.5"	description="Adjusts the focus point of the distortion."/>
	</MetaData>
	<Shaders>
		<Shared>
varying vec2 center_vec;
float PI2 = radians(360.0);
		</Shared>
		<Shader>
			<VertexShader>
void vert ()
{
  center_vec = TexCoord - center;
  //Multiply by x/y ratio so we see a sphere on the screen
  //instead of an ellipse.
  center_vec.y *= Texture0Info.y / Texture0Info.x;
}
			</VertexShader>
			<FragmentShader>
<![CDATA[
void frag()
{
    float dist_to_center = length(center_vec) / radius;;
	
    vec2 texc;
    if(dist_to_center > 1.0) {
        texc = TexCoord;
    } else {
        float rotation_amount = (1.0 - dist_to_center) * (1.0 - dist_to_center);
        float r = PI2 * rotation_amount * spiral / 4.0;
        float cos_r = cos(r);
        float sin_r = sin(r);
        mat2 rotation = mat2(cos_r, sin_r, -sin_r, cos_r);
        texc = center + rotation * (TexCoord - center);
    }

  if ( texc.x < 0.0 || texc.x > 1.0 || texc.y < 0.0 || texc.y > 1.0 )
    gl_FragColor = vec4(0.0);
  else
    colorOutput(texture2D_0(texc));
}
]]>
			</FragmentShader>
		</Shader>
	</Shaders>
</Effect>