Using a render target causes certain elements of my visual graphics to become hidden

Hey there, I've been experimenting with render targets lately and encountered some issues. I've put together a simplified example below:

init = function() {

  // RENDERER

  canvas = document.getElementById("mycanvas");
  renderer = new THREE.WebGLRenderer({
    antialias: true
  });
  document.body.appendChild( renderer.domElement );
  renderer.setClearColor(0x000000, 1.0);
  renderer.setSize(window.innerWidth, window.innerHeight);

  // SCENE

  texscene = new THREE.Scene();

  texcamera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
  texcamera.position.z = 2;

  // FRAMEBUFFER

  var renderTargetParams = {
    minFilter:THREE.LinearFilter,
    stencilBuffer:false,
    depthBuffer:false,
    wrapS: THREE.RepeatWrapping,
    wrapT: THREE.RepeatWrapping      
  };
  rendertarget = new THREE.WebGLRenderTarget( 512, 512, renderTargetParams );

  // CUBE

  var cubeGeo = new THREE.BoxGeometry( 1, 1, 1, 1, 1, 1 );
  var cubeMat = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
  texcube = new THREE.Mesh( cubeGeo, cubeMat )
  texscene.add(texcube);

  var blueMaterial = new THREE.MeshBasicMaterial({color:0x7074FF})
  var plane = new THREE.PlaneBufferGeometry( 100, 100 );
  var planeObject = new THREE.Mesh(plane,blueMaterial);
  planeObject.position.z = -15;
  texscene.add(planeObject);

  /////////////////////////////////

  //SCENE

  scene = new THREE.Scene();
  camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );

  var boxMaterial = new THREE.MeshBasicMaterial({map:rendertarget.texture});
  var boxGeometry2 = new THREE.BoxGeometry( 5, 5, 5 );
  mainBoxObject = new THREE.Mesh(boxGeometry2,boxMaterial);

  // Move it back so we can see it
  mainBoxObject.position.z = -10;
  // Add it to the main scene
  scene.add(mainBoxObject);

  animate();
}

animate = function() {
  requestAnimationFrame(animate);

  renderer.render(texscene, texcamera, rendertarget);

  renderer.render(scene, camera);

  texcube.rotation.y += 0.01;
  texcube.rotation.z += 0.01;

  mainBoxObject.rotation.x +=0.01;
  mainBoxObject.rotation.y += 0.005;
  mainBoxObject.rotation.z += 0.008;
}

init();
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r83/three.js"></script>

I decided to render a red cube along with a blue plane onto a render target and then use it as a texture. However, the red cube doesn't appear in the final output.

Feel free to check out the render target scene by updating

renderer.render(texscene, texcamera, rendertarget);
renderer.render(scene, camera); 

to renderer.render(texscene, texcamera);

Answer №1

It seems that the issue arises from disabling the depth buffer in my rendertarget settings.

depthBuffer:false,

Once I removed this line, my rendertarget rendered correctly with a red box against a blue background.

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

Utilize regular expressions in TamperMonkey to extract specific groups of text

I'm currently working on a TamperMonkey userscript that aims to identify URLs matching a specific pattern, visit these pages, extract relevant information, and then update the link for each URL with the extracted text. I'm facing some challenges ...

What is the best way to organize a flatlist for rendering?

I'm struggling with separating some flat-lists into different components. How can I arrange the rendering of the flat-list like the sample form (Picture "Sample UI")? I've tried, but it's not working correctly as it renders flat list A first ...

Encountering issues with the addEventListener function in a React application

Here's the scenario: I'm currently working on integrating a custom web component into a React application and I'm facing some challenges when it comes to handling events from this web component. It seems that the usual way of handling events ...

Is there a way to access the original query string without it being automatically altered by the browser?

I'm currently encountering an issue with query strings. When I send an activation link via email, the link contains a query string including a user activation token. Here's an example of the link: http://localhost:3000/#/activation?activation_cod ...

Retrieve items from a JSON file using Ionic framework's $http.get method

Issue with Console: SyntaxError: Unexpected token { in JSON at position 119 Xcode controller: str="http://www.website.com/user-orders.php?e="+$scope.useremail; $http.get(str) .success(function (response){ $scope.user_orders = response; ses ...

Nodemailer contact form malfunctioning

I've been working on setting up a contact form in React and utilizing nodemailer to send messages to my email, but I seem to be encountering some issues. I have a server.js file located in the main folder along with Mailer.js which contains the form c ...

Adding a Timepicker to a Datepicker on a jsp webpage with javascript

I am working on a JSP page that includes a date picker. I want to enhance this datepicker by adding a start time and end time within the calendar itself. How can I achieve this? Additionally, I need to implement validation ensuring that the start time is a ...

The request to http://localhost:8080 from http//:localhost:3000 has been restricted due to CORS policy blocking access. This is due to the absence of the 'Access-Control-Allow-Origin' header in the

const fileStorage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, "images"); }, filename: function (req, file, cb) { cb(null, uuidv4()); }, }); const fileFilter = (req, file, cb) => { if ( file.mi ...

The second node child process encounters execution issues in Linux

For a challenge, I needed to find a way to automatically restart my bot within itself. After some trial and error, I came up with a solution. However, when testing on a Raspberry Pi via ssh, the process exits after the first child process ends. Surprisingl ...

Issue encountered while constructing an array within the component data following the 'created' event

It's been a while since I've dealt with Vue.Js, so my memory is a bit fuzzy. I'm facing an issue where I can't seem to modify a data array within a function that is called in the created hook. My goal is to create a multidimensional ar ...

Color Your Plone Website with a Custom JavaScript Colorscheme

Currently, I have implemented a custom theme by registering the javascript in the skin.xml file and then creating a specific folder within the browser to store the script. Below is the script shared by one of the users: $(document).ready(function(){ ...

What is the process for creating a local repository for Node.js npm?

When it comes to the building process in node js, there are a few goals that need to be called: Begin by calling npm install, which creates a folder called node_modules and places all dependencies from package.json into it. [for UI development] Execute a ...

Issue with DWR and Android web browser

I recently encountered an issue while trying to access an application through the Android browser. The application uses DWR to maintain connections with connected clients. Everything seems to be working fine, except for the fact that if there is a 2-minut ...

issue encountered while passing a callback in a res.render() function

Currently, I am working on a small application where I am fetching data from remote JSON files to generate statistics that will be displayed in an EJS file later. My objective is to pass separate values for rendering and then utilize them within the EJS d ...

Error message: "npm start cannot locate package.json file, even though the file is present

As I attempt to execute npm start within my Node.js project directory, I am facing a challenge. Despite having the package.json file in the correct location (C:\Myfirstproject\Vinci\Projet_Web), I keep encountering an error message that read ...

Unusual actions observed in ajax rails form calculator with pre-filled values

I have a form calculator in Rails that utilizes AJAX without a database. While it functions properly, I have noticed some peculiar behavior which I would like to address. Firstly, I navigate to the /interest_calculator page Then, I input 10 into @first_0 ...

Modifying text on input buttons using Javascript

Including product names, text forms, and buttons on a webpage is essential for showcasing products effectively. Each product is assigned an ID such as p1, p2, etc., while the input types are identified by i1, i2, etc. When users enter information into the ...

Implementing file uploads with Bootstrap, jQuery, and Laravel

Looking to incorporate the blueimp jquery file upload feature into my Laravel app. Check it out here: https://github.com/blueimp/jQuery-File-Upload The form is set up and working properly with the plugin, but facing issues with creating server-side script ...

Struggling to update a Knockout observable array

I'm attempting to send some data to a Knockout observable array. Despite receiving data from my AJAX call without any errors during script execution, I find that the userNames array remains empty when accessed. What could be causing this issue? UserH ...

What is the best way to download a vast number of files with nodejs?

I have a total of 25000 image links that I need to download to my local machine using the request package in nodejs. It successfully downloads up to 14000 to 15000, but then I start encountering errors. Error { Error: socket hang up at TLSSocket.onHa ...