*
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
#ifndef IRenderPath_h__
|
||||
#define IRenderPath_h__
|
||||
|
||||
#include "CG.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
class IScene;
|
||||
namespace RenderPath
|
||||
{
|
||||
class IRenderPath
|
||||
{
|
||||
public:
|
||||
virtual ~IRenderPath() {}
|
||||
virtual void Render(LifeGraphics::IScene* pScene) = 0;
|
||||
protected:
|
||||
IRenderer* pRenderer;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // IRenderPath_h__
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef IRenderPathShadow_h__
|
||||
#define IRenderPathShadow_h__
|
||||
|
||||
#include "renderpath/IRenderPath.h"
|
||||
#include "Light.h"
|
||||
#include "ShadowMapManager.h"
|
||||
#include "queries/IFrustumQuery.h"
|
||||
|
||||
namespace LifeGraphics { namespace RenderPath
|
||||
{
|
||||
class IRenderPathShadow : public IRenderPath
|
||||
{
|
||||
public:
|
||||
IRenderPathShadow(ShadowMapManager* sm)
|
||||
{
|
||||
pShadowManager = sm;
|
||||
}
|
||||
virtual ~IRenderPathShadow() {}
|
||||
virtual void SetLight(const Light& _light) = 0;
|
||||
protected:
|
||||
Light light;
|
||||
ShadowMapManager* pShadowManager;
|
||||
IConstantBuffer* cbCamera;
|
||||
IConstantBuffer* cbLight;
|
||||
IFrustumQuery frustumQuery;
|
||||
};
|
||||
}}
|
||||
#endif // IRenderPathShadow_h__
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef RenderPathDefault_h__
|
||||
#define RenderPathDefault_h__
|
||||
|
||||
#endif // RenderPathDefault_h__
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef RenderPathDefault_h__
|
||||
#define RenderPathDefault_h__
|
||||
|
||||
#include "renderpath/IRenderPath.h"
|
||||
|
||||
namespace LifeGraphics { namespace RenderPath
|
||||
{
|
||||
class RenderPathDefault : public IRenderPath
|
||||
{
|
||||
public:
|
||||
RenderPathDefault();
|
||||
~RenderPathDefault();
|
||||
void Render(IScene* pScene);
|
||||
};
|
||||
}}
|
||||
#endif // RenderPathDefault_h__
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef RenderPathDeferred_h__
|
||||
#define RenderPathDeferred_h__
|
||||
|
||||
#endif // RenderPathDeferred_h__
|
||||
@@ -0,0 +1,4 @@
|
||||
#ifndef RenderPathForward_h__
|
||||
#define RenderPathForward_h__
|
||||
|
||||
#endif // RenderPathForward_h__
|
||||
@@ -0,0 +1,128 @@
|
||||
#include "renderpath/RenderPathOmniShadow.h"
|
||||
|
||||
#include "IScene.h"
|
||||
|
||||
namespace LifeGraphics { namespace RenderPath
|
||||
{
|
||||
RenderPathOmniShadow::RenderPathOmniShadow(ShadowMapManager* sm)
|
||||
:IRenderPathShadow(sm)
|
||||
{
|
||||
pRenderer = CG::me()->GetRenderer();
|
||||
renderTarget = pRenderer->CreateRenderTargetCube(512, FORMAT_R32_FLOAT);
|
||||
|
||||
depthTarget = pRenderer->CreateDepthTargetCube(512, FORMAT_D24_UNORM_S8_UINT);
|
||||
cbCamera = pRenderer->CreateConstantBuffer(sizeof(PER_CAMERA_CONSTANTS));
|
||||
|
||||
//cbLight = pRenderer->CreateConstantBuffer(sizeof(POINT_LIGHT_DATA));
|
||||
}
|
||||
RenderPathOmniShadow::~RenderPathOmniShadow()
|
||||
{
|
||||
}
|
||||
void RenderPathOmniShadow::SetLight(const Light& _light)
|
||||
{
|
||||
light = _light;
|
||||
}
|
||||
void RenderPathOmniShadow::Render(IScene* pScene)
|
||||
{
|
||||
//top, bottom, left, right, front, back directions
|
||||
static LifeMath::float3 dir[6] =
|
||||
{
|
||||
LifeMath::float3( 1, 0, 0),
|
||||
LifeMath::float3( -1, 0, 0),
|
||||
|
||||
LifeMath::float3( 0, 1, 0),
|
||||
LifeMath::float3( 0, -1, 0),
|
||||
|
||||
LifeMath::float3( 0, 0, 1),
|
||||
LifeMath::float3( 0, 0, -1),
|
||||
};
|
||||
|
||||
LifeMath::float3 lightPos = light.getTransform()->GetPosition();
|
||||
|
||||
//compute 6 cube face cameras
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
cam[i].setPosition(lightPos);
|
||||
cam[i].setDirection(dir[i] + lightPos);
|
||||
cam[i].setFov(3.1415f * 0.5f);
|
||||
cam[i].setAspect(1.0f);
|
||||
cam[i].setNear(0.1f);
|
||||
cam[i].setFar(light.getRange());
|
||||
}
|
||||
|
||||
LifeMath::Rect2i vp(0,0,512,512);
|
||||
pRenderer->SetViewport(vp);
|
||||
|
||||
//for render scene depth to 6 cube faces
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
//pRenderer->SetCubeTarget(NULL, depthTarget, i);
|
||||
//pRenderer->ClearRenderTarget()
|
||||
static LifeMath::float4 clearColor(0,0,0,0);
|
||||
pRenderer->ClearDepthStencil(depthTarget->getSurface(i), 1, 1.0f, 0);
|
||||
pRenderer->ClearRenderTarget(renderTarget->getSurface(i), &clearColor);
|
||||
pRenderer->SetTargets(renderTarget->getSurface(i), depthTarget->getSurface(i));
|
||||
|
||||
frustumQuery.SetFrustum(*cam[i].getFrustum());
|
||||
frustumQuery.Filration = true;
|
||||
frustumQuery.filter = NT_MESH;
|
||||
//get all visible objects
|
||||
pScene->PerformQuery(&frustumQuery);
|
||||
|
||||
int nc = frustumQuery.Size();
|
||||
|
||||
PER_CAMERA_CONSTANTS pccs = {0};
|
||||
|
||||
pccs.camNearFar = LifeMath::float4(cam[i].getNear(), cam[i].getFar(), 0.0f,0.0f);
|
||||
pccs.mView = cam[i].getView();
|
||||
pccs.mProj = cam[i].getProj();
|
||||
pccs.mInvVP = pccs.mView * pccs.mProj;
|
||||
LifeMath::float3 camPosl = cam[i].getPosition();
|
||||
LifeMath::float3 camDirl = cam[i].getDirection();
|
||||
pccs.camPos = camPosl;
|
||||
|
||||
pccs.camDir = camDirl;
|
||||
|
||||
cbCamera->Update(&pccs, sizeof(PER_CAMERA_CONSTANTS));
|
||||
pRenderer->SetVSConstantBuffer(cbCamera, 1);
|
||||
pRenderer->SetPSConstantBuffer(cbCamera, 1);
|
||||
|
||||
pRenderer->SetDepthStencilState(pShadowManager->depthState);
|
||||
|
||||
for(int j = 0; j < nc; j++)
|
||||
{
|
||||
IObject* mesh = static_cast<IObject*>(frustumQuery[j]);
|
||||
mesh->bind();
|
||||
|
||||
for(int k = 0; k < mesh->getSumbeshCount(); k++)
|
||||
{
|
||||
IMaterialProxy* mat = mesh->getMaterial(k);
|
||||
mat->SelectTechnique(MT_RENDER_DEFERRED);
|
||||
mat->GetTechnique()->SelectPass(MP_DEPTH_SM);
|
||||
|
||||
IMaterialPass* pass = mat->GetTechnique()->GetPass();
|
||||
pass->Apply();
|
||||
//pRenderer->SetVertexShader(mat->g_buffer_pass_vs);
|
||||
|
||||
/*if(mat->diffuseMap.ptr())
|
||||
{
|
||||
pRenderer->SetPSTexture(mat->diffuseMap.ptr(), 0);
|
||||
}
|
||||
if(mat->AlphaTest || mat->AlphaBlendEnable)
|
||||
{
|
||||
pRenderer->SetPixelShader(pShadowManager->rtdCubePsAT);
|
||||
}
|
||||
else
|
||||
{
|
||||
pRenderer->SetPixelShader(pShadowManager->rtdCubePs);
|
||||
}*/
|
||||
mesh->render(k);
|
||||
}
|
||||
}
|
||||
frustumQuery.Flush();
|
||||
//IGraphicsNode* n = frustumQuery[0]->
|
||||
}
|
||||
|
||||
// renderTarget->ToFile("C:\\cube_shadow.dds");
|
||||
}
|
||||
}}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef RenderPathOmniShadow_h__
|
||||
#define RenderPathOmniShadow_h__
|
||||
|
||||
#include "renderpath/IRenderPathShadow.h"
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
namespace LifeGraphics { namespace RenderPath
|
||||
{
|
||||
class RenderPathOmniShadow : public IRenderPathShadow
|
||||
{
|
||||
public:
|
||||
RenderPathOmniShadow(ShadowMapManager* sm);
|
||||
~RenderPathOmniShadow();
|
||||
void SetLight(const Light& _light);
|
||||
void Render(IScene* pScene);
|
||||
ITexture2D* GetShadowMap()
|
||||
{
|
||||
return renderTarget;
|
||||
}
|
||||
protected:
|
||||
Camera cam[6];
|
||||
ITexture2D* depthTarget;
|
||||
ITexture2D* renderTarget;
|
||||
};
|
||||
}}
|
||||
#endif // RenderPathOmniShadow_h__
|
||||
@@ -0,0 +1,102 @@
|
||||
#include "renderpath/RenderPathSpotShadow.h"
|
||||
#include "IScene.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
namespace RenderPath
|
||||
{
|
||||
RenderPathSpotShadow::RenderPathSpotShadow(ShadowMapManager* sm)
|
||||
:IRenderPathShadow(sm)
|
||||
{
|
||||
pRenderer = CG::me()->GetRenderer();
|
||||
|
||||
renderTarget = pRenderer->CreateRenderTarget(512, 512, FORMAT_R32_FLOAT);
|
||||
|
||||
depthTarget = pRenderer->CreateDepthTarget(512, 512, FORMAT_D24_UNORM_S8_UINT);
|
||||
cbCamera = pRenderer->CreateConstantBuffer(sizeof(PER_CAMERA_CONSTANTS));
|
||||
}
|
||||
RenderPathSpotShadow::~RenderPathSpotShadow()
|
||||
{
|
||||
}
|
||||
void RenderPathSpotShadow::Render(LifeGraphics::IScene* pScene)
|
||||
{
|
||||
Frustum f = *light.getFrustum();
|
||||
frustumQuery.SetFrustum(f);
|
||||
frustumQuery.Filration = true;
|
||||
frustumQuery.filter = NT_MESH;
|
||||
//get all visible objects
|
||||
pScene->PerformQuery(&frustumQuery);
|
||||
|
||||
//if there is any visible objects for light frustum - start rendering shadow map
|
||||
int objCount = frustumQuery.Size();
|
||||
if(objCount)
|
||||
{
|
||||
LifeMath::Rect2i vp(0,0,512,512);
|
||||
pRenderer->SetViewport(vp);
|
||||
pRenderer->SetScissorRectangle(vp);
|
||||
|
||||
pRenderer->SetTargets(renderTarget, depthTarget);
|
||||
LifeMath::float4 color = LifeMath::float4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
pRenderer->ClearDepthStencil(depthTarget, 1.0f, 0);
|
||||
|
||||
PER_CAMERA_CONSTANTS pccs = {0};
|
||||
|
||||
pccs.camNearFar = LifeMath::float4(0.1f, light.getRange(), 0.0f,0.0f);
|
||||
pccs.mView = light.getView();
|
||||
pccs.mProj = light.getProj();
|
||||
pccs.mInvVP = pccs.mView * pccs.mProj;
|
||||
LifeMath::float3 camPosl = light.getPosition();
|
||||
LifeMath::float3 camDirl = light.getDirection();
|
||||
pccs.camPos = camPosl;
|
||||
|
||||
pccs.camDir = camDirl - camPosl;
|
||||
LifeMath::Vec3Normalize(&pccs.camDir);
|
||||
|
||||
cbCamera->Update(&pccs, sizeof(PER_CAMERA_CONSTANTS));
|
||||
pRenderer->SetVSConstantBuffer(cbCamera, 1);
|
||||
pRenderer->SetPSConstantBuffer(cbCamera, 1);
|
||||
|
||||
pRenderer->SetDepthStencilState(this->pShadowManager->depthState);
|
||||
pRenderer->SetPSTextureSampler(this->pShadowManager->samplerPCF, 2);
|
||||
|
||||
//render each visible object to shadow map
|
||||
for(int i = 0; i < objCount; i++)
|
||||
{
|
||||
IObject* mesh = static_cast<IObject*>(frustumQuery[i]);
|
||||
mesh->bind();
|
||||
|
||||
for(int i = 0; i < mesh->getSumbeshCount(); i++)
|
||||
{
|
||||
IMaterialProxy* mat = mesh->getMaterial(i);
|
||||
mat->SelectTechnique(MT_RENDER_DEFERRED);
|
||||
mat->GetTechnique()->SelectPass(MP_DEPTH_SM);
|
||||
IMaterialPass* pass = mat->GetTechnique()->GetPass();
|
||||
pass->Apply();
|
||||
printf("Epic fail\n!");
|
||||
/*pRenderer->SetVertexShader(mat->g_buffer_pass_vs);
|
||||
|
||||
if(mat->diffuseMap.ptr())
|
||||
{
|
||||
pRenderer->SetPSTexture(mat->diffuseMap.ptr(), 0);
|
||||
}
|
||||
if(mat->AlphaTest || mat->AlphaBlendEnable)
|
||||
{
|
||||
pRenderer->SetPixelShader(pShadowManager->rtdPsAT);
|
||||
}
|
||||
else
|
||||
{
|
||||
pRenderer->SetPixelShader(pShadowManager->rtdPs);
|
||||
}*/
|
||||
mesh->render(i);
|
||||
}
|
||||
}
|
||||
|
||||
frustumQuery.Flush();
|
||||
}
|
||||
}
|
||||
void RenderPathSpotShadow::SetLight(const Light& _light)
|
||||
{
|
||||
light = _light;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef RenderPathSpotShadow_h__
|
||||
#define RenderPathSpotShadow_h__
|
||||
|
||||
#include "renderpath/IRenderPathShadow.h"
|
||||
|
||||
namespace LifeGraphics
|
||||
{
|
||||
namespace RenderPath
|
||||
{
|
||||
class RenderPathSpotShadow : public IRenderPathShadow
|
||||
{
|
||||
public:
|
||||
RenderPathSpotShadow(ShadowMapManager* sm);
|
||||
~RenderPathSpotShadow();
|
||||
void Render(LifeGraphics::IScene* pScene);
|
||||
void SetLight(const Light& _light);
|
||||
ITexture2D* GetShadowMap()
|
||||
{
|
||||
return renderTarget;
|
||||
}
|
||||
private:
|
||||
ITexture2D* depthTarget;
|
||||
ITexture2D* renderTarget;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // RenderPathSpotShadow_h__
|
||||
Reference in New Issue
Block a user