raytracing.github.io icon indicating copy to clipboard operation
raytracing.github.io copied to clipboard

Lighting bug

Open adihodos opened this issue 7 years ago • 7 comments

Hi! I ported this to Rust (https://github.com/adihodos/raytracer.git), all went pretty smooth (I even added multithreadead support) until I added lighting support. Raytracing the Cornell box results in this ugliness : raytraced. Can you give me some hints as to why this is happening ?

adihodos avatar Mar 22 '19 13:03 adihodos

That looks like possibly an overfliw from [O,1] when the reals are converted to int pixel values for output?

On Fri, Mar 22, 2019 at 7:02 AM Windows [email protected] wrote:

Hi! I ported this to Rust, all went pretty smooth (I even added multithreadead support) until I added lighting support. Raytracing the Cornell box results in this ugliness : [image: raytraced] https://user-images.githubusercontent.com/155867/54824392-75292b00-4cb3-11e9-8a4f-0e3fbcf8c5a4.png . Can you give me some hints as to why this is happening ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/petershirley/raytracingthenextweek/issues/8, or mute the thread https://github.com/notifications/unsubscribe-auth/ACq6iiLCDUdgClG8132_zyni6AhC0v6Nks5vZNRzgaJpZM4cDhdO .

petershirley avatar Mar 22 '19 13:03 petershirley

I understand. I printed out the pixel values and some are greater than 1. How can this be fixed ?

adihodos avatar Mar 22 '19 14:03 adihodos

@adihodos I got same same thing but when I convert from PPM to PNG use this site https://www.freefileconvert.com/ppm-png it works and those over-saturated image disappear and look as it should Issue is what @petershirley said is but instead you can just use some Image crate

BlackGoku36 avatar Apr 12 '19 15:04 BlackGoku36

This looks similar to an issue I had, which I fixed by normalising the color when I converted to RGB.

Compute the max of r,g,b in the color vector, and scale so it doesn't wrap over 8 bits:

col = vec3( sqrt(col[0]), sqrt(col[1]), sqrt(col[2]) );
float max = ffmax(col[0], ffmax(col[1], col[2]))
int ir = int(255.99*col[0]/max); 
int ig = int(255.99*col[1]/max);
int ib = int(255.99*col[2]/max); 

(there might be a typo here, I didn't copy/paste my code which is in go not C++)

mrc avatar Apr 13 '19 19:04 mrc

You can use this to add a color cap:

inline int colCap(int x) {
	return x > 255 ? 255 : x;
}

birdmanmandbir avatar May 16 '19 18:05 birdmanmandbir

Looks like a duplicate of RayTracing/raytracing.github.io#93 , or the same issue elsewhere.

hollasch avatar Jun 29 '19 08:06 hollasch

Duplicate of #93

hollasch avatar Aug 30 '19 23:08 hollasch