Skip to content

Commit

Permalink
Merge pull request #1765 from xeokit/fix/dtx-cross-sections
Browse files Browse the repository at this point in the history
Implement missing cross section from dtx renderer
  • Loading branch information
xeolabs authored Dec 23, 2024
2 parents 1c5cab9 + 9ae9178 commit 29f31fc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ export class DTXTrianglesColorRenderer {
const sectionPlanes = scene._sectionPlanesState.sectionPlanes;
const baseIndex = dataTextureLayer.layerIndex * numSectionPlanes;
const renderFlags = model.renderFlags;
if (scene.crossSections) {
gl.uniform4fv(this._uSliceColor, scene.crossSections.sliceColor);
gl.uniform1f(this._uSliceThickness, scene.crossSections.sliceThickness);
}
for (let sectionPlaneIndex = 0; sectionPlaneIndex < numAllocatedSectionPlanes; sectionPlaneIndex++) {
const sectionPlaneUniforms = this._uSectionPlanes[sectionPlaneIndex];
if (sectionPlaneUniforms) {
Expand Down Expand Up @@ -247,6 +251,11 @@ export class DTXTrianglesColorRenderer {
this._uTexturePerPolygonIdPortionIds = "uTexturePerPolygonIdPortionIds";
this._uTexturePerObjectMatrix= "uTexturePerObjectMatrix";
this._uCameraEyeRtc = program.getLocation("uCameraEyeRtc");

if (scene.crossSections) {
this._uSliceColor = program.getLocation("sliceColor");
this._uSliceThickness = program.getLocation("sliceThickness");
}
}

_bindProgram(frameCtx) {
Expand Down Expand Up @@ -563,11 +572,14 @@ export class DTXTrianglesColorRenderer {
src.push("uniform vec3 sectionPlanePos" + i + ";");
src.push("uniform vec3 sectionPlaneDir" + i + ";");
}
src.push("uniform float sliceThickness;");
src.push("uniform vec4 sliceColor;");
}
src.push("in vec4 vColor;");
src.push("out vec4 outColor;");
src.push("void main(void) {");

src.push(" vec4 newColor;");
src.push(" newColor = vColor;");
if (clipping) {
src.push(" bool clippable = vFlags2 > 0u;");
src.push(" if (clippable) {");
Expand All @@ -577,9 +589,12 @@ export class DTXTrianglesColorRenderer {
src.push(" dist += clamp(dot(-sectionPlaneDir" + i + ".xyz, vWorldPosition.xyz - sectionPlanePos" + i + ".xyz), 0.0, 1000.0);");
src.push("}");
}
src.push(" if (dist > 0.0) { ");
src.push(" if (dist > sliceThickness) { ");
src.push(" discard;")
src.push(" }");
src.push(" if (dist > 0.0) { ");
src.push(" newColor = sliceColor;");
src.push(" }");
src.push("}");
}

Expand All @@ -597,9 +612,9 @@ export class DTXTrianglesColorRenderer {
src.push(" float blendFactor = uSAOParams[3];");
src.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);");
src.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;");
src.push(" outColor = vec4(vColor.rgb * ambient, 1.0);");
src.push(" outColor = vec4(newColor.rgb * ambient, 1.0);");
} else {
src.push(" outColor = vColor;");
src.push(" outColor = newColor;");
}

src.push("}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,14 @@ export class DTXTrianglesEdgesColorRenderer {
src.push("uniform vec3 sectionPlanePos" + i + ";");
src.push("uniform vec3 sectionPlaneDir" + i + ";");
}
src.push("uniform float sliceThickness;");
src.push("uniform vec4 sliceColor;");
}
src.push("in vec4 vColor;");
src.push("out vec4 outColor;");
src.push("void main(void) {");
src.push(" vec4 newColor;");
src.push(" newColor = vColor;");
if (clipping) {
src.push(" bool clippable = vFlags2 > 0u;");
src.push(" if (clippable) {");
Expand All @@ -390,13 +394,18 @@ export class DTXTrianglesEdgesColorRenderer {
src.push(" dist += clamp(dot(-sectionPlaneDir" + i + ".xyz, vWorldPosition.xyz - sectionPlanePos" + i + ".xyz), 0.0, 1000.0);");
src.push("}");
}
src.push(" if (dist > 0.0) { discard; }");
src.push(" if (dist > sliceThickness) { ");
src.push(" discard;")
src.push(" }");
src.push(" if (dist > 0.0) { ");
src.push(" newColor = sliceColor;");
src.push(" }");
src.push("}");
}
if (scene.logarithmicDepthBufferEnabled) {
src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
}
src.push(" outColor = vColor;");
src.push(" outColor = newColor;");
src.push("}");
return src;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,14 @@ export class DTXTrianglesEdgesRenderer {
src.push("uniform vec3 sectionPlanePos" + i + ";");
src.push("uniform vec3 sectionPlaneDir" + i + ";");
}
src.push("uniform float sliceThickness;");
src.push("uniform vec4 sliceColor;");
}
src.push("in vec4 vColor;");
src.push("out vec4 outColor;");
src.push("void main(void) {");
src.push(" vec4 newColor;");
src.push(" newColor = vColor;");
if (clipping) {
src.push(" bool clippable = vFlags2 > 0u;");
src.push(" if (clippable) {");
Expand All @@ -398,13 +402,18 @@ export class DTXTrianglesEdgesRenderer {
src.push(" dist += clamp(dot(-sectionPlaneDir" + i + ".xyz, vWorldPosition.xyz - sectionPlanePos" + i + ".xyz), 0.0, 1000.0);");
src.push("}");
}
src.push(" if (dist > 0.0) { discard; }");
src.push(" if (dist > sliceThickness) { ");
src.push(" discard;")
src.push(" }");
src.push(" if (dist > 0.0) { ");
src.push(" newColor = sliceColor;");
src.push(" }");
src.push("}");
}
if (scene.logarithmicDepthBufferEnabled) {
src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
}
src.push(" outColor = vColor;");
src.push(" outColor = newColor;");
src.push("}");
return src;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,14 @@ export class DTXTrianglesSilhouetteRenderer {
src.push("uniform vec3 sectionPlanePos" + i + ";");
src.push("uniform vec3 sectionPlaneDir" + i + ";");
}
src.push("uniform float sliceThickness;");
src.push("uniform vec4 sliceColor;");
}
src.push("uniform vec4 color;");
src.push("out vec4 outColor;");
src.push("void main(void) {");
src.push(" vec4 newColor;");
src.push(" newColor = color;");
if (clipping) {
src.push(" bool clippable = vFlags2 > 0u;");
src.push(" if (clippable) {");
Expand All @@ -439,15 +443,18 @@ export class DTXTrianglesSilhouetteRenderer {
src.push(" dist += clamp(dot(-sectionPlaneDir" + i + ".xyz, vWorldPosition.xyz - sectionPlanePos" + i + ".xyz), 0.0, 1000.0);");
src.push("}");
}
src.push(" if (dist > 0.0) { ");
src.push(" if (dist > sliceThickness) { ");
src.push(" discard;")
src.push(" }");
src.push(" if (dist > 0.0) { ");
src.push(" newColor = sliceColor;");
src.push(" }");
src.push("}");
}
if (scene.logarithmicDepthBufferEnabled) {
src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
}
src.push(" outColor = color;");
src.push(" outColor = newColor;");
src.push("}");
return src;
}
Expand Down

0 comments on commit 29f31fc

Please sign in to comment.