@@ -909,7 +909,7 @@ export class BackgroundMaterial extends PushMaterial {
909
909
} ;
910
910
911
911
var join = defines . toString ( ) ;
912
- let effect = scene . getEngine ( ) . createEffect ( "background" , < EffectCreationOptions > {
912
+ subMesh . setEffect ( scene . getEngine ( ) . createEffect ( "background" , < EffectCreationOptions > {
913
913
attributes : attribs ,
914
914
uniformsNames : uniforms ,
915
915
uniformBuffersNames : uniformBuffers ,
@@ -919,10 +919,9 @@ export class BackgroundMaterial extends PushMaterial {
919
919
onCompiled : onCompiled ,
920
920
onError : this . onError ,
921
921
indexParameters : { maxSimultaneousLights : this . _maxSimultaneousLights }
922
- } , engine ) ;
923
- subMesh . setEffect ( effect , defines ) ;
922
+ } , engine ) , defines ) ;
924
923
925
- this . buildUniformLayout ( effect ) ;
924
+ this . buildUniformLayout ( ) ;
926
925
}
927
926
928
927
if ( ! subMesh . effect || ! subMesh . effect . isReady ( ) ) {
@@ -978,35 +977,35 @@ export class BackgroundMaterial extends PushMaterial {
978
977
/**
979
978
* Build the uniform buffer used in the material.
980
979
*/
981
- public buildUniformLayout ( effect : Effect ) : void {
980
+ public buildUniformLayout ( ) : void {
982
981
// Order is important !
983
- effect . _uniformBuffer . addUniform ( "vPrimaryColor" , 4 ) ;
984
- effect . _uniformBuffer . addUniform ( "vPrimaryColorShadow" , 4 ) ;
985
- effect . _uniformBuffer . addUniform ( "vDiffuseInfos" , 2 ) ;
986
- effect . _uniformBuffer . addUniform ( "vReflectionInfos" , 2 ) ;
987
- effect . _uniformBuffer . addUniform ( "diffuseMatrix" , 16 ) ;
988
- effect . _uniformBuffer . addUniform ( "reflectionMatrix" , 16 ) ;
989
- effect . _uniformBuffer . addUniform ( "vReflectionMicrosurfaceInfos" , 3 ) ;
990
- effect . _uniformBuffer . addUniform ( "fFovMultiplier" , 1 ) ;
991
- effect . _uniformBuffer . addUniform ( "pointSize" , 1 ) ;
992
- effect . _uniformBuffer . addUniform ( "shadowLevel" , 1 ) ;
993
- effect . _uniformBuffer . addUniform ( "alpha" , 1 ) ;
994
- effect . _uniformBuffer . addUniform ( "vBackgroundCenter" , 3 ) ;
995
- effect . _uniformBuffer . addUniform ( "vReflectionControl" , 4 ) ;
996
-
997
- effect . _uniformBuffer . create ( ) ;
982
+ this . _uniformBuffer . addUniform ( "vPrimaryColor" , 4 ) ;
983
+ this . _uniformBuffer . addUniform ( "vPrimaryColorShadow" , 4 ) ;
984
+ this . _uniformBuffer . addUniform ( "vDiffuseInfos" , 2 ) ;
985
+ this . _uniformBuffer . addUniform ( "vReflectionInfos" , 2 ) ;
986
+ this . _uniformBuffer . addUniform ( "diffuseMatrix" , 16 ) ;
987
+ this . _uniformBuffer . addUniform ( "reflectionMatrix" , 16 ) ;
988
+ this . _uniformBuffer . addUniform ( "vReflectionMicrosurfaceInfos" , 3 ) ;
989
+ this . _uniformBuffer . addUniform ( "fFovMultiplier" , 1 ) ;
990
+ this . _uniformBuffer . addUniform ( "pointSize" , 1 ) ;
991
+ this . _uniformBuffer . addUniform ( "shadowLevel" , 1 ) ;
992
+ this . _uniformBuffer . addUniform ( "alpha" , 1 ) ;
993
+ this . _uniformBuffer . addUniform ( "vBackgroundCenter" , 3 ) ;
994
+ this . _uniformBuffer . addUniform ( "vReflectionControl" , 4 ) ;
995
+
996
+ this . _uniformBuffer . create ( ) ;
998
997
}
999
998
1000
999
/**
1001
1000
* Unbind the material.
1002
1001
*/
1003
1002
public unbind ( ) : void {
1004
1003
if ( this . _diffuseTexture && this . _diffuseTexture . isRenderTarget ) {
1005
- this . _activeEffect . _uniformBuffer . setTexture ( "diffuseSampler" , null ) ;
1004
+ this . _uniformBuffer . setTexture ( "diffuseSampler" , null ) ;
1006
1005
}
1007
1006
1008
1007
if ( this . _reflectionTexture && this . _reflectionTexture . isRenderTarget ) {
1009
- this . _activeEffect . _uniformBuffer . setTexture ( "reflectionSampler" , null ) ;
1008
+ this . _uniformBuffer . setTexture ( "reflectionSampler" , null ) ;
1010
1009
}
1011
1010
1012
1011
super . unbind ( ) ;
@@ -1046,76 +1045,75 @@ export class BackgroundMaterial extends PushMaterial {
1046
1045
MaterialHelper . BindBonesParameters ( mesh , this . _activeEffect ) ;
1047
1046
1048
1047
let mustRebind = this . _mustRebind ( scene , effect , mesh . visibility ) ;
1049
- let uniformBuffer = effect . _uniformBuffer ;
1050
1048
if ( mustRebind ) {
1051
- uniformBuffer . bindToEffect ( effect , "Material" ) ;
1049
+ this . _uniformBuffer . bindToEffect ( effect , "Material" ) ;
1052
1050
1053
1051
this . bindViewProjection ( effect ) ;
1054
1052
1055
1053
let reflectionTexture = this . _reflectionTexture ;
1056
- if ( ! uniformBuffer . useUbo || ! this . isFrozen || ! uniformBuffer . isSync ) {
1054
+ if ( ! this . _uniformBuffer . useUbo || ! this . isFrozen || ! this . _uniformBuffer . isSync ) {
1057
1055
1058
1056
// Texture uniforms
1059
1057
if ( scene . texturesEnabled ) {
1060
1058
if ( this . _diffuseTexture && MaterialFlags . DiffuseTextureEnabled ) {
1061
- uniformBuffer . updateFloat2 ( "vDiffuseInfos" , this . _diffuseTexture . coordinatesIndex , this . _diffuseTexture . level ) ;
1062
- MaterialHelper . BindTextureMatrix ( this . _diffuseTexture , uniformBuffer , "diffuse" ) ;
1059
+ this . _uniformBuffer . updateFloat2 ( "vDiffuseInfos" , this . _diffuseTexture . coordinatesIndex , this . _diffuseTexture . level ) ;
1060
+ MaterialHelper . BindTextureMatrix ( this . _diffuseTexture , this . _uniformBuffer , "diffuse" ) ;
1063
1061
}
1064
1062
1065
1063
if ( reflectionTexture && MaterialFlags . ReflectionTextureEnabled ) {
1066
- uniformBuffer . updateMatrix ( "reflectionMatrix" , reflectionTexture . getReflectionTextureMatrix ( ) ) ;
1067
- uniformBuffer . updateFloat2 ( "vReflectionInfos" , reflectionTexture . level , this . _reflectionBlur ) ;
1064
+ this . _uniformBuffer . updateMatrix ( "reflectionMatrix" , reflectionTexture . getReflectionTextureMatrix ( ) ) ;
1065
+ this . _uniformBuffer . updateFloat2 ( "vReflectionInfos" , reflectionTexture . level , this . _reflectionBlur ) ;
1068
1066
1069
- uniformBuffer . updateFloat3 ( "vReflectionMicrosurfaceInfos" ,
1067
+ this . _uniformBuffer . updateFloat3 ( "vReflectionMicrosurfaceInfos" ,
1070
1068
reflectionTexture . getSize ( ) . width ,
1071
1069
reflectionTexture . lodGenerationScale ,
1072
1070
reflectionTexture . lodGenerationOffset ) ;
1073
1071
}
1074
1072
}
1075
1073
1076
1074
if ( this . shadowLevel > 0 ) {
1077
- uniformBuffer . updateFloat ( "shadowLevel" , this . shadowLevel ) ;
1075
+ this . _uniformBuffer . updateFloat ( "shadowLevel" , this . shadowLevel ) ;
1078
1076
}
1079
- uniformBuffer . updateFloat ( "alpha" , this . alpha ) ;
1077
+ this . _uniformBuffer . updateFloat ( "alpha" , this . alpha ) ;
1080
1078
1081
1079
// Point size
1082
1080
if ( this . pointsCloud ) {
1083
- uniformBuffer . updateFloat ( "pointSize" , this . pointSize ) ;
1081
+ this . _uniformBuffer . updateFloat ( "pointSize" , this . pointSize ) ;
1084
1082
}
1085
1083
1086
1084
if ( defines . USEHIGHLIGHTANDSHADOWCOLORS ) {
1087
- uniformBuffer . updateColor4 ( "vPrimaryColor" , this . _primaryHighlightColor , 1.0 ) ;
1088
- uniformBuffer . updateColor4 ( "vPrimaryColorShadow" , this . _primaryShadowColor , 1.0 ) ;
1085
+ this . _uniformBuffer . updateColor4 ( "vPrimaryColor" , this . _primaryHighlightColor , 1.0 ) ;
1086
+ this . _uniformBuffer . updateColor4 ( "vPrimaryColorShadow" , this . _primaryShadowColor , 1.0 ) ;
1089
1087
}
1090
1088
else {
1091
- uniformBuffer . updateColor4 ( "vPrimaryColor" , this . _primaryColor , 1.0 ) ;
1089
+ this . _uniformBuffer . updateColor4 ( "vPrimaryColor" , this . _primaryColor , 1.0 ) ;
1092
1090
}
1093
1091
}
1094
1092
1095
- uniformBuffer . updateFloat ( "fFovMultiplier" , this . _fovMultiplier ) ;
1093
+ this . _uniformBuffer . updateFloat ( "fFovMultiplier" , this . _fovMultiplier ) ;
1096
1094
1097
1095
// Textures
1098
1096
if ( scene . texturesEnabled ) {
1099
1097
if ( this . _diffuseTexture && MaterialFlags . DiffuseTextureEnabled ) {
1100
- uniformBuffer . setTexture ( "diffuseSampler" , this . _diffuseTexture ) ;
1098
+ this . _uniformBuffer . setTexture ( "diffuseSampler" , this . _diffuseTexture ) ;
1101
1099
}
1102
1100
1103
1101
if ( reflectionTexture && MaterialFlags . ReflectionTextureEnabled ) {
1104
1102
if ( defines . REFLECTIONBLUR && defines . TEXTURELODSUPPORT ) {
1105
- uniformBuffer . setTexture ( "reflectionSampler" , reflectionTexture ) ;
1103
+ this . _uniformBuffer . setTexture ( "reflectionSampler" , reflectionTexture ) ;
1106
1104
}
1107
1105
else if ( ! defines . REFLECTIONBLUR ) {
1108
- uniformBuffer . setTexture ( "reflectionSampler" , reflectionTexture ) ;
1106
+ this . _uniformBuffer . setTexture ( "reflectionSampler" , reflectionTexture ) ;
1109
1107
}
1110
1108
else {
1111
- uniformBuffer . setTexture ( "reflectionSampler" , reflectionTexture . _lodTextureMid || reflectionTexture ) ;
1112
- uniformBuffer . setTexture ( "reflectionSamplerLow" , reflectionTexture . _lodTextureLow || reflectionTexture ) ;
1113
- uniformBuffer . setTexture ( "reflectionSamplerHigh" , reflectionTexture . _lodTextureHigh || reflectionTexture ) ;
1109
+ this . _uniformBuffer . setTexture ( "reflectionSampler" , reflectionTexture . _lodTextureMid || reflectionTexture ) ;
1110
+ this . _uniformBuffer . setTexture ( "reflectionSamplerLow" , reflectionTexture . _lodTextureLow || reflectionTexture ) ;
1111
+ this . _uniformBuffer . setTexture ( "reflectionSamplerHigh" , reflectionTexture . _lodTextureHigh || reflectionTexture ) ;
1114
1112
}
1115
1113
1116
1114
if ( defines . REFLECTIONFRESNEL ) {
1117
- uniformBuffer . updateFloat3 ( "vBackgroundCenter" , this . sceneCenter . x , this . sceneCenter . y , this . sceneCenter . z ) ;
1118
- uniformBuffer . updateFloat4 ( "vReflectionControl" , this . _reflectionControls . x , this . _reflectionControls . y , this . _reflectionControls . z , this . _reflectionControls . w ) ;
1115
+ this . _uniformBuffer . updateFloat3 ( "vBackgroundCenter" , this . sceneCenter . x , this . sceneCenter . y , this . sceneCenter . z ) ;
1116
+ this . _uniformBuffer . updateFloat4 ( "vReflectionControl" , this . _reflectionControls . x , this . _reflectionControls . y , this . _reflectionControls . z , this . _reflectionControls . w ) ;
1119
1117
}
1120
1118
}
1121
1119
}
@@ -1143,7 +1141,7 @@ export class BackgroundMaterial extends PushMaterial {
1143
1141
}
1144
1142
}
1145
1143
1146
- uniformBuffer . update ( ) ;
1144
+ this . _uniformBuffer . update ( ) ;
1147
1145
1148
1146
this . _afterBind ( mesh , this . _activeEffect ) ;
1149
1147
}
0 commit comments