Page 1 of 1

[PSP] How to add your own Light effects.

Posted: Mon Oct 18, 2010 2:16 am
by Mexicouger
This is a tutorial on how to add your own Colored lighting effects for projectiles, or whatever entities you want to attatch it to.

For this tutorial, we are going to add a pink effect.
We are going to go into 4 files:

-Cl_Main.c
-server.h
-Video_Hardware_model.h
-Defs[QC]

To start off, Let's goto Cl_main.c and add add a Light effect.
Scroll down to this function:
/*
===============
CL_RelinkEntities
===============
*/
void CL_RelinkEntities (void)
Goto near the bottom and find this:

Code: Select all

 if (ent->effects & EF_BLUELIGHT)
        {
            dl = CL_AllocDlight (i);
            VectorCopy (ent->origin,  dl->origin);
            dl->radius = 200 + (rand()&31);
            dl->die = cl.time + 0.001;
            dl->radius = 150 + (rand()&31);
            dl->color[0] = 0.25;
            dl->color[1] = 0.25;
            dl->color[2] = 2;
        }
Now right under it, add this:
//A new light effect is now added.
if (ent->effects & EF_PINKLIGHT)
{
dl = CL_AllocDlight (i);
VectorCopy (ent->origin, dl->origin);
dl->radius = 200 + (rand()&31);
dl->die = cl.time + 0.001;
dl->radius = 150 + (rand()&31);
dl->color[0] = 2; //Red
dl->color[1] = 1.4; //Green
dl->color[2] = 1.8; //Blue
}

Edit these 3 values to get the color that you want.
dl->color[0] = 2; //Red
dl->color[1] = 1.4; //Green
dl->color[2] = 1.8; //Blue

You can also rename the effect name if you like. It can be anything. Just look at the other colors, and you will see.

Now open up server.h
Scroll down until you find this:

// entity effects
#define EF_BRIGHTFIELD 1
#define EF_MUZZLEFLASH 2
#define EF_BRIGHTLIGHT 4
#define EF_DIMLIGHT 8
#ifdef SUPPORTS_KUROK_PROTOCOL
#define EF_REDLIGHT 16
#define EF_BLUELIGHT 32


Now right under EF_BLUELIGHT, Add a new Definition like this:
#define EF_PINKLIGHT 64
Notice that the number[64] is double the last number[32]
If you follow this pattern, Then the next Effect number will be [128].

Save and close and open up Video_Hardware_model.h
Right off the bat, you will notice this:
// entity effects

#define EF_BRIGHTFIELD 1
#define EF_MUZZLEFLASH 2
#define EF_BRIGHTLIGHT 4
#define EF_DIMLIGHT 8
#define EF_REDLIGHT 16
#define EF_BLUELIGHT 32
Can you guess what you are going to do? That is right. Put your definition here too. A matter of fact, you should put it under EF_BLUELIGHT.


#define EF_PINKLIGHT 64

Save and close. Now You might need to delete the normal folder so the .h files will be compiled.
Now we need to crack open the qc. Open up defs.qc. We need to make that transaction to the game-code.

Now about Midway, there should be something that looks like this:
// entity effects

//float EF_BRIGHTFIELD = 1;
float EF_MUZZLEFLASH = 2;
float EF_BRIGHTLIGHT = 4;
float EF_DIMLIGHT = 8;
float EF_FLAG1 = 16;
float EF_FLAG2 = 32;

Now add this Right under float EF_FLAG2 = 32;
float EF_FLAG3 = 64; //Pink light effect
Now compile and you are done!
An example of this might look like...

Code: Select all

self.effects = EF_FLAG3;
That will make a pink light for whatever entity self is.

-Mexicouger

Posted: Mon Oct 18, 2010 2:37 am
by leileilol
Instead of hardcoded changes why not pass lighting parameters from quakec like Darkplaces did, instead of adding more to the effects bitflags?

Posted: Mon Oct 18, 2010 2:41 am
by Mexicouger
leileilol wrote:Instead of hardcoded changes why not pass lighting parameters from quakec like Darkplaces did, instead of adding more to the effects bitflags?
Oh, Kinda like how you can change how the particles act, and the color they are? Good idea. I will look into that. This tutorial works for now however.

Posted: Mon Oct 18, 2010 8:48 am
by mh
leileilol wrote:Instead of hardcoded changes why not pass lighting parameters from quakec like Darkplaces did, instead of adding more to the effects bitflags?
One reason is that the stock ID1 game doesn't do it. Besides, hard-coding stuff in the engine is the Quake way! :D

Posted: Mon Oct 18, 2010 3:07 pm
by Jukki
And this is good tutorial for noo.. i mean beginers to know how to do severeal things.


Btw not very ontopic. But how would i do IT_*weaponname* the same thing (i want engine know i have some custom weapons too)

Posted: Mon Oct 18, 2010 3:50 pm
by Ranger366
well, searching in the WinQuake code for EF_BRIGHTLIGHT or else is easy, if you can "read" you understand the system too, thats not hard thought, even for newbies i think.

Posted: Mon Oct 18, 2010 10:07 pm
by Mexicouger
Jukki wrote:And this is good tutorial for noo.. i mean beginers to know how to do severeal things.


Btw not very ontopic. But how would i do IT_*weaponname* the same thing (i want engine know i have some custom weapons too)
It would look something like this:

Code: Select all

if (cl.stats[STAT_ACTIVEWEAPON] == IT_SHOTGUN)
That is equivalent to this in qc:

Code: Select all

if (self.weapon == IT_SHOTGUN)
Hope that helps