mirror of
https://github.com/mapbase-source/source-sdk-2013.git
synced 2025-01-13 07:17:57 +03:00
Implement GetColorForSurface() failure workaround
This function is used to color impact particles. On Linux I've noticed that this function sometimes is not successful on retrieving the surface color, leaving an odd color to render the particles with. The engine function TraceLineMaterialAndLighting() even has a boolean return value indicating success. GetModelMaterialColorAndLighting() does not though, but I still observe failures (the color parameter is not modified). The color is initialized with an invalid value. If it detects that retrieving the color failed (engine function said so or the invalid value was left in place), this now hamfistedly assumes a lightish grey color, but at least still correctly (presumably) incorporates lighting information. When this situation is detected, a warning is also printed to the console. Because why not.
This commit is contained in:
parent
471a840ed9
commit
e9c45e5235
@ -95,18 +95,23 @@ extern PMaterialHandle g_Material_Spark;
|
||||
//-----------------------------------------------------------------------------
|
||||
void GetColorForSurface( trace_t *trace, Vector *color )
|
||||
{
|
||||
Vector baseColor, diffuseColor;
|
||||
Vector end = trace->startpos + ( ( Vector )trace->endpos - ( Vector )trace->startpos ) * 1.1f;
|
||||
Vector baseColor = vec3_invalid, diffuseColor;
|
||||
const char *kind;
|
||||
|
||||
if ( trace->DidHitWorld() )
|
||||
{
|
||||
if ( trace->hitbox == 0 )
|
||||
{
|
||||
kind = "World";
|
||||
Vector end = trace->startpos + ( trace->endpos - trace->startpos ) * 1.1f;
|
||||
// If we hit the world, then ask the world for the fleck color
|
||||
engine->TraceLineMaterialAndLighting( trace->startpos, end, diffuseColor, baseColor );
|
||||
if ( !engine->TraceLineMaterialAndLighting( trace->startpos, end, diffuseColor, baseColor ) ) {
|
||||
baseColor = vec3_invalid; // Make sure this wasn't modified
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
kind = "Static Prop";
|
||||
// In this case we hit a static prop.
|
||||
staticpropmgr->GetStaticPropMaterialColorAndLighting( trace, trace->hitbox - 1, diffuseColor, baseColor );
|
||||
}
|
||||
@ -117,13 +122,9 @@ void GetColorForSurface( trace_t *trace, Vector *color )
|
||||
C_BaseEntity *pEnt = trace->m_pEnt;
|
||||
if ( !pEnt )
|
||||
{
|
||||
Msg("Couldn't find surface in GetColorForSurface()\n");
|
||||
color->x = 255;
|
||||
color->y = 255;
|
||||
color->z = 255;
|
||||
return;
|
||||
}
|
||||
|
||||
kind = "Null-Entity";
|
||||
} else {
|
||||
kind = "Entity";
|
||||
ICollideable *pCollide = pEnt->GetCollideable();
|
||||
int modelIndex = pCollide->GetCollisionModelIndex();
|
||||
model_t* pModel = const_cast<model_t*>(modelinfo->GetModel( modelIndex ));
|
||||
@ -132,6 +133,14 @@ void GetColorForSurface( trace_t *trace, Vector *color )
|
||||
modelinfo->GetModelMaterialColorAndLighting( pModel, pCollide->GetCollisionOrigin(),
|
||||
pCollide->GetCollisionAngles(), trace, diffuseColor, baseColor );
|
||||
}
|
||||
}
|
||||
|
||||
if ( baseColor == vec3_invalid )
|
||||
{
|
||||
Warning( "Couldn't find surface color of %s\n", kind );
|
||||
baseColor = Vector( .5f, .5f, .5f );
|
||||
diffuseColor = engine->GetLightForPoint( trace->endpos, true );
|
||||
}
|
||||
|
||||
//Get final light value
|
||||
color->x = pow( diffuseColor[0], 1.0f/2.2f ) * baseColor[0];
|
||||
|
Loading…
x
Reference in New Issue
Block a user