Skip to content

Commit

Permalink
[rs] Use the correction matrix in shadow baking
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jul 5, 2019
1 parent f76b414 commit 8cf1dff
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 0 additions & 2 deletions wgpu/examples/shadow/bake.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 2 additions & 1 deletion wgpu/examples/shadow/forward.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion wgpu/examples/shadow/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 8cf1dff

Please sign in to comment.