I’m trying to implement reflection for arbitrary surfaces, and I figured sEnvCubeMap would be the correct way to do this.
Here is my technique:
<technique vs="RefractionReflection_VS" ps="RefractionReflection_PS" >
<pass name="refract" />
</technique>
Pixel shader:
[code]#include “Uniforms.glsl”
#include “Samplers.glsl”
const float bumpyness = 0.0;
const float refractFactor = 0.9;
varying vec3 vPosition_worldSpace;
varying vec3 vNormal_worldSpace;
varying vec3 vTangent_worldSpace;
varying vec3 vEyeDirection_worldSpace;
varying vec2 vTexCoord;
varying vec3 vProjection;
void PS()
{
vec3 eyeDirection_worldSpace = normalize(vEyeDirection_worldSpace);
vec3 normal_textureSpace = normalize(texture2D(sNormalMap, vTexCoord).rgb * 2 - 1);
mat3 invTBN = mat3(
normalize(vTangent_worldSpace),
normalize(cross(vTangent_worldSpace, vNormal_worldSpace)),
normalize(vNormal_worldSpace)
);
vec3 normal_worldSpace = invTBN * normal_textureSpace;
vec3 reflect_worldSpace = reflect(-eyeDirection_worldSpace, normal_worldSpace);
vec3 reflectColor = textureCube(sEnvCubeMap, reflect_worldSpace).rgb;
gl_FragColor = vec4(reflectColor, 1);
}[/code]
Result:
And just to show that my reflect_worldSpace vector is correct, here I output it directly with gl_FragColor = vec4(reflect_worldSpace, 1);: