diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-07 18:13:42 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-07 18:13:42 +0100 |
commit | d3e2f02f5f75afb6d6c62e77577452224e4a34a4 (patch) | |
tree | 6a180eeb4c3f70f5f122325a590d1ac098a11f23 | |
parent | 4032ef64aa33f616a2009ad1e6270cdf646242e7 (diff) | |
download | weareserver-d3e2f02f5f75afb6d6c62e77577452224e4a34a4.tar weareserver-d3e2f02f5f75afb6d6c62e77577452224e4a34a4.tar.bz2 weareserver-d3e2f02f5f75afb6d6c62e77577452224e4a34a4.tar.zst |
emission
-rw-r--r-- | a.md | 3 | ||||
-rw-r--r-- | shared/src/resources.rs | 9 | ||||
-rw-r--r-- | world/src/main.rs | 27 |
3 files changed, 38 insertions, 1 deletions
@@ -54,6 +54,7 @@ except normals are zero. | g_roughness | f32 | | | g_albedo | \[f32;3\] | | | g_transmission | f32 | | +| g_emission | \[f32;3\] | | | va_position | [Resource; 3] | | | va_normal | [Resource; 3] | | | va_texcoord | [Resource; 2] | | @@ -61,11 +62,13 @@ except normals are zero. | va_metallic | Resource | | | va_albedo | [Resource; 3] | | | va_transmission | Resource | | +| va_emission | Resource | | | tex_normal | Resource | Use color channels | | tex_roughness | Resource | Use green channel | | tex_metallic | Resource | Use blue channel | | tex_albedo | Resource | Use color channels | | tex_transmission | Resource | Use alpha channel | +| tex_emission | Resource | Use color channels | ### Texture diff --git a/shared/src/resources.rs b/shared/src/resources.rs index c312531..5b2e852 100644 --- a/shared/src/resources.rs +++ b/shared/src/resources.rs @@ -17,6 +17,7 @@ pub struct Part { pub g_roughness: Option<f32>, pub g_albedo: Option<Vec3A>, pub g_transmission: Option<f32>, + pub g_emission: Option<Vec3A>, pub va_position: Option<[Resource; 3]>, pub va_normal: Option<[Resource; 3]>, pub va_texcoord: Option<[Resource; 2]>, @@ -24,11 +25,13 @@ pub struct Part { pub va_metallic: Option<Resource>, pub va_albedo: Option<[Resource; 3]>, pub va_transmission: Option<Resource>, + pub va_emission: Option<[Resource; 3]>, pub tex_normal: Option<Resource>, pub tex_roughness: Option<Resource>, pub tex_metallic: Option<Resource>, pub tex_albedo: Option<Resource>, pub tex_transmission: Option<Resource>, + pub tex_emission: Option<Resource>, } pub struct PrefabIndex(pub HashMap<String, Resource>); @@ -118,6 +121,7 @@ impl ReadWrite for Part { write_kv_opt(w, b"g_roughness", &self.g_roughness)?; write_kv_opt(w, b"g_albedo", &self.g_albedo)?; write_kv_opt(w, b"g_transmission", &self.g_transmission)?; + write_kv_opt(w, b"g_emission", &self.g_emission)?; write_kv_opt(w, b"va_position", &self.va_position)?; write_kv_opt(w, b"va_normal", &self.va_normal)?; write_kv_opt(w, b"va_texcoord", &self.va_texcoord)?; @@ -125,11 +129,13 @@ impl ReadWrite for Part { write_kv_opt(w, b"va_metallic", &self.va_metallic)?; write_kv_opt(w, b"va_albedo", &self.va_albedo)?; write_kv_opt(w, b"va_transmission", &self.va_transmission)?; + write_kv_opt(w, b"va_emission", &self.va_emission)?; write_kv_opt(w, b"tex_normal", &self.tex_normal)?; write_kv_opt(w, b"tex_roughness", &self.tex_roughness)?; write_kv_opt(w, b"tex_metallic", &self.tex_metallic)?; write_kv_opt(w, b"tex_albedo", &self.tex_albedo)?; write_kv_opt(w, b"tex_transmission", &self.tex_transmission)?; + write_kv_opt(w, b"tex_emission", &self.tex_emission)?; Ok(()) } fn read(r: &mut dyn Read) -> Result<Self> { @@ -146,6 +152,7 @@ impl ReadWrite for Part { b"g_roughness" => s.g_roughness = Some(<_ as ReadWrite>::read(&mut v)?), b"g_albedo" => s.g_albedo = Some(<_ as ReadWrite>::read(&mut v)?), b"g_transmission" => s.g_transmission = Some(<_ as ReadWrite>::read(&mut v)?), + b"g_emission" => s.g_emission = Some(<_ as ReadWrite>::read(&mut v)?), b"va_position" => s.va_position = Some(<_ as ReadWrite>::read(&mut v)?), b"va_normal" => s.va_normal = Some(<_ as ReadWrite>::read(&mut v)?), b"va_texcoord" => s.va_texcoord = Some(<_ as ReadWrite>::read(&mut v)?), @@ -153,11 +160,13 @@ impl ReadWrite for Part { b"va_metallic" => s.va_metallic = Some(<_ as ReadWrite>::read(&mut v)?), b"va_albedo" => s.va_albedo = Some(<_ as ReadWrite>::read(&mut v)?), b"va_transmission" => s.va_transmission = Some(<_ as ReadWrite>::read(&mut v)?), + b"va_emission" => s.va_emission = Some(<_ as ReadWrite>::read(&mut v)?), b"tex_normal" => s.tex_normal = Some(<_ as ReadWrite>::read(&mut v)?), b"tex_roughness" => s.tex_roughness = Some(<_ as ReadWrite>::read(&mut v)?), b"tex_metallic" => s.tex_metallic = Some(<_ as ReadWrite>::read(&mut v)?), b"tex_albedo" => s.tex_albedo = Some(<_ as ReadWrite>::read(&mut v)?), b"tex_transmission" => s.tex_transmission = Some(<_ as ReadWrite>::read(&mut v)?), + b"tex_emission" => s.tex_emission = Some(<_ as ReadWrite>::read(&mut v)?), x => warn!("unknown part key: {:?}", String::from_utf8_lossy(x)), } } diff --git a/world/src/main.rs b/world/src/main.rs index 81d411e..2014996 100644 --- a/world/src/main.rs +++ b/world/src/main.rs @@ -177,6 +177,16 @@ fn main() -> Result<()> { &tex.texture().source().source(), )?); } + let mut tex_emission = None; + if let Some(tex) = p.material().emissive_texture() { + tex_emission = Some(load_texture( + "emission", + &store, + path_base, + &buffers, + &tex.texture().source().source(), + )?); + } let mut tex_roughness = None; let mut tex_metallic = None; if let Some(tex) = p @@ -203,7 +213,7 @@ fn main() -> Result<()> { let g_albedo = if base_color[0] != 1. || base_color[1] != 1. || base_color[2] != 1. { info!( - "global albedo is r={},g={},b={}", + "global albedo is r={},g={},b={}", base_color[0], base_color[1], base_color[2] ); Some(Vec3A::new(base_color[0], base_color[1], base_color[2])) @@ -219,12 +229,25 @@ fn main() -> Result<()> { None }; + let emission = p.material().emissive_factor(); + let g_emission = if emission[0] != 0. || emission[1] != 0. || emission[2] != 0. { + info!( + "global emission is r={},g={},b={}", + base_color[0], base_color[1], base_color[2] + ); + Some(Vec3A::new(emission[0], emission[1], emission[2])) + } else { + debug!("global emission pruned"); + None + }; + let part = store.set( &Part { g_albedo, g_transmission, g_metallic, g_roughness, + g_emission, va_position, va_normal, va_texcoord, @@ -235,7 +258,9 @@ fn main() -> Result<()> { tex_roughness, tex_metallic, tex_transmission, + tex_emission, index, + va_emission: None, // not supported by gltf va_metallic: None, // not supported by gltf va_roughness: None, // not supported by gltf } |