diff --git a/data/shaders/offscreen/mirror.frag b/data/shaders/offscreen/mirror.frag index 669be8ce..54d54d1b 100644 --- a/data/shaders/offscreen/mirror.frag +++ b/data/shaders/offscreen/mirror.frag @@ -8,18 +8,17 @@ 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; void main() { vec4 tmp = vec4(1.0 / inPos.w); - vec4 projCoord = inPos * tmp; + vec4 projCoord = inPos * tmp; // Scale and bias - projCoord += vec4(1.0); - projCoord *= vec4(0.5); + projCoord += vec4(1.0); + projCoord *= vec4(0.5); // Slow single pass blur // For demonstration purposes only @@ -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); - } + }; } \ No newline at end of file diff --git a/data/shaders/offscreen/mirror.frag.spv b/data/shaders/offscreen/mirror.frag.spv index ede82a39..c75e397f 100644 Binary files a/data/shaders/offscreen/mirror.frag.spv and b/data/shaders/offscreen/mirror.frag.spv differ diff --git a/data/shaders/offscreen/mirror.vert b/data/shaders/offscreen/mirror.vert index 62423db0..180c65a2 100644 --- a/data/shaders/offscreen/mirror.vert +++ b/data/shaders/offscreen/mirror.vert @@ -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; diff --git a/data/shaders/offscreen/mirror.vert.spv b/data/shaders/offscreen/mirror.vert.spv index a35245f9..49f2eab6 100644 Binary files a/data/shaders/offscreen/mirror.vert.spv and b/data/shaders/offscreen/mirror.vert.spv differ diff --git a/data/shaders/offscreen/phong.vert b/data/shaders/offscreen/phong.vert index 5f802b0d..de1be5da 100644 --- a/data/shaders/offscreen/phong.vert +++ b/data/shaders/offscreen/phong.vert @@ -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); } diff --git a/data/shaders/offscreen/phong.vert.spv b/data/shaders/offscreen/phong.vert.spv index 05e10191..44f4971a 100644 Binary files a/data/shaders/offscreen/phong.vert.spv and b/data/shaders/offscreen/phong.vert.spv differ diff --git a/offscreen/offscreen.cpp b/offscreen/offscreen.cpp index 166a2a6b..29d84f71 100644 --- a/offscreen/offscreen.cpp +++ b/offscreen/offscreen.cpp @@ -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