void CWorldDimsProxy::OnBind( void *pC_BaseEntity ) { if ( m_pMinsVar && m_pMaxsVar ) { float mins[3] = {-500,-500,-500}; float maxs[3] = {+500,+500,+500}; m_pMinsVar->SetVecValue( (const float*)mins, 3 ); m_pMaxsVar->SetVecValue( (const float*)maxs, 3 ); } }
void CWorldDimsProxy::OnBind( void *pC_BaseEntity ) { if ( m_pMinsVar && m_pMaxsVar ) { C_World *pWorld = GetClientWorldEntity(); if ( pWorld ) { m_pMinsVar->SetVecValue( (const float*)&pWorld->m_WorldMins, 3 ); m_pMaxsVar->SetVecValue( (const float*)&pWorld->m_WorldMaxs, 3 ); } } }
void CThermalMaterialProxy::OnBind( C_BaseEntity *pEntity ) { // FIXME, enable this later return; if( !m_ThermalVar ) { return; } float min, max, period, value; // set default values if these variables don't exist. min = m_ThermalMin ? m_ThermalMin->GetFloatValue() : 0.0f; max = m_ThermalMax ? m_ThermalMax->GetFloatValue() : 1.0f; period = m_ThermalPeriod ? m_ThermalPeriod->GetFloatValue() : 1.0f; // get a value in [0,1] value = ( sin( 2.0f * M_PI * gpGlobals->curtime / period ) * 0.5f ) + 0.5f; // get a value in [min,max] value = ( max - min ) * value + min; Vector color; HueToRGB( 360.f * value, color ); m_ThermalVar->SetVecValue( color[0], color[1], color[2] ); }
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 ); }
void CWorldDimsProxy::OnBind( void *pC_BaseEntity ) { if ( m_pMinsVar && m_pMaxsVar ) { C_World *pWorld = GetClientWorldEntity(); if ( pWorld ) { m_pMinsVar->SetVecValue( (const float*)&pWorld->m_WorldMins, 3 ); m_pMaxsVar->SetVecValue( (const float*)&pWorld->m_WorldMaxs, 3 ); } } if ( ToolsEnabled() ) { ToolFramework_RecordMaterialParams( GetMaterial() ); } }
void CConveyorMaterialProxy::OnBind( void *pC_BaseEntity ) { if( !pC_BaseEntity ) return; C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity ); if ( !pEntity ) return; C_FuncConveyor *pConveyor = dynamic_cast<C_FuncConveyor*>(pEntity); if ( !pConveyor ) return; if ( !m_pTextureScrollVar ) { return; } float flConveyorSpeed = pConveyor->GetConveyorSpeed(); float flRate = abs( flConveyorSpeed ) / 128.0; float flAngle = (flConveyorSpeed >= 0) ? 180 : 0; float sOffset = gpGlobals->curtime * cos( flAngle * ( M_PI / 180.0f ) ) * flRate; float tOffset = gpGlobals->curtime * sin( flAngle * ( M_PI / 180.0f ) ) * flRate; // make sure that we are positive if( sOffset < 0.0f ) { sOffset += 1.0f + -( int )sOffset; } if( tOffset < 0.0f ) { tOffset += 1.0f + -( int )tOffset; } // make sure that we are in a [0,1] range sOffset = sOffset - ( int )sOffset; tOffset = tOffset - ( int )tOffset; if (m_pTextureScrollVar->GetType() == MATERIAL_VAR_TYPE_MATRIX) { VMatrix mat; MatrixBuildTranslation( mat, sOffset, tOffset, 0.0f ); m_pTextureScrollVar->SetMatrixValue( mat ); } else { m_pTextureScrollVar->SetVecValue( sOffset, tOffset, 0.0f ); } }
void CCoreOriginProxy::OnBind( void *pRenderable ) { if( !pRenderable || !m_pSphereOriginTextureVar ) return; IClientRenderable *pRend = ( IClientRenderable* )pRenderable; if ( !pRend ) return; const Vector &origin = pRend->GetRenderOrigin(); m_pSphereOriginTextureVar->SetVecValue(origin[0], origin[1], origin[2], 1); }
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 ); } }
void CTextureScrollMaterialProxy::OnBind( void *pC_BaseEntity ) { if( !m_pTextureScrollVar ) { return; } float rate, angle, scale; // set default values if these variables don't exist. rate = m_TextureScrollRate.GetFloat(); angle = m_TextureScrollAngle.GetFloat(); scale = m_TextureScale.GetFloat(); float sOffset, tOffset; sOffset = gpGlobals->curtime * cos( angle * ( M_PI / 180.0f ) ) * rate; tOffset = gpGlobals->curtime * sin( angle * ( M_PI / 180.0f ) ) * rate; // make sure that we are positive if( sOffset < 0.0f ) { sOffset += 1.0f + -( int )sOffset; } if( tOffset < 0.0f ) { tOffset += 1.0f + -( int )tOffset; } // make sure that we are in a [0,1] range sOffset = sOffset - ( int )sOffset; tOffset = tOffset - ( int )tOffset; if (m_pTextureScrollVar->GetType() == MATERIAL_VAR_TYPE_MATRIX) { VMatrix mat( scale, 0.0f, 0.0f, sOffset, 0.0f, scale, 0.0f, tOffset, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ); m_pTextureScrollVar->SetMatrixValue( mat ); } else { m_pTextureScrollVar->SetVecValue( sOffset, tOffset, 0.0f ); } if ( ToolsEnabled() ) { ToolFramework_RecordMaterialParams( GetMaterial() ); } }
void CTeamColorProxy::OnBind( void *pRenderable ) { if( !pRenderable || !m_pColorTextureVar ) return; IClientRenderable *pRend = ( IClientRenderable* )pRenderable; C_BaseEntity *pEnt = pRend->GetIClientUnknown()->GetBaseEntity(); if ( !pEnt ) return; Vector &teamcolor = pEnt->GetTeamColor(); m_pColorTextureVar->SetVecValue(teamcolor[0], teamcolor[1], teamcolor[2], 1); }
inline bool ASW_SetMaterialVarVector4D( IMaterial* pMat, const char* pVarName, const Vector4D &vValue ) { Assert( pMat != NULL ); Assert( pVarName != NULL ); if ( pMat == NULL || pVarName == NULL ) { return false; } bool bFound = false; IMaterialVar* pVar = pMat->FindVar( pVarName, &bFound ); if ( bFound ) { pVar->SetVecValue( vValue.Base(), 4 ); } return bFound; }
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 ); }
void DrawSpriteModel( IClientEntity *baseentity, CEngineSprite *psprite, const Vector &origin, float fscale, float frame, int rendermode, int r, int g, int b, int a, const Vector& forward, const Vector& right, const Vector& up, float flHDRColorScale ) { float scale; IMaterial *material; // don't even bother culling, because it's just a single // polygon without a surface cache if ( fscale > 0 ) scale = fscale; else scale = 1.0f; if ( rendermode == kRenderNormal ) { render->SetBlend( 1.0f ); } material = psprite->GetMaterial( (RenderMode_t)rendermode, frame ); if ( !material ) return; CMatRenderContextPtr pRenderContext( materials ); if ( ShouldDrawInWireFrameMode() || r_drawsprites.GetInt() == 2 ) { IMaterial *pMaterial = materials->FindMaterial( "debug/debugspritewireframe", TEXTURE_GROUP_OTHER ); pRenderContext->Bind( pMaterial, NULL ); } else { pRenderContext->Bind( material, (IClientRenderable*)baseentity ); } unsigned char color[4]; color[0] = r; color[1] = g; color[2] = b; color[3] = a; IMaterialVar *pHDRColorScaleVar = material->FindVarFast( "$HDRCOLORSCALE", &s_nHDRColorScaleCache ); if( pHDRColorScaleVar ) { pHDRColorScaleVar->SetVecValue( flHDRColorScale, flHDRColorScale, flHDRColorScale ); } Vector point; IMesh* pMesh = pRenderContext->GetDynamicMesh(); CMeshBuilder meshBuilder; meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 ); Vector vec_a; Vector vec_b; Vector vec_c; Vector vec_d; // isolate common terms VectorMA( origin, psprite->GetDown() * scale, up, vec_a ); VectorScale( right, psprite->GetLeft() * scale, vec_b ); VectorMA( origin, psprite->GetUp() * scale, up, vec_c ); VectorScale( right, psprite->GetRight() * scale, vec_d ); float flMinU, flMinV, flMaxU, flMaxV; psprite->GetTexCoordRange( &flMinU, &flMinV, &flMaxU, &flMaxV ); meshBuilder.Color4ubv( color ); meshBuilder.TexCoord2f( 0, flMinU, flMaxV ); VectorAdd( vec_a, vec_b, point ); meshBuilder.Position3fv( point.Base() ); meshBuilder.AdvanceVertex(); meshBuilder.Color4ubv( color ); meshBuilder.TexCoord2f( 0, flMinU, flMinV ); VectorAdd( vec_c, vec_b, point ); meshBuilder.Position3fv( point.Base() ); meshBuilder.AdvanceVertex(); meshBuilder.Color4ubv( color ); meshBuilder.TexCoord2f( 0, flMaxU, flMinV ); VectorAdd( vec_c, vec_d, point ); meshBuilder.Position3fv( point.Base() ); meshBuilder.AdvanceVertex(); meshBuilder.Color4ubv( color ); meshBuilder.TexCoord2f( 0, flMaxU, flMaxV ); VectorAdd( vec_a, vec_d, point ); meshBuilder.Position3fv( point.Base() ); meshBuilder.AdvanceVertex(); meshBuilder.End(); pMesh->Draw(); }
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 ); }