I am trying to integrate a webgl gaussian splatting renderer inside of threejs and for that I am creating a custom mesh class (which is possible according to the docs).
When creating my class I fetch my data, upload it and then create instanced geometry :
const geometry = new THREE.InstancedBufferGeometry();
geometry.instanceCount = count;
geometry.setAttribute("splatPosition", new THREE.BufferAttribute(new Float32Array([-2, -2, 2, -2, 2, 2, -2, 2]), 2));
const indexBuffer = new Uint32Array(count); // Buffer is updated on a later stage
const indexAttrib = new THREE.InstancedBufferAttribute(indexBuffer, 1, false);
indexAttrib.setUsage(THREE.DynamicDrawUsage);
indexAttrib.needsUpdate = true;
geometry.setAttribute("splatIndex", indexAttrib);
this.geometry = geometry;
Beginning of constructor :
super(new THREE.SphereGeometry(0.5, 32, 32), new THREE.MeshStandardMaterial({color: 0x00ff00}));
// this.renderOrder = -100; // Changes nothing
this.frustumCulled = false;
this.visible = true;
this.castShadow = false;
this.loaded = false;
Material creation :
const material = new THREE.RawShaderMaterial({
uniforms: {
focal: {type: 'v2', value: new THREE.Vector2()},
viewport: {type: 'v2', value: new THREE.Vector2()},
time: {type: 'f', value: 0},
opacity: {type: 'f', value: 1.0},
texture: {type: 't', value: null}
},
glslVersion: THREE.GLSL3,
vertexShader: vertexShaderSource,
fragmentShader: fragmentShaderSource,
side: THREE.DoubleSide,
blending: THREE.CustomBlending,
blendDst: THREE.OneMinusDstAlphaFactor,
blendDstAlpha: THREE.OneMinusDstAlphaFactor,
blendSrc: THREE.OneFactor,
blendSrcAlpha: THREE.OneFactor,
blendEquation: THREE.AddEquation,
depthTest: false,
depthWrite: false,
forceSinglePass: true,
transparent: false
});
My material is correctly compiled, has the right attributes and uniforms are set. I update the uniforms in onBeforeRender, which is correctly called. However, no opengl call is then made to draw the model.
Note that if I replace the instanced geometry and shader with say a sphere and default material, everything works fine. My node is also added correctly to the scene.
Replaced custom instanced geo by sphere, shouldn’t have worked but it did. Tried overriding InstancedMesh instead of Mesh, tried BufferGeometry alone. Nothing did the work.
Edorion is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.