Trunk Shader question - gl_LightSource[1].ambient

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2479
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Trunk Shader question - gl_LightSource[1].ambient

Post by Griff »

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.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6633
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

I think that the color of the sun becomes also the color of the ambient light. Will have to recheck though. Just look at the main planet of the same system with different sun colors, you should be able to note the ambient color difference.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

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!
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2479
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Post by Griff »

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

Code: Select all

diffuse += gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
and the CobraIII on the right uses lightsource 1's ambient instead

Code: Select all

diffuse += gl_FrontMaterial.ambient * gl_LightSource[1].ambient;
Image
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
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

I've just found out the relevant bit of code:

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);
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!
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

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.
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2479
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Post by Griff »

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

Code: Select all

diffuse += gl_FrontMaterial.ambient * gl_LightModel.ambient;
and it's working great!
as an aside, debug.oxp works great on windows7 RC 64-bit
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

No problem! And thanks Ahruman for clarifying which ambient light is which!
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
Post Reply