Skip to content

Commit

Permalink
more wip
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Nov 29, 2024
1 parent 592ae84 commit b4feff1
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 138 deletions.
6 changes: 5 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion assets/shaders/bound_material_baker.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ fn fragment(
// alpha discard
pbr_input.material.base_color = alpha_discard(pbr_input.material, pbr_input.material.base_color);

if pbr_input.material.base_color.a < 0.5 {
discard;
}

// use max of emissive and color (imposters only take albedo)
pbr_input.material.base_color = max(pbr_input.material.base_color, pbr_input.material.emissive);
// pbr_input.material.base_color = max(pbr_input.material.base_color, pbr_input.material.emissive);

return pack_pbrinput(pbr_input);
}
12 changes: 10 additions & 2 deletions assets/shaders/floor_bake.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
@group(2) @binding(100)
var<uniform> offset: f32;

struct VertexOut {
@builtin(position) position: vec4<f32>,
@location(0) inverse_rotation_0c: vec3<f32>,
@location(1) inverse_rotation_1c: vec3<f32>,
@location(2) inverse_rotation_2c: vec3<f32>,
@location(3) uv: vec2<f32>,
}

@fragment
fn fragment(in: ImposterVertexOut) -> @location(0) vec2<u32> {
fn fragment(in: VertexOut) -> @location(0) vec2<u32> {
let inv_rot = mat3x3(
in.inverse_rotation_0c,
in.inverse_rotation_1c,
in.inverse_rotation_2c,
);

var props = sample_tile_material(clamp(in.uv_c, vec2(0.0001), vec2(17.0/18.0 - 0.0001)), vec2(0u,0u), vec2(offset, offset));
var props = sample_tile_material(vec4<f32>(clamp(in.uv, vec2(0.0001), vec2(17.0/18.0 - 0.0001)), vec2<f32>(0.0)), vec2(0u,0u), vec2(offset, offset));
var pbr_input = unpack_pbrinput(props, in.position);
pbr_input.N = inv_rot * normalize(pbr_input.N);
pbr_input.world_normal = pbr_input.N;
Expand Down
43 changes: 37 additions & 6 deletions assets/shaders/floor_fragment.wgsl
Original file line number Diff line number Diff line change
@@ -1,29 +1,60 @@
#import bevy_pbr::{
forward_io::FragmentOutput,
pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing},
pbr_types::{STANDARD_MATERIAL_FLAGS_ALPHA_MODE_ADD, STANDARD_MATERIAL_FLAGS_FOG_ENABLED_BIT},
}

#import boimp::shared::{ImposterVertexOut, unpack_pbrinput};
#ifdef PREPASS_PIPELINE
#import bevy_pbr::prepass_io::FragmentOutput;
#else
#import bevy_pbr::forward_io::FragmentOutput;
#endif

#import boimp::shared::unpack_pbrinput;
#import boimp::bindings::sample_tile_material;

@group(2) @binding(100)
var<uniform> offset: f32;

struct VertexOut {
@builtin(position) position: vec4<f32>,
@location(0) inverse_rotation_0c: vec3<f32>,
@location(1) inverse_rotation_1c: vec3<f32>,
@location(2) inverse_rotation_2c: vec3<f32>,
@location(3) uv: vec2<f32>,
}

@fragment
fn fragment(in: ImposterVertexOut) -> FragmentOutput {
fn fragment(in: VertexOut) -> FragmentOutput {
var out: FragmentOutput;

#ifdef PREPASS_PIPELINE

#ifdef NORMAL_PREPASS
out.normal = vec4<f32>(0.0, 1.0, 0.0, 0.0);
#endif
// we don't support MOTION_VECTOR or DEFERRED
#ifdef DEPTH_CLAMP_ORTHO
out.frag_depth = in.position.z;
#endif

#else

let inv_rot = mat3x3(
in.inverse_rotation_0c,
in.inverse_rotation_1c,
in.inverse_rotation_2c,
);

var props = sample_tile_material(clamp(in.uv_c, vec2(0.0001), vec2(17.0/18.0 - 0.0001)), vec2(0u,0u), vec2(offset, offset));
var props = sample_tile_material(vec4<f32>(clamp(in.uv, vec2(0.0001), vec2(17.0/18.0 - 0.0001)), vec2<f32>(0.0)), vec2(0u,0u), vec2(offset, offset));

if props.rgba.a == 0.0 {
discard;
// hacky - we are using opaque to ensure imposters render above the floor
// so we have to put the ground color here
// todo use some nice
props.rgba = vec4<f32>(0.07323897, 0.17064494, 0.033104762, 1.0);
props.roughness = 1.0;
props.metallic = 0.0;
props.normal = vec3<f32>(0.0, 1.0, 0.0);
}

props.rgba.a = 1.0;
Expand All @@ -37,7 +68,7 @@ fn fragment(in: ImposterVertexOut) -> FragmentOutput {
pbr_input.material.flags |= STANDARD_MATERIAL_FLAGS_FOG_ENABLED_BIT;
out.color = main_pass_post_lighting_processing(pbr_input, out.color);

// out.color = clamp(out.color, vec4(0.2, 0.0, 0.0, 0.2), vec4(1.0));
#endif

return out;
}
19 changes: 13 additions & 6 deletions assets/shaders/floor_vertex.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
#import boimp::shared::ImposterVertexOut;
#import boimp::bindings::{imposter_data, sample_uvs_unbounded, grid_weights, sample_positions_from_camera_dir};

struct VertexOut {
@builtin(position) position: vec4<f32>,
@location(0) inverse_rotation_0c: vec3<f32>,
@location(1) inverse_rotation_1c: vec3<f32>,
@location(2) inverse_rotation_2c: vec3<f32>,
@location(3) uv: vec2<f32>,
}

@vertex
fn vertex(vertex: Vertex) -> ImposterVertexOut {
var out: ImposterVertexOut;
fn vertex(vertex: Vertex) -> VertexOut {
var out: VertexOut;

var model = mesh_functions::get_world_from_local(vertex.instance_index);

Expand All @@ -30,11 +38,10 @@ fn vertex(vertex: Vertex) -> ImposterVertexOut {
out.inverse_rotation_0c = inv_rot[0];
out.inverse_rotation_1c = inv_rot[1];
out.inverse_rotation_2c = inv_rot[2];
out.base_world_position = imposter_world_position;

out.world_position = mesh_functions::mesh_position_local_to_world(model, vec4<f32>(vertex.position, 1.0)).xyz;
out.position = position_world_to_clip(out.world_position);
out.uv_c = vertex.uv;
let world_position = mesh_functions::mesh_position_local_to_world(model, vec4<f32>(vertex.position, 1.0)).xyz;
out.position = position_world_to_clip(world_position);
out.uv = vertex.uv;

return out;
}
7 changes: 3 additions & 4 deletions crates/common/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub struct AppConfig {
pub scene_load_distance: f32,
pub scene_unload_extra_distance: f32,
pub scene_imposter_distances: Vec<f32>,
pub scene_imposter_height_ratio: f32,
pub scene_imposter_multisample: bool,
pub sysinfo_visible: bool,
pub scene_log_to_console: bool,
pub max_avatars: usize,
Expand All @@ -211,8 +211,8 @@ impl Default for AppConfig {
scene_threads: 4,
scene_load_distance: 50.0,
scene_unload_extra_distance: 15.0,
scene_imposter_distances: vec![200.0],
scene_imposter_height_ratio: 25.0,
scene_imposter_distances: vec![150.0, 300.0, 600.0, 1200.0, 2400.0, 4800.0],
scene_imposter_multisample: true,
sysinfo_visible: true,
scene_log_to_console: false,
max_avatars: 100,
Expand Down Expand Up @@ -405,7 +405,6 @@ pub struct SceneLoadDistance {
pub load: f32,
pub unload: f32, // additional
pub load_imposter: f32,
pub imposter_height_ratio: f32,
}

#[derive(Debug)]
Expand Down
4 changes: 4 additions & 0 deletions crates/imposters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ common = { workspace = true }
ipfs = { workspace = true }
scene_material = { workspace = true }
scene_runner = { workspace = true }
tween = { workspace = true }
console = { workspace = true }

bevy = { workspace = true }
boimp = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
anyhow = { workspace = true }
urlencoding = { workspace = true }
bevy_console = { workspace = true }
async-fs = "2.0"
clap = { workspace = true }

[lints]
workspace = true
Loading

0 comments on commit b4feff1

Please sign in to comment.