diff --git a/source/GLRender/Axis.ts b/source/GLRender/Axis.ts index d9a70cc..4ad5672 100644 --- a/source/GLRender/Axis.ts +++ b/source/GLRender/Axis.ts @@ -54,6 +54,9 @@ class Axis extends GLContextObject{ shader.radius([this.r, this.r, this.r]); shader.position(this.pos); + shader.fogColor(this.renderer.fogColor); + shader.fogDensity(this.renderer.fogDensity); + // 绘制 X 轴 shader.color([1, 0, 0]); this.gl.drawArrays(this.gl.LINES, 0, 2); diff --git a/source/GLRender/BasicCube.ts b/source/GLRender/BasicCube.ts index cecd755..070d83b 100644 --- a/source/GLRender/BasicCube.ts +++ b/source/GLRender/BasicCube.ts @@ -50,7 +50,7 @@ class BaseCube extends GLContextObject{ /** * 颜色 */ - public color = [.5, .5, .5]; + public color = [1, 1, 1]; /** * 绘制立方体 @@ -79,6 +79,9 @@ class BaseCube extends GLContextObject{ // 指定颜色 shader.color(this.color); + shader.fogColor(this.renderer.fogColor); + shader.fogDensity(this.renderer.fogDensity); + // 开始绘制 this.gl.drawElements(this.gl.LINES, 24, this.gl.UNSIGNED_SHORT, 0); } diff --git a/source/GLRender/BasicShader.ts b/source/GLRender/BasicShader.ts index c747e80..9ae83ef 100644 --- a/source/GLRender/BasicShader.ts +++ b/source/GLRender/BasicShader.ts @@ -12,7 +12,9 @@ interface IBasicsShaderUniform { uRadius: ObjectData, uMvp: ObjectData, uPosition: ObjectData, - uColor: ObjectData + uColor: ObjectData, + uFogColor: ObjectData, + uFogDensity: ObjectData } /** @@ -31,8 +33,11 @@ class BasicsShader extends GLShader { }); const cubeRadius = 2**.5; + const farFogLine = 2.5; this.fogDensity = [ this.fogDensity[0], this.camera.eye[2] - cubeRadius, - this.camera.eye[2] + cubeRadius + 4 + this.camera.eye[2] + cubeRadius + farFogLine ]; this.canvas.on("mousewheel", () => { @@ -57,12 +58,17 @@ class ClassicRenderer extends BasicRenderer<{}, IClassicRendererParams> { let dist = this.camera.eyeDist; this.fogDensity = [ this.fogDensity[0], dist - cubeRadius, - dist + cubeRadius + 4 + dist + cubeRadius + farFogLine ]; }); // 运行 this.run(); + + // 测试数据传递 + // setInterval(() => { + // this.basicGroup.upLoadData(new Array(100 * 3).fill(0).map(() => (Math.random() - .5) * 2)); + // }, 500); } loop(t: number): void {