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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
#include "common.h"
#include "main.h"
#include "rwcore.h"
#include "rwplcore.h"
#include "CutsceneShadow.h"
#include "RwHelper.h"
#define DLIGHT_VALUE 0.8f /* Directional light intensity */
CCutsceneShadow::CCutsceneShadow()
{
m_pAtomic = nil;
m_nRwObjectType = -1;
m_pLight = nil;
m_nBlurPasses = 0;
m_bResample = false;
m_bGradient = false;
}
CCutsceneShadow::~CCutsceneShadow()
{
Destroy();
}
bool
CCutsceneShadow::Create(RwObject *object, int32 rasterSize, bool resample, int32 blurPasses, bool gradient)
{
ASSERT(object != nil);
RwRGBAReal color;
RwFrame *frame;
if (!object)
return false;
m_pLight = RpLightCreate(rpLIGHTDIRECTIONAL);
ASSERT(m_pLight != nil);
if (!m_pLight)
return false;
color.red = color.green = color.blue = DLIGHT_VALUE;
color.alpha = 0.0f;
RpLightSetColor(m_pLight, &color);
frame = RwFrameCreate();
ASSERT(frame != nil);
RpLightSetFrame(m_pLight, frame);
SetLightProperties(180.0f, 90.0f, false);
m_pObject = object;
m_nRwObjectType = RwObjectGetType(m_pObject);
switch ( m_nRwObjectType )
{
case rpCLUMP:
{
RpClumpGetBoundingSphere(m_pClump, &m_BoundingSphere, 1);
m_BaseSphere.radius = m_BoundingSphere.radius;
RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpClumpGetFrame(m_pClump)));
break;
}
case rpATOMIC:
{
m_BoundingSphere = *RpAtomicGetBoundingSphere(m_pAtomic);
m_BaseSphere.radius = m_BoundingSphere.radius;
RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpAtomicGetFrame(m_pAtomic)));
break;
}
default:
{
Destroy();
return false;
break;
}
}
if ( !m_Camera.Create(rasterSize) )
{
Destroy();
return false;
}
m_nBlurPasses = blurPasses;
m_bResample = resample;
m_bGradient = gradient;
if ( m_bResample && !m_ResampleCamera.Create(rasterSize - 1) )
{
Destroy();
return false;
}
if ( m_nBlurPasses != 0 )
{
if ( !m_BlurCamera.Create(resample ? rasterSize - 1 : rasterSize) )
{
Destroy();
return false;
}
}
if ( m_bGradient )
{
if ( !m_GradientCamera.Create(resample ? rasterSize - 1 : rasterSize) )
{
Destroy();
return false;
}
m_GradientCamera.MakeGradientRaster();
}
m_Camera.SetLight(m_pLight);
switch ( m_nRwObjectType )
{
case rpATOMIC:
m_Camera.SetFrustum(1.1f * m_BoundingSphere.radius);
break;
case rpCLUMP:
m_Camera.SetFrustum(1.1f * m_BoundingSphere.radius);
break;
}
m_Camera.SetCenter(&m_BaseSphere.center);
return true;
}
RwFrame *
CCutsceneShadow::SetLightProperties(float angleY, float angleX, bool setLight)
{
ASSERT(m_pLight != nil);
RwFrame *frame;
static RwV3d Xaxis = { 1.0f, 0.0f, 0.0f };
static RwV3d Yaxis = { 0.0f, 1.0f, 0.0f };
frame = RpLightGetFrame(m_pLight);
ASSERT(frame != nil);
if ( !frame )
return nil;
RwFrameRotate(frame, &Yaxis, angleY, rwCOMBINEREPLACE);
RwFrameRotate(frame, &Xaxis, angleX, rwCOMBINEPOSTCONCAT);
if ( setLight )
m_Camera.SetLight(m_pLight);
return frame;
}
bool
CCutsceneShadow::IsInitialized()
{
return m_pObject != nil;
}
void
CCutsceneShadow::Destroy()
{
m_Camera.Destroy();
m_ResampleCamera.Destroy();
m_BlurCamera.Destroy();
m_GradientCamera.Destroy();
m_pAtomic = nil;
m_nRwObjectType = -1;
if (m_pLight)
{
RwFrame *frame = RpLightGetFrame(m_pLight);
RpLightSetFrame(m_pLight, nil);
RwFrameDestroy(frame);
RpLightDestroy(m_pLight);
m_pLight = nil;
}
}
RwRaster *
CCutsceneShadow::Update()
{
switch ( m_nRwObjectType )
{
case rpCLUMP:
ASSERT(m_pClump != nil);
RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpClumpGetFrame(m_pClump)));
break;
case rpATOMIC:
ASSERT(m_pAtomic != nil);
RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpAtomicGetFrame(m_pAtomic)));
break;
}
m_Camera.SetCenter(&m_BaseSphere.center);
switch ( m_nRwObjectType )
{
case rpCLUMP:
m_Camera.Update(m_pClump);
break;
case rpATOMIC:
m_Camera.Update(m_pAtomic);
break;
}
RwRaster *raster = m_Camera.GetRwRenderRaster();
ASSERT(raster != nil);
if ( m_bResample )
return m_ResampleCamera.RasterResample(raster);
if ( m_nBlurPasses )
return m_BlurCamera.RasterBlur(raster, m_nBlurPasses);
if ( m_bGradient )
return m_GradientCamera.RasterGradient(raster);
return raster;
}
RwTexture *
CCutsceneShadow::UpdateForCutscene()
{
Update();
return GetShadowRwTexture();
}
CShadowCamera *
CCutsceneShadow::GetShadowCamera(int32 camType)
{
switch ( camType )
{
case RESAMPLE: return &m_ResampleCamera;
case BLUR: return &m_BlurCamera;
case GRADIENT: return &m_GradientCamera;
}
return &m_Camera;
}
RwTexture *
CCutsceneShadow::GetShadowRwTexture()
{
if ( m_bResample )
return m_ResampleCamera.GetRwRenderTexture();
else
return m_Camera.GetRwRenderTexture();
}
void
CCutsceneShadow::DrawBorderAroundTexture(RwRGBA const& color)
{
if ( m_bResample )
m_ResampleCamera.DrawOutlineBorder(color);
else
m_Camera.DrawOutlineBorder(color);
}
|