1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#include "cbase.h"
#include "materialsystem/imaterialproxy.h"
#include "materialsystem/imaterialvar.h"
#include "materialsystem/imaterial.h"
#include "portalrenderable_flatbasic.h"
#include "c_prop_portal.h"
#include "toolframework_client.h"
#include <KeyValues.h>
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
class CPortalStaticProxy : public IMaterialProxy
{
protected:
IMaterialVar *m_StaticOutput;
public:
virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
virtual void OnBind( void *pBind );
virtual void Release( void ) { delete this; }
virtual IMaterial * GetMaterial() { return ( m_StaticOutput ) ? m_StaticOutput->GetOwningMaterial() : NULL; }
float ComputeStaticAmount( CPortalRenderable_FlatBasic *pPortal );
};
bool CPortalStaticProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
{
char const* pszResultVar = pKeyValues->GetString( "resultVar" );
if( !pszResultVar )
return false;
bool foundVar;
m_StaticOutput = pMaterial->FindVar( pszResultVar, &foundVar, false );
if( !foundVar )
return false;
return true;
}
float CPortalStaticProxy::ComputeStaticAmount( CPortalRenderable_FlatBasic *pFlatBasic )
{
float flStaticAmount = pFlatBasic->m_fStaticAmount;
if ( !pFlatBasic->GetLinkedPortal() )
{
flStaticAmount = 1.0f;
}
if ( pFlatBasic->WillUseDepthDoublerThisDraw() )
{
flStaticAmount = 0.0f;
}
else if ( g_pPortalRender->GetRemainingPortalViewDepth() == 0 ) //end of the line, no more views
{
flStaticAmount = 1.0f;
}
else if ( (g_pPortalRender->GetRemainingPortalViewDepth() == 1) && (pFlatBasic->m_fSecondaryStaticAmount > flStaticAmount) ) //fading in from no views to another view (player just walked through it)
{
flStaticAmount = pFlatBasic->m_fSecondaryStaticAmount;
}
return flStaticAmount;
}
void CPortalStaticProxy::OnBind( void *pBind )
{
if ( pBind == NULL )
return;
float flStaticAmount;
IClientRenderable *pRenderable = (IClientRenderable*)pBind;
CPortalRenderable *pRecordedPortal = g_pPortalRender->FindRecordedPortal( pRenderable );
if ( pRecordedPortal )
{
CPortalRenderable_FlatBasic *pRecordedFlatBasic = dynamic_cast<CPortalRenderable_FlatBasic *>(pRecordedPortal);
if ( !pRecordedFlatBasic )
return;
flStaticAmount = ComputeStaticAmount( pRecordedFlatBasic );
}
else
{
CPortalRenderable_FlatBasic *pFlatBasic = dynamic_cast<CPortalRenderable_FlatBasic*>( pRenderable );
if ( !pFlatBasic )
return;
flStaticAmount = ComputeStaticAmount( pFlatBasic );
}
m_StaticOutput->SetFloatValue( flStaticAmount );
if ( ToolsEnabled() )
{
ToolFramework_RecordMaterialParams( GetMaterial() );
}
}
EXPOSE_INTERFACE( CPortalStaticProxy, IMaterialProxy, "PortalStaticModel" IMATERIAL_PROXY_INTERFACE_VERSION );
class CPortalStaticPortalProxy : public CPortalStaticProxy
{
public:
virtual void OnBind( void *pBind );
};
void CPortalStaticPortalProxy::OnBind( void *pBind )
{
if ( pBind == NULL )
return;
IClientRenderable *pRenderable = (IClientRenderable*)( pBind );
C_Prop_Portal *pPortal = (C_Prop_Portal *)pRenderable;
float flStaticAmount = ComputeStaticAmount( pPortal );
m_StaticOutput->SetFloatValue( flStaticAmount );
}
EXPOSE_INTERFACE( CPortalStaticPortalProxy, IMaterialProxy, "PortalStatic" IMATERIAL_PROXY_INTERFACE_VERSION );
class CPortalOpenAmountProxy : public CPortalStaticProxy
{
public:
virtual void OnBind( void *pBind );
};
void CPortalOpenAmountProxy::OnBind( void *pBind )
{
if ( pBind == NULL )
return;
IClientRenderable *pRenderable = (IClientRenderable*)( pBind );
C_Prop_Portal *pPortal = (C_Prop_Portal *)pRenderable;
m_StaticOutput->SetFloatValue( pPortal->m_fOpenAmount );
}
EXPOSE_INTERFACE( CPortalOpenAmountProxy, IMaterialProxy, "PortalOpenAmount" IMATERIAL_PROXY_INTERFACE_VERSION );
|