Don't render the reflection on the far side of the floor
This commit is contained in:
parent
d9d3a3e3b3
commit
0e88fb6811
4 changed files with 24 additions and 16 deletions
|
|
@ -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,18 +24,19 @@ void main()
|
|||
// Slow single pass blur
|
||||
// For demonstration purposes only
|
||||
const float blurSize = 1.0 / 512.0;
|
||||
vec4 reflection = vec4(0.0);
|
||||
for (int x = -3; x <= 3; x++)
|
||||
{
|
||||
for (int y = -3; y <= 3; y++)
|
||||
{
|
||||
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);
|
||||
|
||||
|
||||
if (inNormal.z > 0) {
|
||||
vec4 reflection = vec4(0.0);
|
||||
for (int x = -3; x <= 3; x++)
|
||||
{
|
||||
for (int y = -3; y <= 3; y++)
|
||||
{
|
||||
reflection += texture(samplerColor, vec2(projCoord.s + x * blurSize, projCoord.t + y * blurSize)) / 49.0;
|
||||
}
|
||||
}
|
||||
outFragColor += reflection * 1.5 * (color.r);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
|
@ -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;
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue