Commit 60983959 authored by Laszlo Agocs's avatar Laszlo Agocs
Browse files

Fix shadowmap example for Metal

parent 8b8c7752
qsb --glsl 120 --hlsl 50 --msl 12 -c shadowmap.vert -o shadowmap.vert.qsb qsb --glsl 120 --hlsl 50 --msl 12 -c shadowmap.vert -o shadowmap.vert.qsb
qsb --glsl 120 --hlsl 50 --msl 12 -c shadowmap.frag -o shadowmap.frag.qsb qsb --glsl 120 --hlsl 50 --msl 12 -c shadowmap.frag -o shadowmap.frag.qsb
qsb --glsl 120 --hlsl 50 --msl 12 -c light.vert -o light.vert.qsb qsb --glsl 120 --hlsl 50 --msl 12 -c main.vert -o main.vert.qsb
qsb --glsl 120 --hlsl 50 --msl 12 -c light.frag -o light.frag.qsb qsb --glsl 120 --hlsl 50 --msl 12 -c main.frag -o main.frag.qsb
qsb --glsl 120 --hlsl 50 --msl 12 shadowmap.vert -o shadowmap.vert.qsb
qsb --glsl 120 --hlsl 50 --msl 12 shadowmap.frag -o shadowmap.frag.qsb
qsb --glsl 120 --hlsl 50 --msl 12 main.vert -o main.vert.qsb
qsb --glsl 120 --hlsl 50 --msl 12 main.frag -o main.frag.qsb
...@@ -17,7 +17,11 @@ void main() ...@@ -17,7 +17,11 @@ void main()
{ {
vec4 adjustedLcVertPos = vLCVertPos; vec4 adjustedLcVertPos = vLCVertPos;
adjustedLcVertPos.z -= 0.0001; // bias to avoid acne adjustedLcVertPos.z -= 0.0001; // bias to avoid acne
float sc = textureProj(shadowMap, adjustedLcVertPos);
// no textureProj, that seems to end up not doing the perspective divide for z (?)
vec3 v = adjustedLcVertPos.xyz / adjustedLcVertPos.w;
float sc = texture(shadowMap, v); // sampler is comparison enabled so compares to z
float shadowFactor = 0.2; float shadowFactor = 0.2;
if (sc > 0 || ubuf.useShadow == 0) if (sc > 0 || ubuf.useShadow == 0)
shadowFactor = 1.0; shadowFactor = 1.0;
......
...@@ -128,8 +128,8 @@ void Window::customInit() ...@@ -128,8 +128,8 @@ void Window::customInit()
d.ps = m_r->newGraphicsPipeline(); d.ps = m_r->newGraphicsPipeline();
d.releasePool << d.ps; d.releasePool << d.ps;
d.ps->setShaderStages({ d.ps->setShaderStages({
{ QRhiGraphicsShaderStage::Vertex, getShader(QLatin1String(":/light.vert.qsb")) }, { QRhiGraphicsShaderStage::Vertex, getShader(QLatin1String(":/main.vert.qsb")) },
{ QRhiGraphicsShaderStage::Fragment, getShader(QLatin1String(":/light.frag.qsb")) } { QRhiGraphicsShaderStage::Fragment, getShader(QLatin1String(":/main.frag.qsb")) }
}); });
d.ps->setDepthTest(true); d.ps->setDepthTest(true);
d.ps->setDepthWrite(true); d.ps->setDepthWrite(true);
...@@ -225,7 +225,7 @@ void Window::customRender() ...@@ -225,7 +225,7 @@ void Window::customRender()
if (m_r->isClipDepthZeroToOne()) { if (m_r->isClipDepthZeroToOne()) {
// convert x, y [-1, 1] -> [0, 1] // convert x, y [-1, 1] -> [0, 1]
*sbp++ = 0.5f; *sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = 0.5f; *sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = 0.0f;
*sbp++ = 0.0f; *sbp++ = 0.5f; *sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = m_r->isYUpInNDC() ? -0.5f : 0.5f; *sbp++ = 0.0f; *sbp++ = 0.0f;
*sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = 1.0f; *sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = 0.0f; *sbp++ = 1.0f; *sbp++ = 0.0f;
*sbp++ = 0.5f; *sbp++ = 0.5f; *sbp++ = 0.0f; *sbp++ = 1.0f; *sbp++ = 0.5f; *sbp++ = 0.5f; *sbp++ = 0.0f; *sbp++ = 1.0f;
} else { } else {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<qresource> <qresource>
<file>shadowmap.vert.qsb</file> <file>shadowmap.vert.qsb</file>
<file>shadowmap.frag.qsb</file> <file>shadowmap.frag.qsb</file>
<file>light.vert.qsb</file> <file>main.vert.qsb</file>
<file>light.frag.qsb</file> <file>main.frag.qsb</file>
</qresource> </qresource>
</RCC> </RCC>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment