Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voxels and SDF #152

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
882b92b
Add a voxel crate
QuantumEntangledAndy Feb 10, 2022
e526cd7
Attempt to add 3d textures
QuantumEntangledAndy Feb 10, 2022
d914660
Merge branch 'main' of /~https://github.com/lowenware/dotrix into feat/…
QuantumEntangledAndy Mar 2, 2022
8d079da
Update to 3D texture loads
QuantumEntangledAndy Mar 5, 2022
671e30a
Housekeeping for voxel rewrite
QuantumEntangledAndy Mar 7, 2022
9f6d9ec
Add prototype jump flood algorithm
QuantumEntangledAndy Mar 7, 2022
c5ef50c
Name shader module on load
QuantumEntangledAndy Mar 10, 2022
a255c10
Add alternate 3d texture bindings
QuantumEntangledAndy Mar 10, 2022
8361c86
Split SDF from and voxel generation into stages
QuantumEntangledAndy Mar 10, 2022
2f99afd
Compute the distance transform from a jump flood
QuantumEntangledAndy Mar 10, 2022
bd58e5e
Use local space for jump flood
QuantumEntangledAndy Mar 11, 2022
9698aa3
Add prototype circletrace render
QuantumEntangledAndy Mar 11, 2022
4ae98fc
Add map buffers and create buffer methods
QuantumEntangledAndy Mar 11, 2022
b1979cf
Debug voxel-sdf render
QuantumEntangledAndy Mar 11, 2022
c580b9c
Bug fix to voxel numerical gradient
QuantumEntangledAndy Mar 11, 2022
378eaf2
BUg fixing and tracking for sphere-tracing
QuantumEntangledAndy Mar 13, 2022
df2a69d
SDF Voxels working
QuantumEntangledAndy Mar 16, 2022
bdd9fda
Reduce artifacts
QuantumEntangledAndy Mar 17, 2022
e0bd715
Add a method for async fetching textures from the gpu
QuantumEntangledAndy Mar 17, 2022
18c9638
Clean up SDF files
QuantumEntangledAndy Mar 17, 2022
fe02cc0
Cleanup of sdf code
QuantumEntangledAndy Mar 17, 2022
074b47d
Workaround /~https://github.com/gfx-rs/naga/issues/1527
QuantumEntangledAndy Mar 18, 2022
4d5ac87
Tera based module voxel render wgsl
QuantumEntangledAndy Apr 16, 2022
3336564
Merge branch 'main' of /~https://github.com/lowenware/dotrix into feat/…
QuantumEntangledAndy Apr 16, 2022
0d7f2ea
Use pbr lights enum
QuantumEntangledAndy Apr 16, 2022
1db1dbc
Reduce repeated and redundent code in lighting
QuantumEntangledAndy Apr 16, 2022
d33f79d
Add live reload the sdf voxels
QuantumEntangledAndy Apr 16, 2022
e77b155
Add method to change a texture without a rebind
QuantumEntangledAndy Apr 18, 2022
f2c18c5
Use transform for voxel grid world positions
QuantumEntangledAndy Apr 19, 2022
5946cd5
Use jinja include statements instead of variable
QuantumEntangledAndy Apr 19, 2022
e62ee8e
Seperate voxel map functions from render
QuantumEntangledAndy Apr 19, 2022
a4291bf
Fixes to grid scaling
QuantumEntangledAndy Apr 19, 2022
77eb486
Move pixel_radius calcaulation to ray_march step
QuantumEntangledAndy Apr 19, 2022
642d026
Remove debug backing
QuantumEntangledAndy Apr 19, 2022
ab844b9
Don't panic in sdf render when matrix cannot be inverted, instead ret…
QuantumEntangledAndy Apr 19, 2022
7fefc0e
Add scaleing controls to sdf example
QuantumEntangledAndy Apr 19, 2022
fdaef3d
Unload `texture` and `texture_view`
QuantumEntangledAndy Apr 19, 2022
6266852
Add appropiate scales to clipping box
QuantumEntangledAndy Apr 19, 2022
e656169
Apply min_scale in map sdf once
QuantumEntangledAndy Apr 19, 2022
867d6f8
MaterialSet prototype
QuantumEntangledAndy Apr 20, 2022
a3f3eee
All material data in material set
QuantumEntangledAndy Apr 20, 2022
1447223
Working on trilinear-surface rendering
QuantumEntangledAndy Apr 20, 2022
fbf9023
Add triplanar rendering of voxels
QuantumEntangledAndy Apr 22, 2022
ff53a87
Add more material to voxel sdf example
QuantumEntangledAndy Apr 22, 2022
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
408 changes: 408 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ name = "dotrix"
path = "src/lib.rs"

[features]
default = [ "egui", "overlay", "pbr", "primitives", "sky", "terrain" ]
default = [ "egui", "overlay", "pbr", "primitives", "sky", "terrain", "voxel" ]

overlay = ["dotrix_overlay"]
sky = ["dotrix_sky"]
pbr = ["dotrix_pbr"]
primitives = ["dotrix_primitives"]
egui = ["dotrix_egui"]
terrain = ["dotrix_terrain"]
voxel = ["dotrix_voxel"]

[workspace]
members = [
Expand All @@ -34,6 +35,7 @@ members = [
"dotrix_primitives",
"dotrix_sky",
"dotrix_terrain",
"dotrix_voxel",
]

[dependencies.dotrix_core]
Expand Down Expand Up @@ -76,6 +78,11 @@ version = "0.5"
path = "./dotrix_terrain"
optional = true

[dependencies.dotrix_voxel]
version = "0.5"
path = "./dotrix_voxel"
optional = true

[dev-dependencies.rand]
version = "0.8"

Expand Down Expand Up @@ -125,3 +132,8 @@ path = "examples/msaa/main.rs"
[[example]]
name = "normal_map"
path = "examples/normal_map/main.rs"

[[example]]
name = "voxel_sdf"
path = "examples/voxel_sdf/main.rs"
required-features = ["voxel"]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions assets/textures/Bricks075B/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Source

https://ambientcg.com/view?id=Bricks075B

# Licensing

All the PBR materials, brushes, photos and 3D models which are offered for download on ambientCG are provided under the Creative Commons CC0 1.0 Universal License.

Creative Commons - CC0 1.0 Universal

# Summary

The Creative Commons CC0 license gives you the freedom to use these assets…

… in your own creations of any kind for free.
… even in situations that require them to be redistributed as individual files (for example as part of an open source video game or tool).
… for commercial projects.

There is no requirement to give credit but it would of course be appreciated.

# Giving credit

If you wish to give credit you can do so using this text:

```
Contains assets from ambientCG.com, licensed under CC0 1.0 Universal.
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions assets/textures/PaintedPlaster010/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Source

https://ambientcg.com/view?id=PaintedPlaster010

# Licensing

All the PBR materials, brushes, photos and 3D models which are offered for download on ambientCG are provided under the Creative Commons CC0 1.0 Universal License.

Creative Commons - CC0 1.0 Universal

# Summary

The Creative Commons CC0 license gives you the freedom to use these assets…

… in your own creations of any kind for free.
… even in situations that require them to be redistributed as individual files (for example as part of an open source video game or tool).
… for commercial projects.

There is no requirement to give credit but it would of course be appreciated.

# Giving credit

If you wish to give credit you can do so using this text:

```
Contains assets from ambientCG.com, licensed under CC0 1.0 Universal.
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions assets/textures/PavingStones113/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Source

https://ambientcg.com/view?id=Bricks076C

# Licensing

All the PBR materials, brushes, photos and 3D models which are offered for download on ambientCG are provided under the Creative Commons CC0 1.0 Universal License.

Creative Commons - CC0 1.0 Universal

# Summary

The Creative Commons CC0 license gives you the freedom to use these assets…

… in your own creations of any kind for free.
… even in situations that require them to be redistributed as individual files (for example as part of an open source video game or tool).
… for commercial projects.

There is no requirement to give credit but it would of course be appreciated.

# Giving credit

If you wish to give credit you can do so using this text:

```
Contains assets from ambientCG.com, licensed under CC0 1.0 Universal.
```
4 changes: 2 additions & 2 deletions dotrix_core/src/assets/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ mod tests {
[-width, width, width],
];

width = width / 2.0;
width /= 2.0;

let verticies_test_original_2: Vec<[f32; 3]> = vec![
[-width, -width, -width],
Expand All @@ -367,7 +367,7 @@ mod tests {
[-width, width, width],
];

width = width / 2.0;
width /= 2.0;

let verticies_test_original_3: Vec<[u32; 3]> = vec![
[-width as u32, -width as u32, -width as u32],
Expand Down
1 change: 1 addition & 0 deletions dotrix_core/src/assets/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl Shader {
/// Loads the shader to GPU
pub fn load(&mut self, renderer: &Renderer) {
if !self.module.loaded() {
self.module.label = self.name.clone();
renderer.load_shader(&mut self.module, &self.code);
}
}
Expand Down
13 changes: 13 additions & 0 deletions dotrix_core/src/assets/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,17 @@ impl Texture {
pub fn unload(&mut self) {
self.buffer.unload();
}

/// Fetch data from the gpu
///
/// This is useful textures that are altered on the gpu
///
/// This operation is slow and should mostly be
/// used for debugging
pub fn fetch_from_gpu(
&mut self,
renderer: &mut Renderer,
) -> impl std::future::Future<Output = Result<Vec<u8>, wgpu::BufferAsyncError>> {
renderer.fetch_texture(&self.buffer, [self.width, self.height, self.depth])
}
}
2 changes: 1 addition & 1 deletion dotrix_core/src/cubemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Default for CubeMap {
bottom: Id::default(),
back: Id::default(),
front: Id::default(),
buffer: TextureBuffer::new("CubeMap Texture Buffer"),
buffer: TextureBuffer::new_cube("CubeMap Texture Buffer"),
}
}
}
Expand Down
57 changes: 56 additions & 1 deletion dotrix_core/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Renderer {
buffer.load(self.context(), attributes, indices, count as u32);
}*/

/// Loads the texture buffer to GPU
/// Loads the texture buffer to GPU, this will recreate the texture and will need to be rebound
pub fn load_texture<'a>(
&self,
texture: &mut Texture,
Expand All @@ -95,11 +95,42 @@ impl Renderer {
texture.load(self.context(), width, height, layers);
}

/// Load data from cpu to a texture buffer on GPU
/// This will fail if texture has not been loaded with `load_texture`
/// possible unexpected results occur if the dimensions differs from it dimensions at load time
pub fn update_texture<'a>(
&self,
texture: &mut Texture,
width: u32,
height: u32,
layers: &'a [&'a [u8]],
) {
texture.update(self.context(), width, height, layers);
}

/// This will `[update_texture]` if texture has been loaded or `[load_texture]` if not
/// the same cavets of `[update_texture]` apply in that care must be taken not to change
/// the dimensions between `load` and `update`
pub fn update_or_load_texture<'a>(
&self,
texture: &mut Texture,
width: u32,
height: u32,
layers: &'a [&'a [u8]],
) {
texture.update_or_load(self.context(), width, height, layers);
}

/// Loads the buffer to GPU
pub fn load_buffer<'a>(&self, buffer: &mut Buffer, data: &'a [u8]) {
buffer.load(self.context(), data);
}

/// Create a buffer on GPU without data
pub fn create_buffer(&self, buffer: &mut Buffer, size: u32, mapped: bool) {
buffer.create(self.context(), size, mapped);
}

/// Loads the sampler to GPU
pub fn load_sampler(&self, sampler: &mut Sampler) {
sampler.load(self.context());
Expand Down Expand Up @@ -164,6 +195,26 @@ impl Renderer {
.run_compute_pipeline(pipeline.shader, &pipeline.bindings, args);
}

/// Copy a texture to a buffer
pub fn copy_texture_to_buffer(
&mut self,
texture: &Texture,
buffer: &Buffer,
extent: [u32; 3],
bytes_per_pixel: u32,
) {
self.context_mut()
.run_copy_texture_to_buffer(texture, buffer, extent, bytes_per_pixel);
}

/// Fetch texture from GPU
pub fn fetch_texture(
&mut self,
texture: &Texture,
dimensions: [u32; 3],
) -> impl std::future::Future<Output = Result<Vec<u8>, wgpu::BufferAsyncError>> {
texture.fetch_from_gpu(dimensions, self.context_mut())
}
/// Returns surface size
pub fn surface_size(&self) -> Vec2 {
let ctx = self.context();
Expand Down Expand Up @@ -263,6 +314,10 @@ pub fn release(mut renderer: Mut<Renderer>) {
if renderer.cycle == 0 {
renderer.cycle = 1;
}
// Check for resource cleanups and mapping callbacks
if let Some(context) = renderer.context.as_ref() {
context.device.poll(wgpu::Maintain::Poll);
}
}

/// Resize handling system
Expand Down
Loading