Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glsl refraction getting mapped upside down

I am implementing refraction in glsl. I am using the refract function provided in frag shader to get the desired effect. But the refraction I am getting, its upside down. I think this is wrong.. any idea why is it so?

This is what I do in vertex shader:

vec3 worldView = normalize(vec3(WorldCameraPosition-worldPos));
refractor = refract(-worldView, worldNorm, Eta); // eta = 0.66;

and then frag shader I do:

vec4 refractColor = textureCube(cubeMap, refractor); 

http://www.cse.ohio-state.edu/~duttas/Images_5542/Capture.PNG http://www.cse.ohio-state.edu/~duttas/Images_5542/Capture.PNG

like image 207
mindbender Avatar asked Nov 14 '12 19:11

mindbender


1 Answers

If you're talking about the refractions on those spheres, I'm pretty sure what you've got is the correct result, it's supposed to be upside down. Due to the way the light refracts off the spherical surface the image you see in the sphere is reversed:

https://summerexplorations.files.wordpress.com/2011/07/marbles2.jpg?w=584

Real world example:

http://www.physicscentral.com/explore/pictures/images/crystal-ball_2.jpg
(source: physicscentral.com)

like image 177
Tim Avatar answered Nov 06 '22 06:11

Tim