void HSV_Select_SV::Paint() { surface()->DrawSetTexture(m_iMat); surface()->DrawSetColor(Color(255, 255, 255, 255)); int x, y, sx, sy; GetBounds(x, y, sx, sy); Vertex_t points[4]; points[0].m_TexCoord.Init(0, 0); points[1].m_TexCoord.Init(1, 0); points[2].m_TexCoord.Init(1, 1); points[3].m_TexCoord.Init(0, 1); IMaterial *pMatColorpicker = materials->FindMaterial("vgui/colorpicker", TEXTURE_GROUP_OTHER); if (IsErrorMaterial(pMatColorpicker)) return; bool bFound = false; IMaterialVar *pVar_00 = pMatColorpicker->FindVar("$COLOR_00", &bFound); IMaterialVar *pVar_10 = pMatColorpicker->FindVar("$COLOR_10", &bFound); IMaterialVar *pVar_11 = pMatColorpicker->FindVar("$COLOR_11", &bFound); IMaterialVar *pVar_01 = pMatColorpicker->FindVar("$COLOR_01", &bFound); if (!bFound) return; Vector col; HSV2RGB(m_flH, 1, 1, col); pVar_00->SetVecValue(1, 1, 1); pVar_10->SetVecValue(col.Base(), 3); pVar_11->SetVecValue(0, 0, 0); pVar_01->SetVecValue(0, 0, 0); surface()->DrawTexturedRect(0, 0, sx, sy); }
//------------------------------------------------------------------------------ // Purpose : Create leak effect if material requests it // Input : // Output : //------------------------------------------------------------------------------ void LeakEffect( trace_t &tr ) { Vector diffuseColor, baseColor; Vector vTraceDir = (tr.endpos - tr.startpos); VectorNormalize(vTraceDir); Vector vTraceStart = tr.endpos - 0.1*vTraceDir; Vector vTraceEnd = tr.endpos + 0.1*vTraceDir; IMaterial* pTraceMaterial = engine->TraceLineMaterialAndLighting( vTraceStart, vTraceEnd, diffuseColor, baseColor ); if (!pTraceMaterial) return; bool found; IMaterialVar *pLeakVar = pTraceMaterial->FindVar( "$leakamount", &found, false ); if( !found ) return; C_Splash* pLeak = new C_Splash(); if (!pLeak) return; ClientEntityList().AddNonNetworkableEntity( pLeak->GetIClientUnknown() ); IMaterialVar* pLeakColorVar = pTraceMaterial->FindVar( "$leakcolor", &found ); if (found) { Vector color; pLeakColorVar->GetVecValue(color.Base(),3); pLeak->m_vStartColor = pLeak->m_vEndColor = color; } IMaterialVar* pLeakNoiseVar = pTraceMaterial->FindVar( "$leaknoise", &found ); if (found) { pLeak->m_flNoise = pLeakNoiseVar->GetFloatValue(); } IMaterialVar* pLeakForceVar = pTraceMaterial->FindVar( "$leakforce", &found ); if (found) { float flForce = pLeakForceVar->GetFloatValue(); pLeak->m_flSpeed = flForce; pLeak->m_flSpeedRange = pLeak->m_flNoise * flForce; } pLeak->m_flSpawnRate = pLeakVar->GetFloatValue();; pLeak->m_flParticleLifetime = 10; pLeak->m_flWidthMin = 1; pLeak->m_flWidthMax = 5; pLeak->SetLocalOrigin( tr.endpos ); QAngle angles; VectorAngles( tr.plane.normal, angles ); pLeak->SetLocalAngles( angles ); pLeak->Start(&g_ParticleMgr, NULL); pLeak->m_flStopEmitTime = gpGlobals->curtime+5.0; pLeak->SetNextClientThink(gpGlobals->curtime+20.0); }
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 HSV_Select_Hue::Paint() { surface()->DrawSetTexture(m_iMat); surface()->DrawSetColor(Color(255, 255, 255, 255)); int x, y, sx, sy; GetBounds(x, y, sx, sy); Vector rgbs[7]; for (int i = 0; i < 7; i++) HSV2RGB(i * 60.0f, 1, 1, rgbs[i]); Vertex_t points[4]; points[0].m_TexCoord.Init(0, 0); points[1].m_TexCoord.Init(1, 0); points[2].m_TexCoord.Init(1, 1); points[3].m_TexCoord.Init(0, 1); IMaterial *pMatColorpicker = materials->FindMaterial("vgui/colorpicker", TEXTURE_GROUP_OTHER); if (IsErrorMaterial(pMatColorpicker)) return; bool bFound = false; IMaterialVar *pVar_00 = pMatColorpicker->FindVar("$COLOR_00", &bFound); IMaterialVar *pVar_10 = pMatColorpicker->FindVar("$COLOR_10", &bFound); IMaterialVar *pVar_11 = pMatColorpicker->FindVar("$COLOR_11", &bFound); IMaterialVar *pVar_01 = pMatColorpicker->FindVar("$COLOR_01", &bFound); if (!bFound) return; int delta_y = sy / 6; int cur_pos_y = sy; for (int i = 0; i < 6; i++) { if (i == 5) delta_y = cur_pos_y; pVar_00->SetVecValue(rgbs[i + 1].Base(), 3); pVar_10->SetVecValue(rgbs[i + 1].Base(), 3); pVar_11->SetVecValue(rgbs[i].Base(), 3); pVar_01->SetVecValue(rgbs[i].Base(), 3); points[0].m_Position.Init(0, cur_pos_y - delta_y); points[1].m_Position.Init(sx, cur_pos_y - delta_y); points[2].m_Position.Init(sx, cur_pos_y); points[3].m_Position.Init(0, cur_pos_y); surface()->DrawTexturedPolygon(4, points); cur_pos_y -= delta_y; } }
//----------------------------------------------------------------------------- // Purpose: Updates and renders all effects //----------------------------------------------------------------------------- int C_HopwireExplosion::DrawModel( int flags ) { AddParticles(); #ifndef C17 CMatRenderContextPtr pRenderContext( materials ); pRenderContext->Flush(); UpdateRefractTexture(); IMaterial *pMat = materials->FindMaterial( "effects/strider_pinch_dudv", TEXTURE_GROUP_CLIENT_EFFECTS ); float refract = m_FXCoreAlpha.Interp( gpGlobals->curtime ); float scale = m_FXCoreScale.Interp( gpGlobals->curtime ); IMaterialVar *pVar = pMat->FindVar( "$refractamount", NULL ); pVar->SetFloatValue( refract ); pRenderContext->Bind( pMat, (IClientRenderable*)this ); float sin1 = sinf( gpGlobals->curtime * 10 ); float sin2 = sinf( gpGlobals->curtime ); float scaleY = ( sin1 * sin2 ) * 32.0f; float scaleX = (sin2 * sin2) * 32.0f; // FIXME: The ball needs to sort properly at all times static color32 white = {255,255,255,255}; DrawSpriteTangentSpace( GetRenderOrigin() + ( CurrentViewForward() * 128.0f ), scale+scaleX, scale+scaleY, white ); #endif return 1; }
void CASWHudCrosshair::DrawSniperScope( int x, int y ) { C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer(); if ( !pPlayer ) return; C_ASW_Marine *pMarine = pPlayer->GetMarine(); if ( !pMarine ) return; const int NUM_CIRCLE_POINTS = 40; static vgui::Vertex_t points[ NUM_CIRCLE_POINTS ]; float width = YRES( asw_sniper_scope_radius.GetFloat() ); float height = YRES( asw_sniper_scope_radius.GetFloat() ); for ( int i = 0; i < NUM_CIRCLE_POINTS; i++ ) { float flAngle = 2.0f * M_PI * ( (float) i / (float) NUM_CIRCLE_POINTS ); points[ i ].Init( Vector2D( x + width * cos( flAngle ), y + height * sin( flAngle ) ), Vector2D( 0.5f + 0.5f * cos( flAngle ), 0.5f + 0.5f * sin( flAngle ) ) ); } surface()->DrawSetColor( Color(255,255,255,255) ); surface()->DrawSetTexture( m_nSniperMagnifyTexture ); IMaterial *pMaterial = materials->FindMaterial( "effects/magnifyinglens", TEXTURE_GROUP_OTHER ); IMaterialVar *pMagnificationCenterVar = pMaterial->FindVar( "$magnifyCenter", NULL ); float flCenterX = ( ( float )x / ( float )ScreenWidth() ) - 0.5f; float flCenterY = ( ( float )y / ( float )ScreenHeight() ) - 0.5f; pMagnificationCenterVar->SetVecValue( flCenterX, flCenterY, 0, 0 ); vgui::surface()->DrawTexturedPolygon( NUM_CIRCLE_POINTS, points ); }
//----------------------------------------------------------------------------- // 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(); }
//----------------------------------------------------------------------------- // 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 ); }
//----------------------------------------------------------------------------- // 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(); }
//----------------------------------------------------------------------------- // Creates, destroys particles attached to an attachment //----------------------------------------------------------------------------- void C_EnvParticleScript::CreateParticle( const char *pAttachmentName, const char *pSpriteName ) { // Find the attachment int nAttachment = LookupAttachment( pAttachmentName ); if ( nAttachment <= 0 ) return; // Get the sprite materials PMaterialHandle hMat = m_ParticleEffect.FindOrAddMaterial( pSpriteName ); ParticleScriptParticle_t *pParticle = (ParticleScriptParticle_t*)m_ParticleEffect.AddParticle(sizeof(ParticleScriptParticle_t), hMat); if ( pParticle == NULL ) return; // Get the sprite size from the material's materialvars bool bFound = false; IMaterialVar *pMaterialVar = NULL; IMaterial *pMaterial = ParticleMgr()->PMaterialToIMaterial( hMat ); if ( pMaterial ) { pMaterialVar = pMaterial->FindVar( "$spritesize", &bFound, false ); } if ( bFound ) { pParticle->m_flSize = pMaterialVar->GetFloatValue(); } else { pParticle->m_flSize = 100.0f; } // Make sure the particle cull size reflects our particles if ( pParticle->m_flSize > m_flMaxParticleSize ) { m_flMaxParticleSize = pParticle->m_flSize; m_ParticleEffect.SetParticleCullRadius( m_flMaxParticleSize ); } // Place the particle on the attachment specified pParticle->m_nAttachment = nAttachment; QAngle vecAngles; GetAttachment( nAttachment, pParticle->m_Pos, vecAngles ); if ( m_flSequenceScale != 1.0f ) { pParticle->m_Pos -= GetAbsOrigin(); pParticle->m_Pos *= m_flSequenceScale; pParticle->m_Pos += GetAbsOrigin(); } }
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(); } }
const char *GetMaterialVar( MaterialSystemMaterial_t materialHandle, const char *propertyName ) { IMaterial *material = ( IMaterial * )materialHandle; IMaterialVar *var; bool found; var = material->FindVar( propertyName, &found, false ); if( found ) { return var->GetStringValue(); } else { return NULL; } }
//----------------------------------------------------------------------------- // Loads VTF files //----------------------------------------------------------------------------- static bool LoadSrcVTFFiles( IVTFTexture *pSrcVTFTextures[6], const char *pSkyboxMaterialBaseName, int *pUnionTextureFlags, bool bHDR ) { const char *facingName[6] = { "rt", "lf", "bk", "ft", "up", "dn" }; int i; for( i = 0; i < 6; i++ ) { char srcMaterialName[1024]; sprintf( srcMaterialName, "%s%s", pSkyboxMaterialBaseName, facingName[i] ); IMaterial *pSkyboxMaterial = g_pMaterialSystem->FindMaterial( srcMaterialName, "skybox" ); IMaterialVar *pSkyTextureVar = pSkyboxMaterial->FindVar( bHDR ? "$hdrbasetexture" : "$basetexture", NULL ); const char *vtfName = pSkyTextureVar->GetStringValue(); char srcVTFFileName[MAX_PATH]; Q_snprintf( srcVTFFileName, MAX_PATH, "materials/%s.vtf", vtfName ); CUtlBuffer buf; if( !g_pFullFileSystem->ReadFile( srcVTFFileName, NULL, buf ) ) return false; pSrcVTFTextures[i] = CreateVTFTexture(); if (!pSrcVTFTextures[i]->Unserialize(buf)) { Warning("*** Error unserializing skybox texture: %s\n", pSkyboxMaterialBaseName ); return false; } *pUnionTextureFlags |= pSrcVTFTextures[i]->Flags(); int flagsNoAlpha = pSrcVTFTextures[i]->Flags() & ~( TEXTUREFLAGS_EIGHTBITALPHA | TEXTUREFLAGS_ONEBITALPHA ); int flagsFirstNoAlpha = pSrcVTFTextures[0]->Flags() & ~( TEXTUREFLAGS_EIGHTBITALPHA | TEXTUREFLAGS_ONEBITALPHA ); if ( (pSrcVTFTextures[i]->Width() != pSrcVTFTextures[0]->Width()) || (pSrcVTFTextures[i]->Height() != pSrcVTFTextures[0]->Height()) || (flagsNoAlpha != flagsFirstNoAlpha) ) { Warning("*** Error: Skybox vtf files for %s weren't compiled with the same size texture and/or same flags!\n", pSkyboxMaterialBaseName ); return false; } if( bHDR ) { pSrcVTFTextures[i]->ConvertImageFormat( IMAGE_FORMAT_RGB323232F, false ); pSrcVTFTextures[i]->GenerateMipmaps(); pSrcVTFTextures[i]->ConvertImageFormat( IMAGE_FORMAT_RGBA16161616F, false ); } } return true; }
//----------------------------------------------------------------------------- // Purpose: Attach the jetpack bar to the main panel //----------------------------------------------------------------------------- void CHudEMP::Init( void ) { if ( !m_pEMPIcon ) { m_pEMPIcon = materials->FindMaterial( "Hud/emp/emp_damage", TEXTURE_GROUP_VGUI ); assert( m_pEMPIcon ); m_pEMPIcon->IncrementReferenceCount(); m_pFrameVar = m_pEMPIcon->FindVar( "$frame", NULL, false ); m_nNumFrames = m_pEMPIcon->GetNumAnimationFrames(); } SetPos( HUDEMP_LEFT, HUDEMP_TOP ); SetSize( HUDEMP_WIDTH, HUDEMP_HEIGHT ); vgui::Panel *pParent = GetClientModeNormal()->GetViewport(); SetParent(pParent); }
void GetMaterialReflectivity( MaterialSystemMaterial_t materialHandle, float *reflectivityVect ) { IMaterial *material = ( IMaterial * )materialHandle; const IMaterialVar *reflectivityVar; bool found; reflectivityVar = material->FindVar( "$reflectivity", &found, false ); if( !found ) { Vector tmp; material->GetReflectivity( tmp ); VectorCopy( tmp.Base(), reflectivityVect ); } else { reflectivityVar->GetVecValue( reflectivityVect, 3 ); } }
//------------------------------------------------------------------------------ // Purpose : // Input : // Output : //------------------------------------------------------------------------------ void CBreakableSurface::Spawn(void) { BaseClass::Spawn(); SetCollisionGroup( COLLISION_GROUP_BREAKABLE_GLASS ); m_bIsBroken = false; if (m_nQuadError == QUAD_ERR_MULT_FACES) { Warning("Rejecting func_breakablesurf. Has multiple faces that aren't NODRAW.\n"); UTIL_Remove(this); } else if (m_nQuadError == QUAD_ERR_NOT_QUAD) { Warning("Rejecting func_breakablesurf. Drawn face isn't a quad.\n"); UTIL_Remove(this); } int materialCount = modelinfo->GetModelMaterialCount( const_cast<model_t*>(GetModel()) ); if( materialCount != 1 ) { Warning( "Encountered func_breakablesurf that has a material applied to more than one surface!\n" ); UTIL_Remove(this); } // Get at the first material; even if there are more than one. IMaterial* pMaterial; modelinfo->GetModelMaterials( const_cast<model_t*>(GetModel()), 1, &pMaterial ); // The material should point to a cracked version of itself bool foundVar; IMaterialVar* pCrackName = pMaterial->FindVar( "$crackmaterial", &foundVar, false ); if (foundVar) { PrecacheMaterial( pCrackName->GetStringValue() ); } // Init the Panel bit vector to all true. ( no panes are broken ) int bitVecLength = MAX_NUM_PANELS * MAX_NUM_PANELS; for( int i=0;i<bitVecLength;i++ ) { m_RawPanelBitVec.Set( i, true ); } }
IMaterialVar *ShaderEditorInterface::GetPPEMaterialVarFast( ShaderEditVarToken &token, const char *pszPPEName, const char *pszNodeName, const char *pszVarName ) { if ( token == SHADEREDIT_MVAR_TOKEN_FAILED ) return NULL; if ( token <= m_iLastInvalidVarToken ) { int iEffectIndex = GetPPCache()->FindPostProcessingEffect( pszPPEName ); if ( iEffectIndex < 0 ) { token = SHADEREDIT_MVAR_TOKEN_FAILED; return NULL; } IMaterial *pMaterial = GetPPCache()->GetPostProcessingEffect( iEffectIndex )->FindMaterial( pszNodeName ); if ( pMaterial == NULL ) { token = SHADEREDIT_MVAR_TOKEN_FAILED; return NULL; } bool bFound = false; IMaterialVar *pVar = pMaterial->FindVar( pszVarName, &bFound ); if ( pVar == NULL || !bFound ) { token = SHADEREDIT_MVAR_TOKEN_FAILED; return NULL; } token = m_iNextValidVarToken++; m_cachedMVars.AddToTail( pVar ); return pVar; } int iLocalIndex = token - m_iLastInvalidVarToken - 1; Assert( iLocalIndex >= 0 && iLocalIndex < m_cachedMVars.Count() ); return m_cachedMVars[ iLocalIndex ]; }
//----------------------------------------------------------------------------- // 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 ); } }
//----------------------------------------------------------------------------- // Reloads all textures //----------------------------------------------------------------------------- void CTextureManager::ForceAllTexturesIntoHardware( void ) { if ( IsX360() ) return; IMaterial *pMaterial = MaterialSystem()->FindMaterial( "engine/preloadtexture", "texture preload" ); pMaterial = ((IMaterialInternal *)pMaterial)->GetRealTimeVersion(); //always work with the realtime material internally bool bFound; IMaterialVar *pBaseTextureVar = pMaterial->FindVar( "$basetexture", &bFound ); if( !bFound ) { return; } for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) { // Put the texture back onto the board ForceTextureIntoHardware( m_TextureList[i], pMaterial, pBaseTextureVar ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CMaterialModifyProxy::OnBindSetVar( C_MaterialModifyControl *pControl ) { IMaterial *pMaterial = pControl->GetMaterial(); if( !pMaterial ) { Assert( 0 ); return; } if ( pMaterial != m_pMaterial ) { // Warning( "\t%s!=%s\n", pMaterial->GetName(), m_pMaterial->GetName() ); return; } bool bFound; IMaterialVar *pMaterialVar = pMaterial->FindVar( pControl->GetMaterialVariableName(), &bFound, false ); if ( !bFound ) return; if( Q_strcmp( pControl->GetMaterialVariableValue(), "" ) ) { // const char *pMaterialName = m_pMaterial->GetName(); // const char *pMaterialVarName = pMaterialVar->GetName(); // const char *pMaterialVarValue = pControl->GetMaterialVariableValue(); // if( debug_materialmodifycontrol_client.GetBool() // && Q_stristr( m_pMaterial->GetName(), "faceandhair" ) // && Q_stristr( pMaterialVar->GetName(), "self" ) // ) // { // static int count = 0; // DevMsg( 1, "CMaterialModifyProxy::OnBindSetVar \"%s\" %s=%s %d pControl=0x%p\n", // m_pMaterial->GetName(), pMaterialVar->GetName(), pControl->GetMaterialVariableValue(), count++, pControl ); // } pMaterialVar->SetValueAutodetectType( pControl->GetMaterialVariableValue() ); } }
int C_NEORagdoll::DrawModel( int flags ) { C_NEOPlayer *pPlayer = dynamic_cast<C_NEOPlayer*>(m_hPlayer.Get()); if ( pPlayer && (pPlayer->IsLocalNEOPlayer() || pPlayer->m_bIsOnDeathScreen) ) return 0; if ( pPlayer->m_iVision == 3 ) // Thermal vision { IMaterial* matThermal = g_pMaterialSystem->FindMaterial( "dev/thermal", "Other textures" ); if ( g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_0() ) { bool found = false; IMaterialVar* matVar = matThermal->FindVar( "$eyevec", &found ); if ( found ) { Vector forward; pPlayer->GetVectors( &forward, nullptr, nullptr ); matVar->SetVecValue( forward.x, forward.y, forward.z ); } } modelrender->ForcedMaterialOverride( matThermal ); int result = InternalDrawModel( flags ); modelrender->ForcedMaterialOverride( nullptr ); return result; } return BaseClass::DrawModel( flags ); }
//----------------------------------------------------------------------------- // 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 ); }
//----------------------------------------------------------------------------- // 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(); }
//----------------------------------------------------------------------------- // 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 ); materials->PopMatrix(); }
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 ); } }
int C_NEOPlayer::DrawModel( int flags ) { C_NEOPlayer* localPlayer = C_NEOPlayer::GetLocalNEOPlayer(); int result = -1; if ( localPlayer ) { if ( GetTeamNumber() == localPlayer->GetTeamNumber() ) m_bUnknown = true; if ( m_iOldVision != 3 ) { if ( m_bUnknown2 ) { m_bUnknown2 = false; dlight_t* light = effects->CL_AllocDlight( LIGHT_INDEX_TE_DYNAMIC + index ); light->origin = GetAbsOrigin(); light->radius = 96.f; light->decay = 192.f; light->color.r = 64; light->color.g = 64; light->color.b = 255; light->color.exponent = 10; light->die = gpGlobals->curtime + 0.1f; return 0; } if ( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_0() ) return 0; UpdateRefractTexture(); IMaterial* thermopticMaterial = GetThermopticMaterial(); UpdateThermopticMaterial( thermopticMaterial, m_flUnknown ); modelrender->ForcedMaterialOverride( thermopticMaterial ); result = BaseClass::InternalDrawModel( flags ); modelrender->ForcedMaterialOverride( nullptr ); } else { if ( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_0() ) return BaseClass::DrawModel( flags ); IMaterial* matThermal = g_pMaterialSystem->FindMaterial( "dev/thermal", TEXTURE_GROUP_OTHER ); if ( IsErrorMaterial( matThermal ) ) { DevMsg( SPEW_MESSAGE, "F**k me...\n" ); // Their message, not mine kek BaseClass::DrawModel( flags ); } bool found = false; IMaterialVar* matVar = matThermal->FindVar( "$eyevec", &found ); if ( found ) { Vector forward; GetVectors( &forward, nullptr, nullptr ); matVar->SetVecValue( forward.x, forward.y, forward.z, 3.f ); } modelrender->ForcedMaterialOverride( matThermal ); result = BaseClass::InternalDrawModel( flags ); modelrender->ForcedMaterialOverride( nullptr ); } if ( m_iThermoptic == 1 ) { if ( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_0() ) return BaseClass::DrawModel( flags ); IMaterial* matMotion = g_pMaterialSystem->FindMaterial( "dev/motion", TEXTURE_GROUP_OTHER ); if ( IsErrorMaterial( matMotion ) ) { DevMsg( SPEW_MESSAGE, "F**k me...\n" ); BaseClass::DrawModel( flags ); } float velocity = localPlayer->GetLocalVelocity().Length() / 75.f; if ( velocity > 4.f ) velocity = 4.f; bool found = false; IMaterialVar* matVar = matMotion->FindVar( "$eyevec", &found ); if ( found ) { Vector forward; GetVectors( &forward, nullptr, nullptr ); matVar->SetVecValue( forward.x, forward.y, forward.z, velocity ); } modelrender->ForcedMaterialOverride( matMotion ); result = BaseClass::InternalDrawModel( flags ); modelrender->ForcedMaterialOverride( nullptr ); } if ( m_iVision == 3 ) // Thermal vision { if ( !g_pMaterialSystemHardwareConfig->SupportsPixelShaders_2_0() ) return BaseClass::DrawModel( flags ); IMaterial* matThermal = g_pMaterialSystem->FindMaterial( "dev/vm_thermal", "Other textures" ); if ( IsErrorMaterial( matThermal ) ) { DevMsg( SPEW_MESSAGE, "F**k me...\n" ); BaseClass::DrawModel( flags ); } bool found = false; IMaterialVar* matVar = matThermal->FindVar( "$eyevec", &found ); if ( found ) { Vector forward; GetVectors( &forward, nullptr, nullptr ); matVar->SetVecValue( forward.x, forward.y, forward.z, 3.f ); } modelrender->ForcedMaterialOverride( matThermal ); result = BaseClass::InternalDrawModel( flags ); modelrender->ForcedMaterialOverride( nullptr ); } if ( m_bUnknown2 ) m_bUnknown2 = false; if ( result >= 0 ) return result; } return BaseClass::DrawModel( flags ); }
//----------------------------------------------------------------------------- // Loads VTF files //----------------------------------------------------------------------------- static bool LoadSrcVTFFiles( IVTFTexture *pSrcVTFTextures[6], const char *pSkyboxMaterialBaseName, int *pUnionTextureFlags, bool bHDR ) { const char *facingName[6] = { "rt", "lf", "bk", "ft", "up", "dn" }; int i; for( i = 0; i < 6; i++ ) { char srcMaterialName[1024]; sprintf( srcMaterialName, "%s%s", pSkyboxMaterialBaseName, facingName[i] ); IMaterial *pSkyboxMaterial = g_pMaterialSystem->FindMaterial( srcMaterialName, "skybox" ); //IMaterialVar *pSkyTextureVar = pSkyboxMaterial->FindVar( bHDR ? "$hdrbasetexture" : "$basetexture", NULL ); //, bHDR ? false : true ); IMaterialVar *pSkyTextureVar = pSkyboxMaterial->FindVar( "$basetexture", NULL ); // Since we're setting it to black anyway, just use $basetexture for HDR const char *vtfName = pSkyTextureVar->GetStringValue(); char srcVTFFileName[MAX_PATH]; Q_snprintf( srcVTFFileName, MAX_PATH, "materials/%s.vtf", vtfName ); CUtlBuffer buf; if ( !g_pFullFileSystem->ReadFile( srcVTFFileName, NULL, buf ) ) { // Try looking for a compressed HDR texture if ( bHDR ) { /* // FIXME: We need a way to uncompress this format! bool bHDRCompressed = true; pSkyTextureVar = pSkyboxMaterial->FindVar( "$hdrcompressedTexture", NULL ); vtfName = pSkyTextureVar->GetStringValue(); Q_snprintf( srcVTFFileName, MAX_PATH, "materials/%s.vtf", vtfName ); if ( !g_pFullFileSystem->ReadFile( srcVTFFileName, NULL, buf ) ) */ { return false; } } else { return false; } } pSrcVTFTextures[i] = CreateVTFTexture(); if (!pSrcVTFTextures[i]->Unserialize(buf)) { Warning("*** Error unserializing skybox texture: %s\n", pSkyboxMaterialBaseName ); return false; } *pUnionTextureFlags |= pSrcVTFTextures[i]->Flags(); int flagsNoAlpha = pSrcVTFTextures[i]->Flags() & ~( TEXTUREFLAGS_EIGHTBITALPHA | TEXTUREFLAGS_ONEBITALPHA ); int flagsFirstNoAlpha = pSrcVTFTextures[0]->Flags() & ~( TEXTUREFLAGS_EIGHTBITALPHA | TEXTUREFLAGS_ONEBITALPHA ); // NOTE: texture[0] is a side texture that could be 1/2 height, so allow this and also allow 4x4 faces if ( ( ( pSrcVTFTextures[i]->Width() != pSrcVTFTextures[0]->Width() ) && ( pSrcVTFTextures[i]->Width() != 4 ) ) || ( ( pSrcVTFTextures[i]->Height() != pSrcVTFTextures[0]->Height() ) && ( pSrcVTFTextures[i]->Height() != pSrcVTFTextures[0]->Height()*2 ) && ( pSrcVTFTextures[i]->Height() != 4 ) ) || ( flagsNoAlpha != flagsFirstNoAlpha ) ) { Warning("*** Error: Skybox vtf files for %s weren't compiled with the same size texture and/or same flags!\n", pSkyboxMaterialBaseName ); return false; } if ( bHDR ) { pSrcVTFTextures[i]->ConvertImageFormat( IMAGE_FORMAT_RGB323232F, false ); pSrcVTFTextures[i]->GenerateMipmaps(); pSrcVTFTextures[i]->ConvertImageFormat( IMAGE_FORMAT_RGBA16161616F, false ); } } 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; }
void CGlowObjectManager::ApplyEntityGlowEffects( const CViewSetup *pSetup, int nSplitScreenSlot, CMatRenderContextPtr &pRenderContext, float flBloomScale, int x, int y, int w, int h ) { //=======================================================// // Render objects into stencil buffer // //=======================================================// // Set override shader to the same simple shader we use to render the glow models IMaterial *pMatGlowColor = materials->FindMaterial( "dev/glow_color", TEXTURE_GROUP_OTHER, true ); g_pStudioRender->ForcedMaterialOverride( pMatGlowColor ); ShaderStencilState_t stencilStateDisable; stencilStateDisable.m_bEnable = false; float flSavedBlend = render->GetBlend(); // Set alpha to 0 so we don't touch any color pixels render->SetBlend( 0.0f ); pRenderContext->OverrideDepthEnable( true, false ); int iNumGlowObjects = 0; for ( int i = 0; i < m_GlowObjectDefinitions.Count(); ++ i ) { if ( m_GlowObjectDefinitions[i].IsUnused() || !m_GlowObjectDefinitions[i].ShouldDraw( nSplitScreenSlot ) ) continue; if ( m_GlowObjectDefinitions[i].m_bRenderWhenOccluded || m_GlowObjectDefinitions[i].m_bRenderWhenUnoccluded ) { if ( m_GlowObjectDefinitions[i].m_bRenderWhenOccluded && m_GlowObjectDefinitions[i].m_bRenderWhenUnoccluded ) { ShaderStencilState_t stencilState; stencilState.m_bEnable = true; stencilState.m_nReferenceValue = 1; stencilState.m_CompareFunc = STENCILCOMPARISONFUNCTION_ALWAYS; stencilState.m_PassOp = STENCILOPERATION_REPLACE; stencilState.m_FailOp = STENCILOPERATION_KEEP; stencilState.m_ZFailOp = STENCILOPERATION_REPLACE; stencilState.SetStencilState( pRenderContext ); m_GlowObjectDefinitions[i].DrawModel(); } else if ( m_GlowObjectDefinitions[i].m_bRenderWhenOccluded ) { ShaderStencilState_t stencilState; stencilState.m_bEnable = true; stencilState.m_nReferenceValue = 1; stencilState.m_CompareFunc = STENCILCOMPARISONFUNCTION_ALWAYS; stencilState.m_PassOp = STENCILOPERATION_KEEP; stencilState.m_FailOp = STENCILOPERATION_KEEP; stencilState.m_ZFailOp = STENCILOPERATION_REPLACE; stencilState.SetStencilState( pRenderContext ); m_GlowObjectDefinitions[i].DrawModel(); } else if ( m_GlowObjectDefinitions[i].m_bRenderWhenUnoccluded ) { ShaderStencilState_t stencilState; stencilState.m_bEnable = true; stencilState.m_nReferenceValue = 2; stencilState.m_nTestMask = 0x1; stencilState.m_nWriteMask = 0x3; stencilState.m_CompareFunc = STENCILCOMPARISONFUNCTION_EQUAL; stencilState.m_PassOp = STENCILOPERATION_INCRSAT; stencilState.m_FailOp = STENCILOPERATION_KEEP; stencilState.m_ZFailOp = STENCILOPERATION_REPLACE; stencilState.SetStencilState( pRenderContext ); m_GlowObjectDefinitions[i].DrawModel(); } } iNumGlowObjects++; } // Need to do a 2nd pass to warm stencil for objects which are rendered only when occluded for ( int i = 0; i < m_GlowObjectDefinitions.Count(); ++ i ) { if ( m_GlowObjectDefinitions[i].IsUnused() || !m_GlowObjectDefinitions[i].ShouldDraw( nSplitScreenSlot ) ) continue; if ( m_GlowObjectDefinitions[i].m_bRenderWhenOccluded && !m_GlowObjectDefinitions[i].m_bRenderWhenUnoccluded ) { ShaderStencilState_t stencilState; stencilState.m_bEnable = true; stencilState.m_nReferenceValue = 2; stencilState.m_CompareFunc = STENCILCOMPARISONFUNCTION_ALWAYS; stencilState.m_PassOp = STENCILOPERATION_REPLACE; stencilState.m_FailOp = STENCILOPERATION_KEEP; stencilState.m_ZFailOp = STENCILOPERATION_KEEP; stencilState.SetStencilState( pRenderContext ); m_GlowObjectDefinitions[i].DrawModel(); } } pRenderContext->OverrideDepthEnable( false, false ); render->SetBlend( flSavedBlend ); stencilStateDisable.SetStencilState( pRenderContext ); g_pStudioRender->ForcedMaterialOverride( NULL ); // If there aren't any objects to glow, don't do all this other stuff // this fixes a bug where if there are glow objects in the list, but none of them are glowing, // the whole screen blooms. if ( iNumGlowObjects <= 0 ) return; //============================================= // Render the glow colors to _rt_FullFrameFB //============================================= { PIXEvent pixEvent( pRenderContext, "RenderGlowModels" ); RenderGlowModels( pSetup, nSplitScreenSlot, pRenderContext ); } // Get viewport int nSrcWidth = pSetup->width; int nSrcHeight = pSetup->height; int nViewportX, nViewportY, nViewportWidth, nViewportHeight; pRenderContext->GetViewport( nViewportX, nViewportY, nViewportWidth, nViewportHeight ); // Get material and texture pointers ITexture *pRtQuarterSize1 = materials->FindTexture( "_rt_SmallFB1", TEXTURE_GROUP_RENDER_TARGET ); { //=======================================================================================================// // At this point, pRtQuarterSize0 is filled with the fully colored glow around everything as solid glowy // // blobs. Now we need to stencil out the original objects by only writing pixels that have no // // stencil bits set in the range we care about. // //=======================================================================================================// IMaterial *pMatHaloAddToScreen = materials->FindMaterial( "dev/halo_add_to_screen", TEXTURE_GROUP_OTHER, true ); // Do not fade the glows out at all (weight = 1.0) IMaterialVar *pDimVar = pMatHaloAddToScreen->FindVar( "$C0_X", NULL ); pDimVar->SetFloatValue( 1.0f ); // Set stencil state ShaderStencilState_t stencilState; stencilState.m_bEnable = true; stencilState.m_nWriteMask = 0x0; // We're not changing stencil stencilState.m_nTestMask = 0xFF; stencilState.m_nReferenceValue = 0x0; stencilState.m_CompareFunc = STENCILCOMPARISONFUNCTION_EQUAL; stencilState.m_PassOp = STENCILOPERATION_KEEP; stencilState.m_FailOp = STENCILOPERATION_KEEP; stencilState.m_ZFailOp = STENCILOPERATION_KEEP; stencilState.SetStencilState( pRenderContext ); // Draw quad pRenderContext->DrawScreenSpaceRectangle( pMatHaloAddToScreen, 0, 0, nViewportWidth, nViewportHeight, 0.0f, -0.5f, nSrcWidth / 4 - 1, nSrcHeight / 4 - 1, pRtQuarterSize1->GetActualWidth(), pRtQuarterSize1->GetActualHeight() ); stencilStateDisable.SetStencilState( pRenderContext ); } }
int C_StriderFX::DrawModel( int ) { static color32 white = {255,255,255,255}; Vector params[STRIDERFX_PARAMETERS]; bool hasParam[STRIDERFX_PARAMETERS]; if ( !m_active ) return 1; C_BaseEntity *ent = cl_entitylist->GetEnt( m_entityIndex ); if ( ent ) { QAngle angles; ent->GetAttachment( m_attachment, m_worldPosition, angles ); } // This forces time to drive from the main clock instead of being integrated per-draw below // that way the effect moves on even when culled for visibility if ( m_limitHitTime > 0 && m_tMax > 0 ) { float dt = m_limitHitTime - gpGlobals->curtime; if ( dt < 0 ) { dt = 0; } // if the clock needs to move, update it. if ( m_tMax - dt > m_t ) { m_t = m_tMax - dt; m_beamEndPosition = m_worldPosition; } } else { // don't have enough info to derive the time, integrate current frame time m_t += gpGlobals->frametime; if ( m_tMax > 0 ) { m_t = clamp( m_t, 0, m_tMax ); m_beamEndPosition = m_worldPosition; } } float t = m_t; bool hasAny = false; memset( hasParam, 0, sizeof(hasParam) ); for ( int i = 0; i < STRIDERFX_PARAMETERS; i++ ) { hasParam[i] = g_StriderCannonEnvelope.m_parameters[i].Interp( params[i], t ); hasAny = hasAny || hasParam[i]; } pixelvis_queryparams_t gunParams; gunParams.Init(m_worldPosition, 4.0f); float gunFractionVisible = PixelVisibility_FractionVisible( gunParams, &m_queryHandleGun ); bool gunVisible = gunFractionVisible > 0.0f ? true : false; // draw the narrow beam if ( hasParam[STRIDERFX_NARROW_BEAM_COLOR] && hasParam[STRIDERFX_NARROW_BEAM_SIZE] ) { IMaterial *pMat = materials->FindMaterial( "sprites/bluelaser1", TEXTURE_GROUP_CLIENT_EFFECTS ); float width = NARROW_BEAM_WIDTH * params[STRIDERFX_NARROW_BEAM_SIZE].x; color32 color; float bright = params[STRIDERFX_NARROW_BEAM_COLOR].x; ScaleColor( color, white, bright ); Strider_DrawLine( m_beamEndPosition, m_targetPosition, width, pMat, color ); } // draw the wide beam if ( hasParam[STRIDERFX_WIDE_BEAM_COLOR] && hasParam[STRIDERFX_WIDE_BEAM_SIZE] ) { IMaterial *pMat = materials->FindMaterial( "effects/blueblacklargebeam", TEXTURE_GROUP_CLIENT_EFFECTS ); float width = WIDE_BEAM_WIDTH * params[STRIDERFX_WIDE_BEAM_SIZE].x; color32 color; float bright = params[STRIDERFX_WIDE_BEAM_COLOR].x; ScaleColor( color, white, bright ); Vector wideBeamEnd = m_beamEndPosition; if ( hasParam[STRIDERFX_WIDE_BEAM_LENGTH] ) { float amt = params[STRIDERFX_WIDE_BEAM_LENGTH].x; wideBeamEnd = m_beamEndPosition * amt + m_targetPosition * (1-amt); } Strider_DrawLine( wideBeamEnd, m_targetPosition, width, pMat, color ); } // after glow sprite bool updated = false; CMatRenderContextPtr pRenderContext( materials ); // warpy sprite bit if ( hasParam[STRIDERFX_WARP_SCALE] && !hasParam[STRIDERFX_BUBBLE_SIZE] && gunVisible ) { if ( !updated ) { updated = true; pRenderContext->Flush(); UpdateRefractTexture(); } IMaterial *pMat = materials->FindMaterial( "effects/strider_pinch_dudv", TEXTURE_GROUP_CLIENT_EFFECTS ); float size = WARP_SIZE; float refract = params[STRIDERFX_WARP_SCALE].x * WARP_REFRACT * gunFractionVisible; pRenderContext->Bind( pMat, (IClientRenderable*)this ); IMaterialVar *pVar = pMat->FindVar( "$refractamount", NULL ); pVar->SetFloatValue( refract ); Strider_DrawSprite( m_worldPosition, size, white ); } // darkening sprite // glowy blue flare sprite if ( hasParam[STRIDERFX_FLARE_COLOR] && hasParam[STRIDERFX_FLARE_SIZE] && hasParam[STRIDERFX_DARKNESS] && gunVisible ) { IMaterial *pMat = materials->FindMaterial( "effects/blueblackflash", TEXTURE_GROUP_CLIENT_EFFECTS ); float size = FLARE_SIZE * params[STRIDERFX_FLARE_SIZE].x; color32 color; float bright = params[STRIDERFX_FLARE_COLOR].x * gunFractionVisible; ScaleColor( color, white, bright ); color.a = (int)(255 * params[STRIDERFX_DARKNESS].x); pRenderContext->Bind( pMat, (IClientRenderable*)this ); Strider_DrawSprite( m_worldPosition, size, color ); } // bubble warpy sprite if ( hasParam[STRIDERFX_BUBBLE_SIZE] ) { Vector wideBeamEnd = m_beamEndPosition; if ( hasParam[STRIDERFX_WIDE_BEAM_LENGTH] ) { float amt = params[STRIDERFX_WIDE_BEAM_LENGTH].x; wideBeamEnd = m_beamEndPosition * amt + m_targetPosition * (1-amt); } pixelvis_queryparams_t endParams; endParams.Init(wideBeamEnd, 4.0f, 0.001f); float endFractionVisible = PixelVisibility_FractionVisible( endParams, &m_queryHandleBeamEnd ); bool endVisible = endFractionVisible > 0.0f ? true : false; if ( endVisible ) { if ( !updated ) { updated = true; pRenderContext->Flush(); UpdateRefractTexture(); } IMaterial *pMat = materials->FindMaterial( "effects/strider_bulge_dudv", TEXTURE_GROUP_CLIENT_EFFECTS ); float refract = endFractionVisible * WARP_BUBBLE_REFRACT * params[STRIDERFX_BUBBLE_REFRACT].x; float size = WARP_BUBBLE_SIZE * params[STRIDERFX_BUBBLE_SIZE].x; IMaterialVar *pVar = pMat->FindVar( "$refractamount", NULL ); pVar->SetFloatValue( refract ); pRenderContext->Bind( pMat, (IClientRenderable*)this ); Strider_DrawSprite( wideBeamEnd, size, white ); } } else { // call this to have the check ready on the first frame pixelvis_queryparams_t endParams; endParams.Init(m_beamEndPosition, 4.0f, 0.001f); PixelVisibility_FractionVisible( endParams, &m_queryHandleBeamEnd ); } if ( hasParam[STRIDERFX_AFTERGLOW_COLOR] && gunVisible ) { IMaterial *pMat = materials->FindMaterial( "effects/blueblackflash", TEXTURE_GROUP_CLIENT_EFFECTS ); float size = AFTERGLOW_SIZE;// * params[STRIDERFX_FLARE_SIZE].x; color32 color; float bright = params[STRIDERFX_AFTERGLOW_COLOR].x * gunFractionVisible; ScaleColor( color, white, bright ); pRenderContext->Bind( pMat, (IClientRenderable*)this ); Strider_DrawSprite( m_worldPosition, size, color ); dlight_t *dl = effects->CL_AllocDlight( m_entityIndex ); dl->origin = m_worldPosition; dl->color.r = 40; dl->color.g = 60; dl->color.b = 255; dl->color.exponent = 5; dl->radius = bright * 128; dl->die = gpGlobals->curtime + 0.001; } if ( m_t >= STRIDERFX_END_ALL_TIME && !hasAny ) { EffectShutdown(); } return 1; }