pointSprite.geom 1.6 KB
Newer Older
1 2 3 4 5
// PointSprite::geometryShaderText

uniform float size;
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
6 7 8
uniform vec4 planeClip;

VARYING_IN vec3 posClip[1];
9

10
#ifdef WITH_PLANE
11 12
uniform vec3 eyePos;
VARYING_OUT vec3 shiftedEye;
13
#endif
14

15
VARYING_OUT vec2 spriteCoord;
16
VARYING_OUT vec3 sphereCenter;
17

18
#ifdef WITH_COLOR_PER_VERTEX 
19 20
VARYING_IN vec4 color[1];
VARYING_OUT vec4 colorsprite;
21 22
#endif

Sylvain's avatar
Sylvain committed
23
#ifdef WITH_PLANE
24 25 26 27 28 29 30
void corner( vec4 center, vec3 planeX, vec3 planeY, float x, float y)
{
	spriteCoord = vec2(x,y);
	vec4 pos = center + size*( x*vec4(planeX,0.0) + y*vec4(planeY,0.0)+ vec4(0.0,0.0,0.5,0.0));
	gl_Position = ProjectionMatrix *  pos;
	EmitVertex();
}
31
#else
32 33 34 35 36 37 38
void corner( vec4 center, float x, float y)
{
	spriteCoord = vec2(x,y);
	vec4 pos = center + vec4(size*x, size*y, 0.0, 0.0);
	gl_Position = ProjectionMatrix *  pos;
	EmitVertex();
}
Sylvain's avatar
Sylvain committed
39 40
#endif

41 42
void main()
{
43
	if (dot(planeClip,vec4(posClip[0],1.0))<=0.0)
44
	{
Sylvain's avatar
Sylvain committed
45 46 47 48
#ifdef WITH_COLOR_PER_VERTEX 
	colorsprite = color[0];
#endif
	vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
49
	sphereCenter = posCenter.xyz;
50
	
51
#ifdef WITH_PLANE
52 53 54
	shiftedEye = eyePos - sphereCenter;
	vec3 V = -shiftedEye;
	normalize(V);
Sylvain's avatar
Sylvain committed
55

56 57 58 59 60 61 62 63
	vec3 planeX = vec3(-V[2],0.0,V[0]); //cross(V, vec3(0.0,1.0,0.0));
	normalize(planeX);
	vec3 planeY = cross(planeX,V);

	corner(posCenter, planeX, planeY, -1.4, 1.4);
	corner(posCenter, planeX, planeY, -1.4,-1.4);
	corner(posCenter, planeX, planeY,  1.4, 1.4);
	corner(posCenter, planeX, planeY,  1.4,-1.4);
64
#else
65 66 67 68
	corner(posCenter, -1.4, 1.4);
	corner(posCenter, -1.4,-1.4);
	corner(posCenter,  1.4, 1.4);
	corner(posCenter,  1.4,-1.4);
69
#endif	
70

71
	EndPrimitive();
72
	}
73
}
74