Diffuse vs. Specular light color

Started by AeroShark333, November 01, 2021, 07:12:56 AM

Previous topic - Next topic

AeroShark333

Hello,

I was trying to create a glass/mirror-like object.
For this I needed to get rid of the World's ambient lighting and the Light's diffuse lighting.

I was able to get rid of the World's ambient lighting (which affected all objects in the scene unfortunately, but for those objects I used Object3D#setAdditionalColor again to mimic ambient lighting)
However, I wasn't able to change the diffuse nor specular color seperately..? Or I wouldn't know how to...
The Light class has a Light#setIntensity() method but I suppose that works on both diffuse and specular color.

According to the Wiki, the shaders do seem ready to support distinctive diffuse and specular lighting colors
(https://www.jpct.net/wiki/index.php/OpenGL_ES_2.0_support)
uniform vec3 diffuseColors[8]; - The diffuse color of each light source.
uniform vec3 specularColors[8]; - The specular color of each light source.

It seemed a little odd to me that these variables are seperately declared there but they seem to always be the same arrays basically..? (If I'm not mistaken and didn't overlook something)

I believe the following three (or four) things would help me a lot:
- Allow Object3D#setAdditionalColor(r,g,b) to have negative values for r, g and b so they can cancel out the World's ambient lighting (rather than having to do it in the opposite way...)
- Add Light#setSpecularIntensity(r,g,b) to control specular lighting intensity seperately
- Add Light#setDiffuseIntensity(r,g,b) to control diffuse lighting intensity seperately
(- Perhaps extra Object3D lighting modes (ambient only, additional only, diffuse only, specular only; and different combinations of these 4).)

Thank you for your time :)

Cheers,
AeroShark333

EgonOlsen

Are you using your own shaders or the default ones?

AeroShark333

Default ones but I guess I could write custom shaders too to work around this

EgonOlsen

Maybe that's the best approach after all. Just take a fitting default shader and modify it to do what you want. After all, you might want to do that anyway, because the specular implementation actually isn't that great IIRC and more of an afterthought. I didn't really expect it to be used by anybody, to be honest... ;)

The changes that you suggested would partly break compatibility with desktop jPCT as well.

AeroShark333

Okay, thank you! I'll probably do that then

Just out of curiosity, would the first suggestion also break things..?
Quote- Allow Object3D#setAdditionalColor(r,g,b) to have negative values for r, g and b so they can cancel out the World's ambient lighting (rather than having to do it in the opposite way...)

In the shader it seems that
vertexColor = ambientColor + additionalColor;
I don't think shaders would mind additionalColor to be negative valued

EgonOlsen

Quote from: AeroShark333 on November 06, 2021, 08:52:36 AM
I don't think shaders would mind additionalColor to be negative valued
That depends on the graphics chip. Some don't mind and just clip the values below 0 and larger than 1, some render everything dark and some so crazy. One could do the clipping in the shader and/or in the code (for the fixed function pipeline, which still exists) but that would decrease performance (albeit it shouldn't be that much of an issue). But it would break compatibility with desktop jPCT, because on that one, RGBColor extends AWTColor (I don't know the reason anymore, but I'm sure that there was one... ;) ) and that doesn't support it.

AeroShark333

Ah okay...
I wasn't sure if setAdditionalColor still relied on RGBColor afterwards, since there's an (int, int, int) method for it too

Thanks for explaining! :)