Trunk Shader question - gl_LightSource[1].ambient
Moderators: winston, another_commander, Getafix
- Griff
- Oolite 2 Art Director
- Posts: 2483
- Joined: Fri Jul 14, 2006 12:29 pm
- Location: Probably hugging his Air Fryer
Trunk Shader question - gl_LightSource[1].ambient
in trunk, does gl_LightSource[1] have an ambient colour? i've been trying to use it in a shader and it doesn't seem to add any extra lighting into the final colour, gl_LightSource[0].ambient does, it adds a sort of grey/white light, which is perfectly useable in a shader, but i was wondering if we could have a coloured ambient light to go with our coloured suns.
-
- Quite Grand Sub-Admiral
- Posts: 6683
- Joined: Wed Feb 28, 2007 7:54 am
Yes, ambient light and sun colour are kept in sync throughout the game.
I'm not 100% sure if gl_LightSource[1] is the one used, but you can assign that to highlight all ship surfaces, then change the sun colour* and see if the highlight colour in the shade changes to match the new sun colour.
*Yep, you can change sun & ambient light colour in real time now typing
system.info.sun_color=whatever
inside the debug console!
I'm not 100% sure if gl_LightSource[1] is the one used, but you can assign that to highlight all ship surfaces, then change the sun colour* and see if the highlight colour in the shade changes to match the new sun colour.
*Yep, you can change sun & ambient light colour in real time now typing
system.info.sun_color=whatever
inside the debug console!
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
- Griff
- Oolite 2 Art Director
- Posts: 2483
- Joined: Fri Jul 14, 2006 12:29 pm
- Location: Probably hugging his Air Fryer
I tried a test at Lave by fiddling with a fragment shader, the cobraIII on the left has the ambient from light 0 added to it
and the CobraIII on the right uses lightsource 1's ambient instead
It's not a big deal, i've just been noticing that some of the suns in trunk have really lovely colours to them these days and was playing about trying to get the lighting in the shaders to match
Code: Select all
diffuse += gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
Code: Select all
diffuse += gl_FrontMaterial.ambient * gl_LightSource[1].ambient;
It's not a big deal, i've just been noticing that some of the suns in trunk have really lovely colours to them these days and was playing about trying to get the lighting in the shaders to match
I've just found out the relevant bit of code:
The ambient light is set to pitch black, even though from the comment you'd expect it to be 5% of the sun's colour! Give me a little while, and I'll see what I can do!
Edit: I've 'bumped up' the ambient light to a 'massive' 10%, but in practice there doesn't seem to be much difference. I'll commit that to trunk soon, but you're probably better off using the diffuse colour instead!
Code: Select all
GLfloat sun_ambient[] = { 0.0, 0.0, 0.0, 1.0}; // ambient light about 5%
sun_diffuse[0] = 0.5 * (1.0 + r); // paler
sun_diffuse[1] = 0.5 * (1.0 + g); // paler
sun_diffuse[2] = 0.5 * (1.0 + b); // paler
sun_diffuse[3] = 1.0;
sun_specular[0] = r;
sun_specular[1] = g;
sun_specular[2] = b;
sun_specular[3] = 1.0;
glLightfv(GL_LIGHT1, GL_AMBIENT, sun_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, sun_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, sun_specular);
Edit: I've 'bumped up' the ambient light to a 'massive' 10%, but in practice there doesn't seem to be much difference. I'll commit that to trunk soon, but you're probably better off using the diffuse colour instead!
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
The real ambient light is in gl_LightModel.ambient, as seen in oolite-default-shader.fragment (this is stars_ambient and GL_LIGHT_MODEL_AMBIENT in Universe.m). The per-light ambient properties are supposed to be zero.
E-mail: [email protected]
- Griff
- Oolite 2 Art Director
- Posts: 2483
- Joined: Fri Jul 14, 2006 12:29 pm
- Location: Probably hugging his Air Fryer
Oops, sorry about that reporting bugs when the fault was in my shader, i hope you didn't go to too much trouble kaks.
so, a quick change of that line in the shader to
and it's working great!
as an aside, debug.oxp works great on windows7 RC 64-bit
so, a quick change of that line in the shader to
Code: Select all
diffuse += gl_FrontMaterial.ambient * gl_LightModel.ambient;
as an aside, debug.oxp works great on windows7 RC 64-bit
No problem! And thanks Ahruman for clarifying which ambient light is which!
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)