Game Development Community

Spot Lights / Spotlights in TX2D [SOLVED]

by Aaron Scovel · in Torque X 2D · 10/02/2010 (5:34 pm) · 74 replies

I'm trying to create Spotlights in my game and cant seem to achieve this with the T2DLightComponent

mke3.net/blender/devel/rendering/volumetrics/vol_directlighting01.jpglibx3d.sourceforge.net/ISO-IEC-19775-X3DAbstractSpecification/Images/spotlight.gif
Has anyone achieved this type of light affect with the T2DLightComponent?

PointLight and SpotLight2DAdv both give me the same type of circular/sun/glowing light effect. SpotLight2DAdv has InnerAngel and OuterAngle variables, but I cant get them to do anything. Added Note: SpotLight2DAdv is part of the CEV (Community Enhanced Version)

About the author

Previously a PHP/MySQL Programmer/Web Developer of 10 years. In Aug 2010 I decided to change careers, and this is were I landed! I also parent 3 kids full time. TopNotched.com

#41
10/04/2010 (2:22 am)
@Aaron

I've updated and fixed some things for the lighting. If you want to try them out, to see if it fixes the error, I've uploaded them here

http://www.mediafire.com/?3utb4d5p3gnnq1n

you can just overwrite the previous versions of the .cs files if want
#42
10/04/2010 (5:01 am)
@Alex: It works great now! Thanks for your extra time with this, very much appreciated! You will get credit when it comes due ;-)

Update: I let the Light Demo sit for about 10 minutes while I was writing some replies in the forum and it crashed by the time I returned. I will try to reproduce the error and see what it says.

New Update: I tried to reproduce the crash, letting the demo run for over an hour, but had no problems, must have been a fluke
#43
10/04/2010 (6:23 am)
@Aaron

You're welcome, I'm glad it's working for you now. No credit is necessary, it's enough that you were able to find some use for this. If you're able to reproduce the crash just let me know and I'll try and fix it.
#44
10/04/2010 (5:18 pm)
@Aaron, lol be careful with lights and looking for crashes. I have a computer thats only 3 and a half years old, but its starting to show its wear and crashes when i test lights sometimes. You could just be testing the redundancy of your graphics card and computer, and not even software. Just a heads up.

-Will
#45
10/11/2010 (2:50 pm)
Hey all,

What was the problem with this in the end? I have the latest revision (66) and have followed the tutorial which Alex kindly provided. Still no joy, just a blank screen :-(


Cheers
#46
10/11/2010 (4:17 pm)
@Tim: Alex sent me some files to use, but they should be included in rev 66. I will update my CEV to 66, test it out, and post results.
#47
10/11/2010 (8:08 pm)
@Cheers Aaaron,

I have rev 66, but maybe its an issuse with NOT doing the tut right!:-P
#48
10/11/2010 (9:20 pm)
@Tim: I just ran a test with rev 66 and its working good. Make sure to press the green + on the T2DLightComponent. Finally make sure you save your scene after adding the new material(forgetting either of these steps will cause a black/blank screen).
#49
10/12/2010 (8:09 am)
Cheers Aaron, I'll have a look and post back here.
#50
10/12/2010 (1:23 pm)
hey guys thanks for all your hardwork. I got the light to run pretty well, but I'm having a couple of questions.

How do you change the rotation of the light source?
i have my light mounted to my sceneobject and it only needs to shine in two directions (270 and 90). I cant just flip or change the rotation of the sceneobject, but i cant figure out how to change the direction of the light source on the fly.

Also i cant seem to get a clone of the sceneobject to work with SpotLight. PointLight works fine though. Has anyone else tried this?

Thanks again guys

#51
10/12/2010 (2:52 pm)
Rotation of the spot light is set to the rotation of the scene object it is attached to. If you can't change the rotation of the sceneobject the light is attached to, you could set the light on a blank sceneobject and mount it to your non-rotatable sceneobject. That way you can set the rotation of the light independently of the sceneobject it is attached to.

As for the cloning not working with the SpotLight, that's my fault I forgot to add the spot light specific properties to the SpotLights _CopyTo method.

To fix that, in Lights2DAdv.cs, the _CopyTo Method should be
protected override void _CopyTo(Light light)
        {
            base._CopyTo(light);

            SpotLight2DAdv spotLight = (SpotLight2DAdv)light;
            spotLight.InnerAngle = InnerAngle;
            spotLight.OuterAngle = OuterAngle;
            spotLight.Direction = Direction;
            spotLight.RotationOffset = RotationOffset;
            spotLight.PositionOffset = PositionOffset;
        }
#52
10/12/2010 (6:46 pm)
Ah thanks, turns out i was only changing the flipX and not actually the rotation.

Is it possible to make the light affect a T2DAnimatedSprite with changing animationData?

I attached a Light Component to a T2DAnimatedSprite and followed the same steps for the StaticSprite Material. However when the animationdata changes, the sprite gets extremely bright and is super luminated no matter where on the screen.
#53
10/12/2010 (9:12 pm)
It should work for StaticSprites, AnimatedSprites and TileLayers. The only thing I can think of, as to why it would light up like that, is the material isn't being switched over, so the default lighting material is used; either because of the builder not saving your settings or the UseAlternateLighting check box not being checked on the T2DLightComponent of the object being lit.
#54
10/12/2010 (11:40 pm)
Dang, i'm not sure what is going on. Sad thing is when i switch animationData in the animatedSprite, I'm still using the same material.
#55
10/13/2010 (12:17 am)
I'll put together a test project and see if I can reproduce the issue
#56
10/13/2010 (12:35 am)
I'm not exactly sure what happens in the LightingMaterial2Adv.cs
My understanding of torque underworkings is pretty minimal. However just looking at the functions being called, I'm wondering if its possible to call the SetupEffect or SetupObject again when the Animation Data for the SceneObject that I want the light to affect changes.

a quick summary of whats happening:

-my enemy object has multiple animation data for different states.

-when i create the enemy object dynamically, light works fine and is affected by the advance lighting.

-once the enemy changes to another animation, enemy is not affected by advance lighting anymore, but perhaps some sort of light.

-if the enemy returns to its original state it was created in, advance lighting works for that animation only.

- the animation data that enemy uses are all on one sprite sheet

Sorry for all this trouble, I really appreciate your help.
Ray
#57
10/13/2010 (1:52 am)
Ok, found the issue, but I don't think it's something I can fix, it's just the way the engine works. Each T2DAnimatedSprite has it's own T2DAnimationData class reference which in turn holds a reference to it's material so you'll need to come up with a way to assign the new lighting material to your animation state data.

If you're storing the animation data in a list or array you could just iterate through and replace the material with the material from animation that is working correctly, it should be ok since all the animations are on the same sprite sheet. If that doesn't work correctly just iterate through and create a new LightingMaterial2DAdv and assign the properties from its LightingMaterial (the properties that need to be transferred can be seen in LightComponent2D.cs check the _SetupAlternateLighting method). If the lighting gives you any more issues just let me know.
#58
10/13/2010 (5:15 am)
Got it! just passing on the material when i switch animationdata worked great! Thanks again
#59
10/13/2010 (11:34 pm)
okay this could be another weird bug or i'm just using it incorrectly.

I'm getting a crash when i spawn my enemies with the T2DLightComponent attached. This only happens deploying to the xbox however.

Running through the debug
the error was in T2DAnimatedSprite.cs in the Init() function

for (int i = 0; i < imageMapFrameCount; i++)
                    _animationFramesList.Add(_material.GetRegionCoords(i));
            }

            // do we have an animation frames list?
            Assert.Fatal(_animationFramesList.Count > 0, "doh! failed to create an animation");

seems like _animationFramesList.Count is not getting anything added to it. I checked the framesList in that function and it is fine. I wish i had more of an understanding of whats going on.

I removed the T2DLightComponent, and no more crashes, but then no more spiffy light effect either

*edit* I just realized that my main character still has the T2DLightComponent attached but it is not causing it to crash.
I'm wondering if its the act of registering a new Object with the lightComponent after the light has been registered, this is just pure speculation.




#60
10/14/2010 (9:37 am)
I don't have an xbox I can test with, but I'll see if I can get it to happen on windows