0

I have textures containing normals:

enter image description here

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);

enter image description here

EDIT (with abs() of a color vector):

enter image description here

and depth:

enter image description here

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:

enter image description here

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?

aerion
  • 702
  • 1
  • 11
  • 28
  • Your texture is having trouble displaying negative colors. I assume that is just because you are outputting to the screen? What image format are you using for your textures? Cause your second screenshot is wrong unless your texture is actually capable of storing negative values. – Andon M. Coleman Jun 21 '14 at 01:34
  • It's ok. It was rendering fault. I added a screen of an eye position with abs(). When i use also normalize it's even better. :) Anyway this texture is fine. About reflection... I'm sure I should use one of matrices (model, view, projection) or combination of them or of theirs inversions. But I can't figure out which one and how. – aerion Jun 21 '14 at 19:41

0 Answers0