mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Addressed review comments
This commit is contained in:
parent
8e03f87881
commit
a634da2d07
@ -1,5 +1,8 @@
|
||||
#ifndef SRGB_GLSL
|
||||
#define SRGB_GLSL
|
||||
|
||||
#extension GL_EXT_samplerless_texture_functions : enable
|
||||
|
||||
// Linear RGB, attenuation coefficients for water at roughly R, G, B wavelengths.
|
||||
// See https://en.wikipedia.org/wiki/Electromagnetic_absorption_by_water
|
||||
const vec3 MU_WATER = vec3(0.6, 0.04, 0.01);
|
||||
@ -653,12 +656,12 @@ vec3 greedy_extract_col_light_attr(texture2D t_col_light, sampler s_col_light, v
|
||||
|
||||
vec3 greedy_extract_col_light_kind_terrain(
|
||||
texture2D t_col_light, sampler s_col_light,
|
||||
texture2D t_kind, sampler s_kind,
|
||||
utexture2D t_kind,
|
||||
vec2 f_uv_pos,
|
||||
out float f_light, out float f_glow, out float f_ao, out float f_sky_exposure, out uint f_kind
|
||||
) {
|
||||
float _f_attr;
|
||||
f_kind = uint(texelFetch(sampler2D(t_kind, s_kind), ivec2(f_uv_pos), 0).r * 256);
|
||||
f_kind = uint(texelFetch(t_kind, ivec2(f_uv_pos), 0).r);
|
||||
return greedy_extract_col_light_attr(t_col_light, s_col_light, f_uv_pos, f_light, f_glow, f_ao, _f_attr, f_sky_exposure);
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ uniform texture2D t_col_light;
|
||||
layout(set = 2, binding = 1)
|
||||
uniform sampler s_col_light;
|
||||
layout(set = 2, binding = 2)
|
||||
uniform texture2D t_kind;
|
||||
uniform utexture2D t_kind;
|
||||
layout(set = 2, binding = 3)
|
||||
uniform sampler s_kind;
|
||||
|
||||
@ -91,7 +91,7 @@ void main() {
|
||||
// float f_light = textureProj(t_col_light, vec3(f_uv_pos + 0.5, textureSize(t_col_light, 0))).a;//1.0;//f_col_light.a * 4.0;// f_light = float(v_col_light & 0x3Fu) / 64.0;
|
||||
float f_light, f_glow, f_ao, f_sky_exposure;
|
||||
uint f_kind;
|
||||
vec3 f_col = greedy_extract_col_light_kind_terrain(t_col_light, s_col_light, t_kind, s_kind, f_uv_pos, f_light, f_glow, f_ao, f_sky_exposure, f_kind);
|
||||
vec3 f_col = greedy_extract_col_light_kind_terrain(t_col_light, s_col_light, t_kind, f_uv_pos, f_light, f_glow, f_ao, f_sky_exposure, f_kind);
|
||||
|
||||
#ifdef EXPERIMENTAL_BAREMINIMUM
|
||||
tgt_color = vec4(simple_lighting(f_pos.xyz, f_col, f_light), 1);
|
||||
|
@ -625,9 +625,9 @@ impl GlobalsLayouts {
|
||||
|
||||
Self {
|
||||
globals,
|
||||
shadow_textures,
|
||||
terrain_atlas_layout: VoxelAtlasLayout::new(device),
|
||||
figure_sprite_atlas_layout: VoxelAtlasLayout::new(device),
|
||||
terrain_atlas_layout: VoxelAtlasLayout::new(device),
|
||||
shadow_textures,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ impl AtlasData for TerrainAtlasData {
|
||||
wgpu::TextureFormat::Rgba8Unorm,
|
||||
bytemuck::cast_slice(&self.col_lights),
|
||||
),
|
||||
(wgpu::TextureFormat::R8Unorm, &self.kinds),
|
||||
(wgpu::TextureFormat::R8Uint, &self.kinds),
|
||||
]
|
||||
}
|
||||
|
||||
@ -365,7 +365,7 @@ impl AtlasData for TerrainAtlasData {
|
||||
binding: 2,
|
||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::Texture {
|
||||
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
||||
sample_type: wgpu::TextureSampleType::Uint,
|
||||
view_dimension: wgpu::TextureViewDimension::D2,
|
||||
multisampled: false,
|
||||
},
|
||||
@ -375,7 +375,7 @@ impl AtlasData for TerrainAtlasData {
|
||||
binding: 3,
|
||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::Sampler {
|
||||
filtering: true,
|
||||
filtering: false,
|
||||
comparison: false,
|
||||
},
|
||||
count: None,
|
||||
|
@ -1393,8 +1393,6 @@ impl Renderer {
|
||||
}
|
||||
|
||||
/// Create a new texture from the provided image.
|
||||
///
|
||||
/// Currently only supports Rgba8Srgb
|
||||
pub fn create_texture(
|
||||
&mut self,
|
||||
image: &image::DynamicImage,
|
||||
@ -1410,17 +1408,12 @@ impl Renderer {
|
||||
)
|
||||
}
|
||||
|
||||
/// Create a new dynamic texture with the
|
||||
/// specified dimensions.
|
||||
///
|
||||
/// Currently only supports Rgba8Srgb
|
||||
/// Create a new dynamic texture with the specified dimensions.
|
||||
pub fn create_dynamic_texture(&mut self, dims: Vec2<u32>) -> Texture {
|
||||
Texture::new_dynamic(&self.device, &self.queue, dims.x, dims.y)
|
||||
}
|
||||
|
||||
/// Update a texture with the provided offset, size, and data.
|
||||
///
|
||||
/// Currently only supports Rgba8Srgb
|
||||
pub fn update_texture<T: bytemuck::Pod>(
|
||||
&mut self,
|
||||
texture: &Texture,
|
||||
|
@ -374,7 +374,7 @@ where
|
||||
let alive = *last_used + delta > tick;
|
||||
if !alive {
|
||||
if let Some(model_entry) = model_entry.get_done() {
|
||||
atlas.atlas.deallocate(model_entry.allocation().id);
|
||||
atlas.allocator.deallocate(model_entry.allocation().id);
|
||||
}
|
||||
}
|
||||
alive
|
||||
|
@ -579,7 +579,7 @@ impl FigureMgr {
|
||||
span!(_guard, "clean", "FigureManager::clean");
|
||||
|
||||
if self.any_watcher_reloaded() {
|
||||
self.atlas.atlas.clear();
|
||||
self.atlas.allocator.clear();
|
||||
|
||||
self.model_cache.clear_models();
|
||||
self.theropod_model_cache.clear_models();
|
||||
@ -7252,15 +7252,16 @@ impl FigureMgr {
|
||||
}
|
||||
|
||||
pub struct FigureAtlas {
|
||||
atlas: AtlasAllocator,
|
||||
allocator: AtlasAllocator,
|
||||
// atlas_texture: Texture<ColLightFmt>,
|
||||
}
|
||||
|
||||
impl FigureAtlas {
|
||||
pub fn new(renderer: &mut Renderer) -> Self {
|
||||
let atlas = Self::make_atlas(renderer).expect("Failed to create texture atlas for figures");
|
||||
let allocator =
|
||||
Self::make_allocator(renderer).expect("Failed to create texture atlas for figures");
|
||||
Self {
|
||||
atlas, /* atlas_texture, */
|
||||
allocator, /* atlas_texture, */
|
||||
}
|
||||
}
|
||||
|
||||
@ -7290,8 +7291,8 @@ impl FigureAtlas {
|
||||
vertex_ranges: [Range<u32>; N],
|
||||
) -> FigureModelEntry<N> {
|
||||
span!(_guard, "create_figure", "FigureColLights::create_figure");
|
||||
let atlas = &mut self.atlas;
|
||||
let allocation = atlas
|
||||
let allocator = &mut self.allocator;
|
||||
let allocation = allocator
|
||||
.allocate(guillotiere::Size::new(
|
||||
atlas_size.x as i32,
|
||||
atlas_size.y as i32,
|
||||
@ -7343,8 +7344,8 @@ impl FigureAtlas {
|
||||
blocks_offset: Vec3<f32>,
|
||||
) -> TerrainModelEntry<N> {
|
||||
span!(_guard, "create_figure", "FigureColLights::create_figure");
|
||||
let atlas = &mut self.atlas;
|
||||
let allocation = atlas
|
||||
let allocator = &mut self.allocator;
|
||||
let allocation = allocator
|
||||
.allocate(guillotiere::Size::new(
|
||||
atlas_size.x as i32,
|
||||
atlas_size.y as i32,
|
||||
@ -7382,10 +7383,10 @@ impl FigureAtlas {
|
||||
}
|
||||
}
|
||||
|
||||
fn make_atlas(renderer: &mut Renderer) -> Result<AtlasAllocator, RenderError> {
|
||||
fn make_allocator(renderer: &mut Renderer) -> Result<AtlasAllocator, RenderError> {
|
||||
let max_texture_size = renderer.max_texture_size();
|
||||
let atlas_size = guillotiere::Size::new(max_texture_size as i32, max_texture_size as i32);
|
||||
let atlas = AtlasAllocator::with_options(atlas_size, &guillotiere::AllocatorOptions {
|
||||
let allocator = AtlasAllocator::with_options(atlas_size, &guillotiere::AllocatorOptions {
|
||||
// TODO: Verify some good empirical constants.
|
||||
small_size_threshold: 32,
|
||||
large_size_threshold: 256,
|
||||
@ -7412,7 +7413,7 @@ impl FigureAtlas {
|
||||
),
|
||||
)?;
|
||||
Ok((atlas, texture)) */
|
||||
Ok(atlas)
|
||||
Ok(allocator)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -758,47 +758,44 @@ impl<V: RectRasterableVol> Terrain<V> {
|
||||
large_size_threshold: 1024,
|
||||
..guillotiere::AllocatorOptions::default()
|
||||
});
|
||||
let [col_lights, kinds] = [
|
||||
wgpu::TextureFormat::Rgba8Unorm,
|
||||
wgpu::TextureFormat::R8Unorm,
|
||||
]
|
||||
.map(|fmt| {
|
||||
renderer.create_texture_raw(
|
||||
&wgpu::TextureDescriptor {
|
||||
label: Some("Terrain atlas texture"),
|
||||
size: wgpu::Extent3d {
|
||||
width: max_texture_size,
|
||||
height: max_texture_size,
|
||||
depth_or_array_layers: 1,
|
||||
let [col_lights, kinds] = [wgpu::TextureFormat::Rgba8Unorm, wgpu::TextureFormat::R8Uint]
|
||||
.map(|fmt| {
|
||||
renderer.create_texture_raw(
|
||||
&wgpu::TextureDescriptor {
|
||||
label: Some("Terrain atlas texture"),
|
||||
size: wgpu::Extent3d {
|
||||
width: max_texture_size,
|
||||
height: max_texture_size,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: fmt,
|
||||
usage: wgpu::TextureUsage::COPY_DST | wgpu::TextureUsage::SAMPLED,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: fmt,
|
||||
usage: wgpu::TextureUsage::COPY_DST | wgpu::TextureUsage::SAMPLED,
|
||||
},
|
||||
&wgpu::TextureViewDescriptor {
|
||||
label: Some("Terrain atlas texture view"),
|
||||
format: Some(fmt),
|
||||
dimension: Some(wgpu::TextureViewDimension::D2),
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
base_mip_level: 0,
|
||||
mip_level_count: None,
|
||||
base_array_layer: 0,
|
||||
array_layer_count: None,
|
||||
},
|
||||
&wgpu::SamplerDescriptor {
|
||||
label: Some("Terrain atlas texture sampler"),
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Linear,
|
||||
min_filter: wgpu::FilterMode::Linear,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
});
|
||||
&wgpu::TextureViewDescriptor {
|
||||
label: Some("Terrain atlas texture view"),
|
||||
format: Some(fmt),
|
||||
dimension: Some(wgpu::TextureViewDimension::D2),
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
base_mip_level: 0,
|
||||
mip_level_count: None,
|
||||
base_array_layer: 0,
|
||||
array_layer_count: None,
|
||||
},
|
||||
&wgpu::SamplerDescriptor {
|
||||
label: Some("Terrain atlas texture sampler"),
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Nearest,
|
||||
min_filter: wgpu::FilterMode::Nearest,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
});
|
||||
let textures = renderer.terrain_bind_atlas_textures(col_lights, kinds);
|
||||
Ok((atlas, textures))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user