Commit 5f24ae0a authored by Laszlo Agocs's avatar Laszlo Agocs

Reintroduce a simpler, still broken shadowmap example

parent 05bc4e93
......@@ -14,7 +14,8 @@ SUBDIRS += \
triquadcube \
offscreen \
floattexture \
mrt
mrt \
shadowmap
qtConfig(vulkan) {
SUBDIRS += \
......
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 light.vert -o light.vert.qsb
qsb --glsl 120 --hlsl 50 --msl 12 -c light.frag -o light.frag.qsb
#version 440
layout(location = 0) in vec4 vLCVertPos;
layout(location = 0) out vec4 fragColor;
layout(binding = 1) uniform sampler2DShadow shadowMap;
layout(std140, binding = 0) uniform buf {
mat4 mvp;
mat4 lightMvp;
int useShadow;
} ubuf;
void main()
{
vec4 adjustedLcVertPos = vLCVertPos;
adjustedLcVertPos.z -= 0.0001; // bias to avoid acne
float sc = textureProj(shadowMap, adjustedLcVertPos);
float shadowFactor = 0.2;
if (sc > 0 || ubuf.useShadow == 0)
shadowFactor = 1.0;
fragColor = vec4(0.5, 0.3 + ubuf.useShadow * 0.2, 0.7, 1.0) * shadowFactor;
}
#version 440
layout(location = 0) in vec4 position;
layout(std140, binding = 0) uniform buf {
mat4 mvp;
mat4 lightMvp;
int useShadow;
} ubuf;
out gl_PerVertex { vec4 gl_Position; };
layout(location = 0) out vec4 vLCVertPos;
void main()
{
// [-1,1] -> [0,1]
mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0);
vLCVertPos = shadowMatrix * ubuf.lightMvp * position;
gl_Position = ubuf.mvp * position;
}
This diff is collapsed.
#version 440
void main()
{
}
TEMPLATE = app
QT += rhi
SOURCES = \
shadowmap.cpp
RESOURCES = shadowmap.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/rhi/shadowmap
INSTALLS += target
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>shadowmap.vert.qsb</file>
<file>shadowmap.frag.qsb</file>
<file>light.vert.qsb</file>
<file>light.frag.qsb</file>
</qresource>
</RCC>
#version 440
layout(location = 0) in vec4 position;
layout(std140, binding = 0) uniform buf {
mat4 mvp;
} ubuf;
out gl_PerVertex { vec4 gl_Position; };
void main()
{
gl_Position = ubuf.mvp * position;
}
......@@ -157,7 +157,6 @@ protected:
QRhiRenderPassDescriptor *m_rp = nullptr;
QMatrix4x4 m_proj;
QMatrix4x4 m_rawProj;
QElapsedTimer m_timer;
int m_frameCount;
......@@ -338,9 +337,8 @@ void Window::resizeSwapChain()
m_frameCount = 0;
m_timer.restart();
m_rawProj.setToIdentity();
m_rawProj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 1000.0f);
m_proj = m_r->clipSpaceCorrMatrix() * m_rawProj;
m_proj = m_r->clipSpaceCorrMatrix();
m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 1000.0f);
m_proj.translate(0, 0, -4);
}
......
Markdown is supported
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