readRenderTargetPixels without any shader. Just to get the pixelcolor returns [0,0,0]

I defined a render target like that:

scene = new THREE.Scene();
renderTarget = new THREE.WebGLRenderTarget(renderer.domElement.clientWidth, renderer.domElement.clientHeight);

And later I try to read the pixel color at a certain place.

var read = new Uint8Array(1 * 1 * 4);
renderer.readRenderTargetPixels(renderTarget, x, y, 1, 1, read);
console.log('r:' + read[0] + ' g:' + read[1] + ' b:' + read[2]);

This is my renderer:

renderer.render(scene, camera);
renderer.render(scene, camera);

Unfortunately this returns [0,0,0] all of the time. Am I missing something?

I have refactored your code according to the this official example.

Live demo:

I’m not exactly sure what was missing in your application since important bits of your code are not listed in your post. Anyway, try to stick to the official code and things should work :+1:


Thank you so much! This example already really helped.
Why do you need to add a perspectiveCamera? Is it possible to do it with a new THREE.Camera();
I don’t need a perspective Camera as It’s for an ar project.

If I replace the camera in your example, it stops working.

Ah, it’s actually working. Perfect! Thanks!

1 Like