Commit 7e5dc1ac authored by Sylvain Thery's avatar Sylvain Thery

debug raytraced version on VRJ

parent 7c02936c
......@@ -5,37 +5,45 @@ uniform vec3 lightPos;
uniform vec3 ambiant;
uniform float size;
#ifdef WITH_PLANE
VARYING_FRAG vec3 eyePosFrag;
uniform vec3 eyePos;
VARYING_FRAG vec3 shiftedEye;
#endif
#ifdef WITH_COLOR_PER_VERTEX
VARYING_FRAG vec3 colorsprite;
#else
uniform vec3 colorsprite;
#endif
VARYING_FRAG vec2 texCoord;
VARYING_FRAG vec2 spriteCoord;
VARYING_FRAG vec3 sphereCenter;
void main(void)
{
vec3 billboard_frag_pos = sphereCenter + vec3(texCoord, 0.0) * size;
#ifdef WITH_PLANE
vec3 ray_direction = normalize(billboard_frag_pos - eyePosFrag;);
vec3 billboard_frag_pos = vec3(spriteCoord, 0.0) * size;
vec3 ray_direction = normalize(billboard_frag_pos - shiftedEye);
float av = dot(shiftedEye,ray_direction);
float arg = av*av - dot(shiftedEye,shiftedEye) + size*size;
if (arg< 0.0)
discard;
float t = -av - sqrt(arg);
vec3 frag_position_eye = ray_direction * t + eyePos ;
#else
vec3 billboard_frag_pos = sphereCenter + vec3(spriteCoord, 0.0) * size;
vec3 ray_direction = normalize(billboard_frag_pos);
#endif
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;
vec3 frag_position_eye = ray_direction * t ;
#endif
vec4 pos = ProjectionMatrix * vec4(frag_position_eye, 1.0);
gl_FragDepth = (pos.z / pos.w + 1.0) / 2.0;
......@@ -44,4 +52,5 @@ void main(void)
float lambertTerm = dot(N,L);
gl_FragColor = vec4(colorsprite*lambertTerm + ambiant ,1.0);
}
......@@ -5,11 +5,12 @@ uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;
#ifdef WITH_PLANE
uniform vec3 eyePos;
VARYING_OUT vec4 eyePosFrag;
VARYING_OUT vec3 shiftedEye;
#endif
VARYING_OUT vec2 texCoord;
VARYING_OUT vec2 spriteCoord;
VARYING_OUT vec3 sphereCenter;
#ifdef WITH_COLOR_PER_VERTEX
VARYING_IN vec3 color[1];
VARYING_OUT vec3 colorsprite;
......@@ -18,16 +19,16 @@ VARYING_OUT vec3 sphereCenter;
#ifdef WITH_PLANE
void corner( vec4 center, vec3 planeX, vec3 planeY, float x, float y)
{
texCoord = vec2(1.4*x,1.4*y);
vec4 pos = center + size( x*vec4(planeX,0.0) + y*vec4(planeY,0.0)+ vec4(0.0,0.0,0.5,0.0));
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();
}
#else
void corner( vec4 center, float x, float y)
{
texCoord = vec2(1.4*x,1.4*y);
vec4 pos = center + vec4( size*x, size*y, 0.0, 0.0);
spriteCoord = vec2(x,y);
vec4 pos = center + vec4(size*x, size*y, 0.0, 0.0);
gl_Position = ProjectionMatrix * pos;
EmitVertex();
}
......@@ -41,29 +42,27 @@ void main()
#endif
vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
sphereCenter = posCenter.xyz;
#ifdef WITH_PLANE
vec4 EPF = ModelViewMatrix * vec4(eyePos,1.0);
eyePosFrag = EPF.xyz;
shiftedEye = eyePos - sphereCenter;
vec3 V = -shiftedEye;
normalize(V);
vec3 V = sphereCenter-eyePosFrag;
V.normalize();
// vec3 planeX = cross(V, vec3(0.0,1.0,0.0));
vec3 planeX = vec3(-V[2],0.0,V[0]);
vec3 planeY = cross(X,V);
corner(posCenter, planeX, planeY, -1.0, 1.0);
corner(posCenter, planeX, planeY, -1.0,-1.0);
corner(posCenter, planeX, planeY, 1.0, 1.0);
corner(posCenter, planeX, planeY, 1.0,-1.0);
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);
#else
corner(posCenter, -1.0, 1.0);
corner(posCenter, -1.0,-1.0);
corner(posCenter, 1.0, 1.0);
corner(posCenter, 1.0,-1.0);
corner(posCenter, -1.4, 1.4);
corner(posCenter, -1.4,-1.4);
corner(posCenter, 1.4, 1.4);
corner(posCenter, 1.4,-1.4);
#endif
EndPrimitive();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment