What is the best method to extract pixels from a computed texture in three js?

When it comes to computing a multidimensional array of data, I believe that GPUComputationRenderer is the ideal solution.

I initially began from an example project and encountered a roadblock:

var gpuCompute = new GPUComputationRenderer( 100, 100, this.renderer );

var dtPosition = gpuCompute.createTexture();
var dtVelocity = gpuCompute.createTexture();

var velocityVariable = gpuCompute.addVariable( 
   "textureVelocity", 
   this.compFragmentShader(), 
   dtVelocity 
);
var positionVariable = gpuCompute.addVariable( 
   "texturePosition", 
   this.compVertexShader(),   
   dtPosition 
);

gpuCompute.setVariableDependencies( 
   velocityVariable, 
   [ positionVariable, velocityVariable ] 
);
gpuCompute.setVariableDependencies( 
   positionVariable, 
   [ positionVariable, velocityVariable ] 
);

gpuCompute.init();

gpuCompute.compute();

//TODO: Obtain pixels from resulting texture

I have explored some examples on three.js:

In addition, I came across this stack overflow THREE.js read pixels from GPUComputationRenderer texture but found no concrete solution, just references to webGL.

Could there be something vital that I am overlooking? Kindly offer an example or explain where I may be going wrong

Answer №1

There is no requirement to retrieve the data.

The functionality of WebGLRenderer.readRenderTargetPixels is limited because GPUComputationRenderer does not directly render to WebGLRenderer. Instead, it utilizes WebGLRenderTargets which act as offscreen 'invisible' canvases.

The information provided in the stack overflow discussion confirms the difficulty of this task. Without performing complex calculations and converting/packing float textures into integer textures, retrieving data from the GPU/GLSL side back to the CPU/JavaScript side is extremely challenging.

As mentioned earlier, there is no obligation to get the data back. Judging from your code, it seems like you have experience with vertex/fragment shaders. I have successfully used this technique with point clouds in the past.

You can pass the dtPositions (or possibly dtPositions.texture) as a uniform to a shader material applied to your 'display' mesh. This shader can extract the position from the texture and move the vertex accordingly.

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

Where is the optimal location for placing a JavaScript listening function within an Angular component?

Summary: Incorporating a BioDigital HumanAPI anatomical model into my Angular 5 application using an iFrame. The initialization of the API object is as follows: this.human = new HumanAPI(iFrameSrc); An important API function human.on(...) registers clic ...

What could be causing the div to not respond to ngAnimate?

Recently, I encountered an issue with adding animations to a list of <div>'s in my webapp. After incorporating ngAnimate into the app.js file and including ng-animate="'animate'" in the <div>, I was disappointed to find that the ...

Outlining in Three.js

Can I achieve a black outline effect on my 3D models using three.js? I'm looking to create graphics similar to Borderlands 2, with toon shading and distinct black outlines. ...

Parsing URLs with Node.js

Currently, I am attempting to parse the URL within a Node.js environment. However, I am encountering issues with receiving null values from the following code. While the path value is being received successfully, the host and protocol values are returnin ...

Generate a new entity by merging two objects containing keys that are identified by dots

I have a unique input as shown below: { survey.subObject1.key1: true, survey.subObject1.key2: "OTHER", survey.subObject2.key3: "[1,2]", survey.subObject2.key4: false, survey2.subObject3.key5: false, survey2.subObject3.key6: false } I a ...

Creating visuals from written content

I am attempting to transform Y[0] into an image rather than text. Currently, it is only displayed as a plain text link and not as an image. <html> <head> <script type="text/javascript"> function modifyContent(){ var rows=document.g ...

Wordpress team exhibition

Does anyone know how to create a Team showcase slider in Wordpress? I have been using slick slider, but I'm looking for a way to add team members easily through a plugin rather than manually. I found an image of what I want it to look like. Can any ...

Tips for Utilizing Both getElementByID and getElementByTagName Functions in JavaScript

Hi! I'm a beginner in JavaScript and I've managed to retrieve some data using getElementById. Now, I want to extract a specific part using getElementsByTagName. document.getElementById('titleUserReviewsTeaser').innerHTML; " < ...

Alignment issue with Div Element detected

I'm currently working on a JavaScript program where I need to create buttons and div elements dynamically. My aim is to have the div elements aligned horizontally. I've successfully created the buttons and div tags, but the issue I'm facing ...

node.js issue with chalk package

**When I want to use the chalk package in node.js, I encounter the following issue:** index.js const chalk = require('chalk'); console.log(chalk.bgRed.inverse("hello world")); console.log(chalk.blue.inverse('Hello') + &ap ...

AngularJS and KendoUI integration experiencing delays during script evaluation

At the moment, I am conducting performance measurements and analysis on our AngularJS-KendoUI application in an effort to identify any bottlenecks. Following a helpful article and an informative presentation, I am using Chrome DevTools timeline tab to anal ...

Using regular expressions to identify the presence of "&", parentheses, and consecutive letters in a string

I specialize in working with JavaScript and I have a need to verify if my text contains certain characters. Specifically, I want to check for the presence of parentheses (), ampersands (&), and repeating letters within the text. Here are some examples: te ...

Vue.js is not incrementing the counter as expected

I've encountered an issue with a button that has a click event to increment data value by 5, but instead of adding 5 it is appended by 5. Click here for the code example <div id="react"> <button @click='counter += 5'>Increment& ...

Flags of Discord.js PermissionsBitField

Where can I find information on the PermissionsBitField.Flags commands? I am specifically looking for the "Guilds and Guilds_messages" flags but have had trouble locating them. Does anyone know why PermissionsBitField.Flags.Guilds and PermissionsBitField. ...

Acquiring and showcasing the mongoose schema property

Within my mongodb collection, I have a plethora of jokes stored, the schema is structured as below: const mongoose = require ("mongoose"); // Dad Joke Schema const jokeSchema = new mongoose.Schema({ content: String }); module.exports = mongoose.mode ...

Ways to efficiently incorporate data into App.vue from the constructor

My app initialization uses main.js in the following way, import App from './App.vue'; const store = { items: [{ todo: 'Clean Apartment.', },{ todo: 'Mow the lawn!', },{ todo: 'Pick up ...

Issue with JQuery on Mobile Devices: Troubles with Dropdown Menu and Loading Function

Having some trouble with my JQuery code on mobile devices. The drop down menu isn't showing up on an iPhone, the load function isn't working to display the additional PHP page on a Samsung Edge 7, and the drop down doesn't seem to be functio ...

Error message 'MODULE_NOT_FOUND' occurs while executing a Docker application

Although I successfully created a docker image, I am encountering issues when trying to run it. This is the command that I am using for running: docker run coderpc/test-server Displayed below is the error message that appears in the console. Error: Canno ...

A guide to utilizing CSS to showcase the content of all four div elements in HTML body simultaneously

Is there a way to use CSS to display the content of all 4 divs in the same place on the HTML body, based on the URL clicked? Only one div should be displayed at a time in the center of the page. For example, if URL #1 is clicked, it should show the conten ...

JavaScript: Repeated Depth First Exploration for hierarchical rearrangement implemented with d3's recursion()

I'm attempting to perform a depth-first search on a complex JSON object, such as the one available through this link. My goal is to generate a modified object structure that looks like this: [ { name: "Original Object", children : [ ...