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 / A couple of problems with lighting.

Author
Message
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 13th Feb 2011 21:53 Edited at: 13th Feb 2011 21:58
Lighting has always been one of those things that seems to be tricky to get working just right without a shader.

I have these things in the scene:

- A Blitzwerks Terrain
- 4 TreeParty Trees
- Grasses from PlantLife
- 2 houses from the Christmas Bonus Model Pack

The terrain seems to be accepting light from the proper direction and shadowing itself appropriately. Can't get it to darken when the night cycle of the game comes around.

The tree coloring is messed up. The trunk looks ok, but the leaves are to bright. (they are supposed to be dark green..) They don't react to changes in light at all.

The grass and houses don't react to light in the slightest, unless I crank up the ambient light very high.

I've tried a lot of things to get things lit consistently, but nothing seems to be creating the results I want.

Currently,

- Normalization is on
- Set object light is set to 1 for everything
- Light 0 is hidden
- Light 1 is positioned where the sunlight should come from
- Light 1 and the ambient light level are reduced as the night cycle approaches


Daytime


Shortly after sunset


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Feb 2011 01:25
Quote: "- 2 houses from the Christmas Bonus Model Pack"


Which models are giving problems? I have the pack and could take a look tomorrow. I know some of the models are missing their normals - or the normals have been set to zero. Shouldn't take long to sort out.

I also have PlantLife but haven't used it much yet. Perhaps they don't have normals either? I'll look at those as well.

Can't help you with the terrain though.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 14th Feb 2011 02:11 Edited at: 14th Feb 2011 05:11
I've made some headway with the terrain. It is acting like the entire terrain is rotated 90 degrees off from where it should be, so the light that's actually in front of you, casts shadows on the terrain towards the right. I'll ask Kaedroho about that one.

The houses are from the Arteria Village Pack One. You're probably right. The houses act like there's no normals.

The grass probably has the same issue.

The trees have me bewildered. They don't react to changes in light at all. I even introduced movement of the light into one of the demos from TreeParty and there's no difference. (except these are still much lighter than they are in the demo..)

I've managed to modify one of our old shader projects to give proper lighting to the terrain. I'll keep working on that one to get it close to what it should be. Progress is progress.

revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 14th Feb 2011 02:38
Hi KISTech, It is true that some plantlife/treelife meshes have no normals. Try this little program I picked up somewhere, it is supposed to fix the meshes but I have had mixed results. If you have "Ultimate Unwrap3D", I have also used it to successfully correct normals issues.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 14th Feb 2011 05:40 Edited at: 14th Feb 2011 06:09
I loaded a different model from the same pack, but not an Arteria model, in place of one of the houses and it's at least accepting light. So it looks like the Arteria models Normals are messed up.

I have several programs that can normally load .X models, but none of them can read the Arteria models to fix the normals.

The little normcalc program you attached crashes whenever I run it.

[EDIT]
While SET NORMALIZATION ON didn't do anything, using SET OBJECT NORMALS Objid actually worked for the houses and the grass objects.

I'm digging into shaders just to make it (cough) "easier" on myself...

@GG,
I've got lighting working on the terrain using just simple light direction and a normal map. What I don't know how to do in a shader is get the hills of the terrain to act as light blockers for the valley below. I have several of Evolved's shadowing shaders that use second cameras and projection. Is that what's going to be needed?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Feb 2011 12:14
Quote: "using SET OBJECT NORMALS Objid actually worked for the houses and the grass objects"


Good. Sounds like they had normals but they hadn't been calculated. I definitely recall that happening with some models and I used the same fix.

Quote: "What I don't know how to do in a shader is get the hills of the terrain to act as light blockers for the valley below."


One solution is to use a conventional shadow shader. Have you tried the shader option of the built-in DBPro set shadow shading on command? I haven't tried it with terrain though.

One thing I've done in the past is to use a pre-baked "horizon map". I think I included a demo on

Shaders for Advanced Terrain

It would be the self-shadowing demo.

If that's anything like what you need I'll resurrect it and see if I can dig out the code I used to create the horizon map. I'll also look into how it compares with conventional shadowing techniques.

Evolved's shadows use shadow maps which is another option. Again I don't know about the relative performance.

The advantages of stencil shadows and shadow mapping is that all objects in the scene can, in theory, cast and receive shadows. My self-shadowing terrain demo only works for the terrain. It might be possible to use a combined approach which works efficiently. Food for thought.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 14th Feb 2011 17:49
Ok. That gives some directions to head in.

I'm using DarkCLOUDS to emulate a full day/night cycle so the shadows everywhere need to be dynamic.

I had created a demo once with DarkLights where there was a day/night cycle and the lightmaps were recreated in a thread every minute or two. This worked reasonably well, but DarkLights doesn't like BlitzTerrain. Perhaps the new object commands will help with that, but in the long run I think I'll still be better off with a lean mean shader.

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 15th Feb 2011 02:59 Edited at: 15th Feb 2011 03:00
I've spent the day messing with shaders, changing lighting, messing with object settings. (pulling whats left of my hair out..)

I've come to the conclusion that there is something that has created a light of some kind and positioned it at 0,0,0. It's a light I cannot seem to shut off or delete, and it has a lighting effect on EVERYTHING except for the terrain now because I'm lighting that with a shader.

Any ideas where this light might be coming from?

I disabled DarkClouds for a while - that wasn't it.
I disabled TreeParty for a while - that wasn't it.
I removed all shaders for a while - that wasn't it.

I've even put this in just before you enter the level.

But that doesn't do it either.

Mang Master
18
Years of Service
User Offline
Joined: 22nd Mar 2008
Location:
Posted: 15th Feb 2011 06:19
Try deleting light 0 .
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Feb 2011 12:07
I don't think you can. Hide light 0 perhaps? Or take control of light 0 and use it.

But that's so obvious I'm sure KISTech must have tried doing that already. Ah! He has. See his first post.

Perhaps one of the Plug-ins is overriding the light 0 setting?

If the terrain isn't affected by the problem I'd suggest deleting everything, starting with the terrain, from the demo till the problem disappears. That might help narrow down the cause.

Are only some objects affected? Are standard DBPro objects affected if artificially introduced into the scene near the origin?

How many lights does your hardware support? I vaguely recall a post (from Chafari?) which demonstrated that some cards support more than 8 lights - 8 might be just the minimum required by DirectX.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 15th Feb 2011 17:46
Yup. Light 0 is the one I'm controlling.

There's really only 2 possible sources then for this mysterious light. DarkCLOUDS, and TreeParty. I've tried running without both of those and it still does it.

I haven't tried replacing the terrain with just a flat plane yet. I'll try that today, and introduce a DBP primitive as well and see how that goes.

Quote: "I vaguely recall a post (from Chafari?) which demonstrated that some cards support more than 8 lights"


Wouldn't it be spectacular if they all did. I'll try deleting more lights and see what happens.

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 15th Feb 2011 19:13
Ok. Probably should have seen this one LONG before now..

If you don't specifically tell DBPro that light 0 is a POINT LIGHT then it seems to sit at 0,0,0 and act as a sort of directional ambient light. Other light numbers don't do this, and start out as a point light as soon as you make it, but not light 0.

Here's a demo showing how I found this out.
It starts out just using light 0 with no modification. You can see as the "Sun" comes up the lighting doesn't change.
Then uncomment line 35 and run it again.



Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Feb 2011 19:38
Light 0 is a directional light by default - it's position should have no effect till you turn it into a positional light.

I'm not sure I understand the point of your snippet. Your snippet (with the commented line reinstated) turns the default light 0 from a directional into a positional light. Then light 0 moves as it's supposed to. It is not an immovable positional light at (0,0,0).

Also, in your original post you said you'd tried hiding light 0. If I add that code to your snippet then light 0 is indeed hidden. What's the problem?
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 15th Feb 2011 20:20
Quote: "I'm not sure I understand the point of your snippet. Your snippet (with the commented line reinstated) turns the default light 0 from a directional into a positional light. Then light 0 moves as it's supposed to. It is not an immovable positional light at (0,0,0).
"


That is the point. Any other light that you make starts out as a point light that you can move around, but not light 0. You may have known that already, but I didn't, and I don't think it's in the documentation.

Quote: "Also, in your original post you said you'd tried hiding light 0. If I add that code to your snippet then light 0 is indeed hidden."


I think I was focused on the terrain to much at the time, since that was where I noticed the problem the most. Turns out there's an issue with BlitzTerrain where the light source shades the terrain 90 degrees off. I just posted a code snippet in the BlitzTerrain thread to demonstrate.

Since 90 degrees off was close to 0,0,0, I thought at the time that it was all the same problem. Turns out it was 2 separate issues with incorrect lighting coming from close to the same position.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Feb 2011 21:10
Quote: "You may have known that already, but I didn't, and I don't think it's in the documentation."


I can't find it in the documentation either.

I thought it was mentioned but obviously not. It's one of those essential little known facts that's not documented. In fact the Help file for set directional light rather confusingly talks about directional lights having an origin at (0,0,0):

Quote: "SET DIRECTIONAL LIGHT
This command will set an existing light to that of a directional light.

Syntax

SET DIRECTIONAL LIGHT Light Number, NX, NY, NZ

Parameters

Light Number

Integer
The light number
NX

Float
The x direction is specified using directional values assuming that the origin of the light is 0,0,0
NY

Float
The y direction is specified using directional values assuming that the origin of the light is 0,0,0
NZ

Float
The z direction is specified using directional values assuming that the origin of the light is 0,0,0"


Anyway, sounds like your problem is solved.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 15th Feb 2011 21:49
Yup, and Kaedroho just confirmed the terrain normals bug, so all is right with the virtual world again.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Feb 2011 22:13
Quote: "so all is right with the virtual world again"

Login to post a reply

Server time is: 2026-07-16 04:36:26
Your offset time is: 2026-07-16 04:36:26