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

debug raytraced version on VRJ

parent 7c02936c
...@@ -5,37 +5,45 @@ uniform vec3 lightPos; ...@@ -5,37 +5,45 @@ uniform vec3 lightPos;
uniform vec3 ambiant; uniform vec3 ambiant;
uniform float size; uniform float size;
#ifdef WITH_PLANE #ifdef WITH_PLANE
VARYING_FRAG vec3 eyePosFrag; uniform vec3 eyePos;
VARYING_FRAG vec3 shiftedEye;
#endif #endif
#ifdef WITH_COLOR_PER_VERTEX #ifdef WITH_COLOR_PER_VERTEX
VARYING_FRAG vec3 colorsprite; VARYING_FRAG vec3 colorsprite;
#else #else
uniform vec3 colorsprite; uniform vec3 colorsprite;
#endif #endif
VARYING_FRAG vec2 spriteCoord;
VARYING_FRAG vec2 texCoord;
VARYING_FRAG vec3 sphereCenter; VARYING_FRAG vec3 sphereCenter;
void main(void) void main(void)
{ {
vec3 billboard_frag_pos = sphereCenter + vec3(texCoord, 0.0) * size;
#ifdef WITH_PLANE #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 #else
vec3 billboard_frag_pos = sphereCenter + vec3(spriteCoord, 0.0) * size;
vec3 ray_direction = normalize(billboard_frag_pos); vec3 ray_direction = normalize(billboard_frag_pos);
#endif
float TD = -dot(ray_direction,sphereCenter); float TD = -dot(ray_direction,sphereCenter);
float c = dot(sphereCenter, sphereCenter) - size * size; float c = dot(sphereCenter, sphereCenter) - size * size;
float arg = TD * TD - c; float arg = TD * TD - c;
if (arg < 0.0) if (arg < 0.0)
discard; discard;
float t = -c / (TD - sqrt(arg)); 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); vec4 pos = ProjectionMatrix * vec4(frag_position_eye, 1.0);
gl_FragDepth = (pos.z / pos.w + 1.0) / 2.0; gl_FragDepth = (pos.z / pos.w + 1.0) / 2.0;
...@@ -44,4 +52,5 @@ void main(void) ...@@ -44,4 +52,5 @@ void main(void)
float lambertTerm = dot(N,L); float lambertTerm = dot(N,L);
gl_FragColor = vec4(colorsprite*lambertTerm + ambiant ,1.0); gl_FragColor = vec4(colorsprite*lambertTerm + ambiant ,1.0);
} }
...@@ -5,11 +5,12 @@ uniform mat4 ModelViewMatrix; ...@@ -5,11 +5,12 @@ uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix; uniform mat4 ProjectionMatrix;
#ifdef WITH_PLANE #ifdef WITH_PLANE
uniform vec3 eyePos; uniform vec3 eyePos;
VARYING_OUT vec4 eyePosFrag; VARYING_OUT vec3 shiftedEye;
#endif #endif
VARYING_OUT vec2 texCoord; VARYING_OUT vec2 spriteCoord;
VARYING_OUT vec3 sphereCenter; VARYING_OUT vec3 sphereCenter;
#ifdef WITH_COLOR_PER_VERTEX #ifdef WITH_COLOR_PER_VERTEX
VARYING_IN vec3 color[1]; VARYING_IN vec3 color[1];
VARYING_OUT vec3 colorsprite; VARYING_OUT vec3 colorsprite;
...@@ -18,16 +19,16 @@ VARYING_OUT vec3 sphereCenter; ...@@ -18,16 +19,16 @@ VARYING_OUT vec3 sphereCenter;
#ifdef WITH_PLANE #ifdef WITH_PLANE
void corner( vec4 center, vec3 planeX, vec3 planeY, float x, float y) void corner( vec4 center, vec3 planeX, vec3 planeY, float x, float y)
{ {
texCoord = vec2(1.4*x,1.4*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)); 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; gl_Position = ProjectionMatrix * pos;
EmitVertex(); EmitVertex();
} }
#else #else
void corner( vec4 center, float x, float y) void corner( vec4 center, float x, float y)
{ {
texCoord = vec2(1.4*x,1.4*y); spriteCoord = vec2(x,y);
vec4 pos = center + vec4( size*x, size*y, 0.0, 0.0); vec4 pos = center + vec4(size*x, size*y, 0.0, 0.0);
gl_Position = ProjectionMatrix * pos; gl_Position = ProjectionMatrix * pos;
EmitVertex(); EmitVertex();
} }
...@@ -41,29 +42,27 @@ void main() ...@@ -41,29 +42,27 @@ void main()
#endif #endif
vec4 posCenter = ModelViewMatrix * POSITION_IN(0); vec4 posCenter = ModelViewMatrix * POSITION_IN(0);
sphereCenter = posCenter.xyz; sphereCenter = posCenter.xyz;
#ifdef WITH_PLANE #ifdef WITH_PLANE
vec4 EPF = ModelViewMatrix * vec4(eyePos,1.0); shiftedEye = eyePos - sphereCenter;
eyePosFrag = EPF.xyz; vec3 V = -shiftedEye;
normalize(V);
vec3 V = sphereCenter-eyePosFrag; vec3 planeX = vec3(-V[2],0.0,V[0]); //cross(V, vec3(0.0,1.0,0.0));
V.normalize(); normalize(planeX);
// vec3 planeX = cross(V, vec3(0.0,1.0,0.0)); vec3 planeY = cross(planeX,V);
vec3 planeX = vec3(-V[2],0.0,V[0]);
vec3 planeY = cross(X,V); corner(posCenter, planeX, planeY, -1.4, 1.4);
corner(posCenter, planeX, planeY, -1.0, 1.0); corner(posCenter, planeX, planeY, -1.4,-1.4);
corner(posCenter, planeX, planeY, -1.0,-1.0); corner(posCenter, planeX, planeY, 1.4, 1.4);
corner(posCenter, planeX, planeY, 1.0, 1.0); corner(posCenter, planeX, planeY, 1.4,-1.4);
corner(posCenter, planeX, planeY, 1.0,-1.0);
#else #else
corner(posCenter, -1.0, 1.0); corner(posCenter, -1.4, 1.4);
corner(posCenter, -1.0,-1.0); corner(posCenter, -1.4,-1.4);
corner(posCenter, 1.0, 1.0); corner(posCenter, 1.4, 1.4);
corner(posCenter, 1.0,-1.0); corner(posCenter, 1.4,-1.4);
#endif #endif
EndPrimitive(); 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