[rs] Use the correction matrix in shadow baking

This commit is contained in:
Dzmitry Malyshau
2019-07-05 13:43:57 -04:00
parent f76b41420e
commit 8cf1dff41f
3 changed files with 4 additions and 4 deletions

View File

@@ -13,6 +13,4 @@ layout(set = 1, binding = 0) uniform Entity {
void main() {
gl_Position = u_ViewProj * u_World * vec4(a_Pos);
// convert from -1,1 Z to 0,1
gl_Position.z = 0.5 * (gl_Position.z + gl_Position.w);
}

View File

@@ -39,7 +39,8 @@ void main() {
// project into the light space
vec4 light_local = light.proj * v_Position;
// compute texture coordinates for shadow lookup
light_local.xyw = (light_local.xyz/light_local.w + 1.0) / 2.0;
light_local.xy = (light_local.xy/light_local.w + 1.0) / 2.0;
light_local.w = light_local.z / light_local.w;
light_local.z = i;
// do the lookup, using HW PCF and comparison
float shadow = texture(sampler2DArrayShadow(t_Shadow, s_Shadow), light_local);

View File

@@ -113,7 +113,8 @@ impl Light {
near: self.depth.start,
far: self.depth.end,
};
let mx_view_proj = cgmath::Matrix4::from(projection.to_perspective()) * mx_view;
let mx_correction = framework::opengl_to_wgpu_matrix();
let mx_view_proj = mx_correction * cgmath::Matrix4::from(projection.to_perspective()) * mx_view;
LightRaw {
proj: *mx_view_proj.as_ref(),
pos: [self.pos.x, self.pos.y, self.pos.z, 1.0],