From 0d05536ab66052af0dfc153e966c82b4e6d27075 Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Mon, 30 May 2022 18:27:52 +0200 Subject: Debug-renderer: add rendering of contacts, solver contacts, and collider AABBs --- src_testbed/lines/debuglines.wgsl | 8 ++++++-- src_testbed/lines/debuglines2d.wgsl | 9 +++++---- src_testbed/lines/mod.rs | 11 ++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src_testbed/lines') diff --git a/src_testbed/lines/debuglines.wgsl b/src_testbed/lines/debuglines.wgsl index 0987839..364d9ac 100644 --- a/src_testbed/lines/debuglines.wgsl +++ b/src_testbed/lines/debuglines.wgsl @@ -25,9 +25,13 @@ struct FragmentOutput { fn vertex(vertex: Vertex) -> VertexOutput { var out: VertexOutput; out.clip_position = view.view_proj * vec4(vertex.pos, 1.0); - //out.color = vertex.color; // https://github.com/bevyengine/bevy/blob/328c26d02c50de0bc77f0d24a376f43ba89517b1/examples/2d/mesh2d_manual.rs#L234 - out.color = vec4((vec4(vertex.color) >> vec4(8u, 8u, 16u, 24u)) & vec4(255u)) / 255.0; + // ... except the above doesn't seem to work in 3d. Not sure what's going on there. + var r = f32(vertex.color & 255u) / 255.0; + var g = f32(vertex.color >> 8u & 255u) / 255.0; + var b = f32(vertex.color >> 16u & 255u) / 255.0; + var a = f32(vertex.color >> 24u & 255u) / 255.0; + out.color = vec4(r, g, b, a); return out; } diff --git a/src_testbed/lines/debuglines2d.wgsl b/src_testbed/lines/debuglines2d.wgsl index 9316531..b722d8a 100644 --- a/src_testbed/lines/debuglines2d.wgsl +++ b/src_testbed/lines/debuglines2d.wgsl @@ -17,10 +17,11 @@ struct VertexOutput { fn vertex(vertex: Vertex) -> VertexOutput { var out: VertexOutput; out.clip_position = view.view_proj * vec4(vertex.place, 1.0); - // What is this craziness? - out.color = vec4((vec4(vertex.color) >> vec4(0u, 8u, 16u, 24u)) & vec4(255u)) / 255.0; - //out.color = vertex.color; - //out.color = vec4(1.0, 0.0, 0.0, 1.0); + var r = f32(vertex.color & 255u) / 255.0; + var g = f32(vertex.color >> 8u & 255u) / 255.0; + var b = f32(vertex.color >> 16u & 255u) / 255.0; + var a = f32(vertex.color >> 24u & 255u) / 255.0; + out.color = vec4(r, g, b, a); return out; } diff --git a/src_testbed/lines/mod.rs b/src_testbed/lines/mod.rs index 7e78ee9..a7dd7bb 100644 --- a/src_testbed/lines/mod.rs +++ b/src_testbed/lines/mod.rs @@ -1,4 +1,5 @@ #![allow(warnings)] +use bevy::render::view::NoFrustumCulling; /** * * NOTE: this module and its submodules are only temporary. It is a copy-paste of the bevy-debug-lines @@ -33,7 +34,7 @@ mod render_dim; // gates-specific code. #[cfg(feature = "dim3")] mod dim { - pub(crate) use crate::lines::render_dim::r3d::{queue, DebugLinePipeline, DrawDebugLines}; + pub(crate) use super::render_dim::r3d::{queue, DebugLinePipeline, DrawDebugLines}; pub(crate) use bevy::core_pipeline::Opaque3d as Phase; use bevy::{asset::Handle, render::mesh::Mesh}; @@ -49,7 +50,7 @@ mod dim { } #[cfg(feature = "dim2")] mod dim { - pub(crate) use crate::lines::render_dim::r2d::{queue, DebugLinePipeline, DrawDebugLines}; + pub(crate) use super::render_dim::r2d::{queue, DebugLinePipeline, DrawDebugLines}; pub(crate) use bevy::core_pipeline::Transparent2d as Phase; use bevy::{asset::Handle, render::mesh::Mesh, sprite::Mesh2dHandle}; @@ -172,6 +173,7 @@ fn setup(mut cmds: Commands, mut meshes: ResMut>) { dim::into_handle(meshes.add(mesh)), NotShadowCaster, NotShadowReceiver, + NoFrustumCulling, Transform::default(), GlobalTransform::default(), Visibility::default(), @@ -190,7 +192,7 @@ fn update( // For each debug line mesh, fill its buffers with the relevant positions/colors chunks. for (mesh_handle, debug_lines_idx) in debug_line_meshes.iter() { let mesh = meshes.get_mut(dim::from_handle(mesh_handle)).unwrap(); - use VertexAttributeValues::{Float32x3, Float32x4, Uint32}; + use VertexAttributeValues::{Float32x3, Uint32}; if let Some(Float32x3(vbuffer)) = mesh.attribute_mut(Mesh::ATTRIBUTE_POSITION) { vbuffer.clear(); if let Some(new_content) = lines @@ -238,7 +240,7 @@ fn extract(mut commands: Commands, query: Query>) { } #[derive(Component)] -struct DebugLinesMesh(usize); +pub(crate) struct DebugLinesMesh(usize); #[derive(Component)] pub(crate) struct RenderDebugLinesMesh; @@ -320,7 +322,6 @@ impl DebugLines { end_color: Color, ) { if self.positions.len() >= MAX_POINTS { - warn!("Tried to add a new line when existing number of lines was already at maximum, ignoring."); return; } -- cgit