i guess this is a rather simple question, i just can’t think of a decent solution:
i’m working on a new water shader. i have a reflection and a refraction texture. along with these i have another texture to which i write the distance between the water surface and the ground. i want to combine the reflection and refraction textures in the following way:
- in shallow water, the refraction should be opaque, in deep water the reflection should be predominant. this way i prevent hard edges where ground and water surface meet. i achieve this with:
gl_FragData[0].rgb = ( ReflectionWaterDepth ) + ( Refraction(1.0-WaterDepth) );
- i want to use a fresnel term, so that if you look down, you can see the ground, but if you look straight ahead, you see the reflection, like this:
vec3 Fresnel = vec3( dot(ViewVector, Normal) );
gl_FragData[0].rgb = ( Reflection*(1.0-Fresnel) ) + ( Refraction*Fresnel );
both work fine seperately, but how can i combine the two? do you have further ideas for optimization/effects? thanks