volumetric changing unlighted sphere
This commit is contained in:
parent
6856e6ac38
commit
38513627ca
2 changed files with 93 additions and 42 deletions
|
|
@ -1,30 +1,46 @@
|
|||
#import bevy_pbr::{
|
||||
forward_io::{VertexOutput, FragmentOutput},
|
||||
pbr_fragment::pbr_input_from_standard_material,
|
||||
pbr_functions::{alpha_discard, apply_pbr_lighting, main_pass_post_lighting_processing},
|
||||
mesh_view_bindings::view,
|
||||
}
|
||||
|
||||
struct MyExtendedMaterial {
|
||||
quantize_steps: u32,
|
||||
struct VoluMaterial {
|
||||
mesh_translation: vec3<f32>,
|
||||
sphere_radius: f32,
|
||||
color: vec4<f32>,
|
||||
}
|
||||
|
||||
@group(2) @binding(100)
|
||||
var<uniform> my_extended_material: MyExtendedMaterial;
|
||||
var<storage, read> volu_material: VoluMaterial;
|
||||
|
||||
fn raymarch_hit(position_: vec3<f32>, direction: vec3<f32>) -> bool {
|
||||
var position = position_;
|
||||
for (var i = 0; i < 200; i++) {
|
||||
if sphere_hit(position) {
|
||||
return true;
|
||||
}
|
||||
position += direction * 0.01;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
fn sphere_hit(p: vec3<f32>) -> bool {
|
||||
return distance(p, volu_material.mesh_translation) < volu_material.sphere_radius;
|
||||
}
|
||||
|
||||
@fragment
|
||||
fn fragment(
|
||||
in: VertexOutput,
|
||||
@builtin(front_facing) is_front: bool,
|
||||
) -> FragmentOutput {
|
||||
var pbr_input = pbr_input_from_standard_material(in, is_front);
|
||||
|
||||
pbr_input.material.base_color = alpha_discard(pbr_input.material, pbr_input.material.base_color);
|
||||
let view_direction = normalize(in.world_position.xyz - view.world_position);
|
||||
|
||||
var out: FragmentOutput;
|
||||
|
||||
out.color = apply_pbr_lighting(pbr_input);
|
||||
|
||||
out.color = main_pass_post_lighting_processing(pbr_input, out.color);
|
||||
if (raymarch_hit(in.world_position.xyz, view_direction)) {
|
||||
out.color = volu_material.color;
|
||||
} else {
|
||||
out.color = vec4(1.0, 1.0, 1.0, 0.2);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue