knightcrawler25 / GLSL-PathTracer

A toy physically based GPU path tracer (C++/OpenGL/GLSL)
MIT License
1.85k stars 175 forks source link

Image save option does work but with artefacts #40

Closed Tetsujinfr closed 3 years ago

Tetsujinfr commented 3 years ago

Not sure why but when saving a render as an image, there are artefacts, while those do not appear on screen. I attach an example.

Just me having this issue? thanks

glsl_pathtracer_screen_vs_imageExport

knightcrawler25 commented 3 years ago

Seems to be working fine for me on Ubuntu 20.04.

img_502

Not sure why it is showing up like that for you. Maybe try changing the following line to write a .jpg instead and see if that works.

https://github.com/knightcrawler25/GLSL-PathTracer/blob/272915a7e016d87fb0d9675c93c98e7022a54ca8/src/Main.cpp#L124

to:

stbi_write_jpg(filename.c_str(), w, h, 3, data, w*3);

Tetsujinfr commented 3 years ago

no, still the same issue when saving as jpg.

The really weird part is that the render on screen is ok, it is only the saved image which shows those artefacts. They seem to appear oàn bright colors only. Maybe some pixel color conversion artefacts at some stage.

Will look at it and try to go back up to the root cause but do you have any idea? Is there some pixel format conversion somewhere in the code?

Le lun. 24 mai 2021 à 13:30, Asif @.***> a écrit :

Seems to be working fine for me on Ubuntu 20.04.

[image: img_502] https://user-images.githubusercontent.com/11459803/119346092-64233c80-bcb7-11eb-941e-733ee7333641.png

Not sure why it is showing up like that for you. Maybe try changing the following line to write a .jpg instead and see if that works.

https://github.com/knightcrawler25/GLSL-PathTracer/blob/272915a7e016d87fb0d9675c93c98e7022a54ca8/src/Main.cpp#L124

to:

stbi_write_jpg(filename.c_str(), w, h, 3, data, w*3);

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/knightcrawler25/GLSL-PathTracer/issues/40#issuecomment-847010139, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHES3XPRYCJST72NIHWXQHTTPJBGJANCNFSM45MJIO4Q .

knightcrawler25 commented 3 years ago

The output from the frame buffer is read at the following line and is then passed on to stbi_write_png and I'm not completely sure (since I'm unable to reproduce the issue), but maybe due to the hardware/drivers that you're running on, this read/conversion might be behaving weirdly. https://github.com/knightcrawler25/GLSL-PathTracer/blob/272915a7e016d87fb0d9675c93c98e7022a54ca8/src/core/TiledRenderer.cpp#L411

You might want to try clamping the output from the tone mapping shader since, as you mentioned, the artefacts seem to be only in the brightest spots, like the light sources or reflections of the light sources.

Tetsujinfr commented 3 years ago

ok so I managed to find a workaround. You were right, the issue was with glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, *data); in TiledRenderer.cpp , which for some reason messes around with the pixel format data type on my platform (Jetson Xavier NX). If I change the data type from GL_UNSIGNED_BYTE to GL_BYTE, then the artefacts goes away but the overall scene brightness is kind of halved. I have tried many combinations but nothing worked, I am not good enough in Ogl to figure it out.

However, when capturing directly the framebuffer pixels with glReadPixels() then the colors are ok, so did some dirty hacks to insert the saveFrame function at the render stage, in between the scene render and the ImGui render.

I have also swapped STB with OpenCV initially, but I do not think that makes any difference.

closing this issue.

Btw, your project is awsome! Trying to tweak it to generate higher res images (gonna play with the fov/orientation of the camera and generate tiles and collate them together, unless you have a better idea).