@@ -95,18 +95,23 @@ extern PMaterialHandle g_Material_Spark;
9595// -----------------------------------------------------------------------------
9696void GetColorForSurface ( trace_t *trace, Vector *color )
9797{
98- Vector baseColor, diffuseColor;
99- Vector end = trace-> startpos + ( ( Vector )trace-> endpos - ( Vector )trace-> startpos ) * 1 . 1f ;
100-
98+ Vector baseColor = vec3_invalid , diffuseColor;
99+ const char *kind ;
100+
101101 if ( trace->DidHitWorld () )
102102 {
103103 if ( trace->hitbox == 0 )
104104 {
105+ kind = " World" ;
106+ Vector end = trace->startpos + ( trace->endpos - trace->startpos ) * 1 .1f ;
105107 // If we hit the world, then ask the world for the fleck color
106- engine->TraceLineMaterialAndLighting ( trace->startpos , end, diffuseColor, baseColor );
108+ if ( !engine->TraceLineMaterialAndLighting ( trace->startpos , end, diffuseColor, baseColor ) ) {
109+ baseColor = vec3_invalid; // Make sure this wasn't modified
110+ }
107111 }
108112 else
109113 {
114+ kind = " Static Prop" ;
110115 // In this case we hit a static prop.
111116 staticpropmgr->GetStaticPropMaterialColorAndLighting ( trace, trace->hitbox - 1 , diffuseColor, baseColor );
112117 }
@@ -117,20 +122,24 @@ void GetColorForSurface( trace_t *trace, Vector *color )
117122 C_BaseEntity *pEnt = trace->m_pEnt ;
118123 if ( !pEnt )
119124 {
120- Msg (" Couldn't find surface in GetColorForSurface()\n " );
121- color->x = 255 ;
122- color->y = 255 ;
123- color->z = 255 ;
124- return ;
125+ kind = " Null-Entity" ;
126+ } else {
127+ kind = " Entity" ;
128+ ICollideable *pCollide = pEnt->GetCollideable ();
129+ int modelIndex = pCollide->GetCollisionModelIndex ();
130+ model_t * pModel = const_cast <model_t *>(modelinfo->GetModel ( modelIndex ));
131+
132+ // Ask the model info about what we need to know
133+ modelinfo->GetModelMaterialColorAndLighting ( pModel, pCollide->GetCollisionOrigin (),
134+ pCollide->GetCollisionAngles (), trace, diffuseColor, baseColor );
125135 }
136+ }
126137
127- ICollideable *pCollide = pEnt->GetCollideable ();
128- int modelIndex = pCollide->GetCollisionModelIndex ();
129- model_t * pModel = const_cast <model_t *>(modelinfo->GetModel ( modelIndex ));
130-
131- // Ask the model info about what we need to know
132- modelinfo->GetModelMaterialColorAndLighting ( pModel, pCollide->GetCollisionOrigin (),
133- pCollide->GetCollisionAngles (), trace, diffuseColor, baseColor );
138+ if ( baseColor == vec3_invalid )
139+ {
140+ Warning ( " Couldn't find surface color of %s\n " , kind );
141+ baseColor = Vector ( .5f , .5f , .5f );
142+ diffuseColor = engine->GetLightForPoint ( trace->endpos , true );
134143 }
135144
136145 // Get final light value
0 commit comments