Flashlight for 3rd Person

Blitz3D Forums/Blitz3D Beginners Area/Flashlight for 3rd Person

IKG(Posted 2006) [#1]
Kind of like the one in Silent Hill games. Any ideas?


Baystep Productions(Posted 2006) [#2]
err. how about a cone set to "add" blend mode?


Matty(Posted 2006) [#3]
Have a play around with this, it uses a projected spotlight texture:

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


IKG(Posted 2006) [#4]
I tried that demo. I was hoping for something a little less complicated...

Edit: How can I make a cone a real time glowing light source? I want to import the cone and make it glow and produce dynamic light when moved around.


Baystep Productions(Posted 2006) [#5]
Well, first you need to learn C, then you need to by a powerful engin like Unreal. Then maybe you could do something like silent hill. ;)

Sorry buddy, unless your using blitz's internal spot lights, its really not gonna look that good.


IKG(Posted 2006) [#6]
Heh was just using Silent Hill as an example. I know this effect is possible though, as I've played some demos like that before.

If that "batman" example can create realtime lighting, than I can probably turn my cone into a realtime light source.

And I do play on switching to Truevision3D in the future ;)


b32(Posted 2006) [#7]
There is a visible light demo for Blitz3D somewhere.
It uses a few shapes next to each other with a different alpha blend value. It gives an atmosphere/blur like effect.
So maybe you could generate a number white cones, with incremental sizes and alpha values.


IKG(Posted 2006) [#8]
No, I want to actually light up the dark areas of the map. I don't want to just "give the effect".


b32(Posted 2006) [#9]
Why not combine the cone with a spotlight then ?


IKG(Posted 2006) [#10]
Didn't know spotlights could render in realtime. Can they? I'll try right now.

Edit: Yeah well this just isn't working. Might be because my meshes are already prelit, but I can't even get a proper light working. Any suggestions for this whole "flashlight" idea in general? It's a must-have for my game.


Sir Gak(Posted 2006) [#11]
How about creating a pivot, then hanging a cone on it such that the pointed vertex tip of the cone is at the pivot and the base is away from the pivot; then, add a light at the pivot pointing toward the cone. Use alpha on the cone so that it's mostly transparent, and DON'T set the cone for collisions. That way, the light is shining down along the axis of the cone and throughout the cone. Maybe you could play with the range/distance on the light, and also maybe use fogging on its range, to make sure the flashlight doesn't illuminate too far, and that it gets diffused as it shines away from the flashlight. Could maybe that work?

Also, set AmbientLight to 0,0,0, to make the scenery dark so that the flashlight can be seen to do its work without being overruled by ambient light.
Here's some code I use in a dungeon crawler game I'm working on. It's not directly a flashlight effect, but I set the light at the pcam (camera at player's position, simulating the player carrying a light source with him as he walks around the dungeon corridors).

;camera stuff
CameraFogMode camera,1
Const fogrange# = 30
CameraFogRange camera,1,fogrange

;light stuff
AmbientLight 0,0,0 ;dungeon to be dark, except for torch (local) lighting
light=CreateLight(2,pcam)
LightRange light,5


IKG(Posted 2006) [#12]
And the light will generate "realtime" light while it is moved?


Sir Gak(Posted 2006) [#13]
Well, my example uses a radius light effect, i.e. the lighting of the environment operates at a radius from the pcam (player-camera) position, but the light effect emanating from the pcam point is definitely real-time. However, I am not using a cone as in your flashlight situation, so the previous post is only theoretical. I'll have to give it a test in the environment of my dungeon game and see if it works.


IKG(Posted 2006) [#14]
Wait, forget my whole "cone" idea for now. What do I have to do to make my light realtime? Just put it in the main loop? Because I've tried that before. Guess I'll just try it again later.

Edit: Doh! I just realized that since I'm using a level editor (3DWS) to make all my maps, I can't use B3D lights since everything already has lightmaps! Damn :(


Sir Gak(Posted 2006) [#15]
Can't you, once you have loaded your level, use the B3D command AmbientLight 0,0,0? That should make general lighting to darkness, and only specific light sources would show the environment.


IKG(Posted 2006) [#16]
No. Just not possible with my prerendered lightmaps. Oh well :(


jfk EO-11110(Posted 2006) [#17]
if you set your map meshes FX to zero instead of 1 (fullbright) then it should work noless. AFAIK you cannot override the FX setting after loading, so you need to set it in world studio. But the flashlight should then be the only light in the scene. and of course in lightmap-lit places the flaslite won't be very effective, like IRL.

But don't expect any shadows with DX-lights (CreateLight).


IKG(Posted 2006) [#18]
Well if I wanted to take off fullbright, I wouldn't render lightmaps in the first place. I'll try it just for now as an experiment, but it might not be the best idea in the long run.

Edit: I can't not render lights in 3DWS. Which means I'm stuck. FX doesn't work and making lights doesn't affect anything.


b32(Posted 2006) [#19]
maybe the mesh has no normals set, try updatennormals mesh


IKG(Posted 2006) [#20]
Nope, doesn't work. Like I said, I can't "not" render lightmaps. Hope that makes sense.


Sir Gak(Posted 2006) [#21]
I guess you might as well forget the flashlight, then?


Ross C(Posted 2006) [#22]
Why not try and writepixels to the lightmap? You'd need to keep a record of the orginal pixel colours your overwriting though. If the torch length wasn't too long, you could get away with doing linepicks in a cone shape, getting the UV co-ords of the texture, and writing brighter pixels.


Ross C(Posted 2006) [#23]
I have another idea here. Basically it would require two renders. Render the level. Hide everything except the cone shape for your torch beam. Render that against a black camera backround. Then texture a sprite in front of the camera with firstly the level render, then multi-texture the torch cone texture. Now, you could set this texture to modx2 or just add. It should give you a decent effect. I'll knock up a demo soon.


IKG(Posted 2006) [#24]
I'm pretty much ditching the idea for now. It's just too hard for a beginner like me. Besides, it would just be more easy to make with a modern engine that supports dynamic lighting. I would rather do it the right way than just try to "cheat" the effect in.


Ross C(Posted 2006) [#25]
Mostly everything you do in games programming is a cheat ;o)


Sir Gak(Posted 2006) [#26]
Ross C is onto something there. After all, programming is just a way to get the computer to accomplish something you want done. IMHO, there is no "cheat", just an algorithm to achieve your goal. The quasi-3D effect of Doom was an algorithm to get the look and feel of a three-dimensional world, spurred on by the limits of technology available when it first came out. You do what you can with what's available to achieve your goal. If a straightforward programming command can't do it, you work "outside the box" to find a way to do it. So, I would encourage you not to ditch it, but keep trying.


Ross C(Posted 2006) [#27]
Well said


Morbius(Posted 2006) [#28]
Ross, did you ever try this?


jfk EO-11110(Posted 2006) [#29]
Since this thread was exhumed, some additional thoughts by me.

True volumetric light with dynamic shadows would be nice, but I think it's not really neccessary.

One thing should be clear:

lightmapped meshes ARE fullbright, the lightmap will then be blended using the multiplying mode. So DX lights won't affect the scene.

You won't be able to override the FX of a loaded B3D in Blitz3D, so you need to save it with the wanted FX. If WordStudio doesn't allow to do that, then you may patch the file, using something like B3DTweak.

You need then to find a good balance of "halffullbright" geometry USING AMBIENTLIGHT, mixed with the lightmap and finally the dynamic DX flashlight. The lack of shadows with the flashlight may look unnatural.

Ross your idea with two renders may allow to do some interesting combinations. Personally I'm not a fan of additional renders. I think in the end of the day there are still more than enough things that will force you to do additional renders. So we should try to keep this overhead on a low level.

One cone shaped flaslight I have seen that was looking really nice was in Deus Ex 2 the flashlight of the drones. It is made of a row of add-blended sprites. The row starts with a small sprite, then they are getting bigger, but also less opaque. The sprites are circular lights with very blured borders. If the flaslight is parallel to the camera, it will be about 25% opaque. If the camera is looking right into the flashlight, the sprites will blind the camera in their addition. The number of sprites is about 10 or so. Since its additional blending, it won't be very slow (compared to alpha)

Additionally you may use a DX light, positioned on a location that is determined using a linepick from the flashlight body. Or you could use a DX light in Cone Mode, tho I think this may be not very efficient, I could be wrong here.

So this sprite-row flashlight is also cone shaped, but it has no sharp edges as a cone mesh based solution usually suffers of.


DQ(Posted 2006) [#30]
ok, i know this isn't exactly related the topic (sorry) but there's something i want cleared for my knowledge:

what exactly do u guys mean when u say something like "render something and then do another render"? or "additional renders"? or "rendered in 2 phases/passes"?

i mean, i think i get the CONCEPT but what is roughly the basic behind the scenes concept of this in blitz? or maybe i don't get the concept... :P

thx.


Shambler(Posted 2006) [#31]

You won't be able to override the FX of a loaded B3D in Blitz3D

You should be able to EntityFX 0 stuff.

@DQ you can have more than one camera in Blitz3D so essentially you can

Hide Camera 2
Show Camera 1
Do a RenderWorld()
Do stuff to this screen e.g. apply a blur filter etc.
Hide Camera 1
Show Camera 2
Do another Renderworld()

If camera 2 is set to not clear the screen ( Use cameraclsmode ) then it can render on top of camera 1's render.


Sir Gak(Posted 2006) [#32]
If camera 2 is set to not clear the screen ( Use cameraclsmode ) then it can render on top of camera 1's render.


What an interesting idea. I am so used to double-buffering this line of thinking never occurred to me!


jfk EO-11110(Posted 2006) [#33]
Shambler - my mistake. I clearly remember EntityAlpha and some other commands didn't work with loaded B3D, some time ago. Now I just tested EntityAlpha and it works.

I guess this depends on the App that was used to export the mesh. May have something to do with missing normals. Fact is: A map mesh that was exported in Maplet/Decorator was imported in giles. I then added some stuff that was made in 3dsMax, with standard normals/smoothing. After exporting the lightmapped result in giles, the maplet/decorator parts of the mesh don't show any diffrence when I toggle FX 1/0, only the parts that I added from 3dsMax show the diffrence (for some reason even after adding an UpdateNormals).