Rendering in Three JS involves efficiently utilizing one buffer to display the output within itself

I have been struggling with a particular issue and I really need some assistance:

In my three js context, I have created a custom material and rendered it into a texture.

`

/* Rendering in texture */
    fbo_renderer_scene = new THREE.Scene();
    fbo_renderer_ripple_update_scene = new THREE.Scene();
    var fbo_texture_light = new THREE.DirectionalLight(0xFFFFFF, 1.5);
    fbo_texture_light.position.set(0.0, 0.0, -1.0).normalize();
    fbo_renderer_scene.add(fbo_texture_light);
    fbo_renderer_ripple_update_scene.add(fbo_texture_light);

    ripple_texture = new THREE.WebGLRenderTarget(width, height, render_target_params);
    ripple_update_texture = new THREE.WebGLRenderTarget(width, height, render_target_params);

    ripple_material = new THREE.ShaderMaterial(
    {

        uniforms: 
        {
            texture1: { type: "t", value: bottom_plane_texture},
        },

        vertexShader: document.getElementById('drop_vert_shader').textContent,
        fragmentShader: document.getElementById('drop_frag_shader').textContent,

        depthWrite: false
    });

    fbo_renderer_camera = new THREE.OrthographicCamera(width / -2.0, width / 2.0, height / 2.0, height / -2.0, -10000, 10000);
    var texture_mesh = new THREE.Mesh(bottom_plane_geometry, ripple_material);
    fbo_renderer_scene.add(texture_mesh);
    renderer.render(fbo_renderer_scene, fbo_renderer_camera, ripple_texture, true);

After rendering, everything is stored in the ripple_texture.

Now, I need to update the ripple shape using another shader when Animate() is called.

This shader should render the updated result back into the ripple_texture:

/* Rendering the updated texture */
fbo_renderer_scene = new THREE.Scene();
fbo_renderer_ripple_update_scene = new THREE.Scene();
var fbo_texture_light = new THREE.DirectionalLight(0xFFFFFF, 1.5);
fbo_texture_light.position.set(0.0, 0.0, -1.0).normalize();
fbo_renderer_scene.add(fbo_texture_light);
fbo_renderer_ripple_update_scene.add(fbo_texture_light);

ripple_texture = new THREE.WebGLRenderTarget(width, height, render_target_params);
ripple_update_texture = new THREE.WebGLRenderTarget(width, height, render_target_params);

ripple_material = new THREE.ShaderMaterial(
{

    uniforms: 
    {
        texture1: { type: "t", value: bottom_plane_texture},
    },

    vertexShader: document.getElementById('drop_vert_shader').textContent,
    fragmentShader: document.getElementById('drop_frag_shader').textContent,

    depthWrite: false
});

fbo_renderer_camera = new THREE.OrthographicCamera(width / -2.0, width / 2.0, height / 2.0, height / -2.0, -10000, 10000);
var texture_mesh = new THREE.Mesh(bottom_plane_geometry, ripple_material);
fbo_renderer_scene.add(texture_mesh);
renderer.render(fbo_renderer_scene, fbo_renderer_camera, ripple_texture, true);

When I attempt to do this, Chromium displays an error:

WebGLRenderingContext-0x3d022469aa80]GL ERROR :GL_INVALID_OPERATION :glDrawElements: Source and destination textures of the draw are the same.

Meanwhile, Firefox shows a black canvas.

I suspect it may be a timing issue, but I am unsure how to resolve it since three js does not have a callback for rendering.

Answer №1

The problem is being pointed out to you:

WebGLRenderingContext-0x3d022469aa80]GL ERROR :GL_INVALID_OPERATION : glDrawElements: Source and destination textures of the draw are the same.

You cannot both read and render to the same texture simultaneously because the rendering process will overwrite the texture data being read, resulting in incorrect output.

To resolve this issue, you must use a different texture for rendering that is separate from the one being read from.

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

Guide on creating event hooks within VUE 2.0 component connections

I have successfully created two dynamic components. Now, I am looking to trigger the "logThat(someObj)" method of component-two using events: $emit/$on with the arguments being passed as shown in this code snippet: Vue.component('component-one', ...

Which SSO framework works best for integrating Facebook and Twitter logins?

I own a website and I'm looking for a way to let users leave reviews and rate products. I need an SSO system that allows them to sign in with their Facebook or Twitter accounts and ensures each user is uniquely identified so they can't rate produ ...

ShaderMaterial experiencing issues with custom attributes functionality

I've been struggling to implement a custom attribute on a shaderMaterial, but for some reason, it's just not working. Below is a simplified version of my code: attributes = { aColor: { type: "f", value:] }, }; for ( i = 0; i < point ...

Having trouble generating an array for checkboxes using jQuery, AJAX, and PHP

I'm almost there, but there's something missing. I'm attempting to send variables from multiple checkboxes to a PHP page using jQuery. This is my code: <div id="students"> <div class="field"> <label> ...

Eliminate web address parameter using regular expressions

Looking to remove a specific URL parameter from a given URL. For instance, if the URL is: http://example.com?foo=bar&baz=boo And I want to eliminate foo=bar to get: http://example.com?baz=boo Or removing baz=boo would leave me with: http://exampl ...

Chrome is having trouble loading basic JavaScript

Here's the JavaScript code I have placed inside the head tag of my HTML: <script type="text/javascript"> function over1() { var img1 = document.getElementById("1").src; document.getElementById("big").src = img1; } function out() { ...

Interactive chat feature with live updates utilizing jQuery's $.Ajax feature for desktop users

I came across a script for real-time chat using $.ajax jQuery, but it only refreshes my messages. Here's an example scenario: I type: Hello to You, and I see this message refreshed. You reply: Hey, in order to see your message, I have to manually refr ...

Embed a function within a string literal and pass it to another component

Is there a way to pass a function defined in actions to an element? Reducer case 'UPDATE_HEADER': return Object.assign({}, state, { headerChildren: state.headerChildren.concat([action.child]) }); Action.js export const deleteH ...

What could be causing the "undefined" property error in my Vue.js component?

In my Vue.js application, I have several components that are structured similarly and are all throwing the same error: TypeError: Cannot read property 'id' of undefined I initially attempted to resolve this issue by enclosing {{ jobs[0].id }} w ...

Exploring Clara.io's json data for 3D geometry within the Three.js

I've encountered an issue with exporting models in Clara.io. According to their instructions, exporting a selection should create a file for JSONLoader and exporting the full scene should result in a file for ObjectLoader. However, none of the export ...

Is there a way to automatically generate and allocate an identifier to an input field?

I've written the code below, but I'm having trouble figuring out if it's accurate. Specifically, I can't seem to access the text inputs that have been created by their respective id attributes. for (i=0;i<t;i++) { div.innerHTML=div. ...

When the user clicks the back button in AngularJS

After searching extensively, I have yet to find a straightforward solution to my issue. The problem lies in a search/filter field that filters the page based on user input. While this filter works efficiently, it clears whenever a navigation item is clicke ...

Using DIV to "enclose" all the elements inside

I need assistance with my HTML code. Here is what I have: <div id="cover" on-tap="_overlayTapped" class$="{{status}}"> <form method="POST" action="/some/action"> <input required id="name" name="name" label="Your name"></input> ...

As the user types, automatically format the input field for a seamless and intuitive experience

My current application is running on Angular 1.3.10 I have implemented a jQuery function to automatically add a backslash to the expiration input field once the user types the third number. Although it was a quick fix, I now aim to move this functionality ...

Render doesn't wait for the componentWillMount lifecycle method

I'm currently working on implementing a redirection to the home page for logged-in users. I'm using ping to fetch login information, setting a state based on the response, and then checking that state in the render method for redirection. However ...

Countdown Clock in JavaScript for Automatic Logout

I am currently working on creating a countdown timer in JavaScript that should decrement the value of a field by one every minute (for example, starting at 20 and then changing to 19, 18, 17, and so on). However, I am facing issues with its functionality ...

Error: Unable to change image -- TypeError: Cannot assign value to null property 'src'

As I work my way through the textbook for one of my classes, I am practicing by building an image swapping page. The concept is simple - clicking on a thumbnail swaps out the main image and enlarges it as if it were linking to another web page. Despite fol ...

Extracting and retrieving data using JavaScript from a URL

After reviewing some code, I am interested in implementing a similar structure. The original code snippet looks like this: htmlItems += '<li><a href="show-feed.html?url=' + items[i].url + '">' + items[i].name + '& ...

Connect ngOptions to an array beyond the current scope

Can the ngOptions be bound to a value that is not within the $scope? I have enums that will be generated as JavaScript code. These enums are not currently part of "the angular domain", but I want to bind an ngOptions to one of the arrays without manually ...

Tips for integrating AngularJS into a webpage

I am currently developing a NodeJS application and I am looking to integrate AngularJS for the client side scripting. After downloading AngularJS via NPM, I encountered an issue where my require statement is not functioning as expected. Can anyone provide ...