Specular light color (float vs float3)

Started by
21 comments, last by cozzie 10 years, 8 months ago

Hi,

I'm playing around with specular lights and now in doubt if I should multiply the specular term for directional and point lights, by the color of the light. If I understand correctly, then:

- for non-metals, specular highlights are 99% of the time 'white'

- for metals, the specular highlights are mostly the color the material itself

With this in mind my first thought would be to have 2 different shaders.

But I might have found a reasonable solution with relatively high performance benefits, where I need only single float for the specular component instead of float3's (what I would need when I multiply them all with the lightcolor).

Basically:

- calculate specular terms for directional lights and point lights (single floats, no specific color)

- in calculation the final pixel color I do:


return float4((saturate(AmbientColInt + (MatDiff * (diffuseDir + diffusePoint)) + (MatSpec * (specularDir + specularPoint)) + MatEmi) * textureColor.rgb), textureColor.a);

Where I basically use the specular material value that determines the color of the highlights.

Say for glass I set it to 1.0 / 1.0 / 1.0 and for metal, to the actual color of the metal.

The only down side here is that I don't let the specular highlights be dependent of the actual light colors (IF it's a down side..).

What do you think?

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Advertisement

IIRC, Crysis 2 used greyscale specular on PS3 to avoid some tech limitations (pretty sure this was solved for Crysis 3 though). They mention it in this paper (I think it's this one, I can't check since I don't have a ppt viewer on this machine and don't have time to install one, gotta go! :P). As long as you don't have wildly different colored lights and strong specs, it should look fine.

Specular highlights are always dependent on the color of the light. This doesn't change for metals vs. non-metals.

OK. But how would you put that into the equation then?

(if the final specular highlight always takes over the material specular color)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Hi Cozzie,

Read some articles on Physically Based Shading and you'll get a good idea of how all this works.

These two blog posts are a great starting point

http://seblagarde.wordpress.com/2011/08/17/hello-world/
http://seblagarde.wordpress.com/2011/08/17/feeding-a-physical-based-lighting-mode/

As well as

Crafting Physically Motivated Shading Models for Game Development (Naty Hoffman)

http://renderwonk.com/publications/s2010-shading-course/

There's a fair amount of information about this out there. It'll take a bit of reading but once you grind through it you'll understand a lot more about how it all fits together.

Greyscale specular was used mostly in light prepass renderers to cut down on bandwidth by storing only diffuse in rgb and specular in the alpha channel of the accumulation buffer.

Check out my project @ www.exitearth.com

- for non-metals, specular highlights are 99% of the time 'white'

- for metals, the specular highlights are mostly the color the material itself

I'd change these "rules" to

-for non-metals, the specular highlights are the color of the light

-for metals, the specular highlights are the color of the light multiplied by the color of the material

The truth is that even this corrected version isn't based on any hard theory; it's just that, in practice, specular highlights on non-metals (e.g. plastic, skin, wood) are generally actually caused by a layer of "clear" material on top of the material, be it oil, varnish, etc.

For instance, if you have a shiny ceramic object with gold leaf/trim, there'll be a difference depending on whether the gold is on top of the varnish; if the gold is on top, the gold parts will only have gold-tinted reflections, whereas if the varnish is on top, you'll see something like the sum of the gold-tinted reflections and the un-tinted reflections (which are also present on the ceramic part).

-~-The Cow of Darkness-~-

Specular highlights are always dependent on the color of the light. This doesn't change for metals vs. non-metals.

- for non-metals, specular highlights are 99% of the time 'white'

- for metals, the specular highlights are mostly the color the material itself

I'd change these "rules" to

-for non-metals, the specular highlights are the color of the light

-for metals, the specular highlights are the color of the light multiplied by the color of the material

The truth is that even this corrected version isn't based on any hard theory; it's just that, in practice, specular highlights on non-metals (e.g. plastic, skin, wood) are generally actually caused by a layer of "clear" material on top of the material, be it oil, varnish, etc.

For instance, if you have a shiny ceramic object with gold leaf/trim, there'll be a difference depending on whether the gold is on top of the varnish; if the gold is on top, the gold parts will only have gold-tinted reflections, whereas if the varnish is on top, you'll see something like the sum of the gold-tinted reflections and the un-tinted reflections (which are also present on the ceramic part).

I was going to say the same things but I reread the ops post and realized that we're all reading it wrong. OP isn't saying that materials have white specular highlights, they're saying that 99% of the time their lights are white causing white specular highlights. I think the original message was lost in formatting.

At least that's what I understood. If all of OPs lights will be white, then it's totally fine to go with a greyscale specular term (diffuse alpha type stuff) because there isn't any color to reflect anyway.

...

...

I was going to say the same things but I reread the ops post and realized that we're all reading it wrong. OP isn't saying that materials have white specular highlights, they're saying that 99% of the time their lights are white causing white specular highlights. I think the original message was lost in formatting.

At least that's what I understood. If all of OPs lights will be white, then it's totally fine to go with a greyscale specular term (diffuse alpha type stuff) because there isn't any color to reflect anyway.

Well, he also said "(...) in doubt if I should multiply the specular term for directional and point lights, by the color of the light." In any case I hope now he has enough information to figure out what he was looking for.

-~-The Cow of Darkness-~-

Thanks.

I think I've got it.

To be sure, I've now assumed that:

- specular highlights for non-metals take the color of the actual light

- specular highlights for metals take the color of the specular material color

The non-metal variant is now (for point lights):


specularPoint = pow(saturate(dot(h, normal)), input.SpecPower) * att;

// calculating final color
return float4((saturate(AmbientColInt + (MatDiff * (diffuseDir + diffusePoint)) + (PointLightColInt * specularPoint)) + MatEmi) * textureColor.rgb), textureColor.a);

And the metals variant:


specularPoint = pow(saturate(dot(h, normal)), input.SpecPower) * att;

// calculating final color
return float4((saturate(AmbientColInt + (MatDiff * (diffuseDir + diffusePoint)) + (MatSpec * specularPoint)) + MatEmi) * textureColor.rgb), textureColor.a);

Any suggestions/ remarks?

(please not that specular for directional light is not included yet, that's working it out later, first getting the basics right, before changing for multiple lights, point & directional)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

No that is still not right. It's really simple:

Metals: specular albedo is RGB

Non-metals: specular albedo is monochrome

The lighting is exactly the same in both cases: specular * lightInensity * specularAlbedo. You don't even need different shaders, for non-metals you just always have R, G, and B set to the same value in your material definition.

This topic is closed to new replies.

Advertisement