Use gl_FrontFacing to determine mirrored surface side, enable clipping (Refs #190)
This commit is contained in:
parent
becdc7c9dc
commit
876f5714eb
7 changed files with 18 additions and 23 deletions
|
|
@ -8,7 +8,6 @@ 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;
|
||||
|
||||
|
|
@ -28,7 +27,9 @@ void main()
|
|||
vec4 color = texture(samplerColorMap, inUV);
|
||||
outFragColor = color * 0.25;
|
||||
|
||||
if (inNormal.z > 0) {
|
||||
if (gl_FrontFacing)
|
||||
{
|
||||
// Only render mirrored scene on front facing (upper) side of mirror surface
|
||||
vec4 reflection = vec4(0.0);
|
||||
for (int x = -3; x <= 3; x++)
|
||||
{
|
||||
|
|
@ -38,5 +39,5 @@ void main()
|
|||
}
|
||||
}
|
||||
outFragColor += reflection * 1.5 * (color.r);
|
||||
}
|
||||
};
|
||||
}
|
||||
Binary file not shown.
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
layout (location = 0) in vec3 inPos;
|
||||
layout (location = 1) in vec2 inUV;
|
||||
layout (location = 3) in vec3 inNormal;
|
||||
|
||||
layout (binding = 0) uniform UBO
|
||||
{
|
||||
|
|
@ -15,19 +14,14 @@ layout (binding = 0) uniform UBO
|
|||
|
||||
layout (location = 0) out vec2 outUV;
|
||||
layout (location = 1) out vec4 outPos;
|
||||
layout (location = 2) out vec3 outNormal;
|
||||
|
||||
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]);
|
||||
}
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
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.
|
|
@ -22,6 +22,7 @@ layout (location = 3) out vec3 outLightVec;
|
|||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
float gl_ClipDistance[];
|
||||
};
|
||||
|
||||
void main()
|
||||
|
|
@ -33,8 +34,6 @@ void main()
|
|||
outLightVec = normalize(ubo.lightPos.xyz - outEyePos);
|
||||
|
||||
// Clip against reflection plane
|
||||
//vec4 clipPlane = vec4(0.0, -1.0, 0.0, 0.0);
|
||||
|
||||
//gl_ClipDistance[0] = dot(inPos, clipPlane);
|
||||
|
||||
vec4 clipPlane = vec4(0.0, -1.0, 0.0, 1.5);
|
||||
gl_ClipDistance[0] = dot(inPos, clipPlane);
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -789,14 +789,15 @@ public:
|
|||
|
||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.debug));
|
||||
|
||||
// Flip culling
|
||||
rasterizationState.cullMode = VK_CULL_MODE_BACK_BIT;
|
||||
|
||||
// Mirror
|
||||
shaderStages[0] = loadShader(getAssetPath() + "shaders/offscreen/mirror.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
||||
shaderStages[1] = loadShader(getAssetPath() + "shaders/offscreen/mirror.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
rasterizationState.cullMode = VK_CULL_MODE_NONE;
|
||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.mirror));
|
||||
|
||||
// Flip culling
|
||||
rasterizationState.cullMode = VK_CULL_MODE_BACK_BIT;
|
||||
|
||||
// Phong shading pipelines
|
||||
pipelineCreateInfo.layout = pipelineLayouts.shaded;
|
||||
// Scene
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue