Skip to content

Commit

Permalink
Pipeline is working
Browse files Browse the repository at this point in the history
  • Loading branch information
GrandmasterB42 committed Sep 15, 2024
0 parents commit 714233e
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
Cargo.lock
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "bevyray"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = "0.14"

[profile.dev]
opt-level = 1

[profile.dev.package."*"]
opt-level = 3
38 changes: 38 additions & 0 deletions assets/shaders/raytrace.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

// Since post processing is a fullscreen effect, we use the fullscreen vertex shader provided by bevy.
// This will import a vertex shader that renders a single fullscreen triangle.
//
// A fullscreen triangle is a single triangle that covers the entire screen.
// The box in the top left in that diagram is the screen. The 4 x are the corner of the screen
//
// Y axis
// 1 | x-----x......
// 0 | | s | . ´
// -1 | x_____x´
// -2 | : .´
// -3 | :´
// +--------------- X axis
// -1 0 1 2 3
//
// As you can see, the triangle ends up bigger than the screen.
//
// You don't need to worry about this too much since bevy will compute the correct UVs for you.
#import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput

@group(0) @binding(0) var screen_texture: texture_2d<f32>;
@group(0) @binding(1) var texture_sampler: sampler;
struct RayTraceLevel {
level: u32,
}
@group(0) @binding(2) var<uniform> settings: RayTraceLevel;

@fragment
fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
// Sample each color channel with an arbitrary shift
return vec4<f32>(
1.0,
0.0,
0.0,
1.0,
);
}
53 changes: 53 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use bevy::{core_pipeline::prepass::DepthPrepass, prelude::*};
use raytracing::{RayTracePlugin, RayTracing};

mod raytracing;

fn main() {
App::new()
.add_plugins((DefaultPlugins, RayTracePlugin))
.add_systems(Startup, setup)
.run();
}

/// Set up a simple 3D scene
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 5.0))
.looking_at(Vec3::default(), Vec3::Y),
camera: Camera {
clear_color: Color::WHITE.into(),
..default()
},
..default()
},
// Add the setting to the camera.
// This component is also used to determine on which camera to run the post processing effect.
RayTracing::Pure,
DepthPrepass,
));

// cube
commands.spawn((PbrBundle {
mesh: meshes.add(Cuboid::default()),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
},));
/*
// light
commands.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
illuminance: 1_000.,
..default()
},
..default()
});
*/
}
Loading

0 comments on commit 714233e

Please sign in to comment.