"Two vibrant hues in a showdown for dominance over a single pixel on the screen in

When using this Three.js application (), the issue arises where the black wireframe competes with the yellow solid, causing pixel flickering on the screen. Is there a way to prevent this from happening? It's worth noting that the flickering effect is more prominent when zooming out.

To visualize the problem better, take a look at this animated GIF:

The obvious solution might be to increase the thickness of the wireframe model, but is there a way to address this issue while keeping the wireframe thin?

Thank you, Humberto.

Here is the code:

   <!DOCTYPE html>
   <html>
   <head>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
       <title>Icosahedron</title>

       <!-- JavaScript Libraries -->
       <script src="threejs.r84/build/three.js"></script>
       <script src="threejs.r84/examples/js/controls/FlyControls.js"></script>
       <!-- CSS -->
       <style type="text/css">
       body  {text-align: center;}
       </style>

       <!-- ThreeJS Code -->
       <script type="text/javascript">
           // check capabilities, and start if sufficient
           var haswebgl = (function() {try {return !! window.WebGLRenderingContext &&
                                                   !! document.createElement('canvas').getContext('experimental-webgl');}
                                       catch(e){return false;}})();

           var hascanvas = !! window.CanvasRenderingContext2D; 

           var context0 = null;

           var clock = new THREE.Clock();


           if (hascanvas)
           {
               document.addEventListener( "DOMContentLoaded", init, false);
           } 

           function init()
           {
               document.getElementById("msgwebglcontext0").innerHTML = "";

               /* spawns the objects, scenes, cameras, renderers etc. */
               context0 = {color: 0xccff33, name: "0"};

               // set the scene
               if (haswebgl)
               {
                   context0.renderer = new THREE.WebGLRenderer({alpha: true, antialias: true });
               }
               else
               {
                   context0.renderer = new THREE.CanvasRenderer({alpha: true, antialias: true });
               }
               context0.renderer.setSize(600, 400);

               context0.viewport = document.getElementById("webglcontext0");
               context0.viewport.appendChild(context0.renderer.domElement);

               context0.scene = new THREE.Scene();
               context0.camera = new THREE.PerspectiveCamera(20, 600/400.0, 0.1, 10000);
               context0.camera.position.z = 4000;
               context0.scene.add(context0.camera);
               context0.controls = new THREE.FlyControls( context0.camera );
               context0.controls.movementSpeed = 1000;
               context0.controls.domElement = context0.viewport;
               context0.controls.rollSpeed = Math.PI / 24;
               context0.controls.autoForward = false;
               context0.controls.dragToLook = false;

               // Create icosahedron
               context0.scene.add(new THREE.Mesh(new THREE.IcosahedronGeometry(503),
                                  new THREE.MeshBasicMaterial({color: 0x000000, wireframe: true})));

               context0.scene.add(new THREE.Mesh(new THREE.IcosahedronGeometry(500),
                                  new THREE.MeshBasicMaterial({color: context0.color, opacity: 0.9, transparent: true, side: THREE.DoubleSide})));

               
               render();
               animate();
           } 

           function animate()
           {
               requestAnimationFrame(animate);
               render();
           } 

           function render()
           {
               var delta = clock.getDelta();
               context0.controls.update(delta);
               context0.renderer.render(context0.scene, context0.camera);
           } 
           

       </script>
   </head>
   <body>
   <div id="info">
       <b>WASD</b> mover, <b>R|F</b> up | down, <b>Q|E</b> roll, <b>up|down</b> pitch, <b>left|right</b> yaw<br/>
   </div>

   <div style="text-align:center; display: table; margin: 0 auto;">
   <span id="webglcontext0" style="width:410px; height:50px; display: table-cell; text-align:center; vertical-align: middle; border-style: solid; border-width: 1px;"></span>
   </div>

   <div id="msgwebglcontext0" style="text-align:center; display: table; margin: 0 auto;">
   <span style="width:700px; height:50px; display: table-cell; text-align:center; vertical-align: middle; border-style: solid; border-width: 1px;">
   Your browser does not seem to support WebGL or this option is not enabled.
   <br>
   If you have any questions, please contact us via email:
   <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#99;&#111;&#110;&#116;&#101;&#117;&#100;&#111;&#115;&#100;&#105;&#103;&#105;&#116;&#97;&#105;&#115;&#64;&#105;&#109;&#46;&#117;&#102;&#102;&#46;&#98;&#114;">&#99;&#111;&#110;&#116;&#101;&#117;&#100;&#111;&#115;&#100;&#105;&#103;&#105;&#116;&#97;&#105;&#115;&#64;&#105;&#109;&#46;&#117;&#102;&#102;&#46;&#98;&#114;</a>.
   </span>
   </div>
   </body>
   </html>

Answer №1

When dealing with large values, adjusting the camera's near frustum can help minimize z-buffer fighting. Instead of using 0.1, consider trying values such as 10 or 20.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Processing JSON data by reading multiple files using Node.js

I've encountered a situation where I have multiple files containing data with time stamps. It's important for me to read these files in order, line by line. However, I noticed that most Node packages utilize asynchronous methods for file reading. ...

What is the best way to mention @here with an attachment?

I'm attempting to use the canvas say command to display an image with an @here mention included, but unfortunately it only shows the image without making the mention. Below is what I have attempted: message.channel.send(`@here\n`+attachment); ...

Expanding a website banner slide to fill the entire width of the page

Is there a way to ensure that the banner images in the website below flow seamlessly? Currently, it seems like the current image is cut off on the left and part of the previous image shows up in its place. I'd like the current image to occupy the ent ...

Modify the collapse orientation in Bootstrap

I would like the button to expand from the bottom when clicked and collapse back down, instead of behaving like a dropdown. <head> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_ ...

performing a jQuery AJAX call from a UIWebView during the initial launch of the app following installation

We have a uiWebview that uses jquery for an ajax request to log in. It functions flawlessly on mobile safari and all browsers. However, when the application is launched for the first time after installation, the ajax request seems to be sent out but no re ...

Tips for updating the display by fetching data from a database through a websocket

I am looking for a solution to update a specific part of my webpage without having to refresh the entire content. On my index.html page, I have three panels displaying various ticket statuses. I want to automatically update the number of resolved tickets s ...

Ways to reload the page following the submission of a form

I implemented a fade dialog to present a form, and successfully submitted the form using ajax to create a new record in the database. Now, I am facing an issue where I cannot refresh the page after the ajax call finishes. Despite attempting to use JavaScr ...

Changing the rotation of an object in THREE.js to match Canvas rotation

Hello amazing minds of stackoverflow. I am in the process of converting three js mesh positions to html5 canvas positions. While I have successfully converted vector3 position to canvas position, I am facing difficulties with converting mesh rotation to ca ...

When attempting to set a dynamic src tag for embedding a Google Map in a React application, an X-Frame-Options

I'm attempting to display a specific location using an iframe embed from Google Maps (shown below): <iframe width="100%" height="200" frameBorder="0" scrolling="no" marginHeight={0} marginWidth={0} id="g ...

How can I modify certain attributes within an array of objects?

https://i.sstatic.net/TKkcV.jpgI need help with updating properties within an object array. Below is my code for reference. I have an object array consisting of two arrays, where the first one contains attribute "first" and the second one contains "last". ...

What is the best way to iterate over each character in a string and trigger a function in JavaScript?

I am currently working on a project to create a random password generator. The code responsible for generating the password is functioning correctly. However, I am facing an issue with converting the characters of the password into phonetic equivalents. I ...

Draggable vue includes a Textarea HTML element that allows users to easily

The issue lies in implementing the draggable functionality on a textarea element. While the textarea allows text input and deletion, trying to select the text using pointer events triggers the dragging function instead, as shown in the image below: https ...

Tips for effectively combining an array with jQuery.val

My goal is to have multiple form fields on a page, gather the input results into an array, and then store them in a database. This process was successful for me initially. However, when I introduced an autocomplete function which retrieves suggestions from ...

"Unleashing the Power of MongoDB's Dynamic $in

Is there a way to dynamically pass a list of strings to a $in clause in MongoDB? I attempted the following code, but it didn't work and I haven't been able to locate more information other than an example with hardcoded values. The restrictedUs ...

if there is an error in a JavaScript statement

<!DOCTYPE html> <html> <head> </head> <body> <hr> <div> <div id="myPosition"> </div> </div> <hr> <!--Storing the gun array --> <div id ...

Encountering an error with Next.JS when using the "use client" directive

Recently encountered a bizarre issue with my next.js project. Every time I input "use client"; on a page, it triggers a "SyntaxError: Unexpected token u in JSON at position 0". Here's the code snippet for reference: "use client" ...

Do not let CKEditor interact with widget content

Even though the HTML content within the aside tag is not editable, CKEditor still performs content filtering and removes tags while displaying hidden input fields. Here is the relevant HTML widget code: <aside class="widget widget-form" contenteditabl ...

Ways to align div elements

I am currently in the process of developing my own custom animation player. Utilizing Three.js for object rendering has been successful so far. However, the challenge lies in incorporating control options at the bottom of the player interface (such as play ...

Using NextJS to navigate user journey by mapping an array of values from Formik to

I really appreciate all the help I've received so far, but I'm facing an issue trying to map an object with an array within it to the router. Here is my current code: const initialValues = { region: query.region || 'all', campt ...

Adding a regional iteration of a library that was unable to be loaded

Recently, I have been experimenting with PhantomJS to capture screenshots of a webpage every five minutes. While the process runs smoothly most of the time, I encountered an issue where the AngularJS library fails to load intermittently. This results in th ...