ray-tracing-renderer icon indicating copy to clipboard operation
ray-tracing-renderer copied to clipboard

Canvas transparency

Open VinAr22 opened this issue 5 years ago • 12 comments

Hello again! Im trying to save canvas as image like this

var data = renderer.domElement.toDataURL("image/png");
var img = new Image();
img.src = data;
$("body").append(img);

this way works only with three WebGLRenderer. In ray traycing renderer i get black background. Whats im doing wrong?

VinAr22 avatar Feb 27 '20 07:02 VinAr22

That's a good question and I'm not sure. I can try to offer some possible solutions.

https://stackoverflow.com/a/26790802 If you follow the instructions here and get the code structured in the right order, does it work? If not, it may be because the renderer doesn't always draw to the screen each frame, and only draws to the screen when the next sample is completely rendered. In this case, does running your code inside the renderer.onSampleRendered callback work?

jaxry avatar Feb 27 '20 08:02 jaxry

Hello! @VinAr22 I can save it normally on my Google browser, and it's also black on Firefox.

RenderTool avatar Feb 27 '20 08:02 RenderTool

Hi! Thanks for the quick response. The method using requestAnimationFrame does not work. renderer.onSampleRendered did the trick

VinAr22 avatar Feb 27 '20 08:02 VinAr22

So i have another question about this topic. Maybe it is possible to save only model view on transparent background? :)

VinAr22 avatar Feb 27 '20 08:02 VinAr22

Good question. It's not possible at the moment, but I'm in the middle of separating the different of stages of rendering (useful for spatial denoising) that will also make transparency possible as well. So we'll probably have that in a few weeks!

jaxry avatar Mar 04 '20 01:03 jaxry

Hello! It'll be cool! Please let me know when it will be possible

VinAr22 avatar Mar 04 '20 09:03 VinAr22

Hello @jaxry! After the update, saving the canvas data does not work with renderer.onSampleRendered. :(

VinAr22 avatar Apr 29 '20 03:04 VinAr22

Thanks for letting me know. onSampleRendered now measures performance as well, and to get an accurate number, the callback is called one frame after the sample is rendered to the screen. Doing so makes the callback fall out of sync with the browser's draw frame.

Unfortunately I don't think we can move the callback back to where it was. Instead, would a separate callback, like renderer.getScreenshot(callback) get the job done?

jaxry avatar Apr 29 '20 20:04 jaxry

Hi @jaxry ! Thanks for the response. I understand correctly, this function already exists? Or is it just planned? it would be cool to be able to save a screenshot.

VinAr22 avatar Apr 30 '20 04:04 VinAr22

I have hard-coded this code:

if (typeof window.screenShot == "function") {
        if (window.doScreenShot){
          window.screenShot();
          window.doScreenShot=false;
        }
      }

At the end of the function drawTile()

if (isLastTile) {
...

HERE
}

nicolab28 avatar May 26 '20 15:05 nicolab28

Hi @nicolab28 ! Is it works with the last version of the ray tracing renderer?

VinAr22 avatar May 26 '20 15:05 VinAr22

I don't think I'm using the very last one, but I don't see why it won't work?

nicolab28 avatar May 27 '20 08:05 nicolab28