From a48a3132c34d7269cf916b4246a04e31d539090d Mon Sep 17 00:00:00 2001 From: Marco Buono Date: Tue, 18 Jul 2023 00:11:57 -0300 Subject: [PATCH] Add additional module path qualification --- crates/bevy_pbr/src/render/pbr.wgsl | 2 +- crates/bevy_pbr/src/render/pbr_functions.wgsl | 13 +++++++------ crates/bevy_pbr/src/render/pbr_lighting.wgsl | 13 +++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/crates/bevy_pbr/src/render/pbr.wgsl b/crates/bevy_pbr/src/render/pbr.wgsl index a174865a1b..3578db8dcb 100644 --- a/crates/bevy_pbr/src/render/pbr.wgsl +++ b/crates/bevy_pbr/src/render/pbr.wgsl @@ -112,7 +112,7 @@ fn fragment( thickness *= (length(mesh.model[0].xyz) + length(mesh.model[1].xyz) + length(mesh.model[2].xyz)) / 3.0; pbr_input.material.thickness = thickness; - var diffuse_transmission = material.diffuse_transmission; + var diffuse_transmission = pbr_bindings::material.diffuse_transmission; #ifdef PBR_TRANSMISSION_TEXTURES_SUPPORTED if ((pbr_bindings::material.flags & STANDARD_MATERIAL_FLAGS_DIFFUSE_TRANSMISSION_TEXTURE_BIT) != 0u) { diffuse_transmission *= textureSample(pbr_bindings::diffuse_transmission_texture, pbr_bindings::diffuse_transmission_sampler, uv).a; diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl index db279d0c65..17092ab43f 100644 --- a/crates/bevy_pbr/src/render/pbr_functions.wgsl +++ b/crates/bevy_pbr/src/render/pbr_functions.wgsl @@ -14,8 +14,9 @@ #import bevy_pbr::environment_map #endif +#import bevy_pbr::utils E #import bevy_pbr::mesh_bindings mesh -#import bevy_pbr::mesh_types MESH_FLAGS_SHADOW_RECEIVER_BIT +#import bevy_pbr::mesh_types MESH_FLAGS_SHADOW_RECEIVER_BIT, MESH_FLAGS_TRANSMITTED_SHADOW_RECEIVER_BIT fn alpha_discard(material: pbr_types::StandardMaterial, output_color: vec4) -> vec4 { var color = output_color; @@ -254,7 +255,7 @@ fn pbr( // F0 = vec3(0.0) var transmitted_shadow: f32 = 1.0; if ((in.flags & (MESH_FLAGS_SHADOW_RECEIVER_BIT | MESH_FLAGS_TRANSMITTED_SHADOW_RECEIVER_BIT)) == (MESH_FLAGS_SHADOW_RECEIVER_BIT | MESH_FLAGS_TRANSMITTED_SHADOW_RECEIVER_BIT) - && (point_lights.data[light_id].flags & mesh_view_types::POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) { + && (view_bindings::point_lights.data[light_id].flags & mesh_view_types::POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) { transmitted_shadow = shadows::fetch_point_shadow(light_id, diffuse_transmissive_lobe_world_position, -in.world_normal); } let light_contrib = lighting::point_light(diffuse_transmissive_lobe_world_position.xyz, light_id, 1.0, 1.0, -in.N, -in.V, vec3(0.0), vec3(0.0), vec2(0.1), diffuse_transmissive_color); @@ -286,7 +287,7 @@ fn pbr( // F0 = vec3(0.0) var transmitted_shadow: f32 = 1.0; if ((in.flags & (MESH_FLAGS_SHADOW_RECEIVER_BIT | MESH_FLAGS_TRANSMITTED_SHADOW_RECEIVER_BIT)) == (MESH_FLAGS_SHADOW_RECEIVER_BIT | MESH_FLAGS_TRANSMITTED_SHADOW_RECEIVER_BIT) - && (point_lights.data[light_id].flags & mesh_view_types::POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) { + && (view_bindings::point_lights.data[light_id].flags & mesh_view_types::POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) { transmitted_shadow = shadows::fetch_spot_shadow(light_id, diffuse_transmissive_lobe_world_position, -in.world_normal); } let light_contrib = lighting::spot_light(diffuse_transmissive_lobe_world_position.xyz, light_id, 1.0, 1.0, -in.N, -in.V, vec3(0.0), vec3(0.0), vec2(0.1), diffuse_transmissive_color); @@ -320,7 +321,7 @@ fn pbr( // F0 = vec3(0.0) var transmitted_shadow: f32 = 1.0; if ((in.flags & (MESH_FLAGS_SHADOW_RECEIVER_BIT | MESH_FLAGS_TRANSMITTED_SHADOW_RECEIVER_BIT)) == (MESH_FLAGS_SHADOW_RECEIVER_BIT | MESH_FLAGS_TRANSMITTED_SHADOW_RECEIVER_BIT) - && (lights.directional_lights[i].flags & mesh_view_types::DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) { + && (view_bindings::lights.directional_lights[i].flags & mesh_view_types::DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT) != 0u) { transmitted_shadow = shadows::fetch_directional_shadow(i, diffuse_transmissive_lobe_world_position, -in.world_normal, view_z); } let light_contrib = lighting::directional_light(i, 1.0, 1.0, -in.N, -in.V, vec3(0.0), vec3(0.0), vec2(0.1), diffuse_transmissive_color); @@ -381,14 +382,14 @@ fn pbr( let emissive_light = emissive.rgb * output_color.a; if transmission > 0.0 { - transmitted_light += bevy_pbr::lighting::transmissive_light(in.world_position, in.frag_coord.xyz, in.N, in.V, ior, thickness, perceptual_roughness, transmissive_color, transmitted_environment_light_specular).rgb; + transmitted_light += lighting::transmissive_light(in.world_position, in.frag_coord.xyz, in.N, in.V, ior, thickness, perceptual_roughness, transmissive_color, transmitted_environment_light_specular).rgb; } if in.material.attenuation_distance < (1.0 / 0.0) /* f32::INFINITY */ { // We reuse the `atmospheric_fog()` function here, as it's fundamentally // equivalent to the attenuation that takes place inside the material volume, // and will allow us to eventually hook up subsurface scattering more easily - var attenuation_fog: Fog; + var attenuation_fog: mesh_view_types::Fog; attenuation_fog.base_color.a = 1.0; attenuation_fog.be = pow(1.0 - in.material.attenuation_color.rgb, vec3(E)) / in.material.attenuation_distance; // TODO: Add the subsurface scattering factor below diff --git a/crates/bevy_pbr/src/render/pbr_lighting.wgsl b/crates/bevy_pbr/src/render/pbr_lighting.wgsl index c6de947ee8..a8997c2723 100644 --- a/crates/bevy_pbr/src/render/pbr_lighting.wgsl +++ b/crates/bevy_pbr/src/render/pbr_lighting.wgsl @@ -1,5 +1,6 @@ #define_import_path bevy_pbr::lighting +#import bevy_pbr::prepass_utils as prepass_utils #import bevy_pbr::utils PI #import bevy_pbr::mesh_view_types as view_types #import bevy_pbr::mesh_view_bindings as view_bindings @@ -320,7 +321,7 @@ fn transmissive_light(world_position: vec4, frag_coord: vec3, N: vec3< // https://blog.demofox.org/2022/01/01/interleaved-gradient-noise-a-different-kind-of-low-discrepancy-sequence fn interleaved_gradient_noise(pixel_coordinates: vec2) -> f32 { #ifdef TAA - let frame = f32(globals.frame_count % 64u); + let frame = f32(view_bindings::globals.frame_count % 64u); let xy = pixel_coordinates + 5.588238 * frame; #else // Don't vary noise per frame if TAA is not enabled @@ -345,7 +346,7 @@ const MAX_TRANSMISSIVE_TAPS = 16; fn fetch_transmissive_background(offset_position: vec2, frag_coord: vec3, perceptual_roughness: f32, distance: f32) -> vec4 { // Calculate view aspect ratio, used to scale offset so that it's proportionate - let aspect = view.viewport.z / view.viewport.w; + let aspect = view_bindings::view.viewport.z / view_bindings::view.viewport.w; // Calculate how “blurry” the transmission should be. // Blur is more or less eyeballed to look approximately “right”, since the “correct” @@ -365,7 +366,7 @@ fn fetch_transmissive_background(offset_position: vec2, frag_coord: vec3, frag_coord: vec3(modified_offset_position * view.viewport.zw, 0.0, 0.0), 0u) > frag_coord.z) { + if prepass_utils::prepass_depth(vec4(modified_offset_position * view_bindings::view.viewport.zw, 0.0, 0.0), 0u) > frag_coord.z { continue; } #endif // Sample the view transmission texture at the offset position + noise offset, to get the background color let sample = textureSample( - bevy_pbr::mesh_view_bindings::view_transmission_texture, - bevy_pbr::mesh_view_bindings::view_transmission_sampler, + view_bindings::view_transmission_texture, + view_bindings::view_transmission_sampler, modified_offset_position, );