@@ -54,11 +54,6 @@ import {
5454 registerRedrawWhenSegmentationDisplayState3DChanged ,
5555 SegmentationLayerSharedObject ,
5656} from "#src/segmentation_display_state/frontend.js" ;
57- import {
58- extractUsedSegmentProperties ,
59- getShaderOutputType ,
60- SegmentationColorUserShader ,
61- } from "#src/segmentation_display_state/property_map.js" ;
6257import type { WatchableValueInterface } from "#src/trackable_value.js" ;
6358import {
6459 AggregateWatchableValue ,
@@ -80,9 +75,9 @@ import type { GL } from "#src/webgl/context.js";
8075import type { WatchableShaderError } from "#src/webgl/dynamic_shader.js" ;
8176import {
8277 parameterizedEmitterDependentShaderGetter ,
83- shaderCodeWithLineDirective ,
8478} from "#src/webgl/dynamic_shader.js" ;
8579import type { ShaderBuilder , ShaderProgram } from "#src/webgl/shader.js" ;
80+ import { glsl_uint64 } from "#src/webgl/shader_lib.js" ;
8681import type { ShaderControlState } from "#src/webgl/shader_ui_controls.js" ;
8782import {
8883 addControlsToBuilder ,
@@ -291,6 +286,14 @@ export class MeshShaderManager {
291286 gl . uniform1ui ( shader . uniform ( "uPickID" ) , pickID ) ;
292287 }
293288
289+ setID ( gl : GL , shader : ShaderProgram , id : bigint ) {
290+ gl . uniform2ui (
291+ shader . uniform ( `uID` ) ,
292+ Number ( id & 0xffffffffn ) ,
293+ Number ( id >> 32n ) ,
294+ ) ;
295+ }
296+
294297 beginModel (
295298 gl : GL ,
296299 shader : ShaderProgram ,
@@ -366,7 +369,7 @@ export class MeshShaderManager {
366369 gl . disableVertexAttribArray ( shader . attribute ( "aVertexNormal" ) ) ;
367370 }
368371
369- makeGetter ( layer : RefCounted & { gl : GL ; displayState : MeshDisplayState , segmentationColorUserShader : SegmentationColorUserShader } ) {
372+ makeGetter ( layer : RefCounted & { gl : GL ; displayState : MeshDisplayState } ) {
370373 const parameters = layer . registerDisposer (
371374 new AggregateWatchableValue ( ( refCounted ) => ( {
372375 shaderBuilderState :
@@ -395,13 +398,15 @@ export class MeshShaderManager {
395398 ) => {
396399 addControlsToBuilder ( shaderBuilderState , builder ) ;
397400 this . vertexPositionHandler . defineShader ( builder ) ;
401+ layer . displayState . segmentationColorUserShader . defineShader ( builder , /*fragment=*/ false ) ;
398402 builder . addAttribute ( "highp vec2" , "aVertexNormal" ) ;
399403 builder . addVarying ( "highp vec4" , "vColor" ) ;
400404 builder . addUniform ( "highp vec4" , "uLightDirection" ) ;
401405 builder . addUniform ( "highp vec4" , "uColor" ) ;
402406 builder . addUniform ( "highp mat3" , "uNormalMatrix" ) ;
403407 builder . addUniform ( "highp mat4" , "uModelViewProjection" ) ;
404408 builder . addUniform ( "highp uint" , "uPickID" ) ;
409+ builder . addUniform ( "highp uvec2" , "uID" ) ;
405410
406411 if ( silhouetteRenderingEnabled ) {
407412 builder . addUniform ( "highp float" , "uSilhouettePower" ) ;
@@ -411,6 +416,7 @@ export class MeshShaderManager {
411416 builder . addUniform ( "highp vec3" , "uFragmentShape" ) ;
412417 }
413418 builder . addVertexCode ( glsl_decodeNormalOctahedronSnorm8 ) ;
419+ builder . addVertexCode ( glsl_uint64 ) ;
414420 let vertexMain = "" ;
415421 if ( this . fragmentRelativeVertices ) {
416422 vertexMain += `
@@ -423,18 +429,14 @@ highp vec3 vertexPosition = getVertexPosition();
423429highp vec3 normalMultiplier = vec3(1.0, 1.0, 1.0);
424430` ;
425431 }
426-
427- layer . segmentationColorUserShader . defineShader ( builder ) ;
428-
429-
430432 vertexMain += `
431433gl_Position = uModelViewProjection * vec4(vertexPosition, 1.0);
432434vec3 origNormal = decodeNormalOctahedronSnorm8(aVertexNormal);
433435vec3 normal = normalize(uNormalMatrix * (normalMultiplier * origNormal));
434436float absCosAngle = abs(dot(normal, uLightDirection.xyz));
435437float lightingFactor = absCosAngle + uLightDirection.w;
436438vColor = uColor;
437- loadSegmentProperties();
439+ loadSegmentProperties(uint64_t(uID) );
438440vColor = segmentColor(vColor);
439441vColor = vec4(lightingFactor * vColor.rgb, vColor.a);
440442` ;
@@ -461,7 +463,6 @@ export interface MeshDisplayState extends SegmentationDisplayState3D {
461463export class MeshLayer extends PerspectiveViewRenderLayer < ThreeDimensionalRenderLayerAttachmentState > {
462464 protected meshShaderManager ;
463465 private getShader ;
464- public segmentationColorUserShader ;
465466 backend : SegmentationLayerSharedObject ;
466467
467468 constructor (
@@ -474,7 +475,6 @@ export class MeshLayer extends PerspectiveViewRenderLayer<ThreeDimensionalRender
474475 /*fragmentRelativeVertices=*/ false ,
475476 VertexPositionFormat . float32 ,
476477 ) ;
477- this . segmentationColorUserShader = new SegmentationColorUserShader ( displayState ) ;
478478 this . getShader = this . meshShaderManager . makeGetter ( this ) ;
479479
480480 registerRedrawWhenSegmentationDisplayState3DChanged ( displayState , this ) ;
@@ -487,7 +487,7 @@ export class MeshLayer extends PerspectiveViewRenderLayer<ThreeDimensionalRender
487487 ) ,
488488 ) ;
489489 this . registerDisposer (
490- displayState . segmentColorShaderControlState . parseResult . changed . add (
490+ displayState . segmentationColorUserShader . changed . add (
491491 this . redrawNeeded . dispatch ,
492492 ) ,
493493 ) ;
@@ -585,6 +585,7 @@ export class MeshLayer extends PerspectiveViewRenderLayer<ThreeDimensionalRender
585585 if ( renderContext . emitPickID ) {
586586 meshShaderManager . setPickID ( gl , shader , pickIndex ! ) ;
587587 }
588+ meshShaderManager . setID ( gl , shader , objectId ) ;
588589 totalChunks += manifestChunk . fragmentIds . length ;
589590
590591 for ( const fragmentId of manifestChunk . fragmentIds ) {
@@ -820,7 +821,6 @@ function hasFragmentChunk(
820821export class MultiscaleMeshLayer extends PerspectiveViewRenderLayer < ThreeDimensionalRenderLayerAttachmentState > {
821822 protected meshShaderManager : MeshShaderManager ;
822823 private getShader ;
823- public segmentationColorUserShader ;
824824 backend : SegmentationLayerSharedObject ;
825825
826826 constructor (
@@ -834,9 +834,6 @@ export class MultiscaleMeshLayer extends PerspectiveViewRenderLayer<ThreeDimensi
834834 source . format . vertexPositionFormat ,
835835 ) ;
836836
837- this . segmentationColorUserShader = new SegmentationColorUserShader ( displayState ) ;
838-
839-
840837 this . getShader = this . meshShaderManager . makeGetter ( this ) ;
841838
842839 registerRedrawWhenSegmentationDisplayState3DChanged ( displayState , this ) ;
@@ -970,36 +967,9 @@ export class MultiscaleMeshLayer extends PerspectiveViewRenderLayer<ThreeDimensi
970967 if ( renderContext . emitPickID ) {
971968 meshShaderManager . setPickID ( gl , shader , pickIndex ! ) ;
972969 }
970+ meshShaderManager . setID ( gl , shader , objectId ) ;
973971
974- this . segmentationColorUserShader . setSegmentPropertyUniforms ( objectId , gl , shader ) ;
975- // const {
976- // segmentPropertyMap: { value: segmentPropertyMap },
977- // } = displayState.segmentationGroupState.value;
978- // if (segmentPropertyMap) {
979- // const { code } =
980- // displayState.segmentColorShaderControlState.parseResult.value;
981- // const index = segmentPropertyMap.getSegmentInlineIndex(objectId);
982-
983- // // setSegmentPropertyUniforms()
984-
985- // if (index !== -1) {
986- // for (const [i, property] of extractUsedSegmentProperties(
987- // segmentPropertyMap,
988- // code,
989- // )) {
990- // const value = property.values[index];
991- // const uniformSetter = getShaderUniformValueSetter(
992- // gl,
993- // property.dataType,
994- // );
995- // uniformSetter.call(
996- // gl,
997- // shader.uniform(`uSegmentNumericalProperty${i}`),
998- // value,
999- // );
1000- // }
1001- // }
1002- // }
972+ displayState . segmentationColorUserShader . enable ( gl , shader ) ;
1003973
1004974 getMultiscaleChunksToDraw (
1005975 manifest ,
0 commit comments