mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Use the correction matrix in shadow baking
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user