@@ -16,7 +16,6 @@ import { PushMaterial } from "../../Materials/pushMaterial";
1616import { ImageProcessingDefinesMixin } from "../../Materials/imageProcessingConfiguration.defines" ;
1717import { ImageProcessingConfiguration } from "../../Materials/imageProcessingConfiguration" ;
1818import type { BaseTexture } from "../../Materials/Textures/baseTexture" ;
19- import { Texture } from "../../Materials/Textures/texture" ;
2019import type { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture" ;
2120import type { IShadowLight } from "../../Lights/shadowLight" ;
2221import { Constants } from "../../Engines/constants" ;
@@ -32,16 +31,21 @@ import {
3231 BindLights ,
3332 BindLogDepth ,
3433 BindTextureMatrix ,
34+ BindIBLParameters ,
35+ BindIBLSamplers ,
3536 HandleFallbacksForShadows ,
3637 PrepareAttributesForBones ,
3738 PrepareAttributesForInstances ,
3839 PrepareDefinesForAttributes ,
3940 PrepareDefinesForFrameBoundValues ,
4041 PrepareDefinesForLights ,
42+ PrepareDefinesForIBL ,
4143 PrepareDefinesForMergedUV ,
4244 PrepareDefinesForMisc ,
4345 PrepareDefinesForMultiview ,
4446 PrepareUniformsAndSamplersList ,
47+ PrepareUniformsAndSamplersForIBL ,
48+ PrepareUniformLayoutForIBL ,
4549} from "../materialHelper.functions" ;
4650import { SerializationHelper } from "../../Misc/decorators.serialization" ;
4751import { ShaderLanguage } from "../shaderLanguage" ;
@@ -597,57 +601,14 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
597601 }
598602
599603 const reflectionTexture = this . _reflectionTexture ;
604+ PrepareDefinesForIBL ( scene , reflectionTexture , defines ) ;
600605 if ( reflectionTexture && MaterialFlags . ReflectionTextureEnabled ) {
601606 if ( ! reflectionTexture . isReadyOrNotBlocking ( ) ) {
602607 return false ;
603608 }
604-
605- defines . REFLECTION = true ;
606- defines . GAMMAREFLECTION = reflectionTexture . gammaSpace ;
607- defines . RGBDREFLECTION = reflectionTexture . isRGBD ;
608- defines . REFLECTIONBLUR = this . _reflectionBlur > 0 ;
609- defines . LODINREFLECTIONALPHA = reflectionTexture . lodLevelInAlpha ;
610609 defines . EQUIRECTANGULAR_RELFECTION_FOV = this . useEquirectangularFOV ;
611610 defines . REFLECTIONBGR = this . switchToBGR ;
612-
613- if ( reflectionTexture . coordinatesMode === Texture . INVCUBIC_MODE ) {
614- defines . INVERTCUBICMAP = true ;
615- }
616-
617- defines . REFLECTIONMAP_3D = reflectionTexture . isCube ;
618- defines . REFLECTIONMAP_OPPOSITEZ = defines . REFLECTIONMAP_3D && this . getScene ( ) . useRightHandedSystem ? ! reflectionTexture . invertZ : reflectionTexture . invertZ ;
619-
620- switch ( reflectionTexture . coordinatesMode ) {
621- case Texture . EXPLICIT_MODE :
622- defines . REFLECTIONMAP_EXPLICIT = true ;
623- break ;
624- case Texture . PLANAR_MODE :
625- defines . REFLECTIONMAP_PLANAR = true ;
626- break ;
627- case Texture . PROJECTION_MODE :
628- defines . REFLECTIONMAP_PROJECTION = true ;
629- break ;
630- case Texture . SKYBOX_MODE :
631- defines . REFLECTIONMAP_SKYBOX = true ;
632- break ;
633- case Texture . SPHERICAL_MODE :
634- defines . REFLECTIONMAP_SPHERICAL = true ;
635- break ;
636- case Texture . EQUIRECTANGULAR_MODE :
637- defines . REFLECTIONMAP_EQUIRECTANGULAR = true ;
638- break ;
639- case Texture . FIXED_EQUIRECTANGULAR_MODE :
640- defines . REFLECTIONMAP_EQUIRECTANGULAR_FIXED = true ;
641- break ;
642- case Texture . FIXED_EQUIRECTANGULAR_MIRRORED_MODE :
643- defines . REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = true ;
644- break ;
645- case Texture . CUBIC_MODE :
646- case Texture . INVCUBIC_MODE :
647- default :
648- defines . REFLECTIONMAP_CUBIC = true ;
649- break ;
650- }
611+ defines . REFLECTIONBLUR = this . _reflectionBlur > 0 ;
651612
652613 if ( this . reflectionFresnel ) {
653614 defines . REFLECTIONFRESNEL = true ;
@@ -662,25 +623,9 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
662623 defines . REFLECTIONFALLOFF = false ;
663624 }
664625 } else {
665- defines . REFLECTION = false ;
666626 defines . REFLECTIONFRESNEL = false ;
667627 defines . REFLECTIONFALLOFF = false ;
668628 defines . REFLECTIONBLUR = false ;
669- defines . REFLECTIONMAP_3D = false ;
670- defines . REFLECTIONMAP_SPHERICAL = false ;
671- defines . REFLECTIONMAP_PLANAR = false ;
672- defines . REFLECTIONMAP_CUBIC = false ;
673- defines . REFLECTIONMAP_PROJECTION = false ;
674- defines . REFLECTIONMAP_SKYBOX = false ;
675- defines . REFLECTIONMAP_EXPLICIT = false ;
676- defines . REFLECTIONMAP_EQUIRECTANGULAR = false ;
677- defines . REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false ;
678- defines . REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false ;
679- defines . INVERTCUBICMAP = false ;
680- defines . REFLECTIONMAP_OPPOSITEZ = false ;
681- defines . LODINREFLECTIONALPHA = false ;
682- defines . GAMMAREFLECTION = false ;
683- defines . RGBDREFLECTION = false ;
684629 }
685630 }
686631
@@ -779,9 +724,6 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
779724
780725 "vPrimaryColor" ,
781726 "vPrimaryColorShadow" ,
782- "vReflectionInfos" ,
783- "reflectionMatrix" ,
784- "vReflectionMicrosurfaceInfos" ,
785727 "fFovMultiplier" ,
786728
787729 "shadowLevel" ,
@@ -798,7 +740,8 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
798740 ] ;
799741
800742 AddClipPlaneUniforms ( uniforms ) ;
801- const samplers = [ "diffuseSampler" , "reflectionSampler" , "reflectionSamplerLow" , "reflectionSamplerHigh" ] ;
743+ const samplers = [ "diffuseSampler" ] ;
744+ PrepareUniformsAndSamplersForIBL ( uniforms , samplers , false ) ;
802745 const uniformBuffers = [ "Material" , "Scene" ] ;
803746
804747 if ( ImageProcessingConfiguration ) {
@@ -908,10 +851,7 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
908851 this . _uniformBuffer . addUniform ( "vPrimaryColor" , 4 ) ;
909852 this . _uniformBuffer . addUniform ( "vPrimaryColorShadow" , 4 ) ;
910853 this . _uniformBuffer . addUniform ( "vDiffuseInfos" , 2 ) ;
911- this . _uniformBuffer . addUniform ( "vReflectionInfos" , 2 ) ;
912854 this . _uniformBuffer . addUniform ( "diffuseMatrix" , 16 ) ;
913- this . _uniformBuffer . addUniform ( "reflectionMatrix" , 16 ) ;
914- this . _uniformBuffer . addUniform ( "vReflectionMicrosurfaceInfos" , 3 ) ;
915855 this . _uniformBuffer . addUniform ( "fFovMultiplier" , 1 ) ;
916856 this . _uniformBuffer . addUniform ( "pointSize" , 1 ) ;
917857 this . _uniformBuffer . addUniform ( "shadowLevel" , 1 ) ;
@@ -920,6 +860,8 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
920860 this . _uniformBuffer . addUniform ( "vReflectionControl" , 4 ) ;
921861 this . _uniformBuffer . addUniform ( "projectedGroundInfos" , 2 ) ;
922862
863+ PrepareUniformLayoutForIBL ( this . _uniformBuffer , true , false , false ) ;
864+
923865 this . _uniformBuffer . create ( ) ;
924866 }
925867
@@ -987,17 +929,7 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
987929 BindTextureMatrix ( this . _diffuseTexture , this . _uniformBuffer , "diffuse" ) ;
988930 }
989931
990- if ( reflectionTexture && MaterialFlags . ReflectionTextureEnabled ) {
991- this . _uniformBuffer . updateMatrix ( "reflectionMatrix" , reflectionTexture . getReflectionTextureMatrix ( ) ) ;
992- this . _uniformBuffer . updateFloat2 ( "vReflectionInfos" , reflectionTexture . level , this . _reflectionBlur ) ;
993-
994- this . _uniformBuffer . updateFloat3 (
995- "vReflectionMicrosurfaceInfos" ,
996- reflectionTexture . getSize ( ) . width ,
997- reflectionTexture . lodGenerationScale ,
998- reflectionTexture . lodGenerationOffset
999- ) ;
1000- }
932+ BindIBLParameters ( scene , defines , this . _uniformBuffer , reflectionTexture ) ;
1001933 }
1002934
1003935 if ( this . shadowLevel > 0 ) {
@@ -1027,15 +959,7 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
1027959 }
1028960
1029961 if ( reflectionTexture && MaterialFlags . ReflectionTextureEnabled ) {
1030- if ( defines . REFLECTIONBLUR && defines . TEXTURELODSUPPORT ) {
1031- this . _uniformBuffer . setTexture ( "reflectionSampler" , reflectionTexture ) ;
1032- } else if ( ! defines . REFLECTIONBLUR ) {
1033- this . _uniformBuffer . setTexture ( "reflectionSampler" , reflectionTexture ) ;
1034- } else {
1035- this . _uniformBuffer . setTexture ( "reflectionSampler" , reflectionTexture . _lodTextureMid || reflectionTexture ) ;
1036- this . _uniformBuffer . setTexture ( "reflectionSamplerLow" , reflectionTexture . _lodTextureLow || reflectionTexture ) ;
1037- this . _uniformBuffer . setTexture ( "reflectionSamplerHigh" , reflectionTexture . _lodTextureHigh || reflectionTexture ) ;
1038- }
962+ BindIBLSamplers ( scene , defines , this . _uniformBuffer , reflectionTexture ) ;
1039963
1040964 if ( defines . REFLECTIONFRESNEL ) {
1041965 this . _uniformBuffer . updateFloat3 ( "vBackgroundCenter" , this . sceneCenter . x , this . sceneCenter . y , this . sceneCenter . z ) ;
0 commit comments