Selection of GPU varies on different devices

I am currently working on implementing GPU picking with Points using code that I adapted from the latter part of an article which can be found at this link

While it has been functioning properly on my desktop, I encountered inconsistencies when testing it across various browsers and devices. To demonstrate this issue, I have created a Codepen showcasing the problem: here

body {
  margin: 0;
}
#c {
  width: 100vw;
  height: 100vh;
  display: block;
}
<canvas id="c"></canvas>
<script type="module">
// Three.js - Picking - RayCaster w/Transparency
// from https://threejsfundamentals.org/threejs/threejs-picking-gpu.html

import * as THREE from "https://threejsfundamentals.org/threejs/resources/threejs/r113/build/three.module.js";

function main() {
  const canvas = document.querySelector("#c");
  const renderer = new THREE.WebGLRenderer({ canvas });

  const fov = 60;
  const aspect = 2; // the canvas default
  const near = 0.1;
  const far = 200;
  const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
  camera.position.z = 30;

  const scene = new THREE.Scene();
  scene.background = new THREE.Color(0);
  const pickingScene = new THREE.Scene();
  pickingScene.background = new THREE.Color(0);

  // More code here...
┊

If you interact (click or tap) on the nodes, their IDs are supposed to appear in the console. However, some devices only return 0, indicating the background is being picked.

Does anyone have insights into why this might be happening?

Additionally, if there are alternative methods for performing picking in this scenario (Point mesh with varying point sizes via ShaderMaterial) that are simpler yet retain performance, I would be interested in exploring those options

UPDATE:

I decided to remove the optimization involving the 1x1 render target, and it seems to have resolved the issue. Now, I'm curious to understand what specific aspect of that optimization was causing the problem...

Answer №1

Unfortunately, the challenge lies in the inability to utilize Points consistently across various devices.

The behavior of whether a point is displayed when its center is offscreen varies from device to device due to differences in drivers. While OpenGL ES / WebGL specifications mandate that points should still be rendered even if their centers are offscreen, some drivers, like AMD and PowerVR based (iPhone), do not adhere to this rule. On the other hand, companies like Intel and NVidia ensure that these points are indeed drawn.

An illustration of this issue can be seen when enlarging circles and ensuring they go offscreen, with varying outcomes on different devices depending on factors such as point size and viewport size.

To tackle this problem, switching to rendering points using quads instead is recommended. This can be achieved by drawing each quad separately, merging them into another mesh, utilizing InstancedMesh with a matrix per point, or customizing shaders for point rendering.

It's worth noting that points come with additional limitations such as not scaling relative to canvas size by default, having a maximum device-independent size that could be as small as 1 pixel, and lacking responsiveness to device pixel ratio settings. These constraints restrict the practicality of points in certain scenarios, particularly when dealing with large circles.

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

Removing an item from an array while also updating one of its attributes in JavaScript

I am facing a challenge with this list of objects: const flights = [ { id: 00, to: "New York", from: "Barcelona", cost: 700, scale: false }, { id: 01, to: "Los Angeles", from: "Madrid", cost: 1100, scale: tru ...

Threejs collada loader tutorial: converting a scene into an object3d

Currently working on an augmented reality project and I'd like to incorporate an Object3D into another object for rendering purposes. Using the ColladaLoader to bring in the object, but the output is a Scene which doesn't quite fit my requiremen ...

Communicating PHP variables with JavaScript through AJAX in a chat application

Hello there! I am currently in the process of developing a chat application for my website that includes user registration and login. My backend server is built using NodeJS to leverage SocketIO capabilities. Within my index.php file, I have implemented ...

The hovering effect on the image link is causing the surrounding div to stretch too far

Whenever I hover over specific points below an image link wrapped in a div, it triggers the hovering effect for the CSS-created image link. Despite trying various solutions like overflow:hidden and display:inline-block, nothing seems to resolve this issue. ...

Sharing images on a web app using Express and MongoDB

My objective is to develop a portfolio-style web application that allows administrators to upload images for other users to view. I am considering using Express and MongoDB for this project. I am uncertain about the best approach to accomplish this. Some ...

Mapping Longitude and Latitude with TopoJSON and D3

Currently utilizing the UK Geo JSON found at this link to generate a UK SVG Map. The goal is to plot longitude and latitude points onto this map. The GeometryCollection place is being added to the map in the following manner: data.objects.places = { ...

When using Vue.js router.push, the URL gets updated but the RankerDetail component does not refresh when navigating with a button

I am currently working on a Vue.js project that involves vue-router, and I've encountered an issue with the RankerDetail component. This particular component is responsible for dynamically displaying data based on the route parameter id. Strangely, wh ...

Modify three.js material without obscuring the object

How can I update a three.js material without making the object it is applied to disappear? The only workaround I've found is to clone both the object and the material, make changes to the cloned material using material.needsUpdate = true, and then re ...

Enhance the speed of filtering a large array of 4000+ objects in React for optimal performance

I am currently dealing with a component that generates an input of type text for filtering an array containing over 4000 objects. const { airports } = useContext(MainContext); const [airportListLocal, setAirportListLocal] = useState<Airport[]>(airp ...

Having issues with using setTimeOut within a for loop in JavaScript React

I'm currently working on a visual sorting algorithm application using React. My implementation involves bubble sort, where I generate an array of numbers from 1 to 50, shuffle them, and then apply the bubble sort method to sort them. However, I am fac ...

Nested Angular click events triggering within each other

In my page layout, I have set up the following configuration. https://i.stack.imgur.com/t7Mx4.png When I select the main box of a division, it becomes highlighted, and the related department and teams are updated in the tabs on the right. However, I also ...

Combining jQuery methods and selectors within a loop

Can a sequence of selectors and methods be generated within a loop? For instance, assuming an array of elements is given: array[0] = '.type1value1, .type1value2, .type1value3'; array[1] = '.type2value1, .type2value2, .type2value3'; ar ...

Creating an HTML string and then displaying its outer HTML in IE10 can be easily achieved. Just write the

My task is to write an HTML string to an element and then retrieve the resulting outer HTML from that element. This needs to be operational in IE10, latest versions of FF, Chrome, Safari, Android, iOS Safari but does not have to support any older browsers. ...

Using an external variable within an internal function in TypeScript

I am facing a situation where I have a variable outside of a function that needs to be updated, but I am unable to access it using "this" as it is not reachable at that point in the code. export class GamesDetailPage { details : any = {}; type : St ...

Introducing the innovative Icon Collapsable JQuery - a versatile tool that

I'm looking to set custom icons for the JQuery Collapsable view without having to make changes to the default JQuery CSS and .JS files. You can take a look at my starting point on jsFiddle here: http://jsfiddle.net/jakechasan/M7LLU/ Although I' ...

Shutting down the jQuery pop-up

I am struggling with trying to display this code as a popup on my website. Here is the code I have: <div id="myDialog" title="myTitle"> <div class="table_cell"> <div class="message"></div> </div> <div class="tabl ...

Using MongoDB in a feathers.js Hook

I'm struggling to make a feathers.js hook wait for a MongoDB call to complete before proceeding. I've tried using returns and promises, but so far nothing has worked. How can I ensure the hook waits for the database query to finish? ...

Exploring ways to retrieve variables from nested arrays in PHP

I'm facing an issue with sending data from my javascript to a php server. It seems that I am unable to access all the variables that are being sent, especially when dealing with nested arrays and JSON strings. Below is the code snippet: sender.js $ ...

Choosing and aiming with jQuery on dynamically created Ajax pages

I am facing an issue with a Select box on a page that is generated through AJAX. Here is the code snippet: <select onchange="setLocation(this.value)"> <option value="https://xy.com/accessories.html?dir=asc&amp;limit=15&amp;order=name"& ...

Verify that each interface in an array includes all of its respective fields - Angular 8

I've recently created a collection of typed interfaces, each with optional fields. I'm wondering if there is an efficient method to verify that all interfaces in the array have their fields filled. Here's the interface I'm working wit ...