shaderExplodeVolumes.geom 1.23 KB
Newer Older
1 2
// ShaderExplodeVolumes::geometryShaderText
uniform float explodeV;
3
uniform float explodeF;
4 5 6 7
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ModelViewMatrix;
uniform vec3 lightPosition;
8

9
uniform vec4 ambient;
10
uniform vec4 backColor;
11
uniform vec4 plane;
12

13
VARYING_IN vec3 colorVertex[3];
14
VARYING_OUT vec4 ColorFS;
15

16

17 18
void main(void)
{
19
	float d = dot(plane,POSITION_IN(0));
20
	
Sylvain Thery's avatar
Sylvain Thery committed
21
	if (d<=0.0)
22
	{
23 24 25 26 27 28
		vec3 v1 = POSITION_IN(2).xyz - POSITION_IN(1).xyz;
		vec3 v2 = POSITION_IN(3).xyz - POSITION_IN(1).xyz;
		vec3 N  = cross(v1,v2);
		N  =  normalize (vec3(NormalMatrix*vec4(N,0.0))); 
		
	// compute face center & lighting informations
29
		vec4 newPos =  ModelViewMatrix * vec4(colorVertex[0],1.0);
30 31
		vec3 L =  normalize (lightPosition - newPos.xyz);
		float lambertTerm = dot(N,L);
32
	
33
		for (int i=1; i<=3; i++)
34
		{
35 36 37 38 39 40 41 42 43 44
			// explode in face
			vec4 P = explodeF * POSITION_IN(i)  + (1.0-explodeF)* vec4(colorVertex[0],1.0);

			// explode in volume
			vec4 Q = explodeV *  P + (1.0-explodeV)* POSITION_IN(0);
			gl_Position = ModelViewProjectionMatrix *  Q;
			if (lambertTerm > 0.0)
				ColorFS = ambient + vec4(colorVertex[i]*lambertTerm, 1.0);
			else
				ColorFS = ambient - backColor*lambertTerm;
45 46 47
			EmitVertex();
		}
		EndPrimitive();
48 49
	}
}