@@ -57,10 +57,9 @@ import {
5757 registerRedrawWhenSegmentationDisplayState3DChanged ,
5858 SegmentationLayerSharedObject ,
5959} from "#src/segmentation_display_state/frontend.js" ;
60- import { PreprocessedSegmentPropertyMap } from "#src/segmentation_display_state/property_map.js" ;
60+ import { addSegmentPropertiesToShaderBuilder , setSegmentPropertyUniforms , shaderCodeWithPropertyPreprocessing } from "#src/segmentation_display_state/property_map.js" ;
6161import type { WatchableValueInterface } from "#src/trackable_value.js" ;
6262import { makeCachedDerivedWatchableValue } from "#src/trackable_value.js" ;
63- import { DataType } from "#src/util/data_type.js" ;
6463import type { Borrowed , RefCounted } from "#src/util/disposable.js" ;
6564import { vec4 } from "#src/util/geom.js" ;
6665import {
@@ -391,12 +390,11 @@ export class MeshShaderManager {
391390 makeGetter ( layer : RefCounted & { gl : GL ; displayState : MeshDisplayState } ) {
392391 const parameters = layer . registerDisposer (
393392 makeCachedDerivedWatchableValue (
394- ( a , b , c ) => {
395- console . log ( "update CDWV" ) ;
393+ ( silhouetteRendering , shaderBuilderState , segmentProperties ) => {
396394 return {
397- silhouetteRenderingEnabled : a > 0 ,
398- shaderBuilderState : b ,
399- segmentProperties : c ,
395+ silhouetteRenderingEnabled : silhouetteRendering > 0 ,
396+ shaderBuilderState,
397+ segmentProperties,
400398 } ;
401399 } ,
402400 [
@@ -407,33 +405,6 @@ export class MeshShaderManager {
407405 ) ,
408406 ) ;
409407
410- parameters . changed . add ( ( ) => {
411- console . log ( "parameters changed" ) ;
412- } ) ;
413-
414- layer . displayState . segmentationGroupState . value . segmentPropertyMap . changed . add (
415- ( ) => {
416- console . log ( "segment property map changed" ) ;
417- } ,
418- ) ;
419-
420- function getShaderOutputType ( ioType : DataType ) : string {
421- switch ( ioType ) {
422- case DataType . UINT8 :
423- case DataType . UINT16 :
424- case DataType . UINT32 :
425- return "uint" ;
426- case DataType . INT8 :
427- case DataType . INT16 :
428- case DataType . INT32 :
429- return "int" ;
430- case DataType . FLOAT32 :
431- return "float" ;
432- case DataType . UINT64 :
433- return "uvec2" ;
434- }
435- }
436-
437408 return parameterizedEmitterDependentShaderGetter ( layer , layer . gl , {
438409 memoizeKey : `mesh/MeshShaderManager/${ this . fragmentRelativeVertices } /${ this . vertexPositionFormat } ` ,
439410 parameters,
@@ -457,44 +428,8 @@ export class MeshShaderManager {
457428 builder . addUniform ( "highp uint" , "uPickID" ) ;
458429 builder . addUniform ( "highp uvec2" , "uID" ) ;
459430
460- // TODO define segment property uniforms here
461- // console.log("segmentProperties", segmentProperties);
462-
463- const shaderCodeWithPropertyPreprocessing = ( code : string ) => {
464- if ( ! segmentProperties ) return code ;
465- const { numericalProperties, tags } = segmentProperties ;
466- numericalProperties ;
467- if ( tags ) {
468- for ( const [ i , tag ] of tags . tags . entries ( ) ) {
469- code = code . replaceAll ( `tag("${ tag } ")` , `uTag${ i } == 1u` ) ;
470- }
471- }
472- return code ;
473- } ;
474-
475431 if ( segmentProperties ) {
476- const { numericalProperties, tags } = segmentProperties ;
477- for ( const property of numericalProperties ) {
478- console . log ( "numeric" , property ) ;
479- // TODO maybe just number it instead of using id
480- builder . addUniform (
481- `highp ${ getShaderOutputType ( property . dataType ) } ` ,
482- property . id . replaceAll ( " " , "_" ) ,
483- ) ;
484- console . log ( "added numeric uniform" , property . id ) ;
485- }
486- if ( tags ) {
487- console . log ( "tags" , tags ) ;
488-
489- for ( const [ i , tag ] of tags . tags . entries ( ) ) {
490- console . log ( "tag" , tag , tag . replaceAll ( " " , "_" ) ) ;
491- builder . addUniform ( "highp uint" , `uTag${ i } ` ) ;
492- builder . addVertexCode (
493- `\n#define TAG_${ tag . replaceAll ( " " , "_" ) . replaceAll ( "-" , "_" ) . toUpperCase ( ) } uTag${ i } \n` ,
494- ) ;
495- // gl.uniform1ui(shader.uniform(`tag${tagIndices.charCodeAt(i)}`), 1);
496- }
497- }
432+ addSegmentPropertiesToShaderBuilder ( segmentProperties , builder ) ;
498433 }
499434
500435 if ( silhouetteRenderingEnabled ) {
@@ -551,88 +486,14 @@ vColor *= pow(1.0 - absCosAngle, uSilhouettePower);
551486
552487 builder . addVertexCode (
553488 "\n#define main userMain\n" +
554- shaderCodeWithLineDirective ( shaderCodeWithPropertyPreprocessing ( shaderBuilderState . parseResult . code ) ) +
489+ shaderCodeWithLineDirective ( shaderCodeWithPropertyPreprocessing ( segmentProperties , shaderBuilderState . parseResult . code ) ) +
555490 "\n#undef main\n" ,
556491 ) ;
557492 } ,
558493 } ) ;
559494 }
560495}
561496
562- const addPropertyUniforms = (
563- gl : GL ,
564- shader : ShaderProgram ,
565- segmentPropertyMap : PreprocessedSegmentPropertyMap ,
566- id : bigint ,
567- ) => {
568- const index = segmentPropertyMap . getSegmentInlineIndex ( id ) ;
569- // const {tags} = segmentPropertyMap;
570- // console.log("index", index, objectId, key);
571- // console.log(
572- // "segmentPropertyMap.numerical",
573- // segmentPropertyMap.numericalProperties,
574- // );
575- // console.log("segmentPropertyMap.numerical", segmentPropertyMap.tags);
576-
577- const getShaderUniformValueSetter = ( gl : GL , ioType : DataType ) => {
578- switch ( ioType ) {
579- case DataType . UINT8 :
580- case DataType . UINT16 :
581- case DataType . UINT32 :
582- return gl . uniform1ui ;
583- case DataType . INT8 :
584- case DataType . INT16 :
585- case DataType . INT32 :
586- return gl . uniform1i ;
587- case DataType . FLOAT32 :
588- return gl . uniform1f ;
589- case DataType . UINT64 :
590- throw new Error ( "nope" ) ;
591- // return gl.uniform
592- } ;
593- } ;
594-
595- if ( index !== - 1 ) {
596- const { labels, tags : tagsProperty , numericalProperties } = segmentPropertyMap ;
597- labels ;
598-
599- for ( const property of numericalProperties ) {
600- const value = property . values [ index ] ;
601- const uniformSetter = getShaderUniformValueSetter ( gl , property . dataType ) ;
602- uniformSetter . call ( gl , shader . uniform ( property . id . replaceAll ( " " , "_" ) ) , value ) ;
603- }
604-
605- // let label = "";
606- // if (labels !== undefined) {
607- // label = labels.values[index];
608- // }
609- if ( tagsProperty !== undefined ) {
610- const { values, tags } = tagsProperty ;
611- const tagIndices = values [ index ] ;
612- for ( let i = 0 ; i < tags . length ; ++ i ) {
613- gl . uniform1ui ( shader . uniform ( `uTag${ i } ` ) , 0 ) ;
614- }
615- for ( let i = 0 , length = tagIndices . length ; i < length ; ++ i ) {
616- const tagIdx = tagIndices . charCodeAt ( i ) ;
617- console . log ( "enable tag" , tagIdx ) ;
618- gl . uniform1ui ( shader . uniform ( `uTag${ tagIdx } ` ) , 1 ) ;
619- }
620- }
621- // if (label.length === 0) return undefined;
622-
623- // if (tags) {
624- // console.log('tags', tags);
625- // // for (const tag of tags) {
626- // }
627- getShaderUniformValueSetter ;
628- // for (const [name, channel] of Object.entries(value)) {
629- // const setter = getShaderUniformValueSetter(gl, channel.dataType);
630- // if (setter) {
631- // setter.call(gl, shader.uniforms[name], channel.value);
632- // }
633- // }
634- }
635- } ;
636497export interface MeshDisplayState extends SegmentationDisplayState3D {
637498 silhouetteRendering : WatchableValueInterface < number > ;
638499
@@ -783,7 +644,7 @@ export class MeshLayer extends PerspectiveViewRenderLayer<ThreeDimensionalRender
783644 } = displayState . segmentationGroupState . value ;
784645 if ( segmentPropertyMap ) {
785646 console . log ( 'key/objectId' , key , objectId ) ;
786- addPropertyUniforms ( gl , shader , segmentPropertyMap , objectId ) ;
647+ setSegmentPropertyUniforms ( gl , shader , segmentPropertyMap , objectId ) ;
787648 }
788649
789650 for ( const fragmentId of manifestChunk . fragmentIds ) {
@@ -1174,7 +1035,7 @@ export class MultiscaleMeshLayer extends PerspectiveViewRenderLayer<ThreeDimensi
11741035 } = displayState . segmentationGroupState . value ;
11751036 if ( segmentPropertyMap ) {
11761037 console . log ( 'key/objectId' , key , objectId ) ;
1177- addPropertyUniforms ( gl , shader , segmentPropertyMap , objectId ) ;
1038+ setSegmentPropertyUniforms ( gl , shader , segmentPropertyMap , objectId ) ;
11781039 }
11791040
11801041 getMultiscaleChunksToDraw (
0 commit comments