void CC_PickerShader ( const CCommand &args )
{
	C_BasePlayer *pPlayer = (C_BasePlayer *) C_BasePlayer::GetLocalPlayer();
	if ( !pPlayer )
		return;

	trace_t tr;
	Vector vecAbsStart, vecAbsEnd, vecDir;

	AngleVectors( pPlayer->EyeAngles(), &vecDir );

	vecAbsStart = pPlayer->EyePosition();
	vecAbsEnd = vecAbsStart + (vecDir * MAX_TRACE_LENGTH);

	UTIL_TraceLine( vecAbsStart, vecAbsEnd, MASK_ALL, pPlayer, COLLISION_GROUP_NONE, &tr );

	if ( tr.DidHitWorld() )
	{
		IMaterial *pMaterial = materials->FindMaterial( tr.surface.name, TEXTURE_GROUP_PRECACHED );
		if ( !IsErrorMaterial( pMaterial ) )
		{
			const char* shadername = pMaterial->GetShaderName();
			Msg("Material shader name: %s\n", shadername);
		}
		else
		{
			Msg("Could not get material shader name.\n");
		}
	}
	else
	{
		Msg("This command only supports world geometry.\n");
	}
}
void QuickRefreshEditorShader()
{
	const char *nameLast = NULL;
	for ( MaterialHandle_t curMatHandle = g_pMaterialSystem->FirstMaterial();
		curMatHandle != g_pMaterialSystem->InvalidMaterial();
		curMatHandle = g_pMaterialSystem->NextMaterial( curMatHandle ) )
	{
		IMaterial *pMat = g_pMaterialSystem->GetMaterial( curMatHandle );
		if ( IsErrorMaterial( pMat ) )
			continue;

		//bool bSanityTest = false;
		//IMaterialVar *pVarBaseTexture = pMat->FindVar( "$basetexture", &bSanityTest, false );
		//if ( !pVarBaseTexture || !bSanityTest )
		//	continue;
		if ( !pMat->ShaderParamCount() )
			continue;

		const char *n = pMat->GetName();

		if ( !n || (nameLast && !Q_strcmp( nameLast, n )) )
			continue;
		nameLast = n;

		const char *shaderName = pMat->GetShaderName();
		if ( !shaderName )
			continue;

		if ( !Q_stricmp( shaderName, "EDITOR_SHADER" ) )
		{
			pMat->Refresh();
			pMat->RecomputeStateSnapshots();
		}
	}
}
示例#3
0
const char *GetMaterialShaderName( MaterialSystemMaterial_t materialHandle )
{
	IMaterial *material = ( IMaterial * )materialHandle;
	return material->GetShaderName();
}