I've started working on a mod with Source 2007 engine and so far I've managed to implement what I've wanted, but as you've already guessed, I've run into a problem and I need help with some ideeas.
I want to make a day/night cycle and the problem is that light_environment generate lighting and shadows on the map coresponding to the compile inputs and I want to change them during game. I'm interested in changeing: ambient , brightness and pitch yaw roll . I am thinking of three posibilities.
First, I've looked in base.fgd and if you look an the values you will see :
- Code: Select all
_light(color255) : "Brightness" : "255 255 255 200"
_ambient(color255) : "Ambient" : "255 255 255 20"
_lightHDR(color255) : "BrightnessHDR" : "-1 -1 -1 1"
_lightscaleHDR(float) : "BrightnessScaleHDR" : "1" : "Amount to scale the light by when compiling for HDR."
_ambientHDR(color255) : "AmbientHDR" : "-1 -1 -1 1"
I've searched a bit about those values and I found them on : "src/utils/vrad/lightmap.cpp" : (lines 1585-...)
- Code: Select all
for (i=0 ; i<(unsigned)num_entities ; i++)
{
e = &entities[i];
name = ValueForKey (e, "classname");
if (strncmp (name, "light", 5))
continue;
// Light_dynamic is actually a real entity; not to be included here...
if (!strcmp (name, "light_dynamic"))
continue;
if (!strcmp (name, "light_spot"))
{
ParseLightSpot( e, dl );
}
else if (!strcmp(name, "light_environment"))
{
ParseLightEnvironment( e, dl );
}
else if (!strcmp(name, "light"))
{
ParseLightPoint( e, dl );
}
else
{
qprintf( "unsupported light entity: \"%s\"\n", name );
}
}
Looks like at map compiling this loop search through entities. When "light_environment" was found calls ParseLightEnvironment :
- Code: Select all
static void ParseLightEnvironment( entity_t* e, directlight_t* dl )
{
Vector dest;
GetVectorForKey (e, "origin", dest );
dl = AllocDLight( dest, false );
ParseLightGeneric( e, dl );
char *angle_str=ValueForKeyWithDefault( e, "SunSpreadAngle" );
if (angle_str)
{
g_SunAngularExtent=atof(angle_str);
g_SunAngularExtent=sin((M_PI/180.0)*g_SunAngularExtent);
printf("sun extent from map=%f\n",g_SunAngularExtent);
}
if ( !gSkyLight )
{
// Sky light.
gSkyLight = dl;
dl->light.type = emit_skylight;
// Sky ambient light.
gAmbient = AllocDLight( dl->light.origin, false );
gAmbient->light.type = emit_skyambient;
if( g_bHDR && LightForKey( e, "_ambientHDR", gAmbient->light.intensity ) )
{
// we have a valid HDR ambient light value
}
else if ( !LightForKey( e, "_ambient", gAmbient->light.intensity ) )
{
VectorScale( dl->light.intensity, 0.5, gAmbient->light.intensity );
}
if ( g_bHDR )
{
VectorScale( gAmbient->light.intensity,
FloatForKeyWithDefault( e, "_AmbientScaleHDR", 1.0 ),
gAmbient->light.intensity );
}
BuildVisForLightEnvironment();
// Add sky and sky ambient lights to the list.
AddDLightToActiveList( gSkyLight );
AddDLightToActiveList( gAmbient );
}
}
And the LightForKey and LightForString procedures:
- Code: Select all
int LightForKey (entity_t *ent, char *key, Vector& intensity )
{
char *pLight;
pLight = ValueForKey( ent, key );
return LightForString( pLight, intensity );
}
int LightForString( char *pLight, Vector& intensity )
{
double r, g, b, scaler;
int argCnt;
VectorFill( intensity, 0 );
// scanf into doubles, then assign, so it is vec_t size independent
r = g = b = scaler = 0;
double r_hdr,g_hdr,b_hdr,scaler_hdr;
argCnt = sscanf ( pLight, "%lf %lf %lf %lf %lf %lf %lf %lf",
&r, &g, &b, &scaler, &r_hdr,&g_hdr,&b_hdr,&scaler_hdr );
if (argCnt==8) // 2 4-tuples
{
if (g_bHDR)
{
r=r_hdr;
g=g_hdr;
b=b_hdr;
scaler=scaler_hdr;
}
argCnt=4;
}
// make sure light is legal
if( r < 0.0f || g < 0.0f || b < 0.0f || scaler < 0.0f )
{
intensity.Init( 0.0f, 0.0f, 0.0f );
return false;
}
intensity[0] = pow( r / 255.0, 2.2 ) * 255; // convert to linear
switch( argCnt)
{
case 1:
// The R,G,B values are all equal.
intensity[1] = intensity[2] = intensity[0];
break;
case 3:
case 4:
// Save the other two G,B values.
intensity[1] = pow( g / 255.0, 2.2 ) * 255;
intensity[2] = pow( b / 255.0, 2.2 ) * 255;
// Did we also get an "intensity" scaler value too?
if ( argCnt == 4 )
{
// Scale the normalized 0-255 R,G,B values by the intensity scaler
VectorScale( intensity, scaler / 255.0, intensity );
}
break;
default:
printf("unknown light specifier type - %s\n",pLight);
return false;
}
// scale up source lights by scaling factor
VectorScale( intensity, lightscale, intensity );
return true;
}
So the ideea is that if I could declare static directlight_t *gAmbient in a header I could include it it my project and start recalculating lighting, but the problem is that lightmap.cpp is not added to the Game Episodic . So my question what does util/vrad project does ? Compiles and make a .dll that is used by hammer at compiling maps ? And how can I make a connection between my project and a way to update the calculations?
The second ideea is that I could disable shadows in light_environment and start thinking of a way implementing a shadow like the shadow_control but applied to world (walls, ground, etc.).
The third ideea is env_global_light . From what I've seen it looks like you could use input to it and change pitch yaw roll. I've started porting it from ASW , no compile error, I've added entity to map, compile, but I can't see a diference with it on. Must be a problem, and I'm going to debug the project and watch what happens with breakpoints.
I need some help with adivces, what solution could work ?
Thanks,
Robert






