shaderFlat.geom 854 Bytes
Newer Older
1 2 3 4 5 6 7
// ShaderFlat::geometryShaderText

uniform float explode;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ModelViewMatrix;
uniform vec3 lightPosition;
Sylvain Thery's avatar
Sylvain Thery committed
8 9
VARYING_OUT float lambertTerm;

10 11 12 13 14
void main(void)
{
	vec3 v1 = POSITION_IN(1).xyz - POSITION_IN(0).xyz;
	vec3 v2 = POSITION_IN(2).xyz - POSITION_IN(0).xyz;
	vec3 N  = cross(v1,v2);
Sylvain Thery's avatar
Sylvain Thery committed
15 16
	N  =  normalize(vec3(NormalMatrix*vec4(N,0.0)));

17 18
	vec3 center = POSITION_IN(0).xyz + POSITION_IN(1).xyz + POSITION_IN(2).xyz; 
	center /= 3.0;
19
	vec4 newPos =  ModelViewMatrix * vec4(center,1.0);
20
	vec3 L =  normalize (lightPosition - newPos.xyz);
Sylvain Thery's avatar
Sylvain Thery committed
21
	lambertTerm = clamp(dot(N,L),0.0,1.0);
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
22

23 24 25 26 27 28 29 30 31
	int i;
	for(i=0; i< NBVERTS_IN; i++)
	{
		vec4 pos =  explode * POSITION_IN(i) + (1.0-explode)* vec4(center,1.0);
		gl_Position = ModelViewProjectionMatrix *  pos;
		EmitVertex();
	}
	EndPrimitive();
}