Esempio n. 1
0
void DiscoverMacroTextures()
{
    CUtlDict<int,int> tempDict;

    g_FaceMacroTextureInfos.SetSize( numfaces );
    for ( int iFace=0; iFace < numfaces; iFace++ )
    {
        texinfo_t *pTexInfo = &texinfo[dfaces[iFace].texinfo];
        if ( pTexInfo->texdata < 0 )
            continue;

        dtexdata_t *pTexData = &dtexdata[pTexInfo->texdata];
        const char *pMaterialName = &g_TexDataStringData[ g_TexDataStringTable[pTexData->nameStringTableID] ];

        MaterialSystemMaterial_t hMaterial = FindMaterial( pMaterialName, NULL, false );

        const char *pMacroTextureName = GetMaterialVar( hMaterial, "$macro_texture" );
        if ( pMacroTextureName )
        {
            if ( tempDict.Find( pMacroTextureName ) == tempDict.InvalidIndex() )
            {
                Msg( "-- DiscoverMacroTextures: %s\n", pMacroTextureName );
                tempDict.Insert( pMacroTextureName, 0 );
            }

            int stringID = TexDataStringTable_AddOrFindString( pMacroTextureName );
            g_FaceMacroTextureInfos[iFace].m_MacroTextureNameID = (unsigned short)stringID;
        }
        else
        {
            g_FaceMacroTextureInfos[iFace].m_MacroTextureNameID = 0xFFFF;
        }
    }
}
Esempio n. 2
0
int GetSurfaceProperties2( MaterialSystemMaterial_t matID, const char *pMatName )
{
	const char *pPropString = NULL;
	int surfaceIndex = -1;

	if ( physprops )
	{
		pPropString = GetMaterialVar( matID, "$surfaceprop2" );
		if ( pPropString )
		{
			surfaceIndex = physprops->GetSurfaceIndex( pPropString );
			if ( surfaceIndex < 0 )
			{
				Msg("Can't find surfacepropblend %s for material %s, using default\n", pPropString, pMatName );
				surfaceIndex = physprops->GetSurfaceIndex( "default" );
			}
		}
		else
		{
			// No surface property 2.
			return -1;
		}
	}

	return surfaceIndex;
}
Esempio n. 3
0
int	FindMiptex (const char *name)
{
	int		i;
	MaterialSystemMaterial_t matID;
	const char *propVal, *propVal2;
	int opacity;
	bool found;
		
	for (i=0 ; i<nummiptex ; i++)
	{
		if (!strcmp (name, textureref[i].name))
		{
			return i;
		}
	}
	if (nummiptex == MAX_MAP_TEXTURES)
		Error ("Too many unique textures, max %d", MAX_MAP_TEXTURES);
	strcpy (textureref[i].name, name);

	textureref[i].lightmapWorldUnitsPerLuxel = 0.0f;
	textureref[i].flags = 0;
	textureref[i].contents = 0;

	matID = FindOriginalMaterial( name, &found );
	if( matID == MATERIAL_NOT_FOUND )
	{
		return 0;
	}

	if (!found)
		Warning("Material not found!: %s\n", name );

	// HANDLE ALL OF THE STUFF THAT ISN'T RENDERED WITH THE MATERIAL THAT IS ONE IT.
	
	// handle sky
	if( ( propVal = GetMaterialVar( matID, "%compileSky" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].flags |= SURF_SKY | SURF_NOLIGHT;
	}
	else if( ( propVal = GetMaterialVar( matID, "%compile2DSky" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].flags |= SURF_SKY | SURF_SKY2D | SURF_NOLIGHT;
	}
	// handle hint brushes
	else if ( ( propVal = GetMaterialVar( matID, "%compileHint" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT | SURF_HINT;
	}
	// handle skip faces
	else if ( ( propVal = GetMaterialVar( matID, "%compileSkip" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT | SURF_SKIP;
	}
	// handle origin brushes
	else if ( ( propVal = GetMaterialVar( matID, "%compileOrigin" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].contents |= CONTENTS_ORIGIN | CONTENTS_DETAIL;
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
	}
	// handle clip brushes
	else if ( ( propVal = GetMaterialVar( matID, "%compileClip" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].contents |= CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP;
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
	}
	else if ( ( propVal = GetMaterialVar( matID, "%playerClip" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].contents |= CONTENTS_PLAYERCLIP;
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
	}
	// handle npc clip brushes
	else if ( ( propVal = GetMaterialVar( matID, "%compileNpcClip" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].contents |= CONTENTS_MONSTERCLIP;
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
	}
	// handle surface lights which are meant to 
	else if ( ( propVal = GetMaterialVar( matID, "%compileNoChop" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].flags |= SURF_NOCHOP;
	}
	// handle triggers
	else if ( ( propVal = GetMaterialVar( matID, "%compileTrigger" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].flags |= ( SURF_NOLIGHT | SURF_TRIGGER );
		if ( g_NodrawTriggers )
		{
			textureref[i].flags |= SURF_NODRAW;
		}
	}
	// handle nolight surfs (except water)
	else if ( (( propVal = GetMaterialVar( matID, "%compileNoLight" ) ) && StringIsTrue( propVal )) && 
		!(( propVal2 = GetMaterialVar( matID, "%compileWater" ) ) && StringIsTrue( propVal2 ) ) )
	{
		textureref[i].flags |= SURF_NOLIGHT;
	}
	else
	{
		// HANDLE ALL OF THE STUFF THAT IS RENDERED WITH THE MATERIAL THAT IS ON IT.

		// Handle ladders.
		if ( ( propVal = GetMaterialVar( matID, "%compileLadder" ) ) &&	StringIsTrue( propVal ) )
		{
			textureref[i].contents |= CONTENTS_LADDER;
		}

		// handle wet materials
		if ( ( propVal = GetMaterialVar( matID, "%noPortal" ) ) &&
			StringIsTrue( propVal ) )
		{
			textureref[i].flags |= SURF_NOPORTAL;
		}

		if ( ( propVal = GetMaterialVar( matID, "%compilePassBullets" ) ) && StringIsTrue( propVal ) )
		{
			// change contents to grate, so bullets pass through
			// NOTE: This has effects on visibility too!
			textureref[i].contents &= ~CONTENTS_SOLID;
			textureref[i].contents |= CONTENTS_GRATE;
		}

		if( g_BumpAll || GetMaterialShaderPropertyBool( matID, UTILMATLIB_NEEDS_BUMPED_LIGHTMAPS ) )
		{
			textureref[i].flags |= SURF_BUMPLIGHT;
		}
		
		if( GetMaterialShaderPropertyBool( matID, UTILMATLIB_NEEDS_LIGHTMAP ) )
		{
			textureref[i].flags &= ~SURF_NOLIGHT;
		}
		else if( !g_bLightIfMissing )
		{
			textureref[i].flags |= SURF_NOLIGHT;
		}
		// handle nodraw faces/brushes
		if ( ( propVal = GetMaterialVar( matID, "%compileNoDraw" ) ) && StringIsTrue( propVal ) )
		{								    
			//		textureref[i].contents |= CONTENTS_DETAIL;
			textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
		}

		// Just a combination of nodraw + pass bullets, makes things easier
		if ( ( propVal = GetMaterialVar( matID, "%compileInvisible" ) ) && StringIsTrue( propVal ) )
		{								    
			// change contents to grate, so bullets pass through
			// NOTE: This has effects on visibility too!
			textureref[i].contents &= ~CONTENTS_SOLID;
			textureref[i].contents |= CONTENTS_GRATE;
			textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
		}

		bool checkWindow = true;
		// handle non solid
		if ( ( propVal = GetMaterialVar( matID, "%compileNonsolid" ) ) && StringIsTrue( propVal ) )
		{
			textureref[i].contents = CONTENTS_OPAQUE;
			// Non-Solid can't be a window either!
			checkWindow = false;
		}
		// handle block LOS
		if ( ( propVal = GetMaterialVar( matID, "%compileBlockLOS" ) ) && StringIsTrue( propVal ) )
		{
			textureref[i].contents = CONTENTS_BLOCKLOS;

			// BlockLOS can't be a window either!
			checkWindow = false;
		}

		if ( ( propVal = GetMaterialVar( matID, "%compileDetail" ) ) &&
			StringIsTrue( propVal ) )
		{
			textureref[i].contents |= CONTENTS_DETAIL;
		}

		bool bKeepLighting = ( ( propVal = GetMaterialVar( matID, "%compileKeepLight" ) ) &&
			StringIsTrue( propVal ) );

		// handle materials that want to be treated as water.
		if ( ( propVal = GetMaterialVar( matID, "%compileWater" ) ) &&
			StringIsTrue( propVal ) )
		{
			textureref[i].contents &= ~(CONTENTS_SOLID|CONTENTS_DETAIL);
			textureref[i].contents |= CONTENTS_WATER;
			textureref[i].flags |= SURF_WARP | SURF_NOSHADOWS | SURF_NODECALS;

			if ( g_DisableWaterLighting && !bKeepLighting )
			{
				textureref[i].flags |= SURF_NOLIGHT;
			}

			// Set this so that we can check at the end of the process the presence of a a WaterLODControl entity.
			g_bHasWater = true;
		}
		const char *pShaderName = GetMaterialShaderName(matID);
		if ( !bKeepLighting && !Q_strncasecmp( pShaderName, "water", 5 ) || !Q_strncasecmp( pShaderName, "UnlitGeneric", 12 ) )
		{
			//if ( !(textureref[i].flags & SURF_NOLIGHT) )
			//	Warning("Forcing lit materal %s to nolight\n", name );
			textureref[i].flags |= SURF_NOLIGHT;
		}

		if ( ( propVal = GetMaterialVar( matID, "%compileSlime" ) ) &&
			StringIsTrue( propVal ) )
		{
			textureref[i].contents &= ~(CONTENTS_SOLID|CONTENTS_DETAIL);
			textureref[i].contents |= CONTENTS_SLIME;
			textureref[i].flags |= SURF_NODECALS;
			// Set this so that we can check at the end of the process the presence of a a WaterLODControl entity.
			g_bHasWater = true;
		}
	
		opacity = GetMaterialShaderPropertyInt( matID, UTILMATLIB_OPACITY );
		
		if ( checkWindow && opacity != UTILMATLIB_OPAQUE )
		{
			// transparent *and solid* brushes that aren't grates or water must be windows
			if ( !(textureref[i].contents & (CONTENTS_GRATE|CONTENTS_WATER)) )
			{
				textureref[i].contents |= CONTENTS_WINDOW;
			}

			textureref[i].contents &= ~CONTENTS_SOLID;
			
			// this affects engine primitive sorting, SURF_TRANS means sort as a translucent primitive
			if ( opacity == UTILMATLIB_TRANSLUCENT )
			{
				textureref[i].flags |= SURF_TRANS;
			}
			
		}
		if ( textureref[i].flags & SURF_NOLIGHT )
		{
			textureref[i].flags &= ~SURF_BUMPLIGHT;
		}
	}

	nummiptex++;

	return i;
}
//-----------------------------------------------------------------------------
// Places Detail Objects in the level
//-----------------------------------------------------------------------------
void EmitDetailModels()
{
	StartPacifier("Placing detail props : ");

	// Place stuff on each face
	dface_t* pFace = dfaces;
	for (int j = 0; j < numfaces; ++j)
	{
		UpdatePacifier( (float)j / (float)numfaces );

		// Get at the material associated with this face
		texinfo_t* pTexInfo = &texinfo[pFace[j].texinfo];
		dtexdata_t* pTexData = GetTexData( pTexInfo->texdata );

		// Try to get at the material
		bool found;
		MaterialSystemMaterial_t handle = 
			FindOriginalMaterial( TexDataStringTable_GetString( pTexData->nameStringTableID ), 
						  &found, false );
		if (!found)
			continue;

		// See if its got any detail objects on it
		const char* pDetailType = GetMaterialVar( handle, "%detailtype" );
		if (!pDetailType)
			continue;

		// Get the detail type...
		DetailObject_t search;
		search.m_Name = pDetailType;
		int objectType = s_DetailObjectDict.Find(search);
		if (objectType < 0)
		{
			Warning("Material %s uses unknown detail object type %s!\n",	
				TexDataStringTable_GetString( pTexData->nameStringTableID ),
				pDetailType);
			continue;
		}

		// Emit objects on a particular face
		DetailObject_t& detail = s_DetailObjectDict[objectType];

		if (pFace[j].dispinfo < 0)
		{
			EmitDetailObjectsOnFace( &pFace[j], detail );
		}
		else
		{
			// Get a CCoreDispInfo. All we need is the triangles and lightmap texture coordinates.
			mapdispinfo_t *pMapDisp = &mapdispinfo[pFace[j].dispinfo];
			CCoreDispInfo coreDispInfo;
			DispMapToCoreDispInfo( pMapDisp, &coreDispInfo, &pFace[j] );

			EmitDetailObjectsOnDisplacementFace( &pFace[j], detail, coreDispInfo );
		}
	}

	// Emit specifically specified detail props
	Vector origin;
	QAngle angles;
	Vector2D pos[2];
	Vector2D tex[2];
	for (int i = 0; i < num_entities; ++i)
	{
		char* pEntity = ValueForKey(&entities[i], "classname");
		if (!strcmp(pEntity, "detail_prop") || !strcmp(pEntity, "prop_detail"))
		{
			GetVectorForKey( &entities[i], "origin", origin );
			GetAnglesForKey( &entities[i], "angles", angles );
			char* pModelName = ValueForKey( &entities[i], "model" );
			int nOrientation = IntForKey( &entities[i], "detailOrientation" );

			AddDetailToLump( pModelName, origin, angles, nOrientation );

			// strip this ent from the .bsp file
			entities[i].epairs = 0;
			continue;
		}

		if (!strcmp(pEntity, "prop_detail_sprite"))
		{
			GetVectorForKey( &entities[i], "origin", origin );
			GetAnglesForKey( &entities[i], "angles", angles );
			int nOrientation = IntForKey( &entities[i], "detailOrientation" );
			GetVector2DForKey( &entities[i], "position_ul", pos[0] );
			GetVector2DForKey( &entities[i], "position_lr", pos[1] );
			GetVector2DForKey( &entities[i], "tex_ul", tex[0] );
			GetVector2DForKey( &entities[i], "tex_size", tex[1] );
			float flTextureSize = FloatForKey( &entities[i], "tex_total_size" );

			tex[1].x += tex[0].x - 0.5f;
			tex[1].y += tex[0].y - 0.5f;
			tex[0].x += 0.5f;
			tex[0].y += 0.5f;
			tex[0] /= flTextureSize;
			tex[1] /= flTextureSize;

			AddDetailSpriteToLump( origin, angles, nOrientation, pos, tex, 1.0f );

			// strip this ent from the .bsp file
			entities[i].epairs = 0;
			continue;
		}
	}

	EndPacifier( true );
}
Esempio n. 5
0
int	FindMiptex (const char *name)
{
	int		i;
	MaterialSystemMaterial_t matID;
	const char *propVal;
	int opacity;
	bool found;
		
	for (i=0 ; i<nummiptex ; i++)
	{
		if (!strcmp (name, textureref[i].name))
		{
			return i;
		}
	}
	if (nummiptex == MAX_MAP_TEXTURES)
		Error ("MAX_MAP_TEXTURES");
	strcpy (textureref[i].name, name);

	textureref[i].lightmapWorldUnitsPerLuxel = 0.0f;
	textureref[i].flags = 0;
	textureref[i].contents = 0;

	matID = FindOriginalMaterial( name, &found );
	if( matID == MATERIAL_NOT_FOUND )
	{
		return 0;
	}

	if (!found)
		Warning("Material not found!: %s\n", name );

	// HANDLE ALL OF THE STUFF THAT ISN'T RENDERED WITH THE MATERIAL THAT IS ONE IT.
	
	// handle sky
	if( ( propVal = GetMaterialVar( matID, "%compileSky" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].flags |= SURF_SKY | SURF_NOLIGHT;
	}
	// handle hint brushes
	else if ( ( propVal = GetMaterialVar( matID, "%compileHint" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT | SURF_HINT;
	}
	// handle skip faces
	else if ( ( propVal = GetMaterialVar( matID, "%compileSkip" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT | SURF_SKIP;
	}
	// handle origin brushes
	else if ( ( propVal = GetMaterialVar( matID, "%compileOrigin" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].contents |= CONTENTS_ORIGIN | CONTENTS_DETAIL;
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
	}
	// handle clip brushes
	else if ( ( propVal = GetMaterialVar( matID, "%compileClip" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].contents |= CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP;
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
	}
	// handle npc clip brushes
	else if ( ( propVal = GetMaterialVar( matID, "%compileNpcClip" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].contents |= CONTENTS_MONSTERCLIP;
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
	}
	// handle triggers
	else if ( ( propVal = GetMaterialVar( matID, "%compileTrigger" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].flags |= SURF_NOLIGHT;
	}
	else if ( ( propVal = GetMaterialVar( matID, "%compilePlayerControlClip" ) ) &&
		StringIsTrue( propVal ) )
	{
		textureref[i].contents |= CONTENTS_DETAIL | CONTENTS_MIST;
		textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
	}
	else
	{
		// HANDLE ALL OF THE STUFF THAT IS RENDERED WITH THE MATERIAL THAT IS ON IT.

		// Handle ladders.
		if ( ( propVal = GetMaterialVar( matID, "%compileLadder" ) ) &&	StringIsTrue( propVal ) )
		{
			textureref[i].contents |= CONTENTS_LADDER;
		}

		// handle wet materials
		if ( ( propVal = GetMaterialVar( matID, "%compileWet" ) ) &&
			StringIsTrue( propVal ) )
		{
			textureref[i].flags |= SURF_WET;
		}

		if ( ( propVal = GetMaterialVar( matID, "%compilePassBullets" ) ) && StringIsTrue( propVal ) )
		{
			// change contents to grate, so bullets pass through
			// NOTE: This has effects on visibility too!
			textureref[i].contents &= ~CONTENTS_SOLID;
			textureref[i].contents |= CONTENTS_GRATE;
		}

		if( g_BumpAll || GetMaterialShaderPropertyBool( matID, UTILMATLIB_NEEDS_BUMPED_LIGHTMAPS ) )
		{
			textureref[i].flags |= SURF_BUMPLIGHT;
		}
		
		if( GetMaterialShaderPropertyBool( matID, UTILMATLIB_NEEDS_LIGHTMAP ) )
		{
			textureref[i].flags &= ~SURF_NOLIGHT;
		}
		else if( !g_bLightIfMissing )
		{
			textureref[i].flags |= SURF_NOLIGHT;
		}

		// handle nodraw faces/brushes
		if ( ( propVal = GetMaterialVar( matID, "%compileNoDraw" ) ) && StringIsTrue( propVal ) )
		{								    
			//		textureref[i].contents |= CONTENTS_DETAIL;
			textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
		}

		// Just a combination of nodraw + pass bullets, makes things easier
		if ( ( propVal = GetMaterialVar( matID, "%compileInvisible" ) ) && StringIsTrue( propVal ) )
		{								    
			// change contents to grate, so bullets pass through
			// NOTE: This has effects on visibility too!
			textureref[i].contents &= ~CONTENTS_SOLID;
			textureref[i].contents |= CONTENTS_GRATE;
			textureref[i].flags |= SURF_NODRAW | SURF_NOLIGHT;
		}

		bool checkWindow = true;
		// handle non solid
		if ( ( propVal = GetMaterialVar( matID, "%compileNonsolid" ) ) &&
			StringIsTrue( propVal ) )
		{
			textureref[i].contents = CONTENTS_OPAQUE;
			
			// Non-Solid can't be a window either!
			checkWindow = false;
		}

		if ( ( propVal = GetMaterialVar( matID, "%compileDetail" ) ) &&
			StringIsTrue( propVal ) )
		{
			textureref[i].contents |= CONTENTS_DETAIL;
		}

		// handle materials that want to be treated as water.
		if ( ( propVal = GetMaterialVar( matID, "%compileWater" ) ) &&
			StringIsTrue( propVal ) )
		{
			textureref[i].contents &= ~(CONTENTS_SOLID|CONTENTS_DETAIL);
			textureref[i].contents |= CONTENTS_WATER;
			textureref[i].flags |= SURF_WARP;
		}
		if ( ( propVal = GetMaterialVar( matID, "%compileSlime" ) ) &&
			StringIsTrue( propVal ) )
		{
			textureref[i].contents &= ~(CONTENTS_SOLID|CONTENTS_DETAIL);
			textureref[i].contents |= CONTENTS_SLIME;
			//textureref[i].flags |= SURF_WARP;
		}
	
		opacity = GetMaterialShaderPropertyInt( matID, UTILMATLIB_OPACITY );
		
		if ( checkWindow && opacity != UTILMATLIB_OPAQUE )
		{
			// transparent *and solid* brushes that aren't grates or water must be windows
			if ( !(textureref[i].contents & (CONTENTS_GRATE|CONTENTS_WATER)) )
			{
				textureref[i].contents |= CONTENTS_WINDOW;
			}

			textureref[i].contents &= ~CONTENTS_SOLID;
			
			// this affects engine primitive sorting, SURF_TRANS means sort as a translucent primitive
			if ( opacity == UTILMATLIB_TRANSLUCENT )
			{
				textureref[i].flags |= SURF_TRANS;
			}
			
		}

	}

	nummiptex++;

	return i;
}