dilevin / computer-graphics-ray-tracing

Computer Graphics Assignment about Ray Tracing
1 stars 5 forks source link

"km" mirror colour and "I" light intensities #43

Closed NPTP closed 4 years ago

NPTP commented 4 years ago

Hi, I don't really understand how we're meant to use the km and I values from materials and lights respectively. They are both 3-vectors but somehow have to scale other values. Using coefficient-wise products leads to bad results. At what stage should km come into the picture: when calculating blinn-phong shading, or elsewhere?

Just to provide an example: I had many strange visual effects, so I turned off the recursive calls for reflections, and am testing just the ambient + diffuse + specular lighting right now. However, my sphere-and-plane is still much brighter than the example image, even though there's "less lighting" being accounted for since I'm not reflecting anything yet: Mine: image Solution: image

I have a suspicion this has something to do with the light intensity "I" (and maybe km when reflections are turned back on) but I'm not sure how to apply it... Thanks!!

EDIT: For completeness, here are some more images. None of these use recursive calls either (getting a different issue there)

Ambient + diffuse: image

Ambient + specular: image

Just ambient: image

NPTP commented 4 years ago

After some tweaks, coefficient-wise product of I and the diffuse and specular coefficients seems to bring the brightness more in line with the solution. Is this correct usage? Still curious where km comes into play.

NPTP commented 4 years ago

Got this far now by also using km to coefficient-wise scale my recursive reflections. Looks like all my reflections, specular etc are in the right place, but still way too bright. Is this still related to I and km or something else might be going on? (keep in mind I am of course also scaling the ambient light by the given constant, and have checked to ensure normalization of all relevant vectors...although I might be missing something!)

Mine (too bright!): image

Solution (just right): image

Xadoy commented 4 years ago

I am encountering the same problem lol, and I have no idea what's happening.

kyokeunpark commented 4 years ago

km is a vector for "Mirror Colour" (from Material.h). I believe it will be used for reflection. From both slides and textbook, it seems like using ka, kd, and ks is enough for blinn phong shading.

Xadoy commented 4 years ago

@NPTP I found my bug. In my loop, I add the ambient so many times. I should only add it once.

NPTP commented 4 years ago

@NPTP I found my bug. In my loop, I add the ambient so many times. I should only add it once.

I thought this might be my problem too, but I only add the ambient once per call to blinn_phong_shading(). Then only Lambertian and specular get added within the loop. So I'm still a bit stumped!

darren-moore commented 4 years ago

coefficient-wise product of I and the diffuse and specular coefficients seems to bring the brightness more in line with the solution. Is this correct usage?

Yes, you should be using coefficient-wise product. It doesn't make sense to use e.g. a dot(scalar) product here.

NPTP commented 4 years ago

I thought this might be my problem too, but I only add the ambient once per call to blinn_phong_shading(). Then only Lambertian and specular get added within the loop. So I'm still a bit stumped!

I think I've tracked the issue down to my Lambertian. Using that alone (leaving ambient/specular at 0) still creates an image that's too bright. I've got, per each light that is visible/reachable from the surface, the kd (diffuse coefficient) doing coefficient-wise product with I (intensity), multiplied by max(0, n•l), where n is the normal at the surface and l is the direction from the ray to the light. I'm still checking to see if I missed normalizing any vectors anywhere (which might scale my output wrongly) and even caught one, but it didn't change the image... still too bright.