Forum

[PSP] How to add your own Light effects.

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

[PSP] How to add your own Light effects.

Postby Mexicouger » Mon Oct 18, 2010 2:16 am

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
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby leileilol » Mon Oct 18, 2010 2:37 am

Instead of hardcoded changes why not pass lighting parameters from quakec like Darkplaces did, instead of adding more to the effects bitflags?
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Postby Mexicouger » Mon Oct 18, 2010 2:41 am

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.
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm

Postby mh » Mon Oct 18, 2010 8:48 am

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
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby Jukki » Mon Oct 18, 2010 3:07 pm

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)
Jukki
 
Posts: 214
Joined: Wed Apr 07, 2010 4:59 am

Postby Ranger366 » Mon Oct 18, 2010 3:50 pm

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.
User avatar
Ranger366
 
Posts: 203
Joined: Thu Mar 18, 2010 5:51 pm

Postby Mexicouger » Mon Oct 18, 2010 10:07 pm

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
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest