forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Implement minimal reflection probes. (bevyengine#10057)"
This reverts commit 54a943d.
- Loading branch information
Showing
24 changed files
with
249 additions
and
1,523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-4.43 MB
assets/environment_maps/cubes_reflection_probe_specular_rgb9e5_zstd.ktx2
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#define_import_path bevy_pbr::environment_map | ||
|
||
#import bevy_pbr::mesh_view_bindings as bindings; | ||
|
||
struct EnvironmentMapLight { | ||
diffuse: vec3<f32>, | ||
specular: vec3<f32>, | ||
}; | ||
|
||
fn environment_map_light( | ||
perceptual_roughness: f32, | ||
roughness: f32, | ||
diffuse_color: vec3<f32>, | ||
NdotV: f32, | ||
f_ab: vec2<f32>, | ||
N: vec3<f32>, | ||
R: vec3<f32>, | ||
F0: vec3<f32>, | ||
) -> EnvironmentMapLight { | ||
|
||
// Split-sum approximation for image based lighting: https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf | ||
// Technically we could use textureNumLevels(environment_map_specular) - 1 here, but we use a uniform | ||
// because textureNumLevels() does not work on WebGL2 | ||
let radiance_level = perceptual_roughness * f32(bindings::lights.environment_map_smallest_specular_mip_level); | ||
let irradiance = textureSampleLevel(bindings::environment_map_diffuse, bindings::environment_map_sampler, vec3(N.xy, -N.z), 0.0).rgb; | ||
let radiance = textureSampleLevel(bindings::environment_map_specular, bindings::environment_map_sampler, vec3(R.xy, -R.z), radiance_level).rgb; | ||
|
||
// No real world material has specular values under 0.02, so we use this range as a | ||
// "pre-baked specular occlusion" that extinguishes the fresnel term, for artistic control. | ||
// See: https://google.github.io/filament/Filament.html#specularocclusion | ||
let specular_occlusion = saturate(dot(F0, vec3(50.0 * 0.33))); | ||
|
||
// Multiscattering approximation: https://www.jcgt.org/published/0008/01/03/paper.pdf | ||
// Useful reference: https://bruop.github.io/ibl | ||
let Fr = max(vec3(1.0 - roughness), F0) - F0; | ||
let kS = F0 + Fr * pow(1.0 - NdotV, 5.0); | ||
let Ess = f_ab.x + f_ab.y; | ||
let FssEss = kS * Ess * specular_occlusion; | ||
let Ems = 1.0 - Ess; | ||
let Favg = F0 + (1.0 - F0) / 21.0; | ||
let Fms = FssEss * Favg / (1.0 - Ems * Favg); | ||
let FmsEms = Fms * Ems; | ||
let Edss = 1.0 - (FssEss + FmsEms); | ||
let kD = diffuse_color * Edss; | ||
|
||
var out: EnvironmentMapLight; | ||
out.diffuse = (FmsEms + kD) * irradiance; | ||
out.specular = FssEss * radiance; | ||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use bevy_app::{App, Plugin}; | ||
use bevy_asset::{load_internal_asset, Handle}; | ||
use bevy_core_pipeline::prelude::Camera3d; | ||
use bevy_ecs::{prelude::Component, query::With}; | ||
use bevy_reflect::Reflect; | ||
use bevy_render::{ | ||
extract_component::{ExtractComponent, ExtractComponentPlugin}, | ||
render_asset::RenderAssets, | ||
render_resource::{ | ||
binding_types::{sampler, texture_cube}, | ||
*, | ||
}, | ||
texture::{FallbackImageCubemap, Image}, | ||
}; | ||
|
||
pub const ENVIRONMENT_MAP_SHADER_HANDLE: Handle<Shader> = | ||
Handle::weak_from_u128(154476556247605696); | ||
|
||
pub struct EnvironmentMapPlugin; | ||
|
||
impl Plugin for EnvironmentMapPlugin { | ||
fn build(&self, app: &mut App) { | ||
load_internal_asset!( | ||
app, | ||
ENVIRONMENT_MAP_SHADER_HANDLE, | ||
"environment_map.wgsl", | ||
Shader::from_wgsl | ||
); | ||
|
||
app.register_type::<EnvironmentMapLight>() | ||
.add_plugins(ExtractComponentPlugin::<EnvironmentMapLight>::default()); | ||
} | ||
} | ||
|
||
/// Environment map based ambient lighting representing light from distant scenery. | ||
/// | ||
/// When added to a 3D camera, this component adds indirect light | ||
/// to every point of the scene (including inside, enclosed areas) based on | ||
/// an environment cubemap texture. This is similar to [`crate::AmbientLight`], but | ||
/// higher quality, and is intended for outdoor scenes. | ||
/// | ||
/// The environment map must be prefiltered into a diffuse and specular cubemap based on the | ||
/// [split-sum approximation](https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf). | ||
/// | ||
/// To prefilter your environment map, you can use `KhronosGroup`'s [glTF-IBL-Sampler](https://github.com/KhronosGroup/glTF-IBL-Sampler). | ||
/// The diffuse map uses the Lambertian distribution, and the specular map uses the GGX distribution. | ||
/// | ||
/// `KhronosGroup` also has several prefiltered environment maps that can be found [here](https://github.com/KhronosGroup/glTF-Sample-Environments). | ||
#[derive(Component, Reflect, Clone, ExtractComponent)] | ||
#[extract_component_filter(With<Camera3d>)] | ||
pub struct EnvironmentMapLight { | ||
pub diffuse_map: Handle<Image>, | ||
pub specular_map: Handle<Image>, | ||
} | ||
|
||
impl EnvironmentMapLight { | ||
/// Whether or not all textures necessary to use the environment map | ||
/// have been loaded by the asset server. | ||
pub fn is_loaded(&self, images: &RenderAssets<Image>) -> bool { | ||
images.get(&self.diffuse_map).is_some() && images.get(&self.specular_map).is_some() | ||
} | ||
} | ||
|
||
pub fn get_bindings<'a>( | ||
environment_map_light: Option<&EnvironmentMapLight>, | ||
images: &'a RenderAssets<Image>, | ||
fallback_image_cubemap: &'a FallbackImageCubemap, | ||
) -> (&'a TextureView, &'a TextureView, &'a Sampler) { | ||
let (diffuse_map, specular_map) = match ( | ||
environment_map_light.and_then(|env_map| images.get(&env_map.diffuse_map)), | ||
environment_map_light.and_then(|env_map| images.get(&env_map.specular_map)), | ||
) { | ||
(Some(diffuse_map), Some(specular_map)) => { | ||
(&diffuse_map.texture_view, &specular_map.texture_view) | ||
} | ||
_ => ( | ||
&fallback_image_cubemap.texture_view, | ||
&fallback_image_cubemap.texture_view, | ||
), | ||
}; | ||
|
||
(diffuse_map, specular_map, &fallback_image_cubemap.sampler) | ||
} | ||
|
||
pub fn get_bind_group_layout_entries() -> [BindGroupLayoutEntryBuilder; 3] { | ||
[ | ||
texture_cube(TextureSampleType::Float { filterable: true }), | ||
texture_cube(TextureSampleType::Float { filterable: true }), | ||
sampler(SamplerBindingType::Filtering), | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.