Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

shaderFlatColor.geom 1.43 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1
2
3
4
5
6
7
8
// ShaderFlatColorPerFace::geometryShaderText
uniform float explode;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix;
uniform mat4 ModelViewMatrix;
uniform vec3 lightPosition;
uniform vec4 ambient;

Sylvain Thery's avatar
Sylvain Thery committed
9
VARYING_IN vec3 colorVertex[3]; // input is triangles -> 3
Sylvain Thery's avatar
Sylvain Thery committed
10
11
12
13
14
15
16
17
18
19
20
21
22
VARYING_OUT vec4 ColorFS;

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);
	N  =  normalize (vec3(NormalMatrix*vec4(N,0.0))); 
	vec3 center = POSITION_IN(0).xyz + POSITION_IN(1).xyz + POSITION_IN(2).xyz; 
	center /= 3.0;
	vec4 newPos =  ModelViewMatrix * vec4(center,0.0);
	vec3 L =  normalize (lightPosition - newPos.xyz);
	float lambertTerm = dot(N,L);
Sylvain Thery's avatar
Sylvain Thery committed
23
24

#ifdef AVERGAGE_COLOR		
Sylvain Thery's avatar
Sylvain Thery committed
25
	int i;
26
	vec3 averageColor=vec3(0.,0.,0.);
Sylvain Thery's avatar
Sylvain Thery committed
27
	for(i=0; i< 3; i++)
Sylvain Thery's avatar
Sylvain Thery committed
28
		averageColor +=colorVertex[i];
Sylvain Thery's avatar
Sylvain Thery committed
29
	averageColor /= 3.0;
Sylvain Thery's avatar
Sylvain Thery committed
30
31
32
33
34
	
	ColorFS = ambient;
	if(lambertTerm > 0.0)
		ColorFS += vec4(averageColor,1.0) * lambertTerm;
			
Sylvain Thery's avatar
Sylvain Thery committed
35
36
37
38
39
40
41
42
43
44
	for(i=0; i< 3; i++)
	{
		vec4 pos =  explode * POSITION_IN(i) + (1.0-explode)* vec4(center,1.0);
		gl_Position = ModelViewProjectionMatrix *  pos;	
		EmitVertex();
	}
	EndPrimitive();
#else
	int i;
	for(i=0; i< 3; i++)
Sylvain Thery's avatar
Sylvain Thery committed
45
46
	{
		vec4 pos =  explode * POSITION_IN(i) + (1.0-explode)* vec4(center,1.0);
Sylvain Thery's avatar
Sylvain Thery committed
47
48
49
		ColorFS = ambient;
		if(lambertTerm > 0.0)
			ColorFS += vec4(colorVertex[i],1.0) * lambertTerm;
Sylvain Thery's avatar
Sylvain Thery committed
50
51
52
53
		gl_Position = ModelViewProjectionMatrix *  pos;
		EmitVertex();
	}
	EndPrimitive();
Sylvain Thery's avatar
Sylvain Thery committed
54
55
#endif

Sylvain Thery's avatar
Sylvain Thery committed
56
}