Shader Code {1}: es.planesphere.vp.glsl
Description: Patch and vertex shader for 
mixing between a round sphere and a 4x3 plane;
a fast fragment shader to texture the shapes to boot.


// shader es.planesphere.vp.glsl code (())_n

varying vec4 V;
varying vec3 N;
varying vec3 P;
varying vec2 texcoord0;
varying vec2 texdim0;


#define PI 3.141519

uniform float shape;
uniform float delta;

vec3 surface(vec2 point)
{	
	vec2 p; // plane
	p.x = (point.x - 0.5) * 2.;
	p.y = (point.y - 0.5) * -2.;
	vec3 s_point;
	s_point.x = p.x * 1.33;
	s_point.y = p.y;
	s_point.z = 0.;

	vec2 pp; // sphere
	pp.x = (point.x-1.) * -2. * PI;
	pp.y = point.y * PI;
	float acc = sin(pp.y);
	vec3 t_point;
	t_point.x = cos(pp.x-1.57074)*acc;
	t_point.z = sin(pp.x-1.57074)*acc;
	t_point.y = cos(pp.y);

	s_point = mix(s_point,t_point,shape);
	return s_point;
}


void main (void)
{
	vec4 W = vec4( surface(gl_Vertex.xy), 1.);
	
	vec3 neighbour1 = surface(vec2(gl_Vertex.x + delta, gl_Vertex.y));
	vec3 neighbour2 = surface(vec2(gl_Vertex.x, gl_Vertex.y + delta));
	
	vec3 tangent = normalize(neighbour1 - W.xyz);
	vec3 bitangent = normalize(neighbour2 - W.xyz);

	//get the normals into eye space
	N = normalize( cross(tangent, bitangent) );
	N = mat3(	gl_ModelViewMatrixInverseTranspose[0].xyz, 
				gl_ModelViewMatrixInverseTranspose[1].xyz,
				gl_ModelViewMatrixInverseTranspose[2].xyz)*N;

	V = vec4(gl_Vertex.xy, 1., 1.);

	texdim0 = vec2 (abs(gl_TextureMatrix[0][0][0]),abs(gl_TextureMatrix[0][1][1]));
    texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);

	gl_Position = gl_ModelViewProjectionMatrix*W;
}


// shader es.direct.fp.glsl code (())_n varying vec2 texcoord0; varying vec2 texdim0; uniform sampler2DRect tex0; varying vec4 V; uniform vec4 alpha; void main (void) { vec2 mapcoord = V.xy*texdim0; vec4 color = texture2DRect(tex0, mapcoord) * alpha; gl_FragColor = color; }