Asked 29 days ago by EclipseProbe232
How can I eliminate artifacts when rendering a wireframe over a textured parametric surface?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 29 days ago by EclipseProbe232
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Greetings !
I am visualizing a parametric surface and overlaying a wireframe while preserving its texture. In general the approach works, but some lines render poorly—likely due to overlapping coordinate issues as shown in the image below:
[
image1260×763 205 KB](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/c/0/c000d91f4c3eca0192144a62f12edf6f47fbe4cc.jpeg "image")
Could you suggest the most effective method to remove these artifacts?
Below is the code used to produce the wireframe:
JAVASCRIPT// Wireframe let geo = new ParametricGeometry( mobius3d, 64, 64 ); const points = []; for(let i=0; i<geo.index.count; i+=2) { points.push( new THREE.Vector3( geo.attributes.position.array[geo.index.array[i] * 3], geo.attributes.position.array[geo.index.array[i] * 3 + 2], geo.attributes.position.array[geo.index.array[i] * 3 + 1] )); } const wfg = new THREE.BufferGeometry().setFromPoints(points); const wfm = new THREE.LineBasicMaterial( {color: 0x222222} ); wireframe = new THREE.Line( wfg, wfm ); scene.add(wireframe);
Comments 0
•Answers 1
•Views 46
Answer by TychoAI Agent • 9 days ago
Looking at your code and the image showing the rendering artifacts in your parametric surface wireframe, I can suggest a few approaches to improve the rendering quality.
The artifacts you're seeing are likely caused by z-fighting or depth precision issues when lines overlap or are very close to each other. Here are some effective methods to address this:
The THREE.Line
class connects all points in sequence. For wireframes, THREE.LineSegments
is more appropriate as it treats each pair of vertices as a separate line segment:
JAVASCRIPT// Change this wireframe = new THREE.Line(wfg, wfm); // To this wireframe = new THREE.LineSegments(wfg, wfm);
Instead of creating a separate wireframe geometry, you could use the built-in wireframe option in your material:
JAVASCRIPTconst material = new THREE.MeshBasicMaterial({ map: yourTexture, wireframe: true, wireframeLinewidth: 1 });
To prevent z-fighting, you can slightly offset the wireframe from the surface:
JAVASCRIPT// After creating your wireframe wireframe.position.add(wireframe.position.clone().normalize().multiplyScalar(0.001));
Adjust the material's depth properties:
JAVASCRIPTconst wfm = new THREE.LineBasicMaterial({ color: 0x222222, depthTest: true, polygonOffset: true, polygonOffsetFactor: 1, polygonOffsetUnits: 1 });
For a cleaner approach that only shows the edges:
JAVASCRIPTconst edges = new THREE.EdgesGeometry(geo); const wireframe = new THREE.LineSegments(edges, new THREE.LineBasicMaterial({ color: 0x222222 })); scene.add(wireframe);
Sometimes increasing the resolution of your parametric geometry can help:
JAVASCRIPTlet geo = new ParametricGeometry(mobius3d, 128, 128); // Increased from 64, 64
Try these approaches individually or in combination to find the solution that works best for your specific case.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
No comments yet.