@@ -16,7 +16,6 @@ import { PushMaterial } from "../../Materials/pushMaterial";
16
16
import { ImageProcessingDefinesMixin } from "../../Materials/imageProcessingConfiguration.defines" ;
17
17
import { ImageProcessingConfiguration } from "../../Materials/imageProcessingConfiguration" ;
18
18
import type { BaseTexture } from "../../Materials/Textures/baseTexture" ;
19
- import { Texture } from "../../Materials/Textures/texture" ;
20
19
import type { RenderTargetTexture } from "../../Materials/Textures/renderTargetTexture" ;
21
20
import type { IShadowLight } from "../../Lights/shadowLight" ;
22
21
import { Constants } from "../../Engines/constants" ;
@@ -32,16 +31,21 @@ import {
32
31
BindLights ,
33
32
BindLogDepth ,
34
33
BindTextureMatrix ,
34
+ BindIBLParameters ,
35
+ BindIBLSamplers ,
35
36
HandleFallbacksForShadows ,
36
37
PrepareAttributesForBones ,
37
38
PrepareAttributesForInstances ,
38
39
PrepareDefinesForAttributes ,
39
40
PrepareDefinesForFrameBoundValues ,
40
41
PrepareDefinesForLights ,
42
+ PrepareDefinesForIBL ,
41
43
PrepareDefinesForMergedUV ,
42
44
PrepareDefinesForMisc ,
43
45
PrepareDefinesForMultiview ,
44
46
PrepareUniformsAndSamplersList ,
47
+ PrepareUniformsAndSamplersForIBL ,
48
+ PrepareUniformLayoutForIBL ,
45
49
} from "../materialHelper.functions" ;
46
50
import { SerializationHelper } from "../../Misc/decorators.serialization" ;
47
51
import { ShaderLanguage } from "../shaderLanguage" ;
@@ -597,57 +601,14 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
597
601
}
598
602
599
603
const reflectionTexture = this . _reflectionTexture ;
604
+ PrepareDefinesForIBL ( scene , reflectionTexture , defines ) ;
600
605
if ( reflectionTexture && MaterialFlags . ReflectionTextureEnabled ) {
601
606
if ( ! reflectionTexture . isReadyOrNotBlocking ( ) ) {
602
607
return false ;
603
608
}
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 ;
610
609
defines . EQUIRECTANGULAR_RELFECTION_FOV = this . useEquirectangularFOV ;
611
610
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 ;
651
612
652
613
if ( this . reflectionFresnel ) {
653
614
defines . REFLECTIONFRESNEL = true ;
@@ -662,25 +623,9 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
662
623
defines . REFLECTIONFALLOFF = false ;
663
624
}
664
625
} else {
665
- defines . REFLECTION = false ;
666
626
defines . REFLECTIONFRESNEL = false ;
667
627
defines . REFLECTIONFALLOFF = false ;
668
628
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 ;
684
629
}
685
630
}
686
631
@@ -779,9 +724,6 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
779
724
780
725
"vPrimaryColor" ,
781
726
"vPrimaryColorShadow" ,
782
- "vReflectionInfos" ,
783
- "reflectionMatrix" ,
784
- "vReflectionMicrosurfaceInfos" ,
785
727
"fFovMultiplier" ,
786
728
787
729
"shadowLevel" ,
@@ -798,7 +740,8 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
798
740
] ;
799
741
800
742
AddClipPlaneUniforms ( uniforms ) ;
801
- const samplers = [ "diffuseSampler" , "reflectionSampler" , "reflectionSamplerLow" , "reflectionSamplerHigh" ] ;
743
+ const samplers = [ "diffuseSampler" ] ;
744
+ PrepareUniformsAndSamplersForIBL ( uniforms , samplers , false ) ;
802
745
const uniformBuffers = [ "Material" , "Scene" ] ;
803
746
804
747
if ( ImageProcessingConfiguration ) {
@@ -908,10 +851,7 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
908
851
this . _uniformBuffer . addUniform ( "vPrimaryColor" , 4 ) ;
909
852
this . _uniformBuffer . addUniform ( "vPrimaryColorShadow" , 4 ) ;
910
853
this . _uniformBuffer . addUniform ( "vDiffuseInfos" , 2 ) ;
911
- this . _uniformBuffer . addUniform ( "vReflectionInfos" , 2 ) ;
912
854
this . _uniformBuffer . addUniform ( "diffuseMatrix" , 16 ) ;
913
- this . _uniformBuffer . addUniform ( "reflectionMatrix" , 16 ) ;
914
- this . _uniformBuffer . addUniform ( "vReflectionMicrosurfaceInfos" , 3 ) ;
915
855
this . _uniformBuffer . addUniform ( "fFovMultiplier" , 1 ) ;
916
856
this . _uniformBuffer . addUniform ( "pointSize" , 1 ) ;
917
857
this . _uniformBuffer . addUniform ( "shadowLevel" , 1 ) ;
@@ -920,6 +860,8 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
920
860
this . _uniformBuffer . addUniform ( "vReflectionControl" , 4 ) ;
921
861
this . _uniformBuffer . addUniform ( "projectedGroundInfos" , 2 ) ;
922
862
863
+ PrepareUniformLayoutForIBL ( this . _uniformBuffer , true , false , false ) ;
864
+
923
865
this . _uniformBuffer . create ( ) ;
924
866
}
925
867
@@ -987,17 +929,7 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
987
929
BindTextureMatrix ( this . _diffuseTexture , this . _uniformBuffer , "diffuse" ) ;
988
930
}
989
931
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 ) ;
1001
933
}
1002
934
1003
935
if ( this . shadowLevel > 0 ) {
@@ -1027,15 +959,7 @@ export class BackgroundMaterial extends BackgroundMaterialBase {
1027
959
}
1028
960
1029
961
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 ) ;
1039
963
1040
964
if ( defines . REFLECTIONFRESNEL ) {
1041
965
this . _uniformBuffer . updateFloat3 ( "vBackgroundCenter" , this . sceneCenter . x , this . sceneCenter . y , this . sceneCenter . z ) ;
0 commit comments