Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Colored Lighting #4

Closed
wants to merge 2 commits into from
Closed

Added Colored Lighting #4

wants to merge 2 commits into from

Conversation

csun
Copy link
Contributor

@csun csun commented Apr 27, 2014

The other half of issue #2

@jdan
Copy link
Owner

jdan commented Apr 27, 2014

Hm I'm a little skeptical, can you describe the math behind this? It doesn't look like the light is adding any color to the surface, only replacing it.

@rcmaniac25
Copy link
Contributor

I think it's fine. It's common for diffuse color to be calculated with

lightColor * surfaceColor * diffuse * attenuation

Where lightColor and surfaceColor are unit vectors and diffuse and attenuation are scalars.

He does lightColor * surfaceColor with lightWith, the diffuse * attenuation portion is taken care of with lighten.

I haven't tested anything, just going off of some graphics shaders I have.

Note: diffuse in the example is brightness in this code and I think you are using attenuation as colorDifference.

@jdan
Copy link
Owner

jdan commented Apr 27, 2014

Awesome, thanks for the explanation.

@jdan
Copy link
Owner

jdan commented Apr 27, 2014

Landed in d3b6336.

I went ahead and made it so Color.prototype.lighten takes an optional second parameter, lightColor, instead of having two closely-named methods.

I'm okay with merging this because the default behavior is still the same. Thanks!

@jdan jdan closed this Apr 27, 2014
@csun
Copy link
Contributor Author

csun commented Apr 27, 2014

Cool! I couldn't find an explanation online of how colored lighting works, so I based my solution on the thought that the visible color of an object is just the color of the light it reflects, and therefore a light that provides less of a certain color gives less to reflect.

@rcmaniac25
Copy link
Contributor

More formal explanation can be found in Lambertian reflectance and looking up flat shading.

There is also a whole lot of explanation from some graphics tutorials, like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants