it heccin borken
This commit is contained in:
62
src/nodes/drawable/line.wgsl
Normal file
62
src/nodes/drawable/line.wgsl
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#import bevy_pbr::{
|
||||||
|
pbr_fragment::pbr_input_from_standard_material,
|
||||||
|
pbr_functions::alpha_discard,
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PREPASS_PIPELINE
|
||||||
|
#import bevy_pbr::{
|
||||||
|
prepass_io::{VertexOutput, FragmentOutput},
|
||||||
|
pbr_deferred_functions::deferred_output,
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#import bevy_pbr::{
|
||||||
|
forward_io::{VertexOutput, FragmentOutput},
|
||||||
|
pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing},
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct MyExtendedMaterial {
|
||||||
|
quantize_steps: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
@group(2) @binding(100)
|
||||||
|
var<uniform> my_extended_material: MyExtendedMaterial;
|
||||||
|
|
||||||
|
@fragment
|
||||||
|
fn fragment(
|
||||||
|
in: VertexOutput,
|
||||||
|
@builtin(front_facing) is_front: bool,
|
||||||
|
) -> FragmentOutput {
|
||||||
|
#ifdef VERTEX_COLORS
|
||||||
|
var out: FragmentOutput;
|
||||||
|
// apply lighting
|
||||||
|
out.color = in.color;
|
||||||
|
return out;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// generate a PbrInput struct from the StandardMaterial bindings
|
||||||
|
var pbr_input = pbr_input_from_standard_material(in, is_front);
|
||||||
|
|
||||||
|
#ifdef VERTEX_COLORS
|
||||||
|
// Multiply emissive color by vertex color
|
||||||
|
pbr_input.material.emissive.rgb *= in.color.rgb;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// alpha discard
|
||||||
|
pbr_input.material.base_color = alpha_discard(pbr_input.material, pbr_input.material.base_color);
|
||||||
|
|
||||||
|
#ifdef PREPASS_PIPELINE
|
||||||
|
// in deferred mode we can't modify anything after that, as lighting is run in a separate fullscreen shader.
|
||||||
|
let out = deferred_output(in, pbr_input);
|
||||||
|
#else
|
||||||
|
var out: FragmentOutput;
|
||||||
|
// apply lighting
|
||||||
|
out.color = apply_pbr_lighting(pbr_input);
|
||||||
|
|
||||||
|
// apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr)
|
||||||
|
// note this does not include fullscreen postprocessing effects like bloom.
|
||||||
|
out.color = main_pass_post_lighting_processing(pbr_input, out.color);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
@@ -11,11 +11,13 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use bevy::{
|
use bevy::{
|
||||||
asset::RenderAssetUsages,
|
asset::{RenderAssetUsages, weak_handle},
|
||||||
|
pbr::{ExtendedMaterial, MaterialExtension},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
render::{
|
render::{
|
||||||
mesh::{Indices, MeshAabb, PrimitiveTopology},
|
mesh::{Indices, MeshAabb, PrimitiveTopology},
|
||||||
primitives::Aabb,
|
primitives::Aabb,
|
||||||
|
render_resource::{AsBindGroup, ShaderRef},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use glam::Vec3;
|
use glam::Vec3;
|
||||||
@@ -25,18 +27,74 @@ use std::sync::{
|
|||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct LinesNodePlugin;
|
type LineMaterial = ExtendedMaterial<BevyMaterial, LineExtension>;
|
||||||
|
const LINE_SHADER_HANDLE: Handle<Shader> = weak_handle!("7d28aa5a-3abd-43bb-b0e9-0de8b81b650d");
|
||||||
|
// No extra data needed for a simple holdout
|
||||||
|
#[derive(Default, Asset, AsBindGroup, TypePath, Debug, Clone)]
|
||||||
|
pub struct LineExtension {
|
||||||
|
#[uniform(100)]
|
||||||
|
unused: u32,
|
||||||
|
}
|
||||||
|
impl MaterialExtension for LineExtension {
|
||||||
|
fn fragment_shader() -> ShaderRef {
|
||||||
|
LINE_SHADER_HANDLE.into()
|
||||||
|
}
|
||||||
|
|
||||||
impl Plugin for LinesNodePlugin {
|
fn prepass_fragment_shader() -> ShaderRef {
|
||||||
fn build(&self, app: &mut App) {
|
LINE_SHADER_HANDLE.into()
|
||||||
app.add_systems(Update, build_line_mesh);
|
}
|
||||||
|
|
||||||
|
fn alpha_mode() -> Option<AlphaMode> {
|
||||||
|
Some(AlphaMode::Opaque)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_line_mesh(
|
pub struct LinesNodePlugin;
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
impl Plugin for LinesNodePlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_systems(Startup, test_cube);
|
||||||
|
app.add_systems(Update, build_line_mesh);
|
||||||
|
app.world_mut().resource_mut::<Assets<Shader>>().insert(
|
||||||
|
LINE_SHADER_HANDLE.id(),
|
||||||
|
Shader::from_wgsl(
|
||||||
|
include_str!("line.wgsl"),
|
||||||
|
std::path::Path::new(file!())
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.join("line.wgsl")
|
||||||
|
.to_string_lossy(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
app.add_plugins(MaterialPlugin::<LineMaterial>::default());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_cube(
|
||||||
mut cmds: Commands,
|
mut cmds: Commands,
|
||||||
mut materials: ResMut<Assets<BevyMaterial>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<LineMaterial>>,
|
||||||
|
) {
|
||||||
|
cmds.spawn((
|
||||||
|
Transform::from_xyz(0.0, 0.5, 0.0),
|
||||||
|
Mesh3d(meshes.add(Cuboid::default())),
|
||||||
|
MeshMaterial3d(materials.add(ExtendedMaterial {
|
||||||
|
base: BevyMaterial {
|
||||||
|
base_color: Color::WHITE,
|
||||||
|
perceptual_roughness: 1.0,
|
||||||
|
// TODO: this should be Blend
|
||||||
|
alpha_mode: AlphaMode::Opaque,
|
||||||
|
// emissive: Color::srgba_u8(128, 128, 128, 255).into(),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
extension: LineExtension { unused: 0 },
|
||||||
|
})),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_line_mesh(
|
||||||
|
mut cmds: Commands,
|
||||||
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<LineMaterial>>,
|
||||||
) {
|
) {
|
||||||
for lines in LINES_REGISTRY
|
for lines in LINES_REGISTRY
|
||||||
.get_valid_contents()
|
.get_valid_contents()
|
||||||
@@ -189,13 +247,16 @@ fn build_line_mesh(
|
|||||||
let e = cmds.spawn((
|
let e = cmds.spawn((
|
||||||
Name::new("LinesNode"),
|
Name::new("LinesNode"),
|
||||||
SpatialNode(Arc::downgrade(&lines.spatial)),
|
SpatialNode(Arc::downgrade(&lines.spatial)),
|
||||||
MeshMaterial3d(materials.add(BevyMaterial {
|
MeshMaterial3d(materials.add(ExtendedMaterial {
|
||||||
base_color: Color::WHITE,
|
base: BevyMaterial {
|
||||||
perceptual_roughness: 1.0,
|
base_color: Color::WHITE,
|
||||||
// TODO: this should be Blend
|
perceptual_roughness: 1.0,
|
||||||
alpha_mode: AlphaMode::Opaque,
|
// TODO: this should be Blend
|
||||||
emissive: Color::srgba_u8(128, 128, 128, 255).into(),
|
alpha_mode: AlphaMode::Opaque,
|
||||||
..default()
|
// emissive: Color::srgba_u8(128, 128, 128, 255).into(),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
extension: LineExtension { unused: 0 },
|
||||||
})),
|
})),
|
||||||
));
|
));
|
||||||
_ = lines.entity.set(e.id().into());
|
_ = lines.entity.set(e.id().into());
|
||||||
@@ -203,7 +264,6 @@ fn build_line_mesh(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Some(aabb) = mesh.compute_aabb() {
|
if let Some(aabb) = mesh.compute_aabb() {
|
||||||
info!(?aabb);
|
|
||||||
*lines.bounds.lock() = aabb;
|
*lines.bounds.lock() = aabb;
|
||||||
entity.insert(aabb);
|
entity.insert(aabb);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ impl DmabufBacking {
|
|||||||
dmatexes: &ImportedDmatexs,
|
dmatexes: &ImportedDmatexs,
|
||||||
images: &mut Assets<Image>,
|
images: &mut Assets<Image>,
|
||||||
) -> Option<Handle<Image>> {
|
) -> Option<Handle<Image>> {
|
||||||
info!("updating dmabuf tex");
|
|
||||||
self.pending_imported_dmatex
|
self.pending_imported_dmatex
|
||||||
.lock()
|
.lock()
|
||||||
.take()
|
.take()
|
||||||
|
|||||||
Reference in New Issue
Block a user