mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fix point shadows.
This commit is contained in:
parent
46a4103890
commit
e5ef8b31ca
@ -40,6 +40,12 @@ uniform u_locals {
|
||||
|
||||
struct BoneData {
|
||||
mat4 bone_mat;
|
||||
// This is actually a matrix, but we explicitly rely on being able to index into it
|
||||
// in column major order, and some shader compilers seem to transpose the matrix to
|
||||
// a different format when it's copied out of the array. So we shouldn't put it in
|
||||
// a local variable (I think explicitly marking it as a vec4[4] works, but I'm not
|
||||
// sure whether it optimizes the same, and in any case the fact that there's a
|
||||
// format change suggests an actual wasteful copy is happening).
|
||||
mat4 normals_mat;
|
||||
};
|
||||
|
||||
@ -78,16 +84,14 @@ void main() {
|
||||
/* uint bone_idx = (v_ao_bone >> 2) & 0x3Fu; */
|
||||
uint bone_idx = (v_pos_norm >> 27) & 0xFu;
|
||||
|
||||
mat4 bone_mat = bones[bone_idx].bone_mat;
|
||||
mat4 normals_mat = bones[bone_idx].normals_mat;
|
||||
mat4 combined_mat = /*model_mat * */bone_mat;
|
||||
// mat4 combined_mat = model_mat * bone_mat;
|
||||
|
||||
vec3 pos = (vec3((uvec3(v_pos_norm) >> uvec3(0, 9, 18)) & uvec3(0x1FFu)) - 256.0) / 2.0;
|
||||
|
||||
// vec4 bone_pos = bones[bone_idx].bone_mat * vec4(pos, 1);
|
||||
|
||||
f_pos = (
|
||||
combined_mat *
|
||||
bones[bone_idx].bone_mat *
|
||||
vec4(pos, 1.0)
|
||||
).xyz + (model_pos - focus_off.xyz);
|
||||
|
||||
@ -110,7 +114,7 @@ void main() {
|
||||
// vec3 norm = normals[normal_idx];
|
||||
uint axis_idx = v_atlas_pos & 3u;
|
||||
|
||||
vec3 norm = normals_mat[axis_idx].xyz;
|
||||
vec3 norm = bones[bone_idx].normals_mat[axis_idx].xyz;
|
||||
// norm = normalize(norm);
|
||||
// vec3 norm = norm_mat * vec4(uvec3(1 << axis_idx) & uvec3(0x1u, 0x3u, 0x7u), 1);
|
||||
|
||||
|
@ -26,7 +26,8 @@
|
||||
*
|
||||
* */
|
||||
|
||||
layout(location = 1) in uint v_pos_norm;
|
||||
layout(location = 0) in uint v_pos_norm;
|
||||
// layout(location = 1) in uint v_atlas_pos;
|
||||
// in uint v_col_light;
|
||||
// in vec4 v_pos;
|
||||
|
||||
|
@ -222,16 +222,8 @@ impl FigurePipeline {
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: &[wgpu::ColorStateDescriptor {
|
||||
format: sc_desc.format,
|
||||
color_blend: wgpu::BlendDescriptor {
|
||||
src_factor: wgpu::BlendFactor::SrcAlpha,
|
||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||
operation: wgpu::BlendOperation::Add,
|
||||
},
|
||||
alpha_blend: wgpu::BlendDescriptor {
|
||||
src_factor: wgpu::BlendFactor::One,
|
||||
dst_factor: wgpu::BlendFactor::One,
|
||||
operation: wgpu::BlendOperation::Add,
|
||||
},
|
||||
color_blend: wgpu::BlendDescriptor::REPLACE,
|
||||
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
||||
write_mask: wgpu::ColorWrite::ALL,
|
||||
}],
|
||||
depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor {
|
||||
|
@ -321,7 +321,7 @@ impl PointShadowPipeline {
|
||||
})*/None,
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: wgpu::CullMode::Front,
|
||||
cull_mode: wgpu::CullMode::Back,
|
||||
polygon_mode: wgpu::PolygonMode::Fill,
|
||||
clamp_depth: false,
|
||||
depth_bias: 0,
|
||||
|
@ -204,8 +204,8 @@ impl<'a> Drawer<'a> {
|
||||
render_pass.set_push_constants(
|
||||
wgpu::ShaderStage::all(),
|
||||
0,
|
||||
&data[(6 * point_light * STRIDE + face as usize * STRIDE)
|
||||
..(6 * point_light * STRIDE + (face + 1) as usize * STRIDE)],
|
||||
&data[(6 * (point_light + 1) * STRIDE + face as usize * STRIDE)
|
||||
..(6 * (point_light + 1) * STRIDE + (face + 1) as usize * STRIDE)],
|
||||
);
|
||||
chunks.clone().for_each(|(model, locals)| {
|
||||
render_pass.set_bind_group(1, &locals.bind_group, &[]);
|
||||
|
@ -955,31 +955,28 @@ impl Scene {
|
||||
// Now, we tackle point lights.
|
||||
// First, create a perspective projection matrix at 90 degrees (to cover a whole
|
||||
// face of the cube map we're using).
|
||||
let shadow_proj = Mat4::perspective_lh_zo(
|
||||
let shadow_proj = Mat4::perspective_rh_zo(
|
||||
90.0f32.to_radians(),
|
||||
point_shadow_aspect,
|
||||
SHADOW_NEAR,
|
||||
SHADOW_FAR,
|
||||
);
|
||||
// NOTE: We negate here to emulate a right-handed projection with a negative
|
||||
// near plane, which produces the correct transformation to exactly match OpenGL's
|
||||
// rendering behavior if we use a left-handed coordinate system everywhere else.
|
||||
let shadow_proj = shadow_proj * Mat4::scaling_3d(-1.0);
|
||||
|
||||
// Next, construct the 6 orientations we'll use for the six faces, in terms of
|
||||
// their (forward, up) vectors.
|
||||
/* let orientations = [
|
||||
let orientations = [
|
||||
(Vec3::new(1.0, 0.0, 0.0), Vec3::new(0.0, -1.0, 0.0)),
|
||||
(Vec3::new(-1.0, 0.0, 0.0), Vec3::new(0.0, -1.0, 0.0)),
|
||||
(Vec3::new(0.0, 1.0, 0.0), Vec3::new(0.0, 0.0, 1.0)),
|
||||
(Vec3::new(0.0, -1.0, 0.0), Vec3::new(0.0, 0.0, -1.0)),
|
||||
(Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, -1.0, 0.0)),
|
||||
(Vec3::new(0.0, 0.0, -1.0), Vec3::new(0.0, -1.0, 0.0)),
|
||||
]; */
|
||||
|
||||
let orientations = [
|
||||
(Vec3::new(1.0, 0.0, 0.0), Vec3::new(0.0, 1.0, 0.0)),
|
||||
(Vec3::new(-1.0, 0.0, 0.0), Vec3::new(0.0, 1.0, 0.0)),
|
||||
(Vec3::new(0.0, 1.0, 0.0), Vec3::new(0.0, 0.0, -1.0)),
|
||||
(Vec3::new(0.0, -1.0, 0.0), Vec3::new(0.0, 0.0, 1.0)),
|
||||
(Vec3::new(0.0, 0.0, 1.0), Vec3::new(0.0, 1.0, 0.0)),
|
||||
(Vec3::new(0.0, 0.0, -1.0), Vec3::new(0.0, 1.0, 0.0)),
|
||||
];
|
||||
|
||||
// NOTE: We could create the shadow map collection at the same time as the
|
||||
// lights, but then we'd have to sort them both, which wastes time. Plus, we
|
||||
// want to prepend our directed lights.
|
||||
@ -987,8 +984,6 @@ impl Scene {
|
||||
// Now, construct the full projection matrix by making the light look at each
|
||||
// cube face.
|
||||
let mut eye = Vec3::new(light.pos[0], light.pos[1], light.pos[2]) - focus_off;
|
||||
// Draw using left-handed coordinates.
|
||||
eye.z = -eye.z;
|
||||
orientations.iter().map(move |&(forward, up)| {
|
||||
// NOTE: We don't currently try to linearize point lights or need a separate
|
||||
// transform for them.
|
||||
|
Loading…
Reference in New Issue
Block a user