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 / Stop light passing through terrain or walls

Author
Message
Lost Coder
16
Years of Service
User Offline
Joined: 6th Aug 2009
Location: Lost in Space.
Posted: 5th May 2010 05:47
I posted the question erlyer with a shadows question as well.

The light problem still exsist.

How do you stop a light (light 0, spot mode) from passing through terrain or walls.

Example:When the sun ( light 0 ) drops below the terrain surface
the light emmitted from the light passes through the surface and lights the bottom of the ball. I can't seem to find a solution to stop the light from passing through.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th May 2010 13:53
A shader. It's the only way.

Standard DX lighting does not account for collision, it only checks the lights vector (direction in XYZ) against the polygon normals to decide the colour of each vertex.

So, you should probably go and find some shaders to try.

But there is one little option that I've used in the past. If you take your objects and enable them all for collision, maybe with Sparky's collision plugin - you need to be able to check collision between 2 3D locations. Get each objects vertex location, and check for collision between the light source, and the vertex location plus it's normal. Then if there is a collision on this line, the vertex is not affected by that light, otherwise affect the vertex colour with the light colour. You could do this with multiple light sources of course and average them, affect the light strength based on distance. You'd ideally use your own lighting system, there's no need to limit it to 8 lights.

With that, you'd pretty much mimic DX lighting, it would look just as smooth, except the light won't pass through solid objects, things would even cast shadows if the surface is detailed enough.

It probably would not be workable to do this in realtime, but it wouldn't be a slouch either, you could load all your level, calculate the vertex lights, then disable lighting - this is much better for performance than using several DX lights, because the object doesn't need to calculate light at all once it's been vertex lit. If you need moving light sources then you need to use real lights, but it depends on what you need, and how complex you want to go with it. Your level could have 1000 light sources all effective at once, and would run faster than any number of DX lights, even just 1 DX light affecting your object would be slower than this method. DX lights could be used for effects and moving light sources, as they still affect things as long as you keep object lighting enabled.

It's similar to a standard lightmap - in fact this is how lightmaps started out back in the Quake era, but faster, fast enough to do it pre-game, and much better for performance again, because there's no need for extra texture passes.


Health, Ammo, and bacon and eggs!
The Viking
17
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 5th May 2010 16:22
Well, as mentioned, a shader is the best... although, I have done it before where you can set the light color when its position is below a certain value, maybe black. Or reposition the light to be in the place of the moon, and color that light to a more silver/blue color.

www.myspace.com/norseblod
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 6th May 2010 22:52
You can get a limited "shadow" effect by making a short range light and making the colors negative. If, for instance, you have a cave mouth that is a transition from one map to another, you can do that in the cave mouth and it will seem like there is a shadow. I have done that technique in C++/DX, but not in DBP.... This is a very limited effect though.

The fastest code is the code never written.
Serge Adjo
19
Years of Service
User Offline
Joined: 3rd Aug 2006
Location:
Posted: 7th May 2010 00:13
In my opinion there are 3 way to achieve this (stop the light):

-Use the command 'SET SHADOW SHADING ON'

-use a 'spot' light and color it in black: 'COLOR LIGHT Light Number, 0, 0, 0' then you point the spot light to the place where it should be a shadow.

-use a shader that produce shadows



Login to post a reply

Server time is: 2026-07-27 20:18:13
Your offset time is: 2026-07-27 20:18:13