2020-07-29 09:17:53 +00:00
|
|
|
#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()
|
|
|
|
{
|
2020-07-31 18:21:58 +00:00
|
|
|
m_pAtomic = nil;
|
2020-07-29 09:17:53 +00:00
|
|
|
m_nRwObjectType = -1;
|
2020-07-31 18:21:58 +00:00
|
|
|
m_pLight = nil;
|
2020-07-29 09:17:53 +00:00
|
|
|
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)
|
|
|
|
{
|
2020-07-31 18:21:58 +00:00
|
|
|
ASSERT(object != nil);
|
2020-07-29 22:32:21 +00:00
|
|
|
|
2020-07-29 09:17:53 +00:00
|
|
|
RwRGBAReal color;
|
|
|
|
RwFrame *frame;
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_pLight = RpLightCreate(rpLIGHTDIRECTIONAL);
|
2020-07-31 18:21:58 +00:00
|
|
|
ASSERT(m_pLight != nil);
|
2020-07-29 09:17:53 +00:00
|
|
|
|
|
|
|
if (!m_pLight)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
color.red = color.green = color.blue = DLIGHT_VALUE;
|
|
|
|
color.alpha = 0.0f;
|
|
|
|
|
|
|
|
RpLightSetColor(m_pLight, &color);
|
|
|
|
|
|
|
|
frame = RwFrameCreate();
|
2020-07-31 18:21:58 +00:00
|
|
|
ASSERT(frame != nil);
|
2020-07-29 22:32:21 +00:00
|
|
|
|
2020-07-29 09:17:53 +00:00
|
|
|
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)
|
|
|
|
{
|
2020-07-31 18:21:58 +00:00
|
|
|
ASSERT(m_pLight != nil);
|
2020-07-29 22:32:21 +00:00
|
|
|
|
2020-07-29 09:17:53 +00:00
|
|
|
RwFrame *frame;
|
|
|
|
static RwV3d Xaxis = { 1.0f, 0.0f, 0.0f };
|
|
|
|
static RwV3d Yaxis = { 0.0f, 1.0f, 0.0f };
|
|
|
|
|
|
|
|
frame = RpLightGetFrame(m_pLight);
|
2020-07-31 18:21:58 +00:00
|
|
|
ASSERT(frame != nil);
|
2020-07-29 22:32:21 +00:00
|
|
|
|
2020-07-29 09:17:53 +00:00
|
|
|
if ( !frame )
|
2020-07-31 18:21:58 +00:00
|
|
|
return nil;
|
2020-07-29 09:17:53 +00:00
|
|
|
|
|
|
|
RwFrameRotate(frame, &Yaxis, angleY, rwCOMBINEREPLACE);
|
|
|
|
RwFrameRotate(frame, &Xaxis, angleX, rwCOMBINEPOSTCONCAT);
|
|
|
|
|
|
|
|
if ( setLight )
|
|
|
|
m_Camera.SetLight(m_pLight);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CCutsceneShadow::IsInitialized()
|
|
|
|
{
|
2020-07-31 18:21:58 +00:00
|
|
|
return m_pObject != nil;
|
2020-07-29 09:17:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CCutsceneShadow::Destroy()
|
|
|
|
{
|
|
|
|
m_Camera.Destroy();
|
|
|
|
m_ResampleCamera.Destroy();
|
|
|
|
m_BlurCamera.Destroy();
|
|
|
|
m_GradientCamera.Destroy();
|
|
|
|
|
2020-07-31 18:21:58 +00:00
|
|
|
m_pAtomic = nil;
|
2020-07-29 09:17:53 +00:00
|
|
|
|
|
|
|
m_nRwObjectType = -1;
|
|
|
|
|
|
|
|
if (m_pLight)
|
|
|
|
{
|
|
|
|
RwFrame *frame = RpLightGetFrame(m_pLight);
|
2020-07-31 18:21:58 +00:00
|
|
|
RpLightSetFrame(m_pLight, nil);
|
2020-07-29 09:17:53 +00:00
|
|
|
RwFrameDestroy(frame);
|
|
|
|
RpLightDestroy(m_pLight);
|
2020-07-31 18:21:58 +00:00
|
|
|
m_pLight = nil;
|
2020-07-29 09:17:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RwRaster *
|
|
|
|
CCutsceneShadow::Update()
|
|
|
|
{
|
|
|
|
switch ( m_nRwObjectType )
|
|
|
|
{
|
|
|
|
case rpCLUMP:
|
2020-07-31 18:21:58 +00:00
|
|
|
ASSERT(m_pClump != nil);
|
2020-07-29 09:17:53 +00:00
|
|
|
RwV3dTransformPoints(&m_BaseSphere.center, &m_BoundingSphere.center, 1, RwFrameGetMatrix(RpClumpGetFrame(m_pClump)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case rpATOMIC:
|
2020-07-31 18:21:58 +00:00
|
|
|
ASSERT(m_pAtomic != nil);
|
2020-07-29 09:17:53 +00:00
|
|
|
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();
|
2020-07-31 18:21:58 +00:00
|
|
|
ASSERT(raster != nil);
|
2020-07-29 09:17:53 +00:00
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2020-08-04 13:24:59 +00:00
|
|
|
case RESAMPLE: return &m_ResampleCamera;
|
|
|
|
case BLUR: return &m_BlurCamera;
|
|
|
|
case GRADIENT: return &m_GradientCamera;
|
2020-07-29 09:17:53 +00:00
|
|
|
}
|
2020-07-29 22:32:21 +00:00
|
|
|
|
|
|
|
return &m_Camera;
|
2020-07-29 09:17:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|