summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-19 16:55:16 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-19 16:55:16 +0100
commitf6fa92e62f0c5ec2150ae22fcfb54c7dc49e5d9b (patch)
tree10aea61d8666ba57b6bb4950571d4fe2803da9cc /client
parent2dd953715cd61ef66b0a9315ec8df68a37fe8885 (diff)
downloadweareserver-f6fa92e62f0c5ec2150ae22fcfb54c7dc49e5d9b.tar
weareserver-f6fa92e62f0c5ec2150ae22fcfb54c7dc49e5d9b.tar.bz2
weareserver-f6fa92e62f0c5ec2150ae22fcfb54c7dc49e5d9b.tar.zst
client: labels and linear normal maps
Diffstat (limited to 'client')
-rw-r--r--client/src/scene_prepare.rs47
1 files changed, 31 insertions, 16 deletions
diff --git a/client/src/scene_prepare.rs b/client/src/scene_prepare.rs
index 4cf6c87..ad0f5e4 100644
--- a/client/src/scene_prepare.rs
+++ b/client/src/scene_prepare.rs
@@ -88,7 +88,7 @@ pub struct ScenePreparer {
queue: Arc<Queue>,
texture_bgl: BindGroupLayout,
- textures: DemandMap<Resource<Image<'static>>, (Arc<Texture>, Arc<BindGroup>)>,
+ textures: DemandMap<(Resource<Image<'static>>, bool), (Arc<Texture>, Arc<BindGroup>)>,
placeholder_textures: DemandMap<TextureIdentityKind, (Arc<Texture>, Arc<BindGroup>)>,
index_buffers: DemandMap<Resource<Vec<[u32; 3]>>, (Arc<Buffer>, u32)>,
vertex_buffers: DemandMap<Resource<Vec<f32>>, Arc<Buffer>>,
@@ -174,8 +174,8 @@ impl ScenePreparer {
let start = Instant::now();
if let Some(buf) = dls.try_get(pres.clone())? {
let buffer = self.device.create_buffer_init(&BufferInitDescriptor {
+ label: Some("index"),
contents: bytemuck::cast_slice(buf.as_slice()),
- label: None,
usage: BufferUsages::INDEX | BufferUsages::COPY_DST,
});
self.index_buffers.insert(
@@ -196,7 +196,7 @@ impl ScenePreparer {
if let Some(buf) = dls.try_get(pres.clone())? {
let buffer = self.device.create_buffer_init(&BufferInitDescriptor {
contents: bytemuck::cast_slice(buf.as_slice()),
- label: None,
+ label: Some("vertex attribute"),
usage: BufferUsages::VERTEX | BufferUsages::COPY_DST,
});
self.vertex_buffers
@@ -209,7 +209,7 @@ impl ScenePreparer {
num_done += 1;
}
}
- for pres in self.textures.needed() {
+ for (pres, linear) in self.textures.needed() {
let start = Instant::now();
if let Some(buf) = dls.try_get(pres.clone())? {
let image = ImageReader::new(Cursor::new(buf.0)).with_guessed_format()?;
@@ -224,8 +224,10 @@ impl ScenePreparer {
&image,
dims.0,
dims.1,
+ linear,
);
- self.textures.insert(pres.clone(), tex_bg, image.len());
+ self.textures
+ .insert((pres.clone(), linear), tex_bg, image.len());
debug!(
"texture created (res={}x{}, took {:?})",
dims.0,
@@ -236,11 +238,19 @@ impl ScenePreparer {
}
}
for kind in self.placeholder_textures.needed() {
- let color = match kind {
- TextureIdentityKind::Normal => [128, 128, 255, 255],
- TextureIdentityKind::Multiply => [255, 255, 255, 255],
+ let (linear, color) = match kind {
+ TextureIdentityKind::Normal => (true, [128, 128, 255, 255]),
+ TextureIdentityKind::Multiply => (false, [255, 255, 255, 255]),
};
- let tex_bg = create_texture(&self.device, &self.queue, &self.texture_bgl, &color, 1, 1);
+ let tex_bg = create_texture(
+ &self.device,
+ &self.queue,
+ &self.texture_bgl,
+ &color,
+ 1,
+ 1,
+ linear,
+ );
self.placeholder_textures.insert(kind, tex_bg, 4);
num_done += 1;
}
@@ -252,7 +262,7 @@ impl ScenePreparer {
) {
let tangents = generate_tangents(&index, &position, &texcoord);
let buffer = self.device.create_buffer_init(&BufferInitDescriptor {
- label: None,
+ label: Some("generated tangent"),
usage: BufferUsages::COPY_DST | BufferUsages::VERTEX,
contents: bytemuck::cast_slice(tangents.as_slice()),
});
@@ -270,7 +280,7 @@ impl ScenePreparer {
) {
let normals = generate_normals(&index, &position);
let buffer = self.device.create_buffer_init(&BufferInitDescriptor {
- label: None,
+ label: Some("generated normal"),
usage: BufferUsages::COPY_DST | BufferUsages::VERTEX,
contents: bytemuck::cast_slice(normals.as_slice()),
});
@@ -288,7 +298,7 @@ impl ScenePreparer {
) {
let texcoords = generate_texcoords(&index, &position);
let buffer = self.device.create_buffer_init(&BufferInitDescriptor {
- label: None,
+ label: Some("generated texcoord"),
usage: BufferUsages::COPY_DST | BufferUsages::VERTEX,
contents: bytemuck::cast_slice(texcoords.as_slice()),
});
@@ -337,7 +347,7 @@ impl ScenePreparer {
let mut tex_albedo = None;
if let Some(albedores) = part.tex_albedo {
- if let Some((_tex, bg)) = self.textures.try_get(albedores) {
+ if let Some((_tex, bg)) = self.textures.try_get((albedores, false)) {
tex_albedo = Some(bg)
}
} else {
@@ -349,8 +359,8 @@ impl ScenePreparer {
}
}
let mut tex_normal = None;
- if let Some(albedores) = part.tex_normal {
- if let Some((_tex, bg)) = self.textures.try_get(albedores) {
+ if let Some(normalres) = part.tex_normal {
+ if let Some((_tex, bg)) = self.textures.try_get((normalres, true)) {
tex_normal = Some(bg)
}
} else {
@@ -406,6 +416,7 @@ fn create_texture(
data: &[u8],
width: u32,
height: u32,
+ linear: bool,
) -> (Arc<Texture>, Arc<BindGroup>) {
let texture = device.create_texture_with_data(
&queue,
@@ -419,7 +430,11 @@ fn create_texture(
mip_level_count: 1,
sample_count: 1,
dimension: TextureDimension::D2,
- format: TextureFormat::Rgba8UnormSrgb,
+ format: if linear {
+ TextureFormat::Rgba8Unorm
+ } else {
+ TextureFormat::Rgba8UnormSrgb
+ },
usage: TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST,
view_formats: &[],
},