-
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
1 parent
479e7d3
commit ebdc7cc
Showing
12 changed files
with
218 additions
and
46 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"type": "raw", | ||
"vertex": "shaders/vertex.glsl", | ||
"fragment": "shaders/fragment.glsl" | ||
"type": "Surface", | ||
"shaders": { | ||
"Fragment": "shaders/fragment.besl" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
main: fn () -> void { | ||
out_color = get_debug_color(in_instance_index); | ||
out_color = vec4f(1.0, 0.0, 0.0, 1.0); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
void main() { | ||
uint material_index = pixel; | ||
|
||
material_count[material_index] += 1; | ||
} |
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,66 @@ | ||
// All threads in the same group will share the same atomic result. | ||
shared uint atomic; | ||
|
||
#define WAVE_SIZE 32 | ||
#define WAVE_SIZE_BASE uint(log2(WAVE_SIZE)) | ||
|
||
layout(buffer_reference, std430, binding = 0) readonly buffer MaterialStartPassInfo { | ||
uint entryCount; | ||
uint treeDepth; | ||
uint treeOffsets[]; | ||
}; | ||
|
||
layout(buffer_reference, std430, binding = 0) coherent buffer TreeBuffer { | ||
uint tree[]; | ||
}; | ||
|
||
layout(local_size_x = WAVE_SIZE) in; | ||
void main() { | ||
uint groupId = gl_WorkGroupID.x; | ||
uint localThreadId = gl_LocalInvocationIndex; | ||
|
||
// A buffer of atomics initialized to 0. | ||
atomicsBuffer = []; | ||
|
||
for (int i = 0; i < treeDepth; ++i) { | ||
// The global thread ID is unique for all threads launched and corresponds to two elements in the tree layer below. | ||
uint globalThreadId = (groupId << WAVE_SIZE_BASE) + localThreadId; | ||
uint readOffset = treeOffsets[i]; | ||
uint writeOffset = treeOffsets[i + 1]; | ||
|
||
// This thread is only valid if the tree has one or two elements in the layer below that this thread should sum up. | ||
bool validThread = globalThreadId < materialStartPassInfo.entryCount; | ||
|
||
if (validThread) { | ||
// Sum the two elements in the previous layer and write them for the current layer. | ||
uint elementReadOffset = readOffset + (globalThreadId * 2); | ||
uint elementWriteOffset = readOffset + globalThreadId; | ||
tree[elementWriteOffset] = tree[elementReadOffset + 0] + tree[elementReadOffset + 1]; | ||
} | ||
|
||
uint weight = 0; | ||
|
||
if (validThread) { | ||
weight = tree[treeOffsets[i] + globalThreadId]; | ||
} | ||
|
||
uint sum = subgroupExclusiveAdd(weight) + weight; | ||
|
||
// The last thread in the wave will write the sum. | ||
if (localThreadId == WAVE_SIZE - 1) { | ||
tree[treeOffsets[i + 1] + groupId] = sum; | ||
} | ||
|
||
// Sync to ensure that the atomic for this thread group has been updated and will be visible for all threads in the group. | ||
groupMemoryBarrier(); barrier(); memoryBarrier(); | ||
|
||
// Two thread groups wrote to the same atomic, only the last one to write survives for the next tree layer. | ||
if (atomic < 1) { | ||
return; | ||
} | ||
|
||
// Sync to make sure that all threads within a group have finished reading the value of `atomic`. | ||
// This is needed because it will be modified again in the next iteration. | ||
groupMemoryBarrier(); barrier(); | ||
} | ||
} |
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,3 @@ | ||
void main() { | ||
out_material_index = 0; | ||
} |
File renamed without changes.
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
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
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
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,42 @@ | ||
#![feature(const_mut_refs)] | ||
|
||
use byte_engine::{application::Application, Vec3f, input_manager, Vector3, orchestrator::{Component, EntityHandle, self, System,}, render_domain::{Mesh, MeshParameters}, math}; | ||
use maths_rs::prelude::{MatTranslate, MatScale, MatInverse}; | ||
|
||
#[ignore] | ||
#[test] | ||
fn gi() { | ||
let mut app = byte_engine::application::GraphicsApplication::new("Gallery Shooter"); | ||
app.initialize(std::env::args()); | ||
|
||
let orchestrator = app.get_mut_orchestrator(); | ||
|
||
orchestrator.spawn(byte_engine::camera::Camera { | ||
position: Vec3f::new(0.0, 0.5, -1.0), | ||
direction: Vec3f::new(0.0, -0.1, 0.9), | ||
fov: 90.0, | ||
aspect_ratio: 1.0, | ||
aperture: 0.0, | ||
focus_distance: 0.0, | ||
}); | ||
|
||
let _floor: EntityHandle<Mesh> = orchestrator.spawn(Mesh{ resource_id: "Box", transform: maths_rs::Mat4f::from_translation(Vec3f::new(0.0, -0.25, 0.0)), }); | ||
let _a: EntityHandle<Mesh> = orchestrator.spawn(Mesh{ resource_id: "Box", transform: maths_rs::Mat4f::from_translation(Vec3f::new(0.0, 0.25, 2.0)) * maths_rs::Mat4f::from_scale(Vec3f::new(0.5, 0.5, 0.5)), }); | ||
let _b: EntityHandle<Mesh> = orchestrator.spawn(Mesh{ resource_id: "Box", transform: maths_rs::Mat4f::from_translation(Vec3f::new(-0.8, 0.17, 1.7)) * maths_rs::Mat4f::from_scale(Vec3f::new(0.34, 0.34, 0.34)), }); | ||
let _c: EntityHandle<Mesh> = orchestrator.spawn(Mesh{ resource_id: "Box", transform: maths_rs::Mat4f::from_translation(Vec3f::new(0.7, 0.13, 1.8)) * maths_rs::Mat4f::from_scale(Vec3f::new(0.26, 0.26, 0.26)), }); | ||
|
||
app.do_loop(); | ||
|
||
app.deinitialize(); | ||
} | ||
|
||
struct Player { | ||
mesh: EntityHandle<Mesh>, | ||
camera: EntityHandle<byte_engine::camera::Camera>, | ||
} | ||
|
||
impl orchestrator::Entity for Player {} | ||
|
||
impl Component for Player { | ||
// type Parameters<'a> = EntityHandle<input_manager::Action<Vec3f>>; | ||
} |