Challenges with Three.js CanvasRenderer

Exploring the world of Three.js has been an interesting journey so far. While working on implementing a fallback using CanvasRenderer for devices that do not support WebGL, I encountered a couple of challenges:

Anomaly in Line Geometry

https://i.sstatic.net/qsb4X.png

Extra Pixel Issue

https://i.sstatic.net/QSbF7.png

Below is my current code snippet:

var width = 960;
var height = 500;
var aspect = width / height;

var D = 1;

var CanvasRenderer = true;

var scene    = new THREE.Scene();
var camera   = new THREE.OrthographicCamera(-D * aspect, D * aspect, D, -D, 1, 1000);

if(CanvasRenderer) {
    var renderer = new THREE.CanvasRenderer({
        alpha: true,
        antialias: true
    });
} else {
     var renderer = new THREE.WebGLRenderer({
alpha: true,
     antialias: true
     });
}

renderer.setSize(width, height);
document.body.appendChild(renderer.domElement);

var geometry = new THREE.BoxGeometry(0.1, 1, 0.5);


var cube = new THREE.Mesh(geometry, [
new THREE.MeshPhongMaterial({
        color: 0x222222, // right
        overdraw: true
    }),
new THREE.MeshPhongMaterial({
        color: 0xffffff,
        overdraw: true
    }),
    new THREE.MeshPhongMaterial({
        color: 0xEDE6F5, // Top
        overdraw: true
    }),
    new THREE.MeshPhongMaterial({
        color: 0xffffff,
        overdraw: true
    }),
    new THREE.MeshPhongMaterial({
        color: 0xFFFFFF, // Left
        overdraw: true
    }),
    new THREE.MeshPhongMaterial({
        colo...
});

scene.add(cube);
scene.add(new THREE.AmbientLight(0xFFFFFF));

camera.position.set(20, 20, 20);
camera.lookAt(scene.position);

renderer.render(scene, camera);
body {
  margin: 0px;
  overflow: hidden;
  background: #EEE;
}
<script src="https://threejs.org/build/three.min.js"></script>
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/renderers/Projector.js"></script>
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/renderers/CanvasRenderer.js"></script>

Divergence in WebGL Output

Comparison with WebGL renderer output:

https://i.sstatic.net/TEeKQ.png

JSFiddle Demo

http://jsfiddle.net/4tbs4tpL/2/

Answer №1

If you are working with the CanvasRenderer, it's important to note that the Material.overdraw property ranges from 0 to 1, and a recommended value is 0.5.

By adjusting the overdraw property to lower values, you may notice a reduction in the artifacts you mentioned.

This information pertains to three.js version r.86.

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

Check to see if modifying the HTML using jQuery results in any errors

Although it may sound straightforward, let me clarify. I am utilizing ajax calls to update the content of the body and I aim to trigger an alert if the updating process fails on the client side, specifically after receiving a response from ajax in case of ...

The WebGLRenderer in ThreeJS is unable to update the domElement property

During the development of a ThreeJS project, I came across this particular error: Uncaught TypeError: Cannot set property 'domElement' of undefined The filename before being converted to regular JS for browsers is: index.js import { Scene, Web ...

Concluding the dialogue once the post request has been successfully processed

My tech stack includes React, Redux, NodeJS, and ExpressJS. For the front-end, I'm utilizing material-ui. Within my application, I have implemented a dialog that allows users to input information and sign up. Upon clicking submit, a POST request is in ...

Extracting information from XML and showcasing it in an HTML format

My current setup includes two hard-coded boxes from line 18 to line 70 in the HTML section. Now, I have an .XML file containing: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <collection> <beanRepresentation> <beanRepId> ...

Uploading my application on multiple servers after making changes using AngularJS and PHP

Currently, I am working on an angular-php web application that is live online for multiple users, each on their own subdomain. These subdomains include: sub1.mydomain.com sub2.mydomain.com sub3.mydomain.com sub4.mydomain.com sub5.mydomain.com Issue: An ...

Having Issues with Loading More Button Functionality in Selenium Automation

Here is a snippet of my code. from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected ...

Troubleshooting Material-UI Menus

I need the menu to adjust its height dynamically as the content of the page increases vertically. Even though I have applied "height:100%" in the styles, it doesn't seem to work. Can anyone assist with this issue? Here is the code snippet: import R ...

ajax is triggering the error handler

I am currently developing a web application and I am trying to send data from a PHP controller to JavaScript. After conducting some research, it seems that the most efficient way to accomplish this is by utilizing Ajax and Json. However, I am encountering ...

Is there a way to order the execution of two functions that each produce promises?

With my code, I first check the status of word.statusId to see if it's dirty. If it is, I update the word and then proceed to update wordForms. If it's clean, I simply update wordForms. I'm looking for advice on whether this is the correct a ...

Calculating interest rates in Javascript: A guide to determining values using two separate rates

I am currently working on an earnings calculator function EarningsCalculator.prototype.calculateEarning = function (interestRate, investmentAmount) { var earningHistory = {}; var currentInvestment = investmentAmount; for (var year = 1; year & ...

The interval becomes congested due to the execution of two simultaneous Ajax calls

I have an Interval set to run a function every 3 seconds. intervalStepper = window.setInterval('intervalTick()','3000'); function intervalTick() { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari ...

Slideshow elements removed

I attempted to remove my links individually from the div id="wrapper", but unfortunately have encountered an issue while doing so: window.onload = function () { setInterval(function () { var wrapper = document.getElementById("wrapper"); var my_l ...

Troublesome CSS Zoom causing issues with jQuery scrollTop

As I design a website that has a fixed width and zooms out on mobile browsers, I've opted to adjust the zoom using CSS rather than viewport meta tags: html, body { zoom: 0.8; } It's been effective so far, but now I'm facing an issue wi ...

The element's position remains unchanged after the .click re-event in the function

Welcome to my first attempt at using jQuery! Please bear with me as I navigate through this learning process. Here's the challenge: I have a series of elements in my HTML. <div class="garden"> <div class="point left">&#9668;</d ...

How can I display a specific element from a child Component when the main Component is clicked on in React?

I am currently working on my first React project and facing a challenge. I have a dropdown list on my main homepage that displays specific details when clicked. However, I am struggling to show the right corresponding detail (for example, black&white paren ...

What are the steps to integrate the aws-iot-device-sdk NPM module with Angular 11? I am encountering errors related to fs, path, and tls during the build process

I manage a browser-based Angular application that was previously on version 5.6. This app consists of two components that subscribe to an IOT topic and listen for updates without publishing. The task at hand is to upgrade to Angular 11.0.3, which I have c ...

Switch the angular attribute by clicking on ng-click

I have a Google Map set up with markers that I need to switch on and off. <marker id='{{marker.id}} 'visible="{{ condition ? 'true' : 'false'}}"> </marker> Additionally, I have created a button to control the v ...

In Java, use an HttpRequest to retrieve the webpage content and ensure that the process waits until the JavaScript has finished

Is there a way in Java to wait for partial content of a webpage to be loaded by JavaScript before initiating the rest of the process? The webpage contains script that loads additional content once the page is fully loaded, and I need to ensure that the p ...

Creating a layered image by drawing a shape over a photo in Ionic using canvas

While there are plenty of examples demonstrating how to draw on a canvas, my specific problem involves loading a photo into memory, adding a shape to exact coordinates over the photo, and then drawing/scaling the photo onto a canvas. I'm unsure of whe ...

Partial view remains stagnant despite successful ajax post completion

I am currently in the process of developing a system that will showcase uploaded images from a file input into a specific div within my view. (with intentions to incorporate document support in the future) The challenge I am facing is that the partial vie ...