#1 2014-06-23 06:51:37


[SOLVED]Adding dynamic spotlights back into the game?

Hey guys, I'm guessing this would be a better question for Lee, but I'll ask here first.

I'm trying to create a simple flashlight that extends from the hudgun origin and points to the cursor position in world space. Problem is it seems for whatever reason, spotlights were obscured in the engine code, and I haven't the slightest idea of how to get it back. The mod works with regular dynamic point lights(explosions and muzzle flares n' all that), but spotlights just create a sort of negative space in the screen where some shading passes are missed.

Please note, I'm just getting started with tesseract, so my knowledge of the engine is very limited. But here's the steps I've taken so far:

In adddynlights();, I added a single line adding another dynamic light to each player in the manner described above:

adddynlight(hudgunorigin(player1->gunselect, player1->o, worldpos, player1), 35, vec(1, 1, 1), 0, 0, 0, 35, vec(1, 1, 1), player1, hudgunorigin(player1->gunselect, player1->o, worldpos, player1), 1); //Essentially, a light that starts from the hudgun and points where the crosshair is.

The last argument controls if it is a spotlight or not, 0 gives a working point light, 1 provides no light and an occasional rectangle blocking out some shading.

So, I come across this tidbit in engine/dynlight.cpp:

void dynlightreaching(const vec &target, vec &color, vec &dir, bool hud)
    vec dyncolor(0, 0, 0);//, dyndir(0, 0, 0);
        dynlight &d = dynlights[i];
        if(d.curradius<=0) continue;

        vec ray(target);
        ray.sub(hud ? d.hud : d.o);
        float mag = ray.squaredlen();
        if(mag >= d.curradius*d.curradius) continue;

        float intensity = 1 - sqrtf(mag)/d.curradius;
        if(d.spot > 0)
            float spotatten = 1 - (1 - ray.dot(d.dir)) / (1 - cos360(d.spot));
            if(spotatten <= 0) continue;
            intensity *= spotatten;

        vec color = d.curcolor;
#if 0
        float x = dyncolor.magnitude(), y = color.magnitude();
            if(dir.iszero()) dir = vec(0, 0, 1);
            else dir.normalize();

If you look at the compiler comments and some inline comments, it leaves out a bit of code related to the direction of spotlights. I took them off, but same thing happens.

I've also tried just parenting a spotlight to the player, no visible result. Anyone know how to get around this?

Last edited by jjsullivan5196 (2014-06-25 04:58:26)


#2 2015-02-13 18:21:42


Re: [SOLVED]Adding dynamic spotlights back into the game?

love how solved things have no real solution.


#3 2015-02-14 01:57:02


Re: [SOLVED]Adding dynamic spotlights back into the game?

Your spot light is direction based vector, meaning it hast to be infront of the player x distance (and the dynlight) in the direction the player is facing. The easiest way to impliment this is to put your obscure spot light at the player1->o.add(vecfromyawpitch(player1->yaw, player1->pitch, 0, 1).mul(5))

so basically get the player position, convert the players yaw and pitch and convert it to a normalize vector, (aka the 3d direction the player is facing) then multiply that by the scaler 5 (or move it 5 units in the direction the player is facing).  Then add this to the position of the player (which unnormalizes the vector). To make sure you are correct you can add a particle in the spot where the spot light should be. This will make it easy to determind the correct spot.

But to do this correctly you should use a light and an ambient non-shadowed light (to create ambience). If this doesnt work please post pictures, to help determind exactly whats going on :) thanx


i would look at lightinfo class in renderlights.cpp
it looks like lightinfo.spot .spotx .spoty .dir all control the lights direction and cut off angle. I wish they would add more functionality for lights and spotlights :) but that probably wont happen.

ok solved it at least for about where and how to attatch the light. First make your light on the camera, then place a spot light like stated above, (basically infront of the light in the direction of the players facing direction) then just make the spotlights attr1 = 40 or something then take your spotlight and do this, spot = e.attach; where as spot and e are both exentity. Then add e to the list of exentity in the ents.h file.

If you have any questions do ask, I think I explaned it understandably, if you have any errors or getting wierd renders then do ask.

I would suggest starting with just attatching a light with out the spotlight, then adding in the spot.

Ps: DONT ADD THE SPOTLIGHT TO THE ENTS vector.<exentities> vector because it could reattatch to a different light 0.0.


Last edited by chasester1 (2015-02-14 02:32:30)


Board footer