当前位置: 首页>>代码示例>>C++>>正文


C++ IMaterialVar::SetTextureValue方法代码示例

本文整理汇总了C++中IMaterialVar::SetTextureValue方法的典型用法代码示例。如果您正苦于以下问题:C++ IMaterialVar::SetTextureValue方法的具体用法?C++ IMaterialVar::SetTextureValue怎么用?C++ IMaterialVar::SetTextureValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMaterialVar的用法示例。


在下文中一共展示了IMaterialVar::SetTextureValue方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OverlayShowTexture

//-----------------------------------------------------------------------------
// Debugging aid to display a texture
//-----------------------------------------------------------------------------
static void OverlayShowTexture( const char* textureName, float scale )
{
	bool			foundVar;
	IMaterial		*pMaterial;
	IMaterialVar	*BaseTextureVar;
	ITexture		*pTex;
	float			x, y, w, h;

	// ___error is created in code in CMaterialSystem::CreateDebugMaterials()
	pMaterial = materials->FindMaterial( "___error", TEXTURE_GROUP_OTHER, true );
	BaseTextureVar = pMaterial->FindVar( "$basetexture", &foundVar, false );
	if (!foundVar)
		return;

	CMatRenderContextPtr pRenderContext( materials );

	if ( textureName && textureName[0] )
	{
		pTex = materials->FindTexture( textureName, TEXTURE_GROUP_OTHER, false );
		BaseTextureVar->SetTextureValue( pTex );

		w = pTex->GetActualWidth() * scale;
		h = pTex->GetActualHeight() * scale;
	}
	else
	{
		w = h = 64.0f * scale;
	}

	// Center relative to current viewport
	int nViewportX, nViewportY, nViewportWidth, nViewportHeight;
	pRenderContext->GetViewport( nViewportX, nViewportY, nViewportWidth, nViewportHeight );
	x = ( nViewportWidth - w ) * 0.5f;
	y = ( nViewportHeight - h ) * 0.5f;

	pRenderContext->Bind( pMaterial );
	IMesh* pMesh = pRenderContext->GetDynamicMesh( true );

	CMeshBuilder meshBuilder;
	meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
	meshBuilder.Position3f( x, y, 0.0f );
	meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
	meshBuilder.AdvanceVertex();
	meshBuilder.Position3f( x+w, y, 0.0f );
	meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
	meshBuilder.AdvanceVertex();
	meshBuilder.Position3f( x+w, y+h, 0.0f );
	meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
	meshBuilder.AdvanceVertex();
	meshBuilder.Position3f( x, y+h, 0.0f );
	meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
	meshBuilder.AdvanceVertex();
	meshBuilder.End();
	pMesh->Draw();
}
开发者ID:BenLubar,项目名称:SwarmDirector2,代码行数:58,代码来源:viewdebug.cpp

示例2: OverlayShowTexture

//-----------------------------------------------------------------------------
// Debugging aid to display a texture
//-----------------------------------------------------------------------------
static void OverlayShowTexture( const char* textureName, float scale )
{
	bool			foundVar;
	IMaterial		*pMaterial;
	IMaterialVar	*BaseTextureVar;
	ITexture		*pTex;
	float			x, y, w, h;

	// screen safe
	x = 32;
	y = 32;

	pMaterial = materials->FindMaterial( "___debug", TEXTURE_GROUP_OTHER, true );
	BaseTextureVar = pMaterial->FindVar( "$basetexture", &foundVar, false );
	if (!foundVar)
		return;

	CMatRenderContextPtr pRenderContext( materials );

	if ( textureName && textureName[0] )
	{
		pTex = materials->FindTexture( textureName, TEXTURE_GROUP_OTHER, false );
		BaseTextureVar->SetTextureValue( pTex );

		w = pTex->GetActualWidth() * scale;
		h = pTex->GetActualHeight() * scale;
	}
	else
	{
		w = h = 64.0f * scale;
	}

	pRenderContext->Bind( pMaterial );
	IMesh* pMesh = pRenderContext->GetDynamicMesh( true );

	CMeshBuilder meshBuilder;
	meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
	meshBuilder.Position3f( x, y, 0.0f );
	meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
	meshBuilder.AdvanceVertex();
	meshBuilder.Position3f( x+w, y, 0.0f );
	meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
	meshBuilder.AdvanceVertex();
	meshBuilder.Position3f( x+w, y+h, 0.0f );
	meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
	meshBuilder.AdvanceVertex();
	meshBuilder.Position3f( x, y+h, 0.0f );
	meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
	meshBuilder.AdvanceVertex();
	meshBuilder.End();
	pMesh->Draw();
}
开发者ID:AluminumKen,项目名称:hl2sb-src,代码行数:55,代码来源:viewdebug.cpp

示例3: TE_PlayerDecal

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : filter - 
//			delay - 
//			pos - 
//			player - 
//			entity - 
//-----------------------------------------------------------------------------
void TE_PlayerDecal( IRecipientFilter& filter, float delay,
	const Vector* pos, int player, int entity  )
{
	if ( cl_playerspraydisable.GetBool() )
		return;

	// No valid target?
	C_BaseEntity *ent = cl_entitylist->GetEnt( entity );
	if ( !ent )
		return;

	// Find player logo for shooter
	player_info_t info;
	engine->GetPlayerInfo( player, &info );

	// Make sure we've got the material for this player's logo
	char texname[ 512 ];
	IMaterial *logo = CreateTempMaterialForPlayerLogo( player, &info, texname, 512 );
	if ( !logo )
		return;

	ITexture *texture = materials->FindTexture( texname, TEXTURE_GROUP_DECAL );
	if ( IsErrorTexture( texture ) ) 
	{
		return; // not found 
	}

	// Update the texture used by the material if need be.
	bool bFound = false;
	IMaterialVar *pMatVar = logo->FindVar( "$basetexture", &bFound );
	if ( bFound && pMatVar )
	{
		if ( pMatVar->GetTextureValue() != texture )
		{
			pMatVar->SetTextureValue( texture );
			logo->RefreshPreservingMaterialVars();
		}
	}

	color32 rgbaColor = { 255, 255, 255, 255 };
	effects->PlayerDecalShoot( 
		logo, 
		(void *)player,
		entity, 
		ent->GetModel(), 
		ent->GetAbsOrigin(), 
		ent->GetAbsAngles(), 
		*pos, 
		0, 
		0,
		rgbaColor );
}
开发者ID:Au-heppa,项目名称:source-sdk-2013,代码行数:60,代码来源:c_te_playerdecal.cpp

示例4: OnBind

void CAccumBuffProxy::OnBind( void *pC_BaseEntity )
{
	AccumParams_t *pAccumParams = (AccumParams_t *) pC_BaseEntity;

	if( !m_pTexture0 || !m_pTexture1 || !m_pAccumBuffWeights )
	{
		return;
	}

	m_pTexture0->SetTextureValue( pAccumParams->m_pTexture0 ); 
	m_pTexture1->SetTextureValue( pAccumParams->m_pTexture1 ); 

	// If we're just using this material to do a clear to black...
	if ( pAccumParams->m_bClear )
	{
		m_pAccumBuffWeights->SetVecValue( 0.0f, 0.0f, 0.0f, 0.0f );
	}
	else
	{
		m_pAccumBuffWeights->SetVecValue( pAccumParams->m_fSampleWeight, 1.0f - pAccumParams->m_fSampleWeight, 0.0f, 0.0f );
	}
}
开发者ID:1n73rf4c3,项目名称:source-sdk-2013,代码行数:22,代码来源:replayrenderer.cpp

示例5: OnBind

void CTextureProxy::OnBind( void *pEntity )
{
	// Bail if no base variable
	if ( !m_pBaseTextureVar )
		return;

	char texture[128];

	if (Q_stricmp(m_szTextureType, "hometeamcrest") == 0 && GetGlobalTeam(TEAM_A)->HasCrest())
		Q_snprintf(texture, sizeof(texture), "%s/%s/teamcrest", TEAMKITS_PATH, GetGlobalTeam(TEAM_A)->GetFolderName());
	else if (Q_stricmp(m_szTextureType, "awayteamcrest") == 0 && GetGlobalTeam(TEAM_B)->HasCrest())
		Q_snprintf(texture, sizeof(texture), "%s/%s/teamcrest", TEAMKITS_PATH, GetGlobalTeam(TEAM_B)->GetFolderName());
	else
		Q_snprintf(texture, sizeof(texture), "%s", m_pDefaultTexture->GetName());

	m_pNewTexture = materials->FindTexture(texture, NULL, true);
		
	m_pBaseTextureVar->SetTextureValue(m_pNewTexture);

	GetMaterial()->RecomputeStateSnapshots();
}
开发者ID:Rahmstein,项目名称:IOS,代码行数:21,代码来源:ios_playertextureproxy.cpp

示例6: UpdateFullScreenDepthTexture

void UpdateFullScreenDepthTexture( void )
{
	if( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_b() )
		return;

	ITexture *pDepthTex = GetFullFrameDepthTexture();
	CMatRenderContextPtr pRenderContext( materials );

	if( IsX360() )
	{	
		pRenderContext->CopyRenderTargetToTextureEx( pDepthTex, -1, NULL, NULL );
	}
	else
	{
		pRenderContext->CopyRenderTargetToTextureEx( pDepthTex, 0, NULL, NULL );
	}

	pRenderContext->SetFullScreenDepthTextureValidityFlag( true );

	if( r_depthoverlay.GetBool() )
	{
		IMaterial *pMaterial = materials->FindMaterial( "debug/showz", TEXTURE_GROUP_OTHER, true );
		pMaterial->IncrementReferenceCount();
		IMaterialVar *BaseTextureVar = pMaterial->FindVar( "$basetexture", NULL, false );
		IMaterialVar *pDepthInAlpha = NULL;
		if( IsPC() )
		{
			pDepthInAlpha = pMaterial->FindVar( "$ALPHADEPTH", NULL, false );
			pDepthInAlpha->SetIntValue( 1 );
		}
		
		BaseTextureVar->SetTextureValue( pDepthTex );

		pRenderContext->OverrideDepthEnable( true, false ); //don't write to depth, or else we'll never see translucents
		pRenderContext->DrawScreenSpaceQuad( pMaterial );
		pRenderContext->OverrideDepthEnable( false, true );
		pMaterial->DecrementReferenceCount();
	}
}
开发者ID:TalonBraveInfo,项目名称:InvasionSource,代码行数:39,代码来源:view_scene.cpp

示例7: OnBind

void CPlayerLogoProxy::OnBind( void *pC_BaseEntity )
{
	// Decal's are bound with the player index as the passed in paramter
	int playerindex = (int)pC_BaseEntity;

	if ( playerindex <= 0 )
		return;

	if ( playerindex > gpGlobals->maxClients )
		return;

	if ( !m_pBaseTextureVar )
		return;

	// Find player
	player_info_t info;
	engine->GetPlayerInfo( playerindex, &info );

	if ( !info.customFiles[0] ) 
		return;

	// So we don't trash this too hard

	ITexture *texture = NULL;

	PlayerLogo logo;
	logo.crc = (unsigned int)info.customFiles[0];
	logo.texture = NULL;

	int lookup = m_Logos.Find( logo );
	if ( lookup == m_Logos.InvalidIndex() )
	{
		char crcfilename[ 512 ];
		char logohex[ 16 ];
		Q_binarytohex( (byte *)&info.customFiles[0], sizeof( info.customFiles[0] ), logohex, sizeof( logohex ) );

		Q_snprintf( crcfilename, sizeof( crcfilename ), "temp/%s", logohex );

		texture = materials->FindTexture( crcfilename, TEXTURE_GROUP_DECAL, false );
		if ( texture )
		{
			// Make sure it doesn't get flushed
			texture->IncrementReferenceCount();
			logo.texture = texture;
		}

		m_Logos.Insert( logo );
	}
	else
	{
		texture = m_Logos[ lookup ].texture;
	}

	if ( texture )
	{
		m_pBaseTextureVar->SetTextureValue( texture );
	}
	else if ( m_pDefaultTexture )
	{
		m_pBaseTextureVar->SetTextureValue( m_pDefaultTexture );
	}

	if ( ToolsEnabled() )
	{
		ToolFramework_RecordMaterialParams( GetMaterial() );
	}
}
开发者ID:Entropy-Soldier,项目名称:ges-legacy-code,代码行数:67,代码来源:proxyplayer.cpp

示例8: Render

//-----------------------------------------------------------------------------
// Purpose: Render the effect
//-----------------------------------------------------------------------------
void CStunEffect::Render( int x, int y, int w, int h )
{
	// Make sure we're ready to play this effect
	if ( m_flFinishTime < gpGlobals->curtime )
		return;

	IMaterial *pMaterial = materials->FindMaterial( "effects/stun", TEXTURE_GROUP_CLIENT_EFFECTS, true );
	if ( pMaterial == NULL )
		return;

	bool bResetBaseFrame = m_bUpdated;

	// Set ourselves to the proper rendermode
	materials->MatrixMode( MATERIAL_VIEW );
	materials->PushMatrix();
	materials->LoadIdentity();
	materials->MatrixMode( MATERIAL_PROJECTION );
	materials->PushMatrix();
	materials->LoadIdentity();

	// Get our current view
	if ( m_pStunTexture == NULL )
	{
		m_pStunTexture = GetPowerOfTwoFrameBufferTexture();
	}

	// Draw the texture if we're using it
	if ( m_pStunTexture != NULL )
	{
		bool foundVar;
		IMaterialVar* pBaseTextureVar = pMaterial->FindVar( "$basetexture", &foundVar, false );

		if ( bResetBaseFrame )
		{
			// Save off this pass
			Rect_t srcRect;
			srcRect.x = x;
			srcRect.y = y;
			srcRect.width = w;
			srcRect.height = h;
			pBaseTextureVar->SetTextureValue( m_pStunTexture );

			materials->CopyRenderTargetToTextureEx( m_pStunTexture, 0, &srcRect, NULL );
			materials->SetFrameBufferCopyTexture( m_pStunTexture );
			m_bUpdated = false;
		}

		byte overlaycolor[4] = { 255, 255, 255, 0 };

		float flEffectPerc = ( m_flFinishTime - gpGlobals->curtime ) / m_flDuration;
		overlaycolor[3] = (byte) (150.0f * flEffectPerc);

		render->ViewDrawFade( overlaycolor, pMaterial );

		float viewOffs = ( flEffectPerc * 32.0f ) * cos( gpGlobals->curtime * 10.0f * cos( gpGlobals->curtime * 2.0f ) );
		float vX = x + viewOffs;
		float vY = y;

		// just do one pass for dxlevel < 80.
		if (g_pMaterialSystemHardwareConfig->GetDXSupportLevel() >= 80)
		{
			materials->DrawScreenSpaceRectangle( pMaterial, vX, vY, w, h,
				0, 0, m_pStunTexture->GetActualWidth()-1, m_pStunTexture->GetActualHeight()-1, 
				m_pStunTexture->GetActualWidth(), m_pStunTexture->GetActualHeight() );

			render->ViewDrawFade( overlaycolor, pMaterial );

			materials->DrawScreenSpaceRectangle( pMaterial, x, y, w, h,
				0, 0, m_pStunTexture->GetActualWidth()-1, m_pStunTexture->GetActualHeight()-1, 
				m_pStunTexture->GetActualWidth(), m_pStunTexture->GetActualHeight() );
		}

		// Save off this pass
		Rect_t srcRect;
		srcRect.x = x;
		srcRect.y = y;
		srcRect.width = w;
		srcRect.height = h;
		pBaseTextureVar->SetTextureValue( m_pStunTexture );

		materials->CopyRenderTargetToTextureEx( m_pStunTexture, 0, &srcRect, NULL );
	}

	// Restore our state
	materials->MatrixMode( MATERIAL_VIEW );
	materials->PopMatrix();
	materials->MatrixMode( MATERIAL_PROJECTION );
	materials->PopMatrix();
}
开发者ID:paralin,项目名称:hl2sdk,代码行数:92,代码来源:episodic_screenspaceeffects.cpp

示例9: GetWaterRefractionTexture

//-----------------------------------------------------------------------------
// Purpose: Render the effect
//-----------------------------------------------------------------------------
void CEP1IntroEffect::Render( int x, int y, int w, int h )
{
	if ( ( m_flFinishTime == 0 ) || ( IsEnabled() == false ) )
		return;

	IMaterial *pMaterial = materials->FindMaterial( "effects/introblur", TEXTURE_GROUP_CLIENT_EFFECTS, true );
	if ( pMaterial == NULL )
		return;

	// Set ourselves to the proper rendermode
	materials->MatrixMode( MATERIAL_VIEW );
	materials->PushMatrix();
	materials->LoadIdentity();
	materials->MatrixMode( MATERIAL_PROJECTION );
	materials->PushMatrix();
	materials->LoadIdentity();

	// Get our current view
	if ( m_pStunTexture == NULL )
	{
		m_pStunTexture = GetWaterRefractionTexture();
	}

	// Draw the texture if we're using it
	if ( m_pStunTexture != NULL )
	{
		bool foundVar;
		IMaterialVar* pBaseTextureVar = pMaterial->FindVar( "$basetexture", &foundVar, false );

		if ( m_bUpdateView )
		{
			// Save off this pass
			Rect_t srcRect;
			srcRect.x = x;
			srcRect.y = y;
			srcRect.width = w;
			srcRect.height = h;
			pBaseTextureVar->SetTextureValue( m_pStunTexture );

			materials->CopyRenderTargetToTextureEx( m_pStunTexture, 0, &srcRect, NULL );
			materials->SetFrameBufferCopyTexture( m_pStunTexture );
			m_bUpdateView = false;
		}

		byte overlaycolor[4] = { 255, 255, 255, 0 };
		
		// Get our fade value depending on our fade duration
		overlaycolor[3] = GetFadeAlpha();

		// Disable overself if we're done fading out
		if ( m_bFadeOut && overlaycolor[3] == 0 )
		{
			// Takes effect next frame (we don't want to hose our matrix stacks here)
			g_pScreenSpaceEffects->DisableScreenSpaceEffect( "episodic_intro" );
			m_bUpdateView = true;
		}

		// Calculate some wavey noise to jitter the view by
		float vX = 2.0f * -fabs( cosf( gpGlobals->curtime ) * cosf( gpGlobals->curtime * 6.0 ) );
		float vY = 2.0f * cosf( gpGlobals->curtime ) * cosf( gpGlobals->curtime * 5.0 );

		// Scale percentage
		float flScalePerc = 0.02f + ( 0.01f * cosf( gpGlobals->curtime * 2.0f ) * cosf( gpGlobals->curtime * 0.5f ) );
		
		// Scaled offsets for the UVs (as texels)
		float flUOffset = ( m_pStunTexture->GetActualWidth() - 1 ) * flScalePerc * 0.5f;
		float flVOffset = ( m_pStunTexture->GetActualHeight() - 1 ) * flScalePerc * 0.5f;
		
		// New UVs with scaling offsets
		float flU1 = flUOffset;
		float flU2 = ( m_pStunTexture->GetActualWidth() - 1 ) - flUOffset;
		float flV1 = flVOffset;
		float flV2 = ( m_pStunTexture->GetActualHeight() - 1 ) - flVOffset;

		// Draw the "zoomed" overlay
		materials->DrawScreenSpaceRectangle( pMaterial, vX, vY, w, h,
			flU1, flV1, 
			flU2, flV2, 
			m_pStunTexture->GetActualWidth(), m_pStunTexture->GetActualHeight() );

		render->ViewDrawFade( overlaycolor, pMaterial );

		// Save off this pass
		Rect_t srcRect;
		srcRect.x = x;
		srcRect.y = y;
		srcRect.width = w;
		srcRect.height = h;
		pBaseTextureVar->SetTextureValue( m_pStunTexture );

		materials->CopyRenderTargetToTextureEx( m_pStunTexture, 0, &srcRect, NULL );
	}

	// Restore our state
	materials->MatrixMode( MATERIAL_VIEW );
	materials->PopMatrix();
	materials->MatrixMode( MATERIAL_PROJECTION );
//.........这里部分代码省略.........
开发者ID:paralin,项目名称:hl2sdk,代码行数:101,代码来源:episodic_screenspaceeffects.cpp

示例10: DoMotionBlur


//.........这里部分代码省略.........

	// Set the camera up so we can draw the overlay
	int oldX, oldY, oldW, oldH;
	pRenderContext->GetViewport( oldX, oldY, oldW, oldH );

	pRenderContext->MatrixMode( MATERIAL_PROJECTION );
	pRenderContext->PushMatrix();
	pRenderContext->LoadIdentity();

	pRenderContext->MatrixMode( MATERIAL_VIEW );
	pRenderContext->PushMatrix();
	pRenderContext->LoadIdentity();

	// set our blur parameters, based on convars or the poison duration
	float add_alpha = asw_motionblur_addalpha.GetFloat();
	float blur_time = asw_motionblur_time.GetFloat();
	float draw_alpha = asw_motionblur_drawalpha.GetFloat();
	if (g_fMarinePoisonDuration > 0)
	{		
		if (g_fMarinePoisonDuration < 1.0f)
		{
			draw_alpha = g_fMarinePoisonDuration;
			add_alpha = 0.3f;
		}
		else
		{
			draw_alpha = 1.0f;
			float over_time = g_fMarinePoisonDuration - 1.0f;
			over_time = -MIN(4.0f, over_time);
			// map 0 to -4, to 0.3 to 0.05
			add_alpha = (over_time + 4) * 0.0625 + 0.05f;
		}
		blur_time = 0.05f;
	}
	if (!g_bBlurredLastTime)
		add_alpha = 1.0f;	// add the whole buffer if this is the first time we're blurring after a while, so we don't end up with images from ages ago

	if ( fNextDrawTime - gpGlobals->curtime > 1.0f)
	{
		fNextDrawTime = 0.0f;
	}

	if( gpGlobals->curtime >= fNextDrawTime ) 
	{
		UpdateScreenEffectTexture( 0, view.x, view.y, view.width, view.height );

		// Set the alpha to whatever our console variable is
		mv = pMatScreen->FindVar( "$alpha", &found, false );
		if (found)
		{
			if ( fNextDrawTime == 0 )
			{
				mv->SetFloatValue( 1.0f );
			}
			else
			{
				mv->SetFloatValue( add_alpha );
			}
		}

		pRenderContext->SetRenderTarget( pMotionBlur );
		pRenderContext->DrawScreenSpaceQuad( pMatScreen );

		// Set the next draw time according to the convar
		fNextDrawTime = gpGlobals->curtime + blur_time;
	}

	// Set the alpha
	mv = pMatScreen->FindVar( "$alpha", &found, false );
	if (found)
	{
		mv->SetFloatValue( draw_alpha );
	}

	// Set the texture to our buffer
	mv = pMatScreen->FindVar( "$basetexture", &found, false );
	if (found)
	{
		pOriginalTexture = mv->GetTextureValue();
		mv->SetTextureValue( pMotionBlur );
	}

	// Pretend we were never here, set everything back
	pRenderContext->SetRenderTarget( pOriginalRenderTarget );
	pRenderContext->DrawScreenSpaceQuad( pMatScreen );

	// Set our texture back to _rt_FullFrameFB
	if (found)
	{
		mv->SetTextureValue( pOriginalTexture );
	}

	pRenderContext->DepthRange( 0.0f, 1.0f );
	pRenderContext->MatrixMode( MATERIAL_PROJECTION );
	pRenderContext->PopMatrix();
	pRenderContext->MatrixMode( MATERIAL_VIEW );
	pRenderContext->PopMatrix();

	g_bBlurredLastTime = true;
}
开发者ID:Nightgunner5,项目名称:Jastian-Summer,代码行数:101,代码来源:asw_view_scene.cpp

示例11: R_StudioSetupSkinAndLighting

IMaterial* CStudioRender::R_StudioSetupSkinAndLighting( IMatRenderContext *pRenderContext, int index, IMaterial **ppMaterials, int materialFlags,  
	void /*IClientRenderable*/ *pClientRenderable, ColorMeshInfo_t *pColorMeshes, StudioModelLighting_t &lighting )
{
	VPROF( "R_StudioSetupSkin" );
	IMaterial *pMaterial = NULL;
	bool bCheckForConVarDrawTranslucentSubModels = false;
	if( m_pRC->m_Config.bWireframe && !m_pRC->m_pForcedMaterial )
	{
		if ( m_pRC->m_Config.bDrawZBufferedWireframe )
			pMaterial = m_pMaterialMRMWireframeZBuffer;
		else
			pMaterial = m_pMaterialMRMWireframe;
	}
	else if( m_pRC->m_Config.bShowEnvCubemapOnly )
	{
		pMaterial = m_pMaterialModelEnvCubemap;
	}
	else
	{
		if ( !m_pRC->m_pForcedMaterial && ( m_pRC->m_nForcedMaterialType != OVERRIDE_DEPTH_WRITE ) )
		{
			pMaterial = ppMaterials[index];
			if ( !pMaterial )
			{
				Assert( 0 );
				return 0;
			}
		}
		else
		{
			materialFlags = 0;
			pMaterial = m_pRC->m_pForcedMaterial;
			if (m_pRC->m_nForcedMaterialType == OVERRIDE_BUILD_SHADOWS)
			{
				// Connect the original material up to the shadow building material
				// Also bind the original material so its proxies are in the correct state
				static unsigned int translucentCache = 0;
				IMaterialVar* pOriginalMaterialVar = pMaterial->FindVarFast( "$translucent_material", &translucentCache );
				Assert( pOriginalMaterialVar );
				IMaterial *pOriginalMaterial = ppMaterials[index];
				if ( pOriginalMaterial )
				{
					// Disable any alpha modulation on the original material that was left over from when it was last rendered
					pOriginalMaterial->AlphaModulate( 1.0f );
					pRenderContext->Bind( pOriginalMaterial, pClientRenderable );
					if ( pOriginalMaterial->IsTranslucent() || pOriginalMaterial->IsAlphaTested() )
					{
						pOriginalMaterialVar->SetMaterialValue( pOriginalMaterial );
					}
					else
					{
						pOriginalMaterialVar->SetMaterialValue( NULL );
					}
				}
				else
				{
					pOriginalMaterialVar->SetMaterialValue( NULL );
				}
			}
			else if( m_pRC->m_nForcedMaterialType == OVERRIDE_DEPTH_WRITE )
			{
				// Disable any alpha modulation on the original material that was left over from when it was last rendered
				ppMaterials[index]->AlphaModulate( 1.0f );

				// Bail if the material is still considered translucent after setting the AlphaModulate to 1.0
				if ( ppMaterials[index]->IsTranslucent() )
				{
					return NULL;
				}

				static unsigned int originalTextureVarCache = 0;
				IMaterialVar *pOriginalTextureVar = ppMaterials[index]->FindVarFast( "$basetexture", &originalTextureVarCache );

				// Select proper override material
				int nAlphaTest = (int) ( ppMaterials[index]->IsAlphaTested() && pOriginalTextureVar->IsTexture() ); // alpha tested base texture
				int nNoCull = (int) ppMaterials[index]->IsTwoSided();
				pMaterial = m_pDepthWrite[nAlphaTest][nNoCull];

				// If we're alpha tested, we should set up the texture variables from the original material
				if ( nAlphaTest != 0 )
				{
					static unsigned int originalTextureFrameVarCache = 0;
					IMaterialVar *pOriginalTextureFrameVar = ppMaterials[index]->FindVarFast( "$frame", &originalTextureFrameVarCache );
					static unsigned int originalAlphaRefCache = 0;
					IMaterialVar *pOriginalAlphaRefVar = ppMaterials[index]->FindVarFast( "$AlphaTestReference", &originalAlphaRefCache );

					static unsigned int textureVarCache = 0;
					IMaterialVar *pTextureVar = pMaterial->FindVarFast( "$basetexture", &textureVarCache );
					static unsigned int textureFrameVarCache = 0;
					IMaterialVar *pTextureFrameVar = pMaterial->FindVarFast( "$frame", &textureFrameVarCache );
					static unsigned int alphaRefCache = 0;
					IMaterialVar *pAlphaRefVar = pMaterial->FindVarFast( "$AlphaTestReference", &alphaRefCache );

					if ( pOriginalTextureVar->IsTexture() ) // If $basetexture is defined
					{
						if( pTextureVar && pOriginalTextureVar )
						{
							pTextureVar->SetTextureValue( pOriginalTextureVar->GetTextureValue() );
						}

//.........这里部分代码省略.........
开发者ID:Axitonium,项目名称:SourceEngine2007,代码行数:101,代码来源:r_studio.cpp

示例12: DoObjectMotionBlur

void ClientModeSDK::DoObjectMotionBlur( const CViewSetup *pSetup )
{
    if ( g_ObjectMotionBlurManager.GetDrawableObjectCount() <= 0 )
        return;

    CMatRenderContextPtr pRenderContext( materials );

    ITexture *pFullFrameFB1 = materials->FindTexture( "_rt_FullFrameFB1", TEXTURE_GROUP_RENDER_TARGET );

    //
    // Render Velocities into a full-frame FB1
    //
    IMaterial *pGlowColorMaterial = materials->FindMaterial( "dev/glow_color", TEXTURE_GROUP_OTHER, true );

    pRenderContext->PushRenderTargetAndViewport();
    pRenderContext->SetRenderTarget( pFullFrameFB1 );
    pRenderContext->Viewport( 0, 0, pSetup->width, pSetup->height );

    // Red and Green are x- and y- screen-space velocities biased and packed into the [0,1] range.
    // A value of 127 gets mapped to 0, a value of 0 gets mapped to -1, and a value of 255 gets mapped to 1.
    //
    // Blue is set to 1 within the object's bounds and 0 outside, and is used as a mask to ensure that
    // motion blur samples only pull from the core object itself and not surrounding pixels (even though
    // the area being blurred is larger than the core object).
    //
    // Alpha is not used
    pRenderContext->ClearColor4ub( 127, 127, 0, 0 );
    // Clear only color, not depth & stencil
    pRenderContext->ClearBuffers( true, false, false );

    // Save off state
    Vector vOrigColor;
    render->GetColorModulation( vOrigColor.Base() );

    // Use a solid-color unlit material to render velocity into the buffer
    g_pStudioRender->ForcedMaterialOverride( pGlowColorMaterial );
    g_ObjectMotionBlurManager.DrawObjects();
    g_pStudioRender->ForcedMaterialOverride( NULL );

    render->SetColorModulation( vOrigColor.Base() );

    pRenderContext->PopRenderTargetAndViewport();

    //
    // Render full-screen pass
    //
    IMaterial *pMotionBlurMaterial;
    IMaterialVar *pFBTextureVariable;
    IMaterialVar *pVelocityTextureVariable;
    bool bFound1 = false, bFound2 = false;

    // Make sure our render target of choice has the results of the engine post-process pass
    ITexture *pFullFrameFB = materials->FindTexture( "_rt_FullFrameFB", TEXTURE_GROUP_RENDER_TARGET );
    pRenderContext->CopyRenderTargetToTexture( pFullFrameFB );

    pMotionBlurMaterial = materials->FindMaterial( "effects/object_motion_blur", TEXTURE_GROUP_OTHER, true );
    pFBTextureVariable = pMotionBlurMaterial->FindVar( "$fb_texture", &bFound1, true );
    pVelocityTextureVariable = pMotionBlurMaterial->FindVar( "$velocity_texture", &bFound2, true );
    if ( bFound1 && bFound2 )
    {
        pFBTextureVariable->SetTextureValue( pFullFrameFB );

        pVelocityTextureVariable->SetTextureValue( pFullFrameFB1 );

        int nWidth, nHeight;
        pRenderContext->GetRenderTargetDimensions( nWidth, nHeight );

        pRenderContext->DrawScreenSpaceRectangle( pMotionBlurMaterial, 0, 0, nWidth, nHeight, 0.0f, 0.0f, nWidth - 1, nHeight - 1, nWidth, nHeight );
    }
}
开发者ID:gamenew09,项目名称:SourceSDK2010,代码行数:70,代码来源:clientmode_sdk.cpp

示例13: TE_PlayerDecal

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : filter - 
//			delay - 
//			pos - 
//			player - 
//			entity - 
//-----------------------------------------------------------------------------
void TE_PlayerDecal( IRecipientFilter& filter, float delay,
	const Vector* pos, int player, int entity  )
{
	if ( cl_playerspraydisable.GetBool() )
		return;

	// No valid target?
	C_BaseEntity *ent = cl_entitylist->GetEnt( entity );
	if ( !ent )
		return;

	// Find player logo for shooter
	player_info_t info;
	engine->GetPlayerInfo( player, &info );

	// Doesn't have a logo
	 if ( !info.customFiles[0] )	
		return;

	IMaterial *logo = materials->FindMaterial( VarArgs("decals/playerlogo%2.2d", player), TEXTURE_GROUP_DECAL );
	if ( IsErrorMaterial( logo ) )
		return;

	char logohex[ 16 ];
	Q_binarytohex( (byte *)&info.customFiles[0], sizeof( info.customFiles[0] ), logohex, sizeof( logohex ) );

	// See if logo has been downloaded.
	char texname[ 512 ];
	Q_snprintf( texname, sizeof( texname ), "temp/%s", logohex );
	char fulltexname[ 512 ];
	Q_snprintf( fulltexname, sizeof( fulltexname ), "materials/temp/%s.vtf", logohex );

	if ( !filesystem->FileExists( fulltexname ) )
	{
		char custname[ 512 ];
		Q_snprintf( custname, sizeof( custname ), "downloads/%s.dat", logohex );
		// it may have been downloaded but not copied under materials folder
		if ( !filesystem->FileExists( custname ) )
			return; // not downloaded yet

		// copy from download folder to materials/temp folder
		// this is done since material system can access only materials/*.vtf files

		if ( !engine->CopyFile( custname, fulltexname) )
			return;
	}

	ITexture *texture = materials->FindTexture( texname, TEXTURE_GROUP_DECAL );
	if ( IsErrorTexture( texture ) ) 
	{
		return; // not found 
	}

	// Update the texture used by the material if need be.
	bool bFound = false;
	IMaterialVar *pMatVar = logo->FindVar( "$basetexture", &bFound );
	if ( bFound && pMatVar )
	{
		if ( pMatVar->GetTextureValue() != texture )
		{
			pMatVar->SetTextureValue( texture );
			logo->RefreshPreservingMaterialVars();
		}
	}

	color32 rgbaColor = { 255, 255, 255, 255 };
	effects->PlayerDecalShoot( 
		logo, 
		(void *)player,
		entity, 
		ent->GetModel(), 
		ent->GetAbsOrigin(), 
		ent->GetAbsAngles(), 
		*pos, 
		0, 
		0,
		rgbaColor );
}
开发者ID:0xFEEDC0DE64,项目名称:UltraGame,代码行数:86,代码来源:c_te_playerdecal.cpp


注:本文中的IMaterialVar::SetTextureValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。