Skip to content

Commit 3c80aff

Browse files
committed
Slight reorganization / renaming
1 parent 65cf58b commit 3c80aff

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

Source/Scene/Cesium3DTileBatchTable.js

+30-34
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,9 @@ define([
853853

854854
var that = this;
855855
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);
857859
var newMain;
858860

859861
if (ContextLimits.maximumVertexTextureImageUnits > 0) {
@@ -905,10 +907,19 @@ define([
905907
};
906908
};
907909

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+
909921
// The color blend mode is intended for the RGB channels so alpha is always just multiplied.
910922
// gl_FragColor is multiplied by the tile color only when tile_colorBlend is 0.0 (highlight)
911-
source = ShaderSource.replaceMain(source, 'tile_main');
912923
return source +
913924
'uniform float tile_colorBlend; \n' +
914925
'void tile_color(vec4 tile_featureColor) \n' +
@@ -920,24 +931,11 @@ define([
920931
'} \n';
921932
}
922933

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.
938936
// Otherwise if _3DTILESDIFFUSE is defined prefer the shader below that can switch the color mode at runtime.
939937
if (!defined(diffuseUniformName)) {
940-
return getDefaultShader(source, isVertexShader);
938+
return getDefaultShader(source, applyHighlight);
941939
}
942940

943941
// Find the diffuse uniform. Examples matches:
@@ -948,7 +946,7 @@ define([
948946

949947
if (!defined(uniformMatch)) {
950948
// Could not find uniform declaration of type vec3, vec4, or sampler2D
951-
return getDefaultShader(source, isVertexShader);
949+
return getDefaultShader(source, applyHighlight);
952950
}
953951

954952
var declaration = uniformMatch[0];
@@ -975,16 +973,10 @@ define([
975973

976974
// The color blend mode is intended for the RGB channels so alpha is always just multiplied.
977975
// 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';
988980

989981
var setColor;
990982
if (type === 'vec3' || type === 'vec4') {
@@ -1015,9 +1007,13 @@ define([
10151007
source + '\n' +
10161008
'void tile_color(vec4 tile_featureColor) \n' +
10171009
'{ \n' +
1018-
setColor +
1019-
applyHighlight +
1020-
'} \n';
1010+
setColor;
1011+
1012+
if (applyHighlight) {
1013+
source += highlight;
1014+
}
1015+
1016+
source += '} \n';
10211017

10221018
return source;
10231019
}
@@ -1027,7 +1023,7 @@ define([
10271023
return;
10281024
}
10291025
return function(source) {
1030-
source = modifyDiffuse(source, diffuseUniformName, false);
1026+
source = modifyDiffuse(source, diffuseUniformName, true);
10311027
if (ContextLimits.maximumVertexTextureImageUnits > 0) {
10321028
// When VTF is supported, per-feature show/hide already happened in the fragment shader
10331029
source +=

0 commit comments

Comments
 (0)