I have textures containing normals:
eye position: Vertex shader:
vec4 posEye = modelViewMatrix * vec4(in_Position.xyz, 1.0f);
fs_PosEye = posEye.xyz;
Fragment shader:
// calculate normal from texture coordinates
vec3 coords;
coords.xy = gl_PointCoord * 2.0 - 1.0;
float r = dot(coords.xy, coords.xy);
if(r>1.0){
discard;
}
coords.z = sqrt(1.0-r);
//calculate eye position
vec4 pixelPos = vec4(fs_PosEye + normalize(coords)*pointRadius,1.0f);
EDIT (with abs()
of a color vector):
and depth:
I have a cube texture also, which I use to render a skybox (you can see a part of it on pictures above).
I need to use them to create a reflection effect.
Textures were rendered using framebuffers before and now I use them in my fragment shader this way:
vec3 N = texture(u_normaltex,fs_texcoord).xyz;
float not_blurred_depth = texture(u_depthtex,fs_texcoord).r;
vec3 position = texture(u_positiontex,fs_texcoord).xyz;
I tried to do something like this (basing on tutorials):
vec4 vCoords = vec4(reflect(position, N), 0.0);
vec4 refl_color = texture(u_cubemaptex, vCoords.xyz);
but I cant achieve a proper effect of reflection.
I can see something like this:
It's incorrect, cause when I look at the ball from above, I should only see a reflected sky. Also I can see the same fragment of skybox anywhere I look at the ball from.
Can you help me make a proper math eqation? Which matrix should I use (if any) and how should I calculate proper cube texture coords?