Hi!
I'm a real noob to Shader programming but I have to implement a refraction shader in a project of mine.
I am using a cubemap for a skybox and to map the refractions onto a sphere in the center of that skybox. I am also moving the camera around that sphere, following a character which is placed on the sphere's surface. My problem now is, that
the refraction shader isn't updating. That means, that I see always the same image on the sphere although I am moving the camera. I'm sure there is something wrong with my OpenGL setup. Can anybody tell me step by step what I have to do to get that shader running? My OpenGL code is a total mess now, so I chose to not post it here, but if you want to see it, I will make up for that.
I chose to use the following Nvidia Cg Tutorial codes:
vertex shader code:
void C7E3v_refraction(float4 position : POSITION,
float2 texCoord : TEXCOORD0,
float3 normal : NORMAL,
out float4 oPosition : POSITION,
out float2 oTexCoord : TEXCOORD0,
out float3 T : TEXCOORD1,
uniform float etaRatio,
uniform float3 eyePositionW,
uniform float4x4 modelViewProj,
uniform float4x4 modelToWorld)
{
oPosition = mul(modelViewProj, position);
oTexCoord = texCoord;
// Compute position and normal in world space
float3 positionW = mul(modelToWorld, position).xyz;
float3 N = mul((float3x3)modelToWorld, normal);
N = normalize(N);
// Compute the incident and refracted vectors
float3 I = normalize(positionW - eyePositionW);
T = refract(I, N, etaRatio);
}
fragment shader code:
void C7E4f_refraction(float2 texCoord : TEXCOORD0,
float3 T : TEXCOORD1,
out float4 color : COLOR,
uniform float transmittance,
uniform sampler2D decalMap,
uniform samplerCUBE environmentMap)
{
// Fetch the decal base color
float4 decalColor = tex2D(decalMap, texCoord);
// Fetch refracted environment color
float4 refractedColor = texCUBE(environmentMap, T);
// Compute the final color
color = lerp(decalColor, refractedColor, transmittance);
}