Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

pointSprite.frag 1.12 KB
Newer Older
1
// PointSprite::fragmentShaderText
2

3
4
5
uniform mat4 ProjectionMatrix;
uniform vec3 lightPos;
uniform vec3 ambiant;
6
uniform float size;
7
8
9
10
#ifdef WITH_PLANE
	VARYING_FRAG vec3 eyePosFrag;
#endif

11
12
13
14
15
16
17
18

#ifdef WITH_COLOR_PER_VERTEX 
	VARYING_FRAG vec3 colorsprite;
#else
	uniform vec3 colorsprite;
#endif


19
VARYING_FRAG vec2 texCoord;
20
21
VARYING_FRAG vec3 sphereCenter;

22
23
void main(void)
{
24
25
26
27
28
	vec3 billboard_frag_pos = sphereCenter + vec3(texCoord, 0.0) * size;
#ifdef WITH_PLANE
	vec3 ray_direction = normalize(billboard_frag_pos - eyePosFrag;);
#else
	vec3 ray_direction = normalize(billboard_frag_pos);
29
#endif
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
	float TD = -dot(ray_direction,sphereCenter);
	float c = dot(sphereCenter, sphereCenter) - size * size;
	float arg = TD * TD - c;
      
	if (arg < 0.0)
		discard;
  
	float t = -c / (TD - sqrt(arg));
	vec3 frag_position_eye = ray_direction * t;
	vec4 pos = ProjectionMatrix * vec4(frag_position_eye, 1.0);
	gl_FragDepth = (pos.z / pos.w + 1.0) / 2.0;

	vec3 N = normalize(frag_position_eye - sphereCenter);
	vec3 L = normalize (lightPos - frag_position_eye);
	float lambertTerm = dot(N,L);
	
	gl_FragColor = vec4(colorsprite*lambertTerm + ambiant ,1.0);
47
}