Fix sprite vertex lookup, normalize sprite

normals in vert shader
This commit is contained in:
Imbris 2021-02-05 22:28:02 -05:00
parent b85e9eae89
commit d317a1a1cc
5 changed files with 18 additions and 14 deletions

View File

@ -96,4 +96,5 @@ void main() {
surf_color += f_select * (surf_color + 0.1) * vec3(0.15, 0.15, 0.15);
tgt_color = vec4(surf_color, 1.0 - clamp((distance(focus_pos.xy, f_pos.xy) - (sprite_render_distance - FADE_DIST)) / FADE_DIST, 0, 1));
//tgt_color = vec4(-f_norm, 1.0);
}

View File

@ -53,7 +53,6 @@ const float SCALE_FACTOR = pow(SCALE, 1.3) * 0.2;
const int EXTRA_NEG_Z = 32768;
const int VERT_EXTRA_NEG_Z = 128;
const int VERT_PAGE_SIZE = 256;
//const int VERT_PAGE_SIZE = 256;
void main() {
// Matrix to transform this sprite instance from model space to chunk space
@ -69,8 +68,8 @@ void main() {
f_inst_light = vec2(inst_light, inst_glow);
// Index of the vertex data in the 1D vertex texture
int vertex_index = int(gl_VertexIndex % VERT_PAGE_SIZE + inst_vert_page);
const int WIDTH = 16384; // TODO: temp
int vertex_index = int(gl_VertexIndex % VERT_PAGE_SIZE + inst_vert_page * VERT_PAGE_SIZE);
const int WIDTH = 8192; // TODO: temp
ivec2 tex_coords = ivec2(vertex_index % WIDTH, vertex_index / WIDTH);
uvec2 pos_atlas_pos_norm_ao = texelFetch(usampler2D(t_sprite_verts, s_sprite_verts), tex_coords, 0).xy;
uint v_pos_norm = pos_atlas_pos_norm_ao.x;
@ -98,7 +97,7 @@ void main() {
// Determine normal
vec3 norm = (inst_mat[(v_pos_norm >> 30u) & 3u].xyz);
f_norm = mix(-norm, norm, v_pos_norm >> 29u & 1u);
f_norm = normalize(mix(-norm, norm, v_pos_norm >> 29u & 1u));
// Expand atlas tex coords to floats
// NOTE: Could defer to fragment shader if we are vert heavy

View File

@ -11,7 +11,6 @@ use std::mem;
use vek::*;
pub const VERT_PAGE_SIZE: u32 = 256;
// pub const VERT_PAGE_SIZE: u32 = 256;
#[repr(C)]
#[derive(Copy, Clone, Debug, Zeroable, Pod)]
@ -90,7 +89,7 @@ impl VertexTrait for Vertex {
}
pub fn create_verts_texture(renderer: &mut Renderer, mut mesh: Mesh<Vertex>) -> Texture {
//renderer.ensure_sufficient_index_length::<Vertex>(VERT_PAGE_SIZE as usize);
renderer.ensure_sufficient_index_length::<Vertex>(VERT_PAGE_SIZE as usize);
// TODO: type buffer by Usage
/*Buffer::new(
&renderer.device,
@ -101,7 +100,7 @@ pub fn create_verts_texture(renderer: &mut Renderer, mut mesh: Mesh<Vertex>) ->
let format = wgpu::TextureFormat::Rg32Uint;
// TODO: temp
const WIDTH: u32 = 16384;
const WIDTH: u32 = 8192;
let height = verts.len() as u32 / WIDTH;
// Fill in verts to full texture size
verts.resize_with(height as usize * WIDTH as usize, Vertex::default);

View File

@ -708,6 +708,10 @@ impl<'pass_ref, 'pass: 'pass_ref> PreparedUiDrawer<'pass_ref, 'pass> {
pub fn set_scissor<'data: 'pass>(&mut self, scissor: Aabr<u16>) {
let Aabr { min, max } = scissor;
// TODO: Got an invalid scissor panic from wgpu,
// use this if you can reproduce
// Note: might have been from changing monitors
// dbg!(&scissor)
self.render_pass.set_scissor_rect(
min.x as u32,
min.y as u32,

View File

@ -14,6 +14,7 @@ use crate::{
ColLightInfo, Consts, Drawer, FirstPassDrawer, FluidVertex, FluidWaves, GlobalModel,
Instances, LodData, Mesh, Model, RenderError, Renderer, SpriteGlobalsBindGroup,
SpriteInstance, SpriteVertex, TerrainLocals, TerrainShadowDrawer, TerrainVertex, Texture,
SPRITE_VERT_PAGE_SIZE,
},
};
@ -45,7 +46,6 @@ use vek::*;
const SPRITE_SCALE: Vec3<f32> = Vec3::new(1.0 / 11.0, 1.0 / 11.0, 1.0 / 11.0);
const SPRITE_LOD_LEVELS: usize = 5;
const SPRITE_VERT_PAGE_SIZE: usize = 256;
#[derive(Clone, Copy, Debug)]
struct Visibility {
@ -434,8 +434,8 @@ impl SpriteRenderContext {
};
// Get starting page count of opaque mesh
let start_page_num =
sprite_mesh.vertices().len() / SPRITE_VERT_PAGE_SIZE;
let start_page_num = sprite_mesh.vertices().len()
/ SPRITE_VERT_PAGE_SIZE as usize;
// Mesh generation exclusively acts using side effects; it
// has no interesting return value, but updates the mesh.
generate_mesh_base_vol_sprite(
@ -443,12 +443,13 @@ impl SpriteRenderContext {
(greedy, sprite_mesh, false),
);
// Get the number of pages after the model was meshed
let end_page_num =
(sprite_mesh.vertices().len() + SPRITE_VERT_PAGE_SIZE - 1)
/ SPRITE_VERT_PAGE_SIZE;
let end_page_num = (sprite_mesh.vertices().len()
+ SPRITE_VERT_PAGE_SIZE as usize
- 1)
/ SPRITE_VERT_PAGE_SIZE as usize;
// Fill the current last page up with degenerate verts
sprite_mesh.vertices_mut_vec().resize_with(
end_page_num * SPRITE_VERT_PAGE_SIZE,
end_page_num * SPRITE_VERT_PAGE_SIZE as usize,
SpriteVertex::default,
);