Light decals...need help... +Halo's explanation

Blitz3D Forums/Blitz3D Programming/Light decals...need help... +Halo's explanation

Kalisme(Posted 2004) [#1]
Ok.... I still don't 100% understand light decals...
I still can't get them working... or subtract from
the shadows... I Emailed Halo...
This is the advice he gave:
;-----------------------------------------------------------
-First, you need to store a list of flat faces in the map. This will only work on BSP-type Geometry, so maplet should be fine, as lone as each face is stored as a separate object. I store one merged copy of the map for rendering, and separate faces which I hide and use for collision. You need to calculate a plane equation for each face and store that, too.

-Second, you take your 3D light position and check the distance between that and each face/plane using the point-plane distance equation. If the distance is negative, the point is behind the face, so it won't be lit. If the distance is greater than the light range, the face won't be lit. If the distance is positive, but less than the light range, the face will be lit.

-Align a pivot to the plane equation using AlignToVector(nx#,ny#,nz#,3) and then MoveEntity 0,0,d#. Transform the light position to the pivot space and UV map the plane vertices according to this position.

-To avoid z-fighting, change the Blitz surface surfacedata pointer to a temporary bank. Add the above face surface to the internal Blitz surface list, and render. Then restore the original surface list.

Post this reply on the forums and ask for help. The last step especially is highly advanced, but this is all I will explain.

-Josh
;---------------------------------------------------------

I sorta understand... but not 100%... infact I'm a bit
confused... (+ I have to catch up on some home work... so it's hard to figure out lighting code and then debug it... then rewrite... ect... ect)
So if NEone could figure it out and post a little demo
or something... U'd be being very very helpful ;)


Drey(Posted 2004) [#2]
what do u mean by Light Decals exactly, are u talkin about corina(brightness around the light that gets cut out when the light is being blocked by something on the screen) or taking about tryin to have a dynamic software ran light on your map and have objects be affected by it?


Kalisme(Posted 2004) [#3]
I mean a basic dynamic real time lighting
effect... like that in Unreal or Quake...
A decal appears on the map (circle of light)
Then that decal subtracts away from the shadows
created by the light map.... Just for Mapping...
Not for charecters... I understand that would be slow as all hell...
So I'd just use vertex lighting for them... Never mind that though...
The decal would be used for gun flashes and other
lighting... Does NE one know how to acheive this?
I'm sure BLITZ3d can acheive this somehow.....
I'm getting stressed trying to find out though....
Please help...


sswift(Posted 2004) [#4]
If your levels have any kind of detail you're not really going to be able to do dynamic quake style lights in Blitz. If I thought it was possible, I'd have written a system to do it a long time ago... I considered the problem thoughroughly, and the fact is that it would end up being slower than my shadow system. The problem is building the mesh. If you have a room lit by a dynamic light with any reasonable size radius, every polygon in that room and some from adjacent rooms is going to have to be added to a mesh and uploaded to the video card.

Now, if your levels are very simple, then you might be able to get away with it. I think you could get away with updating maybe an 8000 poly mesh every frame at the max.

But before you say that is enough, consider that each light you have going at the same time will double the number of polygons that you need to add to a mesh for a specific room.

Plus, in order to calculate the polygons that are lit and get any kind of speed you're gonna need to create some kind of culling system to quikly discard those polygons which you do not need for the light. If you have lots of pipes and stuff in your maps that can be lit by these dynamic lights those chew up polygons and with one light you might be looking at 10,000 - 30,000 polygons a frame for an ordinary level.

Also Halo's remark about remvoign backfacing polygons is wrong... in an aethetic sense. The original Quake did not do this because regardless of culling backfacing polygons, light will still leak under walls, and it looked worse to have light leaking under walls than for areas on the opposite sides of walls to appear illuminated normally. Light leaking under walls without the walls themsevles being lit has the effect of making the level seem less solid.

Also that bit about the z fighting... I don't really understand what Halo is doing there. Which is not to say it won't work. But it sounds like he's telling you to use one of his funky DLL's to modify intnernal Blitz structures which you don't have access to normally. I consider this a no no because it can break in future versions of Blitz if Mark changes how Blitz works.

Of course if Halo has implemented realtime Quake-stle dynamic lightmaps in a modern engine without resorting to greatly simplified level structures, I'd like to see it. The only possible way one might be able to do this is if the level itself were really simple shapes and all the details were seperate meshes added to each room which were affected by the standard Blitz lights but not by these special dynamic lights for the levels. Then you're getting really crazy.

It seems to me that the best thing to do is instead of trying to make fake lights, use the real ones... Subdivide your level up by finding thr length of each edge. If that edge is 9 meters long, and the maximum acceptable length is 1 meter, add nine new vertices along it and split the appropriate connecitng polygons. Then restart your search for edges which are too long.

Well that migth not produce very pretty meshes... might create lots of long thin polyogns... In that case it might be better to split edges based on a grid of fixed size, but ignore edges which might cross a grid line but are otherwise too short to split... But that too might not work very well...

One might also consider splitting based on the area of a particular triangle, but that won't split long thin triangles I suppose.

Anyways, there's a few ideas for a method to use other than dynamic lightmaps to get better looking lighting.


Rogue Vector(Posted 2004) [#5]
Try this:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1000

It might help you.

Regards,

Rogue Vector


JoshK(Posted 2004) [#6]
If your levels have any kind of detail you're not really going to be able to do dynamic quake style lights in Blitz. The problem is building the mesh. If you have a room lit by a dynamic light with any reasonable size radius, every polygon in that room and some from adjacent rooms is going to have to be added to a mesh and uploaded to the video card...blah blah blah blah blah

I told him to store a copy of each face in the map. Then you modify the map mesh by poking an extra surface into the internal Blitz surface list. Surfaces don't get z-ordered, so you get a nice blend of the light. You only are adding the faces that get affected by the light, so you only add a small number of polygons.

The brush structure of maps doesn't have to be very complicated, you just carve out the shape of the room, and then add staticmeshes.


Kalisme(Posted 2004) [#7]
thankx to ppl who have gave advice...
Oh... Rouge Vector... I already got that code...
Very interesting code... I was thinking about
editing it to take a picture of entities then
cast the light... (figure out the distance between them
first) and hopefully it would
cast some kewl shadow stuff... But I don't know
how slow this would be... I'll re-write the code
and test out my theories ASAP... but I SHOULD
finish some of this homework first... awwwwwwwww
That should be ok for shadows....
But I really need to figure out how to
subtract color from a lightmap and leave the
level textures the same... hmmmm....