Cube map refraction

Started by
2 comments, last by _the_phantom_ 18 years, 9 months ago
Hello Everybody, I've read information about Cube maps and refraction, but I have few doubts and I'd like to clarify with the experts in here. I'm new to this forum and hope you all can help me solve my problem. I created a simulation and I wanted to know write shader for the refraction of sphere in the scene. I came across this ShaderDesigner software. Still figuring out how to write proper shader with that. :) Basically i build my simulation with opengl 1.5 and now wanted to use glsl and use the shaders to implement my effect. I already have a cube map designed with my previous. But this glsl behaves differently I think of handling cube map and now i got stuck in here. I need to some info from the expert regarding how to implement cube map with my existing application. I went thru a lot of forum and unable to find appropriate info what I actually need. What I have? 1. I have my existing Simulation Application with Cube map Ext. What I want? 1. Using glsl how to use cube map with my existing Appz. Experts shoot your answers. thanx regards.
Advertisement
what shaders have you made? any lighting shaders? texturing shaders?
Hi there,
Well I've wrote a VS and FS for glsl but it is unsuccessful. So I used this shader which I've google it.

Here it is...

Vertex shader
-------------

uniform vec3 camPos;

varying vec3 vVec;
varying vec3 norm;

void main(){
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

vVec = gl_Vertex.xyz - camPos;
norm = gl_Normal;
}


Fragment shader
---------------

uniform samplerCube Env;

varying vec3 vVec;
varying vec3 norm;

#define ETA 1.12

void main(){
vec3 viewVec = normalize(vVec);
vec3 normal = normalize(norm);

vec4 refl = textureCube(Env, reflect(viewVec, normal));

float d = ETA * dot(viewVec, normal);
float k = saturate(d * d + 1.0 - ETA * ETA);

vec4 refr = textureCube(Env, ETA * viewVec - (d + sqrt(k)) * normal);

gl_FragColor = lerp(refl, refr, k);
}

But seems to be that this shader go some problem... So I've used this to test mine scene.

regards.
as a side point (I'm not really awake enuff to help rigth now), you could always have just used GLSL built in 'refract' function (added in the 1.10 spec and supported anywhere you find GLSL1.10)

This topic is closed to new replies.

Advertisement