102 lines
3.0 KiB
C++
102 lines
3.0 KiB
C++
#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;
|
|
}
|
|
}
|
|
} |