Skip to content

Commit

Permalink
Add lines and points support to PerformanceModel #569
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Feb 26, 2021
1 parent 0b01d73 commit 658025e
Show file tree
Hide file tree
Showing 18 changed files with 282 additions and 393 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class LinesBatchingColorRenderer {
gl.uniformMatrix4fv(this._uViewMatrix, false, (rtcCenter) ? createRTCViewMat(camera.viewMatrix, rtcCenter) : camera.viewMatrix);
gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix);

gl.lineWidth(scene.linesMaterial.lineWidth);

const numSectionPlanes = scene._sectionPlanesState.sectionPlanes.length;
if (numSectionPlanes > 0) {
const sectionPlanes = scene._sectionPlanesState.sectionPlanes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LinesBatchingSilhouetteRenderer {
const camera = scene.camera;
const gl = scene.canvas.gl;
const state = batchingLayer._state;
const rtcCenter = batchingLayer._state.rtcCenter
const rtcCenter = batchingLayer._state.rtcCenter;

if (!this._program) {
this._allocate();
Expand Down Expand Up @@ -76,6 +76,8 @@ class LinesBatchingSilhouetteRenderer {

gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix);

gl.lineWidth(scene.linesMaterial.lineWidth);

const numSectionPlanes = scene._sectionPlanesState.sectionPlanes.length;
if (numSectionPlanes > 0) {
const sectionPlanes = scene._sectionPlanesState.sectionPlanes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class LinesInstancingColorRenderer {
gl.uniformMatrix4fv(this._uViewMatrix, false, (rtcCenter) ? createRTCViewMat(camera.viewMatrix, rtcCenter) : camera.viewMatrix);
gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix);

gl.lineWidth(scene.linesMaterial.lineWidth);

const numSectionPlanes = scene._sectionPlanesState.sectionPlanes.length;
if (numSectionPlanes > 0) {
const sectionPlanes = scene._sectionPlanesState.sectionPlanes;
Expand Down Expand Up @@ -108,6 +110,7 @@ class LinesInstancingColorRenderer {
instanceExt.vertexAttribDivisorANGLE(this._aModelMatrixCol0.location, 0);
instanceExt.vertexAttribDivisorANGLE(this._aModelMatrixCol1.location, 0);
instanceExt.vertexAttribDivisorANGLE(this._aModelMatrixCol2.location, 0);

instanceExt.vertexAttribDivisorANGLE(this._aColor.location, 0);
instanceExt.vertexAttribDivisorANGLE(this._aFlags.location, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class LinesInstancingSilhouetteRenderer {
gl.uniformMatrix4fv(this._uViewMatrix, false, (rtcCenter) ? createRTCViewMat(camera.viewMatrix, rtcCenter) : camera.viewMatrix);
gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix);

gl.lineWidth(scene.linesMaterial.lineWidth);

const numSectionPlanes = scene._sectionPlanesState.sectionPlanes.length;
if (numSectionPlanes > 0) {
const sectionPlanes = scene._sectionPlanesState.sectionPlanes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PointsBatchingColorRenderer {
};

_getHash() {
return this._scene._sectionPlanesState.getHash();
return this._scene._sectionPlanesState.getHash() + this._scene.pointsMaterial.hash;
}

drawLayer(frameCtx, pointsBatchingLayer, renderPass) {
Expand All @@ -32,6 +32,7 @@ class PointsBatchingColorRenderer {
const gl = scene.canvas.gl;
const state = pointsBatchingLayer._state;
const rtcCenter = pointsBatchingLayer._state.rtcCenter;
const pointsMaterial = scene.pointsMaterial;

if (!this._program) {
this._allocate();
Expand Down Expand Up @@ -92,7 +93,9 @@ class PointsBatchingColorRenderer {
this._aOffset.bindArrayBuffer(state.offsetsBuf);
}

gl.uniform1f(this._uPointSize, 10);
gl.uniform1f(this._uPointSize, pointsMaterial.pointSize);
const nearPlaneHeight = (scene.camera.projection === "ortho") ? 1.0 : (gl.drawingBufferHeight / (2 * Math.tan(0.5 * scene.camera.perspective.fov * Math.PI / 180.0)));
gl.uniform1f(this._uNearPlaneHeight, nearPlaneHeight);

gl.drawArrays(gl.POINTS, 0, state.positionsBuf.numItems);
}
Expand Down Expand Up @@ -134,6 +137,7 @@ class PointsBatchingColorRenderer {
this._aFlags2 = program.getAttribute("flags2");

this._uPointSize = program.getLocation("pointSize");
this._uNearPlaneHeight = program.getLocation("nearPlaneHeight");

if (scene.logarithmicDepthBufferEnabled) {
this._uLogDepthBufFC = program.getLocation("logDepthBufFC");
Expand Down Expand Up @@ -169,6 +173,7 @@ class PointsBatchingColorRenderer {
const scene = this._scene;
const sectionPlanesState = scene._sectionPlanesState;
const clipping = sectionPlanesState.sectionPlanes.length > 0;
const pointsMaterial = scene.pointsMaterial;
const src = [];

src.push("// Points batching color vertex shader");
Expand All @@ -195,6 +200,9 @@ class PointsBatchingColorRenderer {
src.push("uniform mat4 positionsDecodeMatrix;");

src.push("uniform float pointSize;");
if (pointsMaterial.perspectivePoints) {
src.push("uniform float nearPlaneHeight;");
}

if (scene.logarithmicDepthBufferEnabled) {
src.push("uniform float logDepthBufFC;");
Expand Down Expand Up @@ -241,8 +249,14 @@ class PointsBatchingColorRenderer {
}
}
src.push("gl_Position = clipPos;");
if (pointsMaterial.perspectivePoints) {
src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");
src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);");
src.push("gl_PointSize = min(gl_PointSize, " + Math.floor(pointsMaterial.maxPerspectivePointSize) + ".0);");
} else {
src.push("gl_PointSize = pointSize;");
}
src.push("}");
src.push("gl_PointSize = pointSize;");
src.push("}");
return src;
}
Expand Down Expand Up @@ -282,11 +296,13 @@ class PointsBatchingColorRenderer {
}
src.push("varying vec4 vColor;");
src.push("void main(void) {");
src.push(" vec2 cxy = 2.0 * gl_PointCoord - 1.0;");
src.push(" float r = dot(cxy, cxy);");
src.push(" if (r > 1.0) {");
src.push(" discard;");
src.push(" }");
if (scene.pointsMaterial.roundPoints) {
src.push(" vec2 cxy = 2.0 * gl_PointCoord - 1.0;");
src.push(" float r = dot(cxy, cxy);");
src.push(" if (r > 1.0) {");
src.push(" discard;");
src.push(" }");
}
if (clipping) {
src.push(" bool clippable = (float(vFlags2.x) > 0.0);");
src.push(" if (clippable) {");
Expand Down
Loading

0 comments on commit 658025e

Please sign in to comment.