Fix bugs with sprite rendering

This commit is contained in:
Imbris 2021-02-07 13:21:35 -05:00 committed by Avi Weinstock
parent 0933a87d84
commit bed1596985
3 changed files with 12 additions and 14 deletions

View File

@ -76,7 +76,7 @@ void main() {
uint v_atlas_pos = pos_atlas_pos_norm_ao.y;
// Expand the model vertex position bits into float values
vec3 v_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 8, 16)) & uvec3(0xFu, 0xFu, 0x0FFFu)) - ivec3(0, 0, VERT_EXTRA_NEG_Z));
vec3 v_pos = vec3(ivec3((uvec3(v_pos_norm) >> uvec3(0, 8, 16)) & uvec3(0xFFu, 0xFFu, 0x0FFFu)) - ivec3(0, 0, VERT_EXTRA_NEG_Z));
// Transform into chunk space and scale
f_pos = (inst_mat * vec4(v_pos, 1.0)).xyz;

View File

@ -269,7 +269,7 @@ impl SpriteLayout {
visibility: wgpu::ShaderStage::VERTEX,
ty: wgpu::BindingType::Texture {
sample_type: wgpu::TextureSampleType::Uint,
view_dimension: wgpu::TextureViewDimension::D1,
view_dimension: wgpu::TextureViewDimension::D2,
multisampled: false,
},
count: None,

View File

@ -247,23 +247,21 @@ fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug + '
let key = (sprite, variation);
// NOTE: Safe because we called sprite_config_for already.
// NOTE: Safe because 0 ≤ ori < 8
let sprite_data_lod_0 = &sprite_data[&key][0];
let mat = Mat4::identity()
// NOTE: offset doesn't change with lod level
// TODO: pull out of per lod level info or remove lod levels
// for sprites entirely
.translated_3d(sprite_data_lod_0.offset)
// Lod scaling etc is baked during meshing
.scaled_3d(SPRITE_SCALE)
.rotated_z(f32::consts::PI * 0.25 * ori as f32)
.translated_3d(
(rel_pos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0))
);
let light = light_map(wpos);
let glow = glow_map(wpos);
for lod_level in 0..SPRITE_LOD_LEVELS {
let sprite_data = &sprite_data[&key][lod_level];
let mat = Mat4::identity()
// Scaling for different LOD resolutions
.scaled_3d(sprite_data.scale)
// Offset
.translated_3d(sprite_data.offset)
.scaled_3d(SPRITE_SCALE)
.rotated_z(f32::consts::PI * 0.25 * ori as f32)
.translated_3d(
(rel_pos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0))
);
// Add an instance for each page in the sprite model
for page in sprite_data.vert_pages.clone() {
// TODO: could be more efficient to create once and clone while