Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
187 lines
6.4 KiB
C++
187 lines
6.4 KiB
C++
// Shader_SelfShadowP.cpp: implementation of the CShader_SelfShadowP class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "Shader_SelfShadowP.h"
|
|
#include "SceneManager.h"
|
|
#include "SceneStateMgr.h"
|
|
#include "BaseGraphicsLayer.h"
|
|
// Shadowmap Texture Size
|
|
#define SHADOWMAPSIZE 512
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
CShader_SelfShadowP::CShader_SelfShadowP()
|
|
{
|
|
|
|
m_iSelfShadowVersion = 1; // Default Nvdia
|
|
|
|
LPDIRECT3DDEVICE8 lpDevice = CSceneManager::GetDevice();
|
|
// Shadow map texture & surface generate
|
|
lpDevice->GetRenderTarget(&m_pBackBuffer);
|
|
lpDevice->GetDepthStencilSurface(&m_pZBuffer);
|
|
m_Depth = 24;
|
|
|
|
D3DFORMAT ZFormat = D3DFMT_D24S8;
|
|
|
|
if(BaseGraphicsLayer::CheckResourceFormatSupport(ZFormat, D3DRTYPE_TEXTURE, D3DUSAGE_DEPTHSTENCIL) != 0)
|
|
{
|
|
|
|
ZFormat = D3DFMT_D16;
|
|
if(BaseGraphicsLayer::CheckResourceFormatSupport(ZFormat, D3DRTYPE_TEXTURE, D3DUSAGE_DEPTHSTENCIL) != 0)
|
|
{
|
|
|
|
ZFormat = D3DFMT_D15S1;
|
|
if(BaseGraphicsLayer::CheckResourceFormatSupport(ZFormat, D3DRTYPE_TEXTURE, D3DUSAGE_DEPTHSTENCIL) != 0)
|
|
{
|
|
m_iSelfShadowVersion = 0; // Ati
|
|
|
|
}
|
|
}
|
|
}
|
|
if(m_iSelfShadowVersion == 1)
|
|
{
|
|
if( BaseGraphicsLayer::m_d3dpp.BackBufferFormat==D3DFMT_A8R8G8B8 ||
|
|
BaseGraphicsLayer::m_d3dpp.BackBufferFormat==D3DFMT_X8R8G8B8 )
|
|
{
|
|
BaseGraphicsLayer::GetDevice()->CreateTexture(512,512,1,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&m_pColorTex);
|
|
BaseGraphicsLayer::GetDevice()->CreateTexture(512,512,1,D3DUSAGE_DEPTHSTENCIL,D3DFMT_D24S8,D3DPOOL_DEFAULT,&m_pZTex);
|
|
}
|
|
if( BaseGraphicsLayer::m_d3dpp.BackBufferFormat==D3DFMT_R5G6B5)
|
|
{
|
|
BaseGraphicsLayer::GetDevice()->CreateTexture(512,512,1,D3DUSAGE_RENDERTARGET,D3DFMT_R5G6B5,D3DPOOL_DEFAULT,&m_pColorTex);
|
|
BaseGraphicsLayer::GetDevice()->CreateTexture(512,512,1,D3DUSAGE_DEPTHSTENCIL,D3DFMT_D16,D3DPOOL_DEFAULT,&m_pZTex);
|
|
}
|
|
|
|
D3DFORMAT CFormat = D3DFMT_A8R8G8B8;
|
|
|
|
if( (ZFormat == D3DFMT_D16) ||
|
|
(ZFormat == D3DFMT_D15S1) )
|
|
CFormat = D3DFMT_R5G6B5;
|
|
|
|
lpDevice->CreateTexture(SHADOWMAPSIZE,SHADOWMAPSIZE,1,D3DUSAGE_RENDERTARGET,CFormat, D3DPOOL_DEFAULT ,&m_pColorTex);
|
|
lpDevice->CreateTexture(SHADOWMAPSIZE,SHADOWMAPSIZE,1,D3DUSAGE_DEPTHSTENCIL,ZFormat, D3DPOOL_DEFAULT ,&m_pZTex);
|
|
|
|
m_pColorTex->GetSurfaceLevel(0,&m_pColorSurf);
|
|
m_pZTex->GetSurfaceLevel(0,&m_pZSurf);
|
|
}
|
|
else // Ati Version
|
|
{
|
|
|
|
CreatePixelShaderFromFile("c:/MP-project/Shaders/ShadowMap.psh");
|
|
lpDevice->CreateTexture( SHADOWMAPSIZE, SHADOWMAPSIZE, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pColorTex );
|
|
m_pColorTex->GetSurfaceLevel( 0, &m_pColorSurf );
|
|
lpDevice->CreateDepthStencilSurface(SHADOWMAPSIZE, SHADOWMAPSIZE, D3DFMT_D16, D3DMULTISAMPLE_NONE, &m_pZSurf);
|
|
|
|
|
|
|
|
// Lookup Map
|
|
lpDevice->CreateTexture( 2048, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_pLookupMap );
|
|
D3DLOCKED_RECT lockedRect;
|
|
m_pLookupMap->LockRect( 0, &lockedRect, NULL, 0 );
|
|
|
|
DWORD* pMap = (DWORD*)lockedRect.pBits;
|
|
for( INT i = 0; i < 2048; i++ )
|
|
{
|
|
*pMap++ = D3DCOLOR_RGBA( i & 0xFF, (i & 0xFF00) >> 3, 0, 0 );
|
|
}
|
|
m_pLookupMap->UnlockRect( 0 );
|
|
|
|
m_ShadowMapViewPort.X = 0;
|
|
m_ShadowMapViewPort.Y = 0;
|
|
m_ShadowMapViewPort.Width = SHADOWMAPSIZE;
|
|
m_ShadowMapViewPort.Height = SHADOWMAPSIZE;
|
|
m_ShadowMapViewPort.MinZ = 0.0f;
|
|
m_ShadowMapViewPort.MaxZ = 1.0f;
|
|
|
|
}
|
|
}
|
|
|
|
CShader_SelfShadowP::~CShader_SelfShadowP()
|
|
{
|
|
if(m_pZSurf)
|
|
{
|
|
m_pZSurf->Release();
|
|
m_pZSurf = NULL;
|
|
}
|
|
if(m_pColorSurf)
|
|
{
|
|
m_pColorSurf->Release();
|
|
m_pColorSurf = NULL;
|
|
}
|
|
if(m_pColorTex)
|
|
{
|
|
m_pColorTex->Release();
|
|
m_pColorTex = NULL;
|
|
}
|
|
if(m_pZTex)
|
|
{
|
|
m_pZTex->Release();
|
|
m_pZTex = NULL;
|
|
}
|
|
m_pBackBuffer = NULL;
|
|
m_pZBuffer = NULL;
|
|
|
|
}
|
|
void CShader_SelfShadowP::Apply()
|
|
{
|
|
CSceneManager::GetDevice()->SetPixelShader(m_dwPixelShader);
|
|
SetupPixelShaderConstants();
|
|
}
|
|
void CShader_SelfShadowP::BeginShadowMap()
|
|
{
|
|
LPDIRECT3DDEVICE8 lpDevice = CSceneManager::GetDevice();
|
|
if(m_iSelfShadowVersion == SELFSHADOW_ATI)
|
|
{
|
|
if(m_pBackBuffer)
|
|
m_pBackBuffer->Release();
|
|
if(m_pZBuffer)
|
|
m_pZBuffer->Release();
|
|
|
|
lpDevice->GetRenderTarget(&m_pBackBuffer);
|
|
lpDevice->GetDepthStencilSurface(&m_pZBuffer);
|
|
lpDevice->GetViewport(&m_BackViewPort);
|
|
lpDevice->SetRenderTarget(m_pColorSurf,m_pZSurf);
|
|
|
|
lpDevice->SetViewport(&m_ShadowMapViewPort);
|
|
lpDevice->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xFFFFE000, 1.0f, 0L );
|
|
}
|
|
}
|
|
void CShader_SelfShadowP::EndShadowMap()
|
|
{
|
|
LPDIRECT3DDEVICE8 lpDevice = CSceneManager::GetDevice();
|
|
if(m_iSelfShadowVersion == SELFSHADOW_ATI)
|
|
{
|
|
lpDevice->SetRenderTarget(m_pBackBuffer,m_pZBuffer);
|
|
lpDevice->SetViewport(&m_BackViewPort);
|
|
}
|
|
}
|
|
|
|
|
|
void CShader_SelfShadowP::SetupPixelShaderConstants()
|
|
{
|
|
/* CSceneStateMgr::_SetD3DTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 0, D3DTSS_ADDRESSW, D3DTADDRESS_WRAP );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 1, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 1, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 1, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 1, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 1, D3DTSS_ADDRESSW, D3DTADDRESS_WRAP );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 2, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 2, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 2, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 2, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 2, D3DTSS_ADDRESSW, D3DTADDRESS_WRAP );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 3, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 3, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 3, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 3, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP );
|
|
CSceneStateMgr::_SetD3DTextureStageState( 3, D3DTSS_ADDRESSW, D3DTADDRESS_WRAP );*/
|
|
}
|
|
|