Jump to content
  • Advertisement
Sign in to follow this  
ajmrm

OpenGL Cube map refraction

This topic is 4894 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!