From 7e15e7a07a2fbcfddffa07fbc2885ac19eedb160 Mon Sep 17 00:00:00 2001 From: travisthomp Date: Mon, 25 Mar 2024 16:19:50 -0400 Subject: [PATCH 1/2] Fixed Splats in Scene Flickering When Adding or Removing * Fixed splats flashing * Made it so that the entire render program doesnt need to rebuild on add or remove splat * Fixed Webgl Warning about drawArraysInstance fetch requires... --- src/renderers/webgl/programs/RenderProgram.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/renderers/webgl/programs/RenderProgram.ts b/src/renderers/webgl/programs/RenderProgram.ts index 4b04ab5..e76fa01 100644 --- a/src/renderers/webgl/programs/RenderProgram.ts +++ b/src/renderers/webgl/programs/RenderProgram.ts @@ -7,6 +7,7 @@ import { Color32 } from "../../../math/Color32"; import { ObjectAddedEvent, ObjectChangedEvent, ObjectRemovedEvent } from "../../../events/Events"; import { Splat } from "../../../splats/Splat"; import { WebGLRenderer } from "../../WebGLRenderer"; +import { Scene } from "../../../index"; const vertexShaderSource = /* glsl */ `#version 300 es precision highp float; @@ -303,7 +304,7 @@ class RenderProgram extends ShaderProgram { e.object.addEventListener("objectChanged", handleObjectChanged); } - this.dispose(); + resetSplatData(); }; const handleObjectRemoved = (event: Event) => { @@ -313,7 +314,7 @@ class RenderProgram extends ShaderProgram { e.object.removeEventListener("objectChanged", handleObjectChanged); } - this.dispose(); + resetSplatData(); }; const handleObjectChanged = (event: Event) => { @@ -324,6 +325,14 @@ class RenderProgram extends ShaderProgram { } }; + const resetSplatData = () => { + this._renderData?.dispose(); + this._renderData = new RenderData(this._scene as Scene); + + this._worker?.terminate(); + createWorker(); + }; + this._render = () => { if (!this._scene || !this._camera || !this.renderData) { console.error("Cannot render without scene and camera"); @@ -478,7 +487,7 @@ class RenderProgram extends ShaderProgram { gl.vertexAttribIPointer(indexAttribute, 1, gl.INT, 0, 0); gl.vertexAttribDivisor(indexAttribute, 1); - gl.drawArraysInstanced(gl.TRIANGLE_FAN, 0, 4, this.renderData.vertexCount); + gl.drawArraysInstanced(gl.TRIANGLE_FAN, 0, 4, this.depthIndex.length); }; this._dispose = () => { From c207535771a393738da53771175bcb4bd5c9d670 Mon Sep 17 00:00:00 2001 From: travisthomp Date: Tue, 26 Mar 2024 01:50:02 -0400 Subject: [PATCH 2/2] fixed Scene import --- src/renderers/webgl/programs/RenderProgram.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/webgl/programs/RenderProgram.ts b/src/renderers/webgl/programs/RenderProgram.ts index e76fa01..0e53aca 100644 --- a/src/renderers/webgl/programs/RenderProgram.ts +++ b/src/renderers/webgl/programs/RenderProgram.ts @@ -7,7 +7,7 @@ import { Color32 } from "../../../math/Color32"; import { ObjectAddedEvent, ObjectChangedEvent, ObjectRemovedEvent } from "../../../events/Events"; import { Splat } from "../../../splats/Splat"; import { WebGLRenderer } from "../../WebGLRenderer"; -import { Scene } from "../../../index"; +import { Scene } from "../../../core/Scene" const vertexShaderSource = /* glsl */ `#version 300 es precision highp float;