Commit 562158de authored by Laszlo Agocs's avatar Laszlo Agocs

Remove the shadowmap example

Out of my league and time is up. Cannot get it work on non-GL. Something
is wrong with the math, no idea what.
parent 8e3100a8
......@@ -14,8 +14,7 @@ SUBDIRS += \
triquadcube \
offscreen \
floattexture \
mrt \
shadowmap
mrt
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 vec3 vECVertNormal;
layout(location = 1) in vec3 vECVertPos;
layout(location = 2) in vec4 vLCVertPos;
layout(location = 0) out vec4 fragColor;
layout(binding = 1) uniform sampler2DShadow shadowMap;
void main()
{
// These should be passed in the ubuf but just hardcode them for now.
// Positions must match the C++ side.
vec3 ECCameraPosition = vec3(0.0, 0.0, 4.0);
vec3 ECLightPosition = vec3(0.0, 10.0, 0.0);
vec3 ka = vec3(0.05, 0.05, 0.05);
vec3 kd = vec3(0.3, 0.7, 0.6);
vec3 ks = vec3(0.66, 0.66, 0.66);
vec3 attenuation = vec3(1.0, 0.0, 0.0);
vec3 color = vec3(1.0, 1.0, 1.0);
float intensity = 0.8;
float specularExp = 150.0;
vec3 unnormL = ECLightPosition - vECVertPos;
float dist = length(unnormL);
float att = 1.0 / (attenuation.x + attenuation.y * dist + attenuation.z * dist * dist);
vec3 N = normalize(vECVertNormal);
vec3 L = normalize(unnormL);
float NL = max(0.0, dot(N, L));
vec3 dColor = att * intensity * color * NL;
vec3 R = reflect(-L, N);
vec3 V = normalize(ECCameraPosition - vECVertPos);
float RV = max(0.0, dot(R, V));
vec3 sColor = att * intensity * color * pow(RV, specularExp);
vec4 adjustedLcVertPos = vLCVertPos;
adjustedLcVertPos.z -= 0.0001; // bias to avoid acne
float sc = textureProj(shadowMap, adjustedLcVertPos);
float shadowFactor = 0.2;
if (sc > 0)
shadowFactor = 1.0;
fragColor = vec4(ka + kd * dColor + ks * sColor, 1.0) * shadowFactor;
}
#version 440
layout(location = 0) in vec4 position;
layout(location = 1) in vec3 normal;
layout(std140, binding = 0) uniform buf {
mat4 clipSpaceCorr;
mat4 mvp; // projection * model_to_view
mat4 mv; // model_to_view
mat4 m; // model
mat4 lightViewProj; // light_cam_projection * light_model_to_view
mat3 n; // normal matrix for model
} ubuf;
out gl_PerVertex { vec4 gl_Position; };
layout(location = 0) out vec3 vECVertNormal;
layout(location = 1) out vec3 vECVertPos;
layout(location = 2) 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 = ubuf.clipSpaceCorr * shadowMatrix * ubuf.lightViewProj * ubuf.m * position;
vECVertNormal = normalize(ubuf.n * normal);
vECVertPos = vec3(ubuf.clipSpaceCorr * ubuf.m * position);
gl_Position = ubuf.clipSpaceCorr * ubuf.mvp * position;
}
This diff is collapsed.
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 clipSpaceCorr;
mat4 mvp;
} ubuf;
out gl_PerVertex { vec4 gl_Position; };
void main()
{
gl_Position = ubuf.clipSpaceCorr * ubuf.mvp * position;
}
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