Wintermute Engine Forum

Wintermute Engine => Scripts, plugins, utilities, goodies => Topic started by: Mnemonic on August 14, 2004, 12:51:29 PM

Title: Flashlight script
Post by: Mnemonic on August 14, 2004, 12:51:29 PM
This example project demonstrates a flashlight scripting in WME. You can set various parameters of the flashlight in the beginning of flashlight.script (you will find the script in the "flashlight" folder in the project below).


Usage:

1) in your scene, create a dummy region called "foreground" and move it to the very bottom of the node list in SceneEdit
2) attach the flashlight.script to your scene

Currently the script displays the light cone at the position of the mouse pointer, if you want to display it at a different position, change the coordinates in the Update() function call in flashlight.script.

You can change the flashlight graphics for example to have a semi transparent edge around the light cone etc.


Download the demo project: http://dead-code.org/download/demos/wme_flashlight_demo.rar (~950 KB)


Requirements:
- WME 1.2.044 or later
- WinRAR 3.0 or later to unpack the archive


(http://dead-code.org/download/demos/flashlight.jpg)
Title: Re: Flashlight script
Post by: Marek on August 16, 2004, 11:54:45 AM
Oh man, that is a slice of pure genius! ::thumbup

When I use a 120x120 tile and change the variables accordingly, there's been known to be a grey stripe appearing on the right side of the screen, then fading away. Something related to the refreshing of the tiles perhaps?
Title: Re: Flashlight script
Post by: Mnemonic on August 16, 2004, 12:09:02 PM
When I use a 120x120 tile and change the variables accordingly, there's been known to be a grey stripe appearing on the right side of the screen, then fading away. Something related to the refreshing of the tiles perhaps?
Um, darn. Ok, you can try to change the two occurences of line:
for(var i = 0; i<=NumTilesWidth; i=i+1)

to:
for(var i = 0; i<=NumTilesWidth+1; i=i+1)

That might help (hopefully).
Title: Re: Flashlight script
Post by: Marek on August 20, 2004, 07:55:14 PM
Yep. It runs smoothly now!
Title: Re: Flashlight script
Post by: SBOVIS on May 21, 2007, 01:53:56 PM
Hi, I am using a 200x200 light and dark graphic, but I am getting problems with the dark area when the pointer gets to the bottom of my 1048x768 screen.

It basically starts to rise up a little then disappears when I move the pointer up, I can email images if needed?

Any ideas??
Title: Re: Flashlight script
Post by: Mnemonic on May 21, 2007, 05:05:00 PM
Add one more row of the dark tiles.

var NumTilesHeight = MainLayer.Height / TileHeight + 2;
Title: Re: Flashlight script
Post by: Orange Brat on May 21, 2007, 08:03:04 PM
This reminds me of Alone in the Dark 4. Ever played it? It features prerendered backgrounds, but the character's flashlight can "light up" the darkened backgrounds. The cool thing is that it also creates shadows based off the flashlight's position, and they react appropriately to the flashlight. Would it be possible, in WME, to make the dynamic shadows react to the light cone?

You'd have to get the 3D coordinates based off the center point of the flashlight cone and trace from the player's world position to this vector in the level. Everything within the circular light cone would need to be influenced, of course.

I'm not sure right off the top of my head how to do this in WME, but what I described above is a start I suppose. There's a PC demo of the game floating around if you want to see the effect first hand. It's not the greatest game, but the effect is nice.

EDIT: Actually, I just played it, and it doesn't cast shadows, so I'm wrong about it. The flashlight is projected onto the walk plane, though and it lights up parts of the background it touches nicely. It looks like a real directx light because of an obvious tessellation effect.
Title: Re: Flashlight script
Post by: Mnemonic on May 21, 2007, 08:57:25 PM
Hmm, you can change the light position for shadow projection in a script, so I think it should be possible to some extent. In combination with the above script or with additive blending it might yield some interesting results.
Title: Re: Flashlight script
Post by: adonf on May 22, 2007, 11:11:37 AM
There are two background pictures for each scene in AITD4: a dark version and a lit version. The light cone is projected on a simplified version of the scene and the resulting image is used as a blend factor between the lit and unlit version. (Well, that's the basic idea but it couldn't work exactly like that on the PS1). The characters and monsters have simple shadows but on the PS1 and on the Dreamcast version they have stencil buffer-type shadows. I don't remember what light source is used for these stencil shadows, though.

But I remember seeing a trailer for this game in early 2000 where the light cone intersects with a pillar in a room and the pillar projects a shadow onto the environment. This was all done in 3DS MAX but rendered with no texture filtering so as to look like PS1 real-time rendering... Maybe that's what confused you ;)

Anyway, the main difference here is that the light cone is projected in 3D, and I don't think that's the case in this flashlight demo, unless I missed something.
Title: Re: Flashlight script
Post by: Orange Brat on May 23, 2007, 05:11:59 AM
I only played it on PS2, and the demo I mentioned above is the PC version. I never saw the PS1 version. I now remember reading an interview talking about the use of two backgrounds. I guess they faked the perceived dynamic shadows on the backgrounds then.
Title: Re: Flashlight script
Post by: adonf on May 23, 2007, 09:47:08 AM
Well on the DC version (which served as a basis for the PS2 and PC versions) the characters' and monsters' shadows are projected to the simplified model for the background. Or maybe on a separate model ? I can't remember, it's been quite a while. But WME is getting close to the techniques that were used in AITD4 now that you can define "shadow" planes in the 3DS collision files and have simplified models for actor shadows.
Title: Re: Flashlight script
Post by: Dan-D on August 16, 2007, 08:37:10 PM
I dont get it. It's possible to create AITD4 like flash light or not?
Title: Re: Flashlight script
Post by: piere on January 17, 2012, 07:17:45 AM
Sorry I know this post is really old, but I need some help. Im designing sort of a puzzle mini game and I have been using this script. Is there a way to make the flashlight stay transparent on the locations the mouse moves too? For example, if you start the game and move the mouse down, everywhere the mouse touches will stay lit and not go away. I was thinking maybe just making one big black image instead of tiling them, or maybe the tiled entities get deleted when the cursor moves over them. If anyone can help, let me know :)    Many thanks !!
Title: Re: Flashlight script
Post by: Endrit on January 17, 2012, 03:43:40 PM
nice idea !
Title: Re: Flashlight script
Post by: piere on January 17, 2012, 04:33:40 PM
Any suggestions Mnemonic ?
Title: Re: Flashlight script
Post by: Mnemonic on January 18, 2012, 07:24:16 PM
I think that having the scene originally covered and removing the cover pieces as you move the mouse pointer over them is the only feasible way.
Title: Re: Flashlight script
Post by: piere on January 23, 2012, 04:39:05 PM
Thanks Mnemonic, any idea of what I would need to do to the code to get started? I did something like when the mouse goes over one of the black tiles, the entity deletes, but it is not working :( 
Title: Re: Flashlight script
Post by: Mnemonic on January 24, 2012, 06:15:24 PM
I think something like this should work:

create a bunch of black interactive entities and put this to their script:

Code: WME Script
  1. on "MouseEntry"
  2. {
  3.   this.Active = false;
  4. }
  5.  
Title: Re: Flashlight script
Post by: Mnemonic on January 25, 2012, 09:40:07 PM
I don't understand the question. It's showing the image you assigned to the entities.
Title: Re: Flashlight script
Post by: piere on January 25, 2012, 10:11:14 PM
Well you know in the normal script, it has the circle for a light. With this new script, it is not displaying the circular flashlight look, only the squares.
Title: Re: Flashlight script
Post by: piere on January 26, 2012, 07:01:11 AM
Nevermind, I got it working. Thank for the help !