pointSprite.geom 1.73 KB
Newer Older
1
2
3
4
5
6
7
8
// PointSprite::geometryShaderText

uniform float size;
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
VARYING_OUT vec2 texCoord;
VARYING_OUT vec2 positionFragIn;
VARYING_OUT vec4 mvpFragIn;
9
10
11
12
13
14

#ifdef WITH_COLOR_PER_VERTEX 
	VARYING_IN vec3 color[1];
	VARYING_OUT vec3 colorsprite;
#endif

Sylvain's avatar
Sylvain committed
15
16
17
18
19
#ifdef WITH_PLANE
uniform vec3 planeX;
uniform vec3 planeY;
#endif

20
21
void main()
{
Sylvain's avatar
Sylvain committed
22
23
24
25
26

#ifdef WITH_COLOR_PER_VERTEX 
	colorsprite = color[0];
#endif

27
28
29
30
	mvpFragIn.x = ProjectionMatrix[2][2];
	mvpFragIn.y = ProjectionMatrix[3][2];
	mvpFragIn.z = ProjectionMatrix[2][3];
	mvpFragIn.w = ProjectionMatrix[3][3];
Sylvain's avatar
Sylvain committed
31
32
33
	
	vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
	positionFragIn = posCenter.zw;
34

Sylvain's avatar
Sylvain committed
35
36
	texCoord = vec2(0.0,1.0);
	#ifdef WITH_PLANE
37
		vec4 pos = posCenter - size*vec4(planeX,0.0) + size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
Sylvain's avatar
Sylvain committed
38
	#else
39
		vec4 pos = posCenter + vec4(-size, size, 0.0, 0.0);
Sylvain's avatar
Sylvain committed
40
	#endif	
41
42
	gl_Position = ProjectionMatrix *  pos;
	EmitVertex();
Sylvain's avatar
Sylvain committed
43
44

	#ifdef WITH_PLANE
45
		pos = posCenter - size*vec4(planeX,0.0) - size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
Sylvain's avatar
Sylvain committed
46
	#else
47
		pos = posCenter + vec4(-size, -size, 0.0, 0.0);
Sylvain's avatar
Sylvain committed
48
	#endif	
49
50
51
	texCoord = vec2(0.0,0.0);
	gl_Position = ProjectionMatrix *  pos;
	EmitVertex();
Sylvain's avatar
Sylvain committed
52
53

	#ifdef WITH_PLANE
54
		pos = posCenter + size*vec4(planeX,0.0) + size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
Sylvain's avatar
Sylvain committed
55
	#else
56
		pos = posCenter + vec4(size, size, 0.0, 0.0);
Sylvain's avatar
Sylvain committed
57
	#endif	
58
59
60
	texCoord = vec2(1.0,1.0);
	gl_Position = ProjectionMatrix *  pos;
	EmitVertex();
Sylvain's avatar
Sylvain committed
61
62

	#ifdef WITH_PLANE
63
		pos = posCenter + size*vec4(planeX,0.0) - size*vec4(planeY,0.0) + size*vec4(0.0,0.0,0.5,0.0);
Sylvain's avatar
Sylvain committed
64
	#else
65
		pos = posCenter + vec4(size, -size, 0.0, 0.0);
Sylvain's avatar
Sylvain committed
66
	#endif	
67
68
69
70
71
	texCoord = vec2(1.0,0.0);
	gl_Position = ProjectionMatrix *  pos;
	EmitVertex();
	EndPrimitive();
}