bool CPlayerTextureProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues ) { #ifdef ALLPROXIESFAIL return false; #endif m_pMaterial = pMaterial; // Check for $basetexture variable m_pBaseTextureVar = pMaterial->FindVar( "$basetexture", NULL ); if ( !m_pBaseTextureVar ) return false; // Set default texture and make sure its not an error texture m_pTexture = m_pBaseTextureVar->GetTextureValue(); if ( IsErrorTexture( m_pTexture ) ) return false; Q_strncpy(m_szTextureType, pKeyValues->GetString("type"), sizeof(m_szTextureType)); if (!Q_strcmp(m_szTextureType, "shirt") || !Q_strcmp(m_szTextureType, "keepershirt")) { m_pDetailTextureVar = pMaterial->FindVar("$detail", NULL); //m_pTextureRegen = new CProceduralRegenerator(); } return true; }
bool CCamoMaterialProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues ) { return false; // hack! Need to make sure that the TGA loader has a valid filesystem before trying // to load the camo pattern. #if 0 // set how big our instance data is. SetInstanceDataSize( sizeof( CamoInstanceData_t ) ); #endif // remember what material we belong to. m_pMaterial = pMaterial; // get pointers to material vars. bool found; m_pCamoTextureVar = m_pMaterial->FindVar( "$baseTexture", &found ); if( !found ) { m_pCamoTextureVar = NULL; return false; } ITexture *pCamoTexture = m_pCamoTextureVar->GetTextureValue(); if (pCamoTexture) pCamoTexture->SetTextureRegenerator( &m_TextureRegen ); // Need to get the palettized texture to create the procedural texture from // somewhere. m_pCamoPatternTextureVar = m_pMaterial->FindVar( "$camoPatternTexture", &found ); if( !found ) { m_pCamoTextureVar = NULL; return false; } IMaterialVar *subBoundingBoxMinVar, *subBoundingBoxMaxVar; subBoundingBoxMinVar = m_pMaterial->FindVar( "$camoBoundingBoxMin", &found, false ); if( !found ) { m_SubBoundingBoxMin = Vector( 0.0f, 0.0f, 0.0f ); } else { subBoundingBoxMinVar->GetVecValue( m_SubBoundingBoxMin.Base(), 3 ); } subBoundingBoxMaxVar = m_pMaterial->FindVar( "$camoBoundingBoxMax", &found, false ); if( !found ) { m_SubBoundingBoxMax = Vector( 1.0f, 1.0f, 1.0f ); } else { subBoundingBoxMaxVar->GetVecValue( m_SubBoundingBoxMax.Base(), 3 ); } LoadCamoPattern(); GenerateRandomPointsInNormalizedCube(); return true; }
void CBaseShader::BindVertexTexture( VertexTextureSampler_t vtSampler, int nTextureVar, int nFrame /* = 0 */) { Assert( !IsSnapshotting() ); IMaterialVar* pTextureVar = s_ppParams[nTextureVar]; if ( !pTextureVar ) return; GetShaderSystem()->BindVertexTexture( vtSampler, pTextureVar->GetTextureValue() ); }
ShaderAPITextureHandle_t CBaseShader::GetShaderAPITextureBindHandle( int nTextureVar, int nFrameVar, int nTextureChannel ) { Assert( !IsSnapshotting() ); Assert( nTextureVar != -1 ); Assert ( s_ppParams ); IMaterialVar* pTextureVar = s_ppParams[nTextureVar]; IMaterialVar* pFrameVar = (nFrameVar != -1) ? s_ppParams[nFrameVar] : NULL; int nFrame = pFrameVar ? pFrameVar->GetIntValue() : 0; return GetShaderSystem()->GetShaderAPITextureBindHandle( pTextureVar->GetTextureValue(), nFrame, nTextureChannel ); }
//----------------------------------------------------------------------------- // 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 ); }
void CBaseShader::BindTexture( Sampler_t sampler1, Sampler_t sampler2, int nTextureVar, int nFrameVar /* = -1 */ ) { Assert( !IsSnapshotting() ); Assert( nTextureVar != -1 ); Assert ( s_ppParams ); IMaterialVar* pTextureVar = s_ppParams[nTextureVar]; IMaterialVar* pFrameVar = (nFrameVar != -1) ? s_ppParams[nFrameVar] : NULL; if (pTextureVar) { int nFrame = pFrameVar ? pFrameVar->GetIntValue() : 0; if ( sampler2 == -1 ) { GetShaderSystem()->BindTexture( sampler1, pTextureVar->GetTextureValue(), nFrame ); } else { GetShaderSystem()->BindTexture( sampler1, sampler2, pTextureVar->GetTextureValue(), nFrame ); } } }
//----------------------------------------------------------------------------- // Called when the texture is bound... //----------------------------------------------------------------------------- void CCamoMaterialProxy::OnBind( C_BaseEntity *pEntity ) { if( !m_pCamoTextureVar ) { return; } m_pEnt = pEntity; ITexture *pCamoTexture = m_pCamoTextureVar->GetTextureValue(); pCamoTexture->Download(); // Mark it so it doesn't get regenerated on task switch m_pEnt = NULL; }
//----------------------------------------------------------------------------- // Binds a texture //----------------------------------------------------------------------------- void CBaseShader::BindTexture( TextureStage_t stage, int nTextureVar, int nFrameVar ) { Assert( !IsSnapshotting() ); Assert( nTextureVar != -1 ); Assert ( s_ppParams ); IMaterialVar* pTextureVar = s_ppParams[nTextureVar]; IMaterialVar* pFrameVar = (nFrameVar != -1) ? s_ppParams[nFrameVar] : NULL; if (pTextureVar) { int nFrame = pFrameVar ? pFrameVar->GetIntValue() : 0; GetShaderSystem()->BindTexture( stage, pTextureVar->GetTextureValue(), nFrame ); } }
void CPupilProxy::OnBind( C_BaseEntity *pBaseEntity ) { if (!pBaseEntity || !m_pAnimatedTextureVar ) return; if( m_pAnimatedTextureVar->GetType() != MATERIAL_VAR_TYPE_TEXTURE ) return; ITexture *pTexture = m_pAnimatedTextureVar->GetTextureValue(); int nFrameCount = pTexture->GetNumAnimationFrames(); // Compute the lighting at the eye position of the entity; use it to dialate the pupil Vector forward; pBaseEntity->GetVectors( &forward, NULL, NULL ); Vector eyePt = pBaseEntity->EyePosition(); Vector color; engine->ComputeLighting( eyePt, &forward, false, color ); // Compute the intensity... float flIntensity = ( 0.299f * color[0] + 0.587f * color[1] + 0.114f * color[2] ) * 0.5; flIntensity = clamp( flIntensity, 0, 1 ); float flLastIntensity = m_pLightingVar->GetFloatValue( ); if ( flIntensity > flLastIntensity ) { float flMaxChange = m_flPupilCloseRate.GetFloat() * gpGlobals->frametime; if ( flIntensity > (flMaxChange + flLastIntensity) ) { flIntensity = flLastIntensity + flMaxChange; } } else { float flMaxChange = m_flPupilOpenRate.GetFloat() * gpGlobals->frametime; if ( flIntensity < (flLastIntensity - flMaxChange) ) { flIntensity = flLastIntensity - flMaxChange; } } int nFrame = nFrameCount * flIntensity; nFrame = clamp( nFrame, 0, nFrameCount - 1 ); m_pAnimatedTextureFrameNumVar->SetIntValue( nFrame ); m_pLightingVar->SetFloatValue( flIntensity ); }
bool CTextureProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues ) { #ifdef ALLPROXIESFAIL return false; #endif // Check for $basetexture variable m_pBaseTextureVar = pMaterial->FindVar( "$basetexture", NULL ); if ( !m_pBaseTextureVar ) return false; // Set default texture and make sure its not an error texture m_pDefaultTexture = m_pBaseTextureVar->GetTextureValue(); if ( IsErrorTexture( m_pDefaultTexture ) ) return false; Q_strncpy(m_szTextureType, pKeyValues->GetString("type"), sizeof(m_szTextureType)); return true; }
bool CZZMaterialProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues ) { // ZZ return false; // hack! Need to make sure that the TGA loader has a valid filesystem before trying // to load the camo pattern. m_pMaterial = pMaterial; // get pointers to material vars. bool found; m_pTextureVar = pMaterial->FindVar( "$baseTexture", &found ); if( !found ) { m_pTextureVar = NULL; return false; } m_pTexture = m_pTextureVar->GetTextureValue(); if (m_pTexture) m_pTexture->SetTextureRegenerator( &m_TextureRegen ); return true; }
void CASWViewRender::DoMotionBlur( const CViewSetup &view ) { if ( asw_motionblur.GetInt() == 0 && g_fMarinePoisonDuration <= 0) { g_bBlurredLastTime = false; return; } static float fNextDrawTime = 0.0f; bool found; IMaterialVar* mv = NULL; IMaterial *pMatScreen = NULL; ITexture *pMotionBlur = NULL; ITexture *pOriginalTexture = NULL; // Get the front buffer material pMatScreen = materials->FindMaterial( "swarm/effects/frontbuffer", TEXTURE_GROUP_OTHER, true ); // Get our custom render target pMotionBlur = g_pASWRenderTargets->GetASWMotionBlurTexture(); // Store the current render target CMatRenderContextPtr pRenderContext( materials ); ITexture *pOriginalRenderTarget = pRenderContext->GetRenderTarget(); // 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; }
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() ); } if( pTextureFrameVar && pOriginalTextureFrameVar ) { pTextureFrameVar->SetIntValue( pOriginalTextureFrameVar->GetIntValue() ); } if( pAlphaRefVar && pOriginalAlphaRefVar ) { pAlphaRefVar->SetFloatValue( pOriginalAlphaRefVar->GetFloatValue() ); } } } } } // Set this bool to check after the bind below bCheckForConVarDrawTranslucentSubModels = true; if ( m_pRC->m_nForcedMaterialType != OVERRIDE_DEPTH_WRITE ) { // Try to set the alpha based on the blend pMaterial->AlphaModulate( m_pRC->m_AlphaMod ); // Try to set the color based on the colormod pMaterial->ColorModulate( m_pRC->m_ColorMod[0], m_pRC->m_ColorMod[1], m_pRC->m_ColorMod[2] ); } } lighting = R_StudioComputeLighting( pMaterial, materialFlags, pColorMeshes ); if ( lighting == LIGHTING_MOUTH ) { if ( !m_pRC->m_Config.bTeeth || !R_TeethAreVisible() ) return NULL; // skin it and light it, but only if we need to. if ( m_pRC->m_Config.m_bSupportsVertexAndPixelShaders ) { R_MouthSetupVertexShader( pMaterial ); } } pRenderContext->Bind( pMaterial, pClientRenderable ); if ( bCheckForConVarDrawTranslucentSubModels ) { bool translucent = pMaterial->IsTranslucent(); if (( m_bDrawTranslucentSubModels && !translucent ) || ( !m_bDrawTranslucentSubModels && translucent )) { m_bSkippedMeshes = true; return NULL; } } return pMaterial; }
//----------------------------------------------------------------------------- // 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 ); }