@@ -853,7 +853,9 @@ define([
853
853
854
854
var that = this ;
855
855
return function ( source ) {
856
- var renamedSource = modifyDiffuse ( source , diffuseUniformName , true ) ;
856
+ // If the color blend mode is HIGHLIGHT, the highlight color will always be applied in the fragment shader.
857
+ // No need to apply the highlight color in the vertex shader as well.
858
+ var renamedSource = modifyDiffuse ( source , diffuseUniformName , false ) ;
857
859
var newMain ;
858
860
859
861
if ( ContextLimits . maximumVertexTextureImageUnits > 0 ) {
@@ -905,10 +907,19 @@ define([
905
907
} ;
906
908
} ;
907
909
908
- function getHighlightOnlyFragmentShader ( source ) {
910
+ function getDefaultShader ( source , applyHighlight ) {
911
+ source = ShaderSource . replaceMain ( source , 'tile_main' ) ;
912
+
913
+ if ( ! applyHighlight ) {
914
+ return source +
915
+ 'void tile_color(vec4 tile_featureColor) \n' +
916
+ '{ \n' +
917
+ ' tile_main(); \n' +
918
+ '} \n' ;
919
+ }
920
+
909
921
// The color blend mode is intended for the RGB channels so alpha is always just multiplied.
910
922
// gl_FragColor is multiplied by the tile color only when tile_colorBlend is 0.0 (highlight)
911
- source = ShaderSource . replaceMain ( source , 'tile_main' ) ;
912
923
return source +
913
924
'uniform float tile_colorBlend; \n' +
914
925
'void tile_color(vec4 tile_featureColor) \n' +
@@ -920,24 +931,11 @@ define([
920
931
'} \n' ;
921
932
}
922
933
923
- function getPassthroughVertexShader ( source ) {
924
- source = ShaderSource . replaceMain ( source , 'tile_main' ) ;
925
- return source +
926
- 'void tile_color(vec4 tile_featureColor) \n' +
927
- '{ \n' +
928
- ' tile_main(); \n' +
929
- '} \n' ;
930
- }
931
-
932
- function getDefaultShader ( source , isVertexShader ) {
933
- return isVertexShader ? getPassthroughVertexShader ( source ) : getHighlightOnlyFragmentShader ( source ) ;
934
- }
935
-
936
- function modifyDiffuse ( source , diffuseUniformName , isVertexShader ) {
937
- // If the glTF does not specify the _3DTILESDIFFUSE semantic, return a basic highlight shader.
934
+ function modifyDiffuse ( source , diffuseUniformName , applyHighlight ) {
935
+ // If the glTF does not specify the _3DTILESDIFFUSE semantic, return the default shader.
938
936
// Otherwise if _3DTILESDIFFUSE is defined prefer the shader below that can switch the color mode at runtime.
939
937
if ( ! defined ( diffuseUniformName ) ) {
940
- return getDefaultShader ( source , isVertexShader ) ;
938
+ return getDefaultShader ( source , applyHighlight ) ;
941
939
}
942
940
943
941
// Find the diffuse uniform. Examples matches:
@@ -948,7 +946,7 @@ define([
948
946
949
947
if ( ! defined ( uniformMatch ) ) {
950
948
// Could not find uniform declaration of type vec3, vec4, or sampler2D
951
- return getDefaultShader ( source , isVertexShader ) ;
949
+ return getDefaultShader ( source , applyHighlight ) ;
952
950
}
953
951
954
952
var declaration = uniformMatch [ 0 ] ;
@@ -975,16 +973,10 @@ define([
975
973
976
974
// The color blend mode is intended for the RGB channels so alpha is always just multiplied.
977
975
// gl_FragColor is multiplied by the tile color only when tile_colorBlend is 0.0 (highlight)
978
- var applyHighlight = '' ;
979
-
980
- if ( ! isVertexShader ) {
981
- // Highlight color is always applied in the fragment shader, from either here or in getHighlightOnlyFragmentShader.
982
- // No need to apply the highlight color in the vertex shader as well.
983
- applyHighlight =
984
- ' gl_FragColor.a *= tile_featureColor.a; \n' +
985
- ' float highlight = ceil(tile_colorBlend); \n' +
986
- ' gl_FragColor.rgb *= mix(tile_featureColor.rgb, vec3(1.0), highlight); \n' ;
987
- }
976
+ var highlight =
977
+ ' gl_FragColor.a *= tile_featureColor.a; \n' +
978
+ ' float highlight = ceil(tile_colorBlend); \n' +
979
+ ' gl_FragColor.rgb *= mix(tile_featureColor.rgb, vec3(1.0), highlight); \n' ;
988
980
989
981
var setColor ;
990
982
if ( type === 'vec3' || type === 'vec4' ) {
@@ -1015,9 +1007,13 @@ define([
1015
1007
source + '\n' +
1016
1008
'void tile_color(vec4 tile_featureColor) \n' +
1017
1009
'{ \n' +
1018
- setColor +
1019
- applyHighlight +
1020
- '} \n' ;
1010
+ setColor ;
1011
+
1012
+ if ( applyHighlight ) {
1013
+ source += highlight ;
1014
+ }
1015
+
1016
+ source += '} \n' ;
1021
1017
1022
1018
return source ;
1023
1019
}
@@ -1027,7 +1023,7 @@ define([
1027
1023
return ;
1028
1024
}
1029
1025
return function ( source ) {
1030
- source = modifyDiffuse ( source , diffuseUniformName , false ) ;
1026
+ source = modifyDiffuse ( source , diffuseUniformName , true ) ;
1031
1027
if ( ContextLimits . maximumVertexTextureImageUnits > 0 ) {
1032
1028
// When VTF is supported, per-feature show/hide already happened in the fragment shader
1033
1029
source +=
0 commit comments