bracer
May 12, 2020, 12:38pm
#1
Hey!
I am working on adding reflection to a grid, but I am having rather big problems understanding what is going wrong. The grid is a screen space grid made following this tutorial: Screen space projected grid with GLSL and WebGL - Jérémy BOUNY
I do like this to project the reflections:
Vertex:
vec3 eye_w = gl_ModelViewMatrixInverse[3].xyz;
vec3 incident = gl_Vertex.xyz - eye_w;
vec3 reflected = reflect(incident, gl_Vertex);
refTexcoord =normalize(reflected);
Frag:
vec4 color = texture2D(mainTex, vec2(refTexcoord.xy));
But the result:
Any idea what is happening?
This is only correct if the object is a unit sphere. The second parameter to reflect()
is the surface normal, which needs to be normalised.
bracer
May 13, 2020, 5:58pm
#3
Thanks for the answer!
I tried a different code instead, and I feel sooo close to getting it…
But something is still odd. It’s hard to say in the photo, so maybe I’ll record a video later.
Maybe you can still see what’s missing in the new code:
Vertex:
viewCoord = (gl_ProjectionMatrix * viewMatrix ) * screenPlaneWorldPosition;
Frag:
vec4 projCoord = normalize(viewCoords / viewCoords.w);
projCoord.xyz = (projCoord.xyz) * 0.5 + 0.5;
projCoord += bump; //normalmap
projCoord = clamp(projCoord, 0.001, 0.999);
vec4 color = texture2D(reflectionTex, vec2(projCoord.x, -projCoord.y));
Thanks for the help!
bracer
May 20, 2020, 10:31pm
#4
Now I tried to skip the screen space grid and use a simple graph.
But still I cannot manage basic reflections.
The image refuses to center on the mesh.
Any ideas what is wrong?
Vertex:
vec3 vEyeNormal = gl_NormalMatrix * gl_Normal;
vec4 vVert4 = gl_ModelViewMatrix * gl_Vertex;
vec3 vEyeVertex = normalize(vVert4.xyz / vVert4.w);
vec4 vCoords = vec4(reflect(vEyeVertex, vEyeNormal), 0.0);
refTexcoord.xyz =normalize(vCoords.xyz);
Frag:
vec4 reflectionColor = texture2D(mainTex, refTexcoord.xy);
Result:
Cheers!
system
closed
October 19, 2021, 7:09pm
#5
This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.