Author Topic: Diffuse vs. Specular light color  (Read 2153 times)

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Diffuse vs. Specular light color
« on: November 01, 2021, 07:12:56 am »
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)
Code: [Select]
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
« Last Edit: November 01, 2021, 07:16:17 am by AeroShark333 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Diffuse vs. Specular light color
« Reply #1 on: November 02, 2021, 07:33:32 am »
Are you using your own shaders or the default ones?

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: Diffuse vs. Specular light color
« Reply #2 on: November 02, 2021, 03:01:59 pm »
Default ones but I guess I could write custom shaders too to work around this

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Diffuse vs. Specular light color
« Reply #3 on: November 03, 2021, 03:38:31 pm »
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.

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: Diffuse vs. Specular light color
« Reply #4 on: November 06, 2021, 08:52:36 am »
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
Code: [Select]
vertexColor = ambientColor + additionalColor;I don't think shaders would mind additionalColor to be negative valued

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Diffuse vs. Specular light color
« Reply #5 on: November 06, 2021, 06:41:33 pm »
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.

Offline AeroShark333

  • float
  • ****
  • Posts: 319
    • View Profile
Re: Diffuse vs. Specular light color
« Reply #6 on: November 07, 2021, 01:28:56 am »
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! :)