mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fix sprite vertex lookup, normalize sprite
normals in vert shader
This commit is contained in:
parent
b85e9eae89
commit
d317a1a1cc
@ -96,4 +96,5 @@ void main() {
|
|||||||
surf_color += f_select * (surf_color + 0.1) * vec3(0.15, 0.15, 0.15);
|
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(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);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,6 @@ const float SCALE_FACTOR = pow(SCALE, 1.3) * 0.2;
|
|||||||
const int EXTRA_NEG_Z = 32768;
|
const int EXTRA_NEG_Z = 32768;
|
||||||
const int VERT_EXTRA_NEG_Z = 128;
|
const int VERT_EXTRA_NEG_Z = 128;
|
||||||
const int VERT_PAGE_SIZE = 256;
|
const int VERT_PAGE_SIZE = 256;
|
||||||
//const int VERT_PAGE_SIZE = 256;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// Matrix to transform this sprite instance from model space to chunk space
|
// 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);
|
f_inst_light = vec2(inst_light, inst_glow);
|
||||||
|
|
||||||
// Index of the vertex data in the 1D vertex texture
|
// Index of the vertex data in the 1D vertex texture
|
||||||
int vertex_index = int(gl_VertexIndex % VERT_PAGE_SIZE + inst_vert_page);
|
int vertex_index = int(gl_VertexIndex % VERT_PAGE_SIZE + inst_vert_page * VERT_PAGE_SIZE);
|
||||||
const int WIDTH = 16384; // TODO: temp
|
const int WIDTH = 8192; // TODO: temp
|
||||||
ivec2 tex_coords = ivec2(vertex_index % WIDTH, vertex_index / WIDTH);
|
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;
|
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;
|
uint v_pos_norm = pos_atlas_pos_norm_ao.x;
|
||||||
@ -98,7 +97,7 @@ void main() {
|
|||||||
|
|
||||||
// Determine normal
|
// Determine normal
|
||||||
vec3 norm = (inst_mat[(v_pos_norm >> 30u) & 3u].xyz);
|
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
|
// Expand atlas tex coords to floats
|
||||||
// NOTE: Could defer to fragment shader if we are vert heavy
|
// NOTE: Could defer to fragment shader if we are vert heavy
|
||||||
|
@ -11,7 +11,6 @@ use std::mem;
|
|||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
pub const VERT_PAGE_SIZE: u32 = 256;
|
pub const VERT_PAGE_SIZE: u32 = 256;
|
||||||
// pub const VERT_PAGE_SIZE: u32 = 256;
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Debug, Zeroable, Pod)]
|
#[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 {
|
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
|
// TODO: type buffer by Usage
|
||||||
/*Buffer::new(
|
/*Buffer::new(
|
||||||
&renderer.device,
|
&renderer.device,
|
||||||
@ -101,7 +100,7 @@ pub fn create_verts_texture(renderer: &mut Renderer, mut mesh: Mesh<Vertex>) ->
|
|||||||
let format = wgpu::TextureFormat::Rg32Uint;
|
let format = wgpu::TextureFormat::Rg32Uint;
|
||||||
|
|
||||||
// TODO: temp
|
// TODO: temp
|
||||||
const WIDTH: u32 = 16384;
|
const WIDTH: u32 = 8192;
|
||||||
let height = verts.len() as u32 / WIDTH;
|
let height = verts.len() as u32 / WIDTH;
|
||||||
// Fill in verts to full texture size
|
// Fill in verts to full texture size
|
||||||
verts.resize_with(height as usize * WIDTH as usize, Vertex::default);
|
verts.resize_with(height as usize * WIDTH as usize, Vertex::default);
|
||||||
|
@ -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>) {
|
pub fn set_scissor<'data: 'pass>(&mut self, scissor: Aabr<u16>) {
|
||||||
let Aabr { min, max } = scissor;
|
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(
|
self.render_pass.set_scissor_rect(
|
||||||
min.x as u32,
|
min.x as u32,
|
||||||
min.y as u32,
|
min.y as u32,
|
||||||
|
@ -14,6 +14,7 @@ use crate::{
|
|||||||
ColLightInfo, Consts, Drawer, FirstPassDrawer, FluidVertex, FluidWaves, GlobalModel,
|
ColLightInfo, Consts, Drawer, FirstPassDrawer, FluidVertex, FluidWaves, GlobalModel,
|
||||||
Instances, LodData, Mesh, Model, RenderError, Renderer, SpriteGlobalsBindGroup,
|
Instances, LodData, Mesh, Model, RenderError, Renderer, SpriteGlobalsBindGroup,
|
||||||
SpriteInstance, SpriteVertex, TerrainLocals, TerrainShadowDrawer, TerrainVertex, Texture,
|
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_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_LOD_LEVELS: usize = 5;
|
||||||
const SPRITE_VERT_PAGE_SIZE: usize = 256;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
struct Visibility {
|
struct Visibility {
|
||||||
@ -434,8 +434,8 @@ impl SpriteRenderContext {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get starting page count of opaque mesh
|
// Get starting page count of opaque mesh
|
||||||
let start_page_num =
|
let start_page_num = sprite_mesh.vertices().len()
|
||||||
sprite_mesh.vertices().len() / SPRITE_VERT_PAGE_SIZE;
|
/ SPRITE_VERT_PAGE_SIZE as usize;
|
||||||
// Mesh generation exclusively acts using side effects; it
|
// Mesh generation exclusively acts using side effects; it
|
||||||
// has no interesting return value, but updates the mesh.
|
// has no interesting return value, but updates the mesh.
|
||||||
generate_mesh_base_vol_sprite(
|
generate_mesh_base_vol_sprite(
|
||||||
@ -443,12 +443,13 @@ impl SpriteRenderContext {
|
|||||||
(greedy, sprite_mesh, false),
|
(greedy, sprite_mesh, false),
|
||||||
);
|
);
|
||||||
// Get the number of pages after the model was meshed
|
// Get the number of pages after the model was meshed
|
||||||
let end_page_num =
|
let end_page_num = (sprite_mesh.vertices().len()
|
||||||
(sprite_mesh.vertices().len() + SPRITE_VERT_PAGE_SIZE - 1)
|
+ SPRITE_VERT_PAGE_SIZE as usize
|
||||||
/ SPRITE_VERT_PAGE_SIZE;
|
- 1)
|
||||||
|
/ SPRITE_VERT_PAGE_SIZE as usize;
|
||||||
// Fill the current last page up with degenerate verts
|
// Fill the current last page up with degenerate verts
|
||||||
sprite_mesh.vertices_mut_vec().resize_with(
|
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,
|
SpriteVertex::default,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user