diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-24 16:01:11 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-24 16:01:11 +0100 |
commit | ce82f40bc4bd03963390d2c95ec688fccc4740b0 (patch) | |
tree | f00f4b1a525d70ebe7e5df38206c5b410ccee03d /client | |
parent | 3344eb2d678f9c5973c8e38083760254b54c20fc (diff) | |
download | weareserver-ce82f40bc4bd03963390d2c95ec688fccc4740b0.tar weareserver-ce82f40bc4bd03963390d2c95ec688fccc4740b0.tar.bz2 weareserver-ce82f40bc4bd03963390d2c95ec688fccc4740b0.tar.zst |
break things
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main.rs | 1 | ||||
-rw-r--r-- | client/src/render/mod.rs | 3 | ||||
-rw-r--r-- | client/src/render/scene/draw.rs | 6 | ||||
-rw-r--r-- | client/src/render/scene/mod.rs | 3 | ||||
-rw-r--r-- | client/src/render/scene/pipelines.rs | 20 | ||||
-rw-r--r-- | client/src/render/scene/textures.rs | 1 | ||||
-rw-r--r-- | client/src/scene_prepare.rs | 0 | ||||
-rw-r--r-- | client/src/shaders/fragment_pbr.wgsl | 11 | ||||
-rw-r--r-- | client/src/shaders/vertex_world.wgsl | 4 | ||||
-rw-r--r-- | client/src/shaders/vertex_world_skin.wgsl | 4 |
10 files changed, 40 insertions, 13 deletions
diff --git a/client/src/main.rs b/client/src/main.rs index 673a71f..4d696b7 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -22,7 +22,6 @@ pub mod download; pub mod interfaces; pub mod network; pub mod render; -pub mod scene_prepare; pub mod shaders; pub mod state; pub mod ui; diff --git a/client/src/render/mod.rs b/client/src/render/mod.rs index eb9e089..da0d7a8 100644 --- a/client/src/render/mod.rs +++ b/client/src/render/mod.rs @@ -76,7 +76,7 @@ impl<'a> Renderer<'a> { &DeviceDescriptor { required_features: Features::PUSH_CONSTANTS, required_limits: Limits { - max_push_constant_size: 112, + max_push_constant_size: 64 + 48 + 16, max_vertex_buffers: 16, ..Limits::default() }, @@ -212,6 +212,7 @@ impl<'a> Renderer<'a> { scene, &self.scene_prepare.prefabs, projection, + camera.position(), ); self.timing.checkpoint("draw ui"); diff --git a/client/src/render/scene/draw.rs b/client/src/render/scene/draw.rs index dabb9cd..672d7ef 100644 --- a/client/src/render/scene/draw.rs +++ b/client/src/render/scene/draw.rs @@ -15,7 +15,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ use super::{DemandMap, RPrefab}; -use glam::{EulerRot, Mat3, Mat4}; +use glam::{EulerRot, Mat3, Mat4, Vec3}; use std::sync::Arc; use weareshared::{packets::Resource, resources::Prefab, tree::SceneTree}; use wgpu::{ @@ -34,6 +34,7 @@ impl ScenePipeline { scene: &SceneTree, prefabs: &DemandMap<Resource<Prefab>, Arc<RPrefab>>, projection: Mat4, + camera_position: Vec3, ) { let mut rpass = commands.begin_render_pass(&RenderPassDescriptor { label: None, @@ -84,6 +85,8 @@ impl ScenePipeline { mb[6], mb[7], mb[8], 0., // ]; let model_basis = bytemuck::cast_slice(&model_basis); + let cp = &[camera_position.x, camera_position.y, camera_position.z, 0.]; + let camera_position = bytemuck::cast_slice(cp); rpass.set_pipeline(&part.pipeline); rpass.set_bind_group(0, &*part.tex_albedo, &[]); @@ -91,6 +94,7 @@ impl ScenePipeline { rpass.set_bind_group(2, &*part.material, &[]); rpass.set_push_constants(ShaderStages::VERTEX, 0, projection.as_flattened()); rpass.set_push_constants(ShaderStages::VERTEX, 64, model_basis); + rpass.set_push_constants(ShaderStages::VERTEX, 112, camera_position); rpass.set_index_buffer(part.index.slice(..), IndexFormat::Uint32); rpass.set_vertex_buffer(0, part.va_position.slice(..)); rpass.set_vertex_buffer(1, part.va_normal.slice(..)); diff --git a/client/src/render/scene/mod.rs b/client/src/render/scene/mod.rs index d83cb95..e314649 100644 --- a/client/src/render/scene/mod.rs +++ b/client/src/render/scene/mod.rs @@ -482,6 +482,7 @@ impl ScenePreparer { visit("textures", &self.textures); visit("materials", &self.materials); visit("pipelines", &self.pipelines); + visit("mip_generation_pipelines", &self.mip_generation_pipelines); } } @@ -512,6 +513,8 @@ impl Widget for &ScenePreparer { self.materials.ui(ui); ui.label("pipelines"); self.pipelines.ui(ui); + ui.label("mip_generation_pipelines"); + self.mip_generation_pipelines.ui(ui); }) .response } diff --git a/client/src/render/scene/pipelines.rs b/client/src/render/scene/pipelines.rs index 3b6758e..675cfae 100644 --- a/client/src/render/scene/pipelines.rs +++ b/client/src/render/scene/pipelines.rs @@ -99,12 +99,20 @@ impl PipelineSpec { let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor { label: None, bind_group_layouts: &[&layouts.texture, &layouts.texture, &layouts.material], - push_constant_ranges: &[PushConstantRange { - // 4x4 view projections - // 3x3(+1 pad) model basis - range: 0..((4 * 4 + 3 * 4) * size_of::<f32>() as u32), - stages: ShaderStages::VERTEX, - }], + push_constant_ranges: &[ + PushConstantRange { + // 4x4 view projections + // 3x3(+1 pad) model basis + // 3(+1 pad) camera position + range: 0..((4 * 4 + 3 * 4) * size_of::<f32>() as u32), + stages: ShaderStages::VERTEX, + }, + PushConstantRange { + range: ((4 * 4 + 3 * 4) * size_of::<f32>() as u32) + ..(4 * 4 + 3 * 4 + 4) * size_of::<f32>() as u32, + stages: ShaderStages::FRAGMENT, + }, + ], }); device.create_render_pipeline(&RenderPipelineDescriptor { label: None, diff --git a/client/src/render/scene/textures.rs b/client/src/render/scene/textures.rs index 0a042bd..463e8f1 100644 --- a/client/src/render/scene/textures.rs +++ b/client/src/render/scene/textures.rs @@ -229,6 +229,7 @@ fn create_texture( // texture.as_image_copy(), // extent, // ); + queue.write_texture( texture.as_image_copy(), data, diff --git a/client/src/scene_prepare.rs b/client/src/scene_prepare.rs deleted file mode 100644 index e69de29..0000000 --- a/client/src/scene_prepare.rs +++ /dev/null diff --git a/client/src/shaders/fragment_pbr.wgsl b/client/src/shaders/fragment_pbr.wgsl index f3ed37e..f3387a1 100644 --- a/client/src/shaders/fragment_pbr.wgsl +++ b/client/src/shaders/fragment_pbr.wgsl @@ -17,7 +17,8 @@ struct VertexOut { @builtin(position) clip: vec4<f32>, @location(0) normal: vec3<f32>, @location(1) tangent: vec3<f32>, - @location(2) texcoord: vec2<f32>, + @location(2) view: vec3<f32>, + @location(3) texcoord: vec2<f32>, } struct Material { @@ -44,9 +45,15 @@ fn main(vo: VertexOut) -> @location(0) vec4<f32> { let normal = tangent_basis * (t_normal.rgb * 2. - 1.); let alpha = t_albedo.a; - let lighting = mix(1., saturate(dot(LIGHT, normal)), 0.9); + + let ambient = 0.1; + let diffuse = saturate(dot(LIGHT, normal)); + let specular = pow(dot(reflect(-LIGHT, normal), vo.view), material.roughness); + + let lighting = ambient + diffuse; // + specular; let color = t_albedo.rgb * lighting; + // let color = vec3(dot(normalize(vo.normal), normalize(vo.view)) * 0.5 + 0.5) ; // TODO better (and faster?) randomness for alpha dither if fract(dot(sin(vo.clip * 123.) * 1213., vec4(3., 2., 1., 4.))) > alpha { diff --git a/client/src/shaders/vertex_world.wgsl b/client/src/shaders/vertex_world.wgsl index 5d69acd..d7bf445 100644 --- a/client/src/shaders/vertex_world.wgsl +++ b/client/src/shaders/vertex_world.wgsl @@ -23,7 +23,8 @@ struct VertexOut { @builtin(position) clip: vec4<f32>, @location(0) normal: vec3<f32>, @location(1) tangent: vec3<f32>, - @location(2) texcoord: vec2<f32>, + @location(2) world: vec3<f32>, + @location(3) texcoord: vec2<f32>, } struct PushConst { @@ -40,6 +41,7 @@ fn main(vi: VertexIn) -> VertexOut { clip, normalize(pc.model_basis * vi.normal), normalize(pc.model_basis * vi.tangent), + vi.position vi.texcoord ); return vo; diff --git a/client/src/shaders/vertex_world_skin.wgsl b/client/src/shaders/vertex_world_skin.wgsl index 288950d..4b45a6f 100644 --- a/client/src/shaders/vertex_world_skin.wgsl +++ b/client/src/shaders/vertex_world_skin.wgsl @@ -25,7 +25,8 @@ struct VertexOut { @builtin(position) clip: vec4<f32>, @location(0) normal: vec3<f32>, @location(1) tangent: vec3<f32>, - @location(2) texcoord: vec2<f32>, + @location(2) world: vec3<f32>, + @location(3) texcoord: vec2<f32>, } struct PushConst { @@ -43,6 +44,7 @@ fn main(vi: VertexIn) -> VertexOut { clip, normalize(pc.model_basis * vi.normal), normalize(pc.model_basis * vi.tangent), + vi.position, vi.texcoord ); return vo; |