<jittershader name="rotation shader">
	<description>
	kaleidoscope
	</description>
	<param name="zoom" type="vec2" default="1. 1." />
	<param name="offset" type="vec2" default="0. 0." />
	<param name="theta" type="float" default="0." />
	<param name="anchor" type="vec2" default="0.5 0.5" />
	<param name="boundmode" type="int" default="0" />
	<param name="tex0" type="int" default="0" />
	<param name="tex1" type="int" default="1" />
	<language name="glsl" version="1.0">
		<bind param="zoom" program="fp" />
		<bind param="offset" program="fp" />
		<bind param="theta" program="fp" />
		<bind param="anchor" program="fp" />
		<bind param="boundmode" program="fp" />
		<bind param="tex0" program="fp" />
		<bind param="tex1" program="fp" />
		<program name="vp" type="vertex" source="sh.passthrudim.vp.glsl" />
		<program name="fp" type="fragment">
<![CDATA[

//setup for 2 texture
varying vec2 texcoord0;
varying vec2 texcoord1;
varying vec2 texdim0;
uniform vec2 zoom;
uniform vec2 offset;
uniform float theta; 
uniform vec2 anchor;
uniform int boundmode; 
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;
const float pi=3.1415926;

void main()
{
	// where is the point?
	vec2 sizea = texdim0;
	vec2 point = texcoord0;
	
	//transormation matrices
	mat2 sca = mat2 (1./zoom.x,0.,0.,1./zoom.y);//scaling matrix (zoom)
	mat2 rot = mat2 (cos(theta),sin(theta),-sin(theta),cos(theta));//rotation matrix

	//perform transform
	vec2 no = ((((point-anchor*sizea)*rot)*sca)+anchor*sizea)+offset;

	//create boundmodes
	vec2 no2 = mod(no,sizea);//wrap	
	
	vec2 no4 = mix(mod(no,sizea),sizea-mod(no,sizea),floor(mod(no,sizea*2.)/sizea));//folded coords
	
	// sampler coord
	vec2 tc = no*float(boundmode==0) + no*float(boundmode==1) + no2*float(boundmode==2) + no*float(boundmode==3) + no4*float(boundmode==4);
	
	
	//sample textures
	vec4 smp0 = texture2DRect(tex0,tc);
	vec4 smp1 = texture2DRect(tex1,texcoord0);
	
	vec2 outbound = sign(floor(no/sizea));//check for point>size
	float boundchk = float(sign(float(outbound.x!=0.)+float(outbound.y!=0.)));
	float checkm0 = float(boundmode==0)*boundchk;
	float checkm1 = float(boundmode==1)*float(boundchk==0.);
	vec4 ifb0 = mix(smp0,smp1,checkm0);//ignore
	vec4 final = ifb0*float(boundmode != 1) + ifb0*float(checkm1==1.);//clear
	
	
	// output texture
	gl_FragColor = final;
}
]]>
		</program>
	</language>
</jittershader>
