-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 714233e
Showing
5 changed files
with
416 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}); | ||
*/ | ||
} |
Oops, something went wrong.