Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions crates/processing_render/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
Flush,
image::{Image, create_readback_buffer, pixel_size, pixels_to_bytes},
render::{
RenderState,
BATCH_INDEX_STEP, RenderState,
command::{CommandBuffer, DrawCommand},
},
surface::Surface,
Expand Down Expand Up @@ -112,19 +112,18 @@ pub struct SurfaceSize(pub u32, pub u32);
/// Custom orthographic projection for Processing's coordinate system.
/// Origin at top-left, Y-axis down, in pixel units (aka screen space).
#[derive(Debug, Clone, Reflect)]
#[reflect(Default)]
pub struct ProcessingProjection {
pub width: f32,
pub height: f32,
pub near: f32,
pub far: f32,
}

impl Default for ProcessingProjection {
fn default() -> Self {
impl ProcessingProjection {
pub fn new(width: f32, height: f32) -> Self {
Self {
width: 1.0,
height: 1.0,
width,
height,
near: 0.0,
far: 1000.0,
}
Expand Down Expand Up @@ -234,14 +233,9 @@ pub fn create(
Tonemapping::None,
// we need to be able to write to the texture
CameraMainTextureUsages::default().with(TextureUsages::COPY_DST),
Projection::custom(ProcessingProjection {
width: width as f32,
height: height as f32,
near: 0.0,
far: 1000.0,
}),
Projection::custom(ProcessingProjection::new(width as f32, height as f32)),
Msaa::Off,
Transform::from_xyz(0.0, 0.0, 999.9),
Transform::from_xyz(0.0, 0.0, BATCH_INDEX_STEP),
render_layer,
CommandBuffer::new(),
RenderState::default(),
Expand Down Expand Up @@ -340,18 +334,13 @@ pub fn mode_2d(
.get_mut(entity)
.map_err(|_| ProcessingError::GraphicsNotFound)?;

*projection = Projection::custom(ProcessingProjection {
width: *width as f32,
height: *height as f32,
near: 0.0,
far: 1000.0,
});
*projection = Projection::custom(ProcessingProjection::new(*width as f32, *height as f32));

let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::GraphicsNotFound)?;

*transform = Transform::from_xyz(0.0, 0.0, 999.9);
*transform = Transform::from_xyz(0.0, 0.0, BATCH_INDEX_STEP);

Ok(())
}
Expand Down
8 changes: 5 additions & 3 deletions crates/processing_render/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use crate::{
render::{material::UntypedMaterial, primitive::rect},
};

pub(crate) const BATCH_INDEX_STEP: f32 = 0.001;

#[derive(Component)]
#[relationship(relationship_target = TransientMeshes)]
pub struct BelongsToGraphics(pub Entity);
Expand Down Expand Up @@ -350,7 +352,7 @@ pub fn flush_draw_commands(

flush_batch(&mut res, &mut batch, &p_material_handles);

let z_offset = -(batch.draw_index as f32 * 0.001);
let z_offset = -(batch.draw_index as f32 * BATCH_INDEX_STEP);
let mut transform = state.transform.to_bevy_transform();

// if the "source" geometry was parented in a gltf scene, we need to make sure that
Expand Down Expand Up @@ -565,7 +567,7 @@ fn flush_batch(
material_handles: &Query<&UntypedMaterial>,
) {
if let Some(mesh) = batch.current_mesh.take() {
let z_offset = -(batch.draw_index as f32 * 0.001);
let z_offset = -(batch.draw_index as f32 * BATCH_INDEX_STEP);
spawn_mesh(res, batch, mesh, z_offset, material_handles);
batch.draw_index += 1;
}
Expand Down Expand Up @@ -616,7 +618,7 @@ fn add_shape3d(
}
};

let z_offset = -(batch.draw_index as f32 * 0.001);
let z_offset = -(batch.draw_index as f32 * BATCH_INDEX_STEP);
let mut transform = state.transform.to_bevy_transform();
transform.translation.z += z_offset;

Expand Down
Loading