opengl - Skybox reflection basing on textures -
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 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 color vector):
and depth:
i have cube texture also, utilize render skybox (you can see part of on pictures above).
i need utilize them create reflection effect.
textures rendered using framebuffers before , utilize them in fragment shader 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 (basing on tutorials):
vec4 vcoords = vec4(reflect(position, n), 0.0); vec4 refl_color = texture(u_cubemaptex, vcoords.xyz);
but cant accomplish proper effect of reflection.
i can see this:
it's incorrect, cause when @ ball above, should see reflected sky. can see same fragment of skybox anywhere @ ball from.
can help me create proper math eqation? matrix should utilize (if any) , how should calculate proper cube texture coords?
opengl reflection textures skybox
No comments:
Post a Comment