MCPcopy
hub / github.com/sparkjsdev/spark / prepareProgramMaterial

Method prepareProgramMaterial

src/PackedSplats.ts:757–802  ·  view source on GitHub ↗
(generator: GsplatGenerator)

Source from the content-addressed store, hash-verified

755 // Get a program and THREE.RawShaderMaterial for a given GsplatGenerator,
756 // generating it if necessary and caching the result.
757 prepareProgramMaterial(generator: GsplatGenerator): {
758 program: DynoProgram;
759 material: THREE.RawShaderMaterial;
760 } {
761 let program = PackedSplats.generatorProgram.get(generator);
762 if (!program) {
763 // A Gsplat needs to be turned into a packed uvec4 for the dyno graph
764 const graph = dynoBlock(
765 { index: "int" },
766 {},
767 ({ index }, _outputs, { roots }) => {
768 generator.inputs.index = index;
769 const gsplat = generator.outputs.gsplat;
770 const output = outputPackedSplat(
771 gsplat,
772 this.dynoRgbMinMaxLnScaleMinMax,
773 );
774 roots.push(output);
775 return undefined;
776 },
777 );
778 if (!PackedSplats.programTemplate) {
779 PackedSplats.programTemplate = new DynoProgramTemplate(
780 getShaders().computeUvec4Template,
781 );
782 }
783 // Create a program from the template and graph
784 program = new DynoProgram({
785 graph,
786 inputs: { index: "_index" },
787 outputs: { output: "target" },
788 template: PackedSplats.programTemplate,
789 });
790 Object.assign(program.uniforms, {
791 targetLayer: { value: 0 },
792 targetBase: { value: 0 },
793 targetCount: { value: 0 },
794 });
795 PackedSplats.generatorProgram.set(generator, program);
796 }
797
798 // Prepare and update our material we'll use to render the Gsplats
799 const material = program.prepareMaterial();
800 PackedSplats.fullScreenQuad.material = material;
801 return { program, material };
802 }
803
804 private saveRenderState(renderer: THREE.WebGLRenderer) {
805 return {

Callers 1

generateMethod · 0.95

Calls 4

dynoBlockFunction · 0.90
outputPackedSplatFunction · 0.90
getShadersFunction · 0.90
prepareMaterialMethod · 0.80

Tested by

no test coverage detected