Don't render the reflection on the far side of the floor

This commit is contained in:
Brad Davis 2016-06-27 01:26:48 -07:00
parent d9d3a3e3b3
commit 0e88fb6811
4 changed files with 24 additions and 16 deletions

View file

@ -8,6 +8,7 @@ layout (binding = 2) uniform sampler2D samplerColorMap;
layout (location = 0) in vec2 inUV;
layout (location = 1) in vec4 inPos;
layout (location = 2) in vec3 inNormal;
layout (location = 0) out vec4 outFragColor;
@ -15,6 +16,7 @@ void main()
{
vec4 tmp = vec4(1.0 / inPos.w);
vec4 projCoord = inPos * tmp;
// Scale and bias
projCoord += vec4(1.0);
projCoord *= vec4(0.5);
@ -22,6 +24,11 @@ void main()
// Slow single pass blur
// For demonstration purposes only
const float blurSize = 1.0 / 512.0;
vec4 color = texture(samplerColorMap, inUV);
outFragColor = color * 0.25;
if (inNormal.z > 0) {
vec4 reflection = vec4(0.0);
for (int x = -3; x <= 3; x++)
{
@ -30,10 +37,6 @@ void main()
reflection += texture(samplerColor, vec2(projCoord.s + x * blurSize, projCoord.t + y * blurSize)) / 49.0;
}
}
vec4 color = texture(samplerColorMap, inUV);
outFragColor = color * 0.25;
outFragColor += reflection * 1.5 * (color.r);
}
}

View file

@ -15,14 +15,19 @@ layout (binding = 0) uniform UBO
layout (location = 0) out vec2 outUV;
layout (location = 1) out vec4 outPos;
layout (location = 2) out vec3 outNormal;
out gl_PerVertex
{
vec4 gl_Position;
};
mat3 mat3_emu(mat4 m4) {
return mat3(
m4[0][0], m4[0][1], m4[0][2],
m4[1][0], m4[1][1], m4[1][2],
m4[2][0], m4[2][1], m4[2][2]);
}
void main()
{
mat3 rotation = mat3_emu(ubo.model);
outNormal = rotation * inNormal;
outUV = inUV;
outPos = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
gl_Position = outPos;