示例#1
0
IMaterial* GLGraphics::GetMaterial (const String& name, bool createIfMissing)
{
	IMaterial* mat = 0;

	if (name.IsValid())
	{
		mMaterials.Lock();
		{
			for (uint i = 0; i < mMaterials.GetSize(); ++i)
			{
				mat = mMaterials[i];

				if (mat != 0 && mat->GetName() == name)
				{
					mMaterials.Unlock();
					return mat;
				}
			}

			if (createIfMissing)
			{
				GLMaterial* glMat = new GLMaterial(name);
				glMat->_SetGraphics(this);
				mMaterials.Expand() = glMat;
				mat = glMat;
			}
			else mat = 0;
		}
		mMaterials.Unlock();
	}
	return mat;
}
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();
		}
	}
}
//-----------------------------------------------------------------------------
// Does the dirty deed
//-----------------------------------------------------------------------------
void CMaterialModifyProxy::OnBindFloatLerp( C_MaterialModifyControl *pControl )
{
	if ( !pControl )
		return;

	if ( pControl->HasNewAnimationCommands() )
	{
		pControl->SetAnimationStartTime( gpGlobals->curtime );
		pControl->ClearAnimationCommands();
	}

	// Read the data from the modify entity
	materialfloatlerpcommands_t sCommands;
	pControl->GetFloatLerpCommands( &sCommands );

	m_flStartValue = sCommands.flStartValue;
	m_flEndValue = sCommands.flEndValue;
	m_flTransitionTime = sCommands.flTransitionTime;
	m_flStartTime = pControl->GetAnimationStartTime();
	bool bFound;
	m_pMaterialVar = m_pMaterial->FindVar( pControl->GetMaterialVariableName(), &bFound, false );

	if( bFound )
	{
		float currentValue;
		if( m_flTransitionTime > 0.0f )
		{
			currentValue = m_flStartValue + ( m_flEndValue - m_flStartValue ) * clamp( ( ( gpGlobals->curtime - m_flStartTime ) / m_flTransitionTime ), 0.0f, 1.0f );
		}
		else
		{
			currentValue = m_flEndValue;
		}

		if( debug_materialmodifycontrol_client.GetBool() && Q_stristr( m_pMaterial->GetName(), "faceandhair" ) && Q_stristr( m_pMaterialVar->GetName(), "warp" ) )
		{
			static int count = 0;
			DevMsg( 1, "CMaterialFloatLerpProxy::OnBind \"%s\" %s=%f %d\n", m_pMaterial->GetName(), m_pMaterialVar->GetName(), currentValue, count++ );
		}
		m_pMaterialVar->SetFloatValue( currentValue );
	}
}
void CBodyDestrutibilityInstance::ReplaceMaterial( IEntity& characterEntity, ICharacterInstance& characterInstance, IMaterial& replacementMaterial )
{
	IMaterial* pCurrentMaterial = characterInstance.GetIMaterial();
	if ((pCurrentMaterial != NULL) && stricmp(pCurrentMaterial->GetName(), replacementMaterial.GetName()))
	{
		characterEntity.SetSlotMaterial(0, &replacementMaterial);
	}

	const bool storeOriginalReplacementMaterials = m_originalMaterials.empty();

	IAttachmentManager *pAttachmentManager = characterInstance.GetIAttachmentManager();
	CRY_ASSERT(pAttachmentManager);

	const int attachmentCount = pAttachmentManager->GetAttachmentCount();
	for (int attachmentIdx = 0; attachmentIdx < attachmentCount; ++attachmentIdx)
	{
		IAttachmentObject *pAttachmentObject = pAttachmentManager->GetInterfaceByIndex(attachmentIdx)->GetIAttachmentObject();
		if (pAttachmentObject)
		{
			IMaterial* pAttachMaterial = (IMaterial*)pAttachmentObject->GetBaseMaterial();
			if ((pAttachMaterial != NULL) && stricmp(pAttachMaterial->GetName(), replacementMaterial.GetName()))
			{
				if (storeOriginalReplacementMaterials)
				{
					IMaterial* pOriginalReplacementMaterial = pAttachmentObject->GetReplacementMaterial();
					if(pOriginalReplacementMaterial != NULL)
					{
						pOriginalReplacementMaterial->AddRef();
						m_originalMaterials.push_back(TAttachmentMaterialPair((uint32)attachmentIdx, pOriginalReplacementMaterial));
					}
				}

				pAttachmentObject->SetReplacementMaterial(&replacementMaterial);
			}
		}

	}
}
bool CClientState::ProcessBSPDecal( SVC_BSPDecal *msg )
{
	model_t	* model;

	if ( msg->m_nEntityIndex )
	{
		model = GetModel( msg->m_nModelIndex );
	}
	else
	{
		model = host_state.worldmodel;
		if ( !model )
		{
			Warning( "ProcessBSPDecal:  Trying to project on world before host_state.worldmodel is set!!!\n" );
		}
	}

	if ( model == NULL )
	{
		IMaterial *mat = Draw_DecalMaterial( msg->m_nDecalTextureIndex );
		char const *matname = "???";
		if ( mat )
		{
			matname = mat->GetName();
		}

		Warning( "Warning! Static BSP decal (%s), on NULL model index %i for entity index %i.\n", 
			matname,
			msg->m_nModelIndex, 
			msg->m_nEntityIndex );
		return true;
	}

	if (r_decals.GetInt())
	{
		g_pEfx->DecalShoot( 
			msg->m_nDecalTextureIndex, 
			msg->m_nEntityIndex, 
			model, 
			vec3_origin, 
			vec3_angle,
			msg->m_Pos, 
			NULL, 
			msg->m_bLowPriority ? 0 : FDECAL_PERMANENT );
	}

	return true;
}
示例#6
0
void Visuals::Misc::ColorModulateSkybox()

{
	if (g_Options.ColorSkybox)
	{
		for (MaterialHandle_t i = g_MatSystem->FirstMaterial(); i != g_MatSystem->InvalidMaterial(); i = g_MatSystem->NextMaterial(i))
		{
			IMaterial *pMaterial = g_MatSystem->GetMaterial(i);

			if (!pMaterial)
				continue;

			const char* group = pMaterial->GetTextureGroupName();
			const char* name = pMaterial->GetName();
			if (strstr(pMaterial->GetTextureGroupName(), "SkyBox textures"))
			{
				switch (g_Options.SkyColor1)
				{
				case 0:
					pMaterial->ColorModulate(1, 1, 1);
					break;
				case 1:
					pMaterial->ColorModulate(0.77, 0.02, 0.77);
					break;
				case 2:
					pMaterial->ColorModulate(0.77, 0.02, 0.02);
					break;
				case 3:
					pMaterial->ColorModulate(0.02, 0.02, 0.77);
					break;
				case 4:
					pMaterial->ColorModulate(0.02, 0.77, 0.02);
					break;
				}
			}

		}
	}
}
void CDoorPanelBehavior::DeinitFlashResources( CDoorPanel& doorPanel )
{
	if (m_pFlashObjectRoot)
	{
		SAFE_RELEASE(m_pFlashObjectRoot);

		if (doorPanel.m_sharingMaterialEntity == 0)
		{
			IEntity* pEntity = doorPanel.GetEntity();

			IEntityRenderProxy* pRenderProxy = static_cast<IEntityRenderProxy*>(pEntity->GetProxy(ENTITY_PROXY_RENDER));
			if (pRenderProxy)
			{
				IMaterial* pMaterial = pRenderProxy->GetRenderMaterial(DOOR_PANEL_MODEL_NORMAL_SLOT);
				if (pMaterial)
				{
					IFlashPlayer* pFlashPlayer = CHUDUtils::GetFlashPlayerFromMaterialIncludingSubMaterials(pMaterial, true);
					if (pFlashPlayer)
					{
						pFlashPlayer->SetFSCommandHandler(NULL);

						pFlashPlayer->Release();
					}

					CDoorPanelBehavior::DecrementNumUniqueFlashInstances(pMaterial->GetName());
					doorPanel.NotifyScreenSharingEvent(eDoorPanelGameObjectEvent_StopShareScreen);
				}
			}

			if (m_pActualAnimatedMaterial)
			{
				m_pActualAnimatedMaterial->ActivateDynamicTextureSources(false);
			}
		}
	}
}
示例#8
0
//------------------------------------------------------------------------
bool CVehiclePartTread::Init(IVehicle* pVehicle, const CVehicleParams& table, IVehiclePart* parent, CVehicle::SPartInitInfo& initInfo, int partType)
{
	if (!CVehiclePartBase::Init(pVehicle, table, parent, initInfo, eVPT_Tread))
		return false;

	CVehicleParams subTable = table.findChild("Tread"); // Tread subtable
	if (!subTable)
		return false;

	string filename = subTable.getAttr("filename");
	if (filename.empty())
		return false;

	subTable.getAttr("uvSpeedMultiplier", m_uvSpeedMultiplier);

	if (table.haveAttr("component"))
	{
		if (CVehicleComponent* pComponent = static_cast<CVehicleComponent*>(m_pVehicle->GetComponent(table.getAttr("component"))))
			pComponent->AddPart(this);
	}

	m_slot = GetEntity()->LoadCharacter(m_slot, filename);

	m_pCharInstance = GetEntity()->GetCharacter(m_slot);
	if (!m_pCharInstance)
		return false;

	if (subTable.haveAttr("materialName"))
	{
		string materialName = subTable.getAttr("materialName");
		materialName.MakeLower();

		IMaterial* pMaterial = 0;
		const char* subMtlName = 0;
		int subMtlSlot = -1;

		// find tread material
		IEntityRenderProxy *pRenderProxy = (IEntityRenderProxy*)GetEntity()->GetProxy(ENTITY_PROXY_RENDER);
		if (pRenderProxy)
		{
			pMaterial = pRenderProxy->GetRenderMaterial(m_slot);
			if (pMaterial)
			{
				// if matname doesn't fit, look in submaterials
				if (string(pMaterial->GetName()).MakeLower().find(materialName) == string::npos)
				{
					for (int i=0; i < pMaterial->GetSubMtlCount(); ++i)
					{
						if (string(pMaterial->GetSubMtl(i)->GetName()).MakeLower().find(materialName) != string::npos)
						{
							subMtlName = pMaterial->GetSubMtl(i)->GetName();
							subMtlSlot = i;
							break;
						}
					}
				}
			}
		}

		if (pMaterial)
		{
			// clone
			IMaterial *pCloned = pMaterial->GetMaterialManager()->CloneMultiMaterial(pMaterial, subMtlName);
			if (pCloned)
			{
				pRenderProxy->SetSlotMaterial(m_slot, pCloned);
				pMaterial = pCloned;
				m_pMaterial = pMaterial;
			}

			if (subMtlSlot > -1)
				m_pShaderResources = pMaterial->GetShaderItem(subMtlSlot).m_pShaderResources;
			else
				m_pShaderResources = pMaterial->GetShaderItem().m_pShaderResources;
		}

		if (m_pShaderResources)
		{
			for (int i = 0; i < EFTT_MAX; ++i)
			{
				if (!m_pShaderResources->GetTexture(i))
					continue;

				SEfTexModificator& modif = *m_pShaderResources->GetTexture(i)->AddModificator();

				modif.SetMember("m_eMoveType[0]", 1.0f);  // ETMM_Fixed: u = m_OscRate[0] + sourceU

				modif.SetMember("m_OscRate[0]", 0.0f);
			}
		}
	}

	char wheelName[256];

	IDefaultSkeleton& rIDefaultSkeleton = m_pCharInstance->GetIDefaultSkeleton();
	for (int i=0; i<rIDefaultSkeleton.GetJointCount(); ++i)
	{
		const char* boneName = rIDefaultSkeleton.GetJointNameByID(i);
		if (0 != boneName)
		{
			// extract wheel name
			const size_t len = strcspn(boneName, "_");
			if (len < strlen(boneName) && len < sizeof(wheelName))
			{
				cry_strcpy(wheelName, boneName, len);

				CVehiclePartSubPartWheel* pWheel = (CVehiclePartSubPartWheel*)m_pVehicle->GetPart(wheelName);
				if (pWheel)
				{
					SWheelInfo wheelInfo;
					wheelInfo.slot = pWheel->m_slot;
					wheelInfo.jointId = i;
					wheelInfo.pWheel = pWheel;
					m_wheels.push_back(wheelInfo);

					m_lastWheelIndex = pWheel->GetWheelIndex();
				}
			}
		}
	}

	m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);

	m_state = eVGS_Default;
	return true;
}