GLBasic forum

Codesnippets => 3D-snippets => Topic started by: Hemlos on 2012-Jul-01

Title: X_AMBIENT_LT observations and tips.
Post by: Hemlos on 2012-Jul-01
Hi gang,

I just made an interesting dicovery about the glbasic ambient light system.
Not only does it rotate inversely, it rotates double of the rotation of the cam.
In the screnshot below you can see the ambient light on the right side of the sphere.
That light is fixed to that vector no matter which way the camera turns.
Also you can observe my spotlights shining to the top of the object.
No matter which way the cam turns, the light is fixed to the camera view of the object.

Note: X_AMBIENT_LT may not function like this in the future, as it may change due to updates in V11.


EDIT: The solution for proper looking ambient light, can be emulated with GLBasic:
Code (glbasic) Select

IF Ambient
X_SPOT_LT 1, 0xffffff, cx,cy,cz,-cx,-cy,-cz, 360
ENDIF


This is proper looking, yet, it is not really ambient light...it is emulated.

This image below shows how glbasic is using the x_ambient currently without any code fixes.

[attachment deleted by admin]
Title: Re: X_AMBIENT_LT observations and tips.
Post by: kanonet on 2012-Jul-01
Which just proves me right: ambient light is totally broken. Per definition an ambient light should shine from all sides/angles with the same intensity. So if X_AMBIENT_LT shines just from one side, its working wrong, obviously.
Title: Re: X_AMBIENT_LT observations and tips.
Post by: Hemlos on 2012-Jul-01
if you face the object from positive Z, toward negative Z....one time....
Then turn off the light by not calling, it will make all objects with the light facing the camera.
Essentially giving you the effect you described.

Title: Re: X_AMBIENT_LT observations and tips.
Post by: erico on 2012-Jul-01
Maybe it is not a bug?
But a way to control the ambient light on which direction it should light globally? (or which direction it should not light)
It makes sense to me, only, if some sort of fast occlusion shader or raytrace per object is going on.

Since a per object occlusion will usually light it all around, maybe having a forced no light from down to up could actually make sense that the object is on an environment, like ground, as it will not be lighted too much under to the point it looks realistic in place.

Quite similar to a global image illumination, where the image has half up lit and half down not, degrade wise. 

That way, theoretically, you can keep things more realistic?

This is just a general idea, I never ever strived too deep into GLB 3d to actually know anything about. :P
I doubt I made any sense at all on what I wrote :(
Title: Re: X_AMBIENT_LT observations and tips.
Post by: Hemlos on 2012-Jul-01
A bug IMO too.

1. You cant turn it off.
2. And worse...if you change the color, the orientation of the ambient light will be different according to the camera vector.
Title: Re: X_AMBIENT_LT observations and tips.
Post by: kanonet on 2012-Jul-01
I dont know what GLB does internally, but i guess it just pins a spotlight with cutoff 180 at the camera, pointing at direction of camera vector. So this is obviously no ambient light, just a fake. If you use this to get the effect that you described, you just use a bug, that works now, but may get fixed in the future. Just use a X_SPOT_LIGHT with cutoff 180 and you get exactly the same.
Btw. A real opengl ambient light gets calculated faster than a (faked one with) spotlight, cuz it doesnt have a position, nor a direction and it ignores normals.
Title: Re: X_AMBIENT_LT observations and tips.
Post by: Hemlos on 2012-Jul-01
Yup youre right, this method is using a bug.
In the current state of x_ambient light, you cant turn it off.
So if you need to turn it off at some point, dont turn it on in the first place!


Title: Re: X_AMBIENT_LT observations and tips.
Post by: kanonet on 2012-Jul-01
Hmm i just tested a real ambient light from my light fixes and its the same, if you activate it once its stays activated - which shows me, that i always used ambient light wrong, you dont need to call it every loop, just call it one time.

Of cause you can deactivate both easily, just call them with the color RGB(0,0,0).
EDIT: RGB(0,0,0) will 'turn off' our ambient light - but before you set one, it is activated and set to a standard value that is something brighter than black, someone need to figure out what it is, so you can turn back to 'normal'.
Title: Re: X_AMBIENT_LT observations and tips.
Post by: Hemlos on 2012-Jul-01
Again, thats using some sort of bug.

Keep in mind, you will need to realign the camera, if you want to turn it back on.
Title: Re: X_AMBIENT_LT observations and tips.
Post by: kanonet on 2012-Jul-01
Which is just an other point why you should not use this bug, but just use a spot light with cutoff 180 - you get same effect, but can change it/turn it off any time without problems.

Btw plz. see my edit in last post.
Title: Re: X_AMBIENT_LT observations and tips.
Post by: Xaron on 2012-Oct-04
Quote from: kanonet on 2012-Jul-01
Which just proves me right: ambient light is totally broken. Per definition an ambient light should shine from all sides/angles with the same intensity. So if X_AMBIENT_LT shines just from one side, its working wrong, obviously.

Is that still the case?
Title: Re: X_AMBIENT_LT observations and tips.
Post by: Hemlos on 2012-Oct-04
I believe this command still functions the same way.
There was a very brief discussion about this, and it turned out to be an intentional thing.
However, the notion that it would be fixed to work proper in V11 was mentioned.
If this is already done or not in v11, i do not know, i dont have that version.


I use this function with my camera, to emulate ambient light, a mediocre fix at best:


Code (glbasic) Select
IF Ambient
X_SPOT_LT 1, 0xffffff, cx,cy,cz,-cx,-cy,-cz, 360
ENDIF
Title: Re: X_AMBIENT_LT observations and tips.
Post by: kanonet on 2012-Oct-04
As far as I know this did not get fixed till now, ambient light is still faked by using a spot light just like Hemlos did. I did send Gernot code how to make a proper light, but I did not get an answer, so I dont know if he will implement it or not.

If you want to try my fixes you can find them here: http://www.kanonet.de/downloads/lightsfixes
Title: Re: X_AMBIENT_LT observations and tips.
Post by: mentalthink on 2012-Oct-04
Hi Kano, thanks for this library... I have to try when I have free time...

I think this it´s very Usefull!!!

Regards,
Title: Re: X_AMBIENT_LT observations and tips.
Post by: sf-in-sf on 2013-May-09
Same for me here. I tried the donut with only a blue ambient light, and it's clear that the lighting is next to the camera. The shadows shouldn't exist and they are way too dark.
Who knows a good reference/tutorial for the direct openGL calls like
glNewList(2, GL_COMPILE)
glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(   0,    0)
glVertex3f( -50,  80, 0)
glCallList(2)  ..........................etc? Thank you!

(quoted from testOGL on this forum)
Title: Re: X_AMBIENT_LT observations and tips.
Post by: mentalthink on 2013-May-09
Yes you have a Gernnot tutorial here, it's very easy to do... You can find Kanonet and a liB mine... you can see how we done our libraries....

Sorry I can't found... but in the examples of GLBasic , you have a sample how do this... call opengl funcitions from GLBasic it's veery very easy, I don't know nothing about C++, and was easy for me make me a library...