Skip to content

Commit

Permalink
Kill bevy_pbr
Browse files Browse the repository at this point in the history
PBR is for 3D stuff. It's nice to not need it.

We'll want to clean up our view conversion definitions in the future.
  • Loading branch information
jgayfer committed Jul 31, 2024
1 parent 1c3fc40 commit 3beedcb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ exclude = ["assets/*", "static/*"]

[dependencies]
bevy = { version = "0.14", default-features = false, features = [
"bevy_pbr",
"bevy_render",
"bevy_core_pipeline",
"bevy_winit",
Expand All @@ -22,7 +21,6 @@ smallvec = "1.13"

[dev-dependencies]
bevy = { version = "0.14", default-features = false, features = [
"bevy_pbr",
"bevy_render",
"bevy_core_pipeline",
"bevy_winit",
Expand Down
24 changes: 20 additions & 4 deletions src/render/lighting/sdf.wgsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
#import bevy_core_pipeline::fullscreen_vertex_shader::FullscreenVertexOutput
#import bevy_render::view::View
#import bevy_light_2d::types::LightOccluder2d
#import bevy_pbr::view_transformations::{
frag_coord_to_ndc,
position_ndc_to_world

fn frag_coord_to_uv(frag_coord: vec2<f32>) -> vec2<f32> {
return (frag_coord - view.viewport.xy) / view.viewport.zw;
}

fn frag_coord_to_ndc(frag_coord: vec2<f32>) -> vec2<f32> {
return uv_to_ndc(frag_coord_to_uv(frag_coord.xy));
}

fn uv_to_ndc(uv: vec2<f32>) -> vec2<f32> {
return uv * vec2(2.0, -2.0) + vec2(-1.0, 1.0);
}

fn ndc_to_world(ndc_position: vec2<f32>) -> vec2<f32> {
return (view.world_from_clip * vec4(ndc_position, 0.0, 1.0)).xy;
}

// We're currently only using a single uniform binding for occluders in
Expand All @@ -12,6 +25,9 @@
// As each occluder is 16 bytes, we can fit 4096 / 16 = 256 occluders.
const MAX_OCCLUDERS: u32 = 256u;

@group(0) @binding(0)
var<uniform> view: View;

// WebGL2 does not support storage buffers, so we fall back to a fixed length
// array in a uniform buffer.
#if AVAILABLE_STORAGE_BUFFER_BINDINGS >= 6
Expand All @@ -24,7 +40,7 @@ const MAX_OCCLUDERS: u32 = 256u;

@fragment
fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
let pos = position_ndc_to_world(frag_coord_to_ndc(in.position)).xy;
let pos = ndc_to_world(frag_coord_to_ndc(in.position.xy));

var sdf = occluder_sd(pos, occluders[0]);

Expand Down

0 comments on commit 3beedcb

Please sign in to comment.