Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Still having trouble with light

Author
Message
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 9th May 2010 12:40
Hi everyone,

I've been reading some threads about creating light and I still can't get my head around it.

First of all, what I'm after... I just want a floating ball of light (like a light bulb or a lantern) going through a garden filled with various objects under the moonlight. So those not within the light will only be visible like 25% let's say and those within the light will be illuminated. (Ignore the light from the moon for now).

I tried to make a simple light:



Looking closely, I can see that there is definitely light that is affecting the two objects (the light is inside the left ball). But the ground isn't being affected.

When it comes to simple lighting, I thought it's just making the light, and telling the objects that they are affected by the light.

But reading threads people are talking about shaders, effects, lightmapping etc. which I have no idea what they are. For now, I just want simple lights =/
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 9th May 2010 14:15
Quote: "But reading threads people are talking about shaders, effects, lightmapping etc. which I have no idea what they are"


Maybe you have expect that the programming of lights was like in real world.When all members of the forum have try to show you the methods that you should use to achieve what you need,....perhaps we thought that you will have enough knowledge to understand it.

It was you the one that says :
Quote: "I have no idea what they are"


So ...the best thing you can do, is try to learn and read carefully what we try to explain to you.

Start with little questions

cheers.

I'm not a grumpy grandpa
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th May 2010 14:40
Quote: "But the ground isn't being affected."


It is - but you can't see it for two reasons:

1. the default light (light 0) is still present so the ground is already almost fully lit by light 0 so adding a second light makes very little difference

2. DBPro uses vertex lighting which doesn't work well for low poly objects like your ground plain object.

What's gone wrong in point 2 is that DBPro calculates the lighting at the corners of the ground plain object and then uses linear interpolation (a kind of averaging) to get the values of the lighting at points in between. Since the corners are beyond the range of light 1 all four corners receive no light from light 1 which in turn means that all points on the plain receive no light from light 1.

The following code illustrates both points by hiding light 0 and placing the light above one corner:



There are two ways to fix the problem:

A. use a high poly plain instead (you can use IanM's free Matrix1 plugins to do this);

B. use a shader.

I suggest you use method A till you have more experience getting things working in DBPro.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 9th May 2010 15:22 Edited at: 9th May 2010 15:46
@chafari

Yeah, I read most of the threads regarding light.

One mentioned using an effect, like a code someone written and using "LOAD EFFECT" to get it.

Shaders and light mapping I still don't understand. Like I can't grasp the concept of it still. But if you think I should keep reading, then read I shall!

@Green Gandalf

Ah I see..... so the fact that the ground was too simple made it hard to see the light in action?

So is this, along with DBPro using vertex lighting, also the reason why if I placed the light in the middle, there is no circular light spot on the ground? Like as though someone just pointed a flashlight onto the ground.

EDIT: WAIT! When you mean vertex lighting, you mean like, DBPro only lights the vertexes of the 3D object right?

Because that square plane has only 4 vertexes, the light is only clearly seen when it's on or near the vertexes right? So if that plane had various segments, (let's say it has 20 vertexes in total) and I placed the light in the middle, there would be light visible in the center of the plain right?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th May 2010 16:18
Quote: "Because that square plane has only 4 vertexes, the light is only clearly seen when it's on or near the vertexes right? So if that plane had various segments, (let's say it has 20 vertexes in total) and I placed the light in the middle, there would be light visible in the center of the plain right? "


Yes.

Quote: "When you mean vertex lighting, you mean like, DBPro only lights the vertexes of the 3D object right?"


Almost. It uses the vertices to calculate the light - but uses those values to "fill-in" the values for the rest of the poly.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 10th May 2010 01:26
@DB_Newbie
We are trying to help you somehow.

In this example, I show you what Green Gandalf means.
Execute the code, and look how you torch illuminates the ground and objects.

Then change the line 11, where we create the matrix:

make matrix 1,100,100,30,30 you have to change for this one:
make matrix 1,100,100,130,130
Have a look again and you will see the circular light on the ground.

You will notice that the box don“t looks well light,as it has just 6 faces and 12 vertex.The sphere has much more faces and vertex, and looks ok.I hope this piece of code can help to you.



I'm not a grumpy grandpa
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 10th May 2010 09:19
Wow! That is 95% exactly what I'm looking for!

I get the lighting now (at least simple DBPro lighting).

Thanks very much you two! lol it seems so obvious now >_>

Since I'm limited in time frame for what I'm doing, that lighting is good for now, it's not bad anyway. If I have time, I'll try to apply better lighting using light mapping and shaders (if I can understand and learn them in time hahaha)

Now I need to learn about putting in an animated character and sprite sheets (*shivers*) (I'm trying to fake water moving for a waterfall or river by looping a sprite sheet with alpha channels XD).

Thanks again guys =D x 1000
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 10th May 2010 18:02
Why are you creating camera 1? Camera 0 exists by default, just use that one.

Also, try and use object with as small a number as you can. Large object numbers cause DBP to reserve the numbers below it wasting memory.

My signature is NOT a moderator plaything! Stop changing it!

Login to post a reply

Server time is: 2026-07-26 04:28:06
Your offset time is: 2026-07-26 04:28:06