611 lines
22 KiB
C++
611 lines
22 KiB
C++
#include "defines.h"
|
|
|
|
#include "Renderpipe.h"
|
|
|
|
#include "shader.h"
|
|
#include "globals.h"
|
|
|
|
void Renderpipe::PrepareDefaultRenderStates()
|
|
{
|
|
g_d3d_device->SetRenderState( D3DRS_LIGHTING, TRUE );
|
|
g_d3d_device->SetRenderState( D3DRS_ZENABLE, TRUE );
|
|
g_d3d_device->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, TRUE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE );
|
|
g_d3d_device->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
|
|
|
|
// Laptop FFP Fallback
|
|
g_d3d_device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
|
|
g_d3d_device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
|
|
|
|
// Default Texturen
|
|
for( int i= 0; i < 6; ++i )
|
|
{
|
|
g_d3d_device->SetSamplerState( i, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( i, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( i, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( i, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP );
|
|
g_d3d_device->SetSamplerState( i, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP );
|
|
g_d3d_device->SetSamplerState( i, D3DSAMP_ADDRESSW, D3DTADDRESS_WRAP );
|
|
}
|
|
// sampler2D shadowSampler : register(s4);
|
|
g_d3d_device->SetSamplerState( 4, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 4, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 4, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 4, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetSamplerState( 4, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetTexture( 4, g_pFullScreenRT[ RT_AUX2 ] );
|
|
// sampler2D depthSampler : register(s5);
|
|
g_d3d_device->SetSamplerState( 5, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 5, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 5, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 5, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetSamplerState( 5, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetTexture( 5, g_pFullScreenRT[ RT_DEPTH ] );
|
|
|
|
g_d3d_device->SetTexture( 0, NULL );
|
|
g_d3d_device->SetTexture( 1, NULL );
|
|
g_d3d_device->SetTexture( 2, g_pTextures[ TI_Light1D ].GetPointer() );
|
|
g_d3d_device->SetSamplerState( 2, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetTexture( 3, g_pTextures[ TI_LightSpec1D ].GetPointer() );
|
|
g_d3d_device->SetSamplerState( 3, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_COLOR_MS ] );
|
|
g_d3d_device->SetDepthStencilSurface( g_pFullScreenRTS[ RTS_DEFAULT_DS ] );
|
|
}
|
|
|
|
void Renderpipe::PrepareWithoutPostProcessing()
|
|
{
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX2 ] );
|
|
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 1.0f, 0 );
|
|
|
|
PrepareDefaultRenderStates();
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_LIGHTING, TRUE );
|
|
g_d3d_device->SetRenderState( D3DRS_ZENABLE, TRUE );
|
|
g_d3d_device->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_COLOR_MS ] );
|
|
g_d3d_device->SetDepthStencilSurface( g_pFullScreenRTS[ RTS_DEFAULT_DS ] );
|
|
}
|
|
|
|
void Renderpipe::PrepareShadowRenderStates()
|
|
{
|
|
g_d3d_device->SetRenderState( D3DRS_LIGHTING, FALSE );
|
|
g_d3d_device->SetRenderState( D3DRS_ZENABLE, TRUE );
|
|
g_d3d_device->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, FALSE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE );
|
|
g_d3d_device->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
|
|
|
|
for( int i= 0; i < 8; ++i )
|
|
{
|
|
g_d3d_device->SetTexture( i, NULL );
|
|
}
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_SHADOW ] );
|
|
g_d3d_device->SetDepthStencilSurface( g_pFullScreenRTS[ RTS_SHADOW_DS ] );
|
|
}
|
|
|
|
void Renderpipe::PreparePreRenderStates()
|
|
{
|
|
g_d3d_device->SetRenderState( D3DRS_LIGHTING, FALSE );
|
|
g_d3d_device->SetRenderState( D3DRS_ZENABLE, TRUE );
|
|
g_d3d_device->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, TRUE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE );
|
|
g_d3d_device->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
|
|
|
|
for( int i= 0; i < 8; ++i )
|
|
{
|
|
g_d3d_device->SetTexture( i, NULL );
|
|
}
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_DEPTH_MS ] );
|
|
g_d3d_device->SetDepthStencilSurface( g_pFullScreenRTS[ RTS_DEFAULT_DS ] );
|
|
}
|
|
|
|
void Renderpipe::PrepareFullScreenQuadRenderStates()
|
|
{
|
|
g_d3d_device->SetRenderState( D3DRS_LIGHTING, FALSE );
|
|
g_d3d_device->SetRenderState( D3DRS_ZENABLE, FALSE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, FALSE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE );
|
|
g_d3d_device->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
|
|
|
|
g_d3d_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
|
|
|
|
g_d3d_device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
|
g_d3d_device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
|
|
|
|
// sampler2D colorSampler : register(s0);
|
|
g_d3d_device->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_COLOR ] );
|
|
// sampler2D depthSampler : register(s1);
|
|
g_d3d_device->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 1, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 1, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetSamplerState( 1, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetTexture( 1, g_pFullScreenRT[ RT_DEPTH ] );
|
|
// sampler2D ditherSampler : register(s2);
|
|
g_d3d_device->SetSamplerState( 2, D3DSAMP_MINFILTER, D3DTEXF_POINT );
|
|
g_d3d_device->SetSamplerState( 2, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
|
|
g_d3d_device->SetSamplerState( 2, D3DSAMP_MIPFILTER, D3DTEXF_POINT );
|
|
g_d3d_device->SetSamplerState( 2, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP );
|
|
g_d3d_device->SetSamplerState( 2, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP );
|
|
g_d3d_device->SetTexture( 2, g_pTextures[ TI_RotMatrix ].GetPointer() );
|
|
// sampler2D mySampler1 : register(s3);
|
|
g_d3d_device->SetSamplerState( 3, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 3, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 3, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 3, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetSamplerState( 3, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetTexture( 3, NULL );
|
|
// sampler2D mySampler2 : register(s4);
|
|
g_d3d_device->SetSamplerState( 4, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 4, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 4, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
|
|
g_d3d_device->SetSamplerState( 4, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetSamplerState( 4, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );
|
|
g_d3d_device->SetTexture( 4, NULL );
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_COLOR_MS ] );
|
|
g_d3d_device->SetDepthStencilSurface( NULL );
|
|
}
|
|
|
|
void Renderpipe::PrepareRenderTargets(UINT nScreenX, UINT nScreenY, UINT nShadowXY, D3DMULTISAMPLE_TYPE multiSampleType)
|
|
{
|
|
// RTs erzeugen
|
|
g_d3d_device->CreateTexture( nScreenX,
|
|
nScreenY,
|
|
1,
|
|
D3DUSAGE_RENDERTARGET,
|
|
D3DFMT_R32F,
|
|
D3DPOOL_DEFAULT,
|
|
&(g_pFullScreenRT[ RT_DEPTH ]),
|
|
NULL);
|
|
g_d3d_device->CreateTexture( nScreenX,
|
|
nScreenY,
|
|
1,
|
|
D3DUSAGE_RENDERTARGET,
|
|
D3DFMT_A8R8G8B8,
|
|
D3DPOOL_DEFAULT,
|
|
&(g_pFullScreenRT[ RT_COLOR ]),
|
|
NULL);
|
|
g_d3d_device->CreateTexture( nScreenX,
|
|
nScreenY,
|
|
0,
|
|
D3DUSAGE_RENDERTARGET | D3DUSAGE_AUTOGENMIPMAP,
|
|
D3DFMT_A8R8G8B8,
|
|
D3DPOOL_DEFAULT,
|
|
&(g_pFullScreenRT[ RT_AUX1 ]),
|
|
NULL);
|
|
g_d3d_device->CreateTexture( nScreenX,
|
|
nScreenY,
|
|
1,
|
|
D3DUSAGE_RENDERTARGET,
|
|
D3DFMT_A8R8G8B8,
|
|
D3DPOOL_DEFAULT,
|
|
&(g_pFullScreenRT[ RT_AUX2 ]),
|
|
NULL);
|
|
g_d3d_device->CreateTexture( nShadowXY,
|
|
nShadowXY,
|
|
1,
|
|
D3DUSAGE_RENDERTARGET,
|
|
D3DFMT_R32F,
|
|
D3DPOOL_DEFAULT,
|
|
&(g_pFullScreenRT[ RT_SHADOW ]),
|
|
NULL);
|
|
|
|
// Multi-sampled depth surface erzeugen
|
|
g_d3d_device->CreateRenderTarget( nScreenX,
|
|
nScreenY,
|
|
D3DFMT_R32F,
|
|
multiSampleType,
|
|
0,
|
|
FALSE,
|
|
&(g_pFullScreenRTS[ RTS_DEPTH_MS ]),
|
|
NULL);
|
|
|
|
// Back Buffer holen
|
|
g_d3d_device->GetRenderTarget( 0, &(g_pFullScreenRTS[ RTS_COLOR_MS ]) );
|
|
|
|
// Depth-stencil Buffer holen
|
|
g_d3d_device->GetDepthStencilSurface( &(g_pFullScreenRTS[ RTS_DEFAULT_DS ]) );
|
|
|
|
// Non-multi-sampled depth-stencil surface erzeugen
|
|
g_d3d_device->CreateDepthStencilSurface( nShadowXY,
|
|
nShadowXY,
|
|
D3DFMT_D24S8,
|
|
D3DMULTISAMPLE_NONE,
|
|
0,
|
|
TRUE,
|
|
&(g_pFullScreenRTS[ RTS_SHADOW_DS ]),
|
|
NULL);
|
|
|
|
|
|
// Texture Surfaces holen
|
|
if( g_pFullScreenRT[ RT_DEPTH ] != NULL )
|
|
{
|
|
g_pFullScreenRT[ RT_DEPTH ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_DEPTH ]) );
|
|
}
|
|
if( g_pFullScreenRT[ RT_COLOR ] != NULL )
|
|
{
|
|
g_pFullScreenRT[ RT_COLOR ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_COLOR ]) );
|
|
}
|
|
if( g_pFullScreenRT[ RT_AUX1 ] != NULL )
|
|
{
|
|
g_pFullScreenRT[ RT_AUX1 ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_AUX1 ]) );
|
|
}
|
|
if( g_pFullScreenRT[ RT_AUX2 ] != NULL )
|
|
{
|
|
g_pFullScreenRT[ RT_AUX2 ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_AUX2 ]) );
|
|
}
|
|
if( g_pFullScreenRT[ RT_SHADOW ] != NULL )
|
|
{
|
|
g_pFullScreenRT[ RT_SHADOW ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_SHADOW ]) );
|
|
}
|
|
}
|
|
|
|
void Renderpipe::SimpleRenderPass()
|
|
{
|
|
/***********************************************************************************/
|
|
// Renderdurchlauf ohne Postprocessing
|
|
|
|
//normale Renderstati
|
|
Renderpipe::PrepareWithoutPostProcessing();
|
|
|
|
// Bildschirm loeschen
|
|
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff20b0f0, 1.0f, 0 );
|
|
|
|
//alle Renderpipes ausfueheren mit normalen Renderstati
|
|
for( int i= 0; i < ObjectCount; i++ )
|
|
{
|
|
g_Objects[ i ].Render();
|
|
}
|
|
|
|
g_SkyBox.RenderSky();
|
|
}
|
|
|
|
void Renderpipe::RenderPassPostProcessing()
|
|
{
|
|
/***********************************************************************************/
|
|
// vorbereitender Renderdurchlauf
|
|
|
|
//Pre-pass Renderstati
|
|
Renderpipe::PreparePreRenderStates();
|
|
|
|
// Bildschirm loeschen
|
|
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0 );
|
|
|
|
//alle Renderpipes ausfueheren mit pre-pass Renderstati
|
|
for( int i= 0; i < ObjectCount; i++ )
|
|
{
|
|
g_Objects[ i ].PreRender();
|
|
}
|
|
|
|
g_SkyBox.RenderSkyDepth();
|
|
|
|
// Tiefe in Textur kopieren
|
|
g_d3d_device->StretchRect( g_pFullScreenRTS[ RTS_DEPTH_MS ], NULL,
|
|
g_pFullScreenRTS[ RTS_DEPTH ], NULL, D3DTEXF_NONE );
|
|
|
|
/***********************************************************************************/
|
|
// Schatten-Renderdurchlauf
|
|
|
|
// Schatten löschen
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX2 ] );
|
|
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 1.0f, 0 );
|
|
|
|
// Shadow splits rendern
|
|
for(int iSplit = g_PSSM.m_iSplitCount; iSplit-- > 0; )
|
|
{
|
|
// Backup scene view-proj matrix
|
|
D3DXMATRIX matSceneVP;
|
|
memcpy( &matSceneVP, &g_matVP, sizeof(D3DXMATRIX) );
|
|
|
|
D3DXMATRIX matSplitVP;
|
|
float float4Vec[4];
|
|
|
|
//[VS] float4x4 matWVP : register(c0);
|
|
D3DXMatrixMultiply( &g_matVP, &g_PSSM.m_ViewMatrices[iSplit], &g_PSSM.m_ProjMatrices[iSplit] );
|
|
D3DXMatrixTranspose( &matSplitVP, &g_matVP );
|
|
memcpy( &g_matWVP, &matSplitVP, sizeof(D3DXMATRIX) );
|
|
g_d3d_device->SetVertexShaderConstantF( 0, (float*)&g_matWVP, 4 );
|
|
|
|
//[VS] float3 viewPos : register(c4);
|
|
//[PS] float3 viewPos : register(c2);
|
|
memcpy(float4Vec, &g_PSSM.m_ViewPos[iSplit], sizeof(float)*3);
|
|
g_d3d_device->SetVertexShaderConstantF( 4, float4Vec, 1 );
|
|
g_d3d_device->SetPixelShaderConstantF( 2, float4Vec, 1 );
|
|
|
|
//[VS] float3 viewDir : register(c10);
|
|
memcpy(float4Vec, &g_PSSM.m_ViewDir[iSplit], sizeof(float)*3);
|
|
g_d3d_device->SetVertexShaderConstantF( 10, float4Vec, 1 );
|
|
|
|
//Shadow-pass Renderstati
|
|
Renderpipe::PrepareShadowRenderStates();
|
|
|
|
// Schattentiefen loeschen
|
|
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0 );
|
|
|
|
//alle Renderpipes ausfueheren mit pre-pass Renderstati
|
|
for( int i= 0; i < ObjectCount; i++ )
|
|
{
|
|
g_Objects[ i ].PreRender();
|
|
}
|
|
|
|
// Pre-processing beginnen
|
|
Renderpipe::PrepareFullScreenQuadRenderStates();
|
|
|
|
//[VS] float4x4 matWVP : register(c0);
|
|
memcpy( &g_matVP, &matSceneVP, sizeof(D3DXMATRIX) );
|
|
D3DXMatrixTranspose( &g_matWVP, &g_matVP );
|
|
g_d3d_device->SetVertexShaderConstantF( 0, (float*)&g_matWVP, 4 );
|
|
|
|
//[VS] float3 viewPos : register(c4);
|
|
//[PS] float3 viewPos : register(c2);
|
|
memcpy(float4Vec, &g_Camera.m_vec3Pos, sizeof(float)*3);
|
|
g_d3d_device->SetVertexShaderConstantF( 4, float4Vec, 1 );
|
|
g_d3d_device->SetPixelShaderConstantF( 2, float4Vec, 1 );
|
|
|
|
//[VS] float3 viewDir : register(c10);
|
|
memcpy(float4Vec, &g_CamFront, sizeof(float)*3);
|
|
g_d3d_device->SetVertexShaderConstantF( 10, float4Vec, 1 );
|
|
|
|
//[PS] float split : register(c23);
|
|
float4Vec[0] = (float)iSplit;
|
|
g_d3d_device->SetPixelShaderConstantF( 23, float4Vec, 1 );
|
|
|
|
//[PS] float4x4 shadowVP : register(c24);
|
|
g_d3d_device->SetPixelShaderConstantF( 24, (float*)&matSplitVP, 4 );
|
|
|
|
//[PS] float2 shadowDepthOffsetScalingInverses : register(c28);
|
|
// float4Vec[0] = -g_PSSM.m_ProjMatrices[iSplit]._43;
|
|
// float4Vec[1] = 1.0f / g_PSSM.m_ProjMatrices[iSplit]._33;
|
|
// g_d3d_device->SetPixelShaderConstantF( 28, float4Vec, 1 );
|
|
|
|
//[PS] float3 g_vShadowViewPos : register(c28);
|
|
memcpy(float4Vec, &g_PSSM.m_ViewPos[iSplit], sizeof(float)*3);
|
|
g_d3d_device->SetPixelShaderConstantF( 28, float4Vec, 1 );
|
|
|
|
//[PS] float3 g_vShadowViewDir : register(c29);
|
|
memcpy(float4Vec, &g_PSSM.m_ViewDir[iSplit], sizeof(float)*3);
|
|
g_d3d_device->SetPixelShaderConstantF( 29, float4Vec, 1 );
|
|
|
|
//[PS] float2 shadowMapScaling : register(c30);
|
|
float4Vec[0] = g_PSSM.m_ProjMatrices[iSplit]._11 / 2.0f;
|
|
float4Vec[1] = g_PSSM.m_ProjMatrices[iSplit]._22 / 2.0f;
|
|
float4Vec[2] = (float)g_nShadowResolution;
|
|
float4Vec[3] = (float)g_nShadowResolution;
|
|
g_d3d_device->SetPixelShaderConstantF( 30, float4Vec, 1 );
|
|
|
|
// Shadow split auf die Szene projezieren
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX2 ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_SHADOW ] );
|
|
g_FullScreenQuad.m_iUsedShader[0] = PSSM_Proj;
|
|
g_FullScreenQuad.Render();
|
|
}
|
|
|
|
// Pre-processing beginnen
|
|
Renderpipe::PrepareFullScreenQuadRenderStates();
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX1 ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_AUX2 ] );
|
|
g_FullScreenQuad.m_iUsedShader[0] = SSAO_BlurH;
|
|
g_FullScreenQuad.Render();
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX2 ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_AUX1 ] );
|
|
g_FullScreenQuad.m_iUsedShader[0] = SSAO_BlurV;
|
|
g_FullScreenQuad.Render();
|
|
|
|
/***********************************************************************************/
|
|
// normaler Renderdurchlauf
|
|
|
|
//normale Renderstati
|
|
Renderpipe::PrepareDefaultRenderStates();
|
|
|
|
// Bildschirm loeschen
|
|
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET , 0xff20b0f0, 1.0f, 0 );
|
|
|
|
//alle Renderpipes ausfueheren mit normalen Renderstati
|
|
for( int i= 0; i < ObjectCount; i++ )
|
|
{
|
|
g_Objects[ i ].Render();
|
|
}
|
|
|
|
g_SkyBox.RenderSky();
|
|
|
|
// Farbe in Textur kopieren
|
|
g_d3d_device->StretchRect( g_pFullScreenRTS[ RTS_COLOR_MS ], NULL,
|
|
g_pFullScreenRTS[ RTS_COLOR ], NULL, D3DTEXF_NONE );
|
|
|
|
// Post-processing beginnen
|
|
Renderpipe::PrepareFullScreenQuadRenderStates();
|
|
|
|
#ifndef DISABLEDOF
|
|
bool bDOFEnabled = (g_Camera.m_fDOF >= 0.0f);
|
|
#else
|
|
bool bDOFEnabled = false;
|
|
#endif
|
|
|
|
float float4Vec[4];
|
|
|
|
// SSAO
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX1 ] );
|
|
g_FullScreenQuad.m_iUsedShader[0] = SSAO;
|
|
g_FullScreenQuad.Render();
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX2 ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_AUX1 ] );
|
|
g_FullScreenQuad.m_iUsedShader[0] = SSAO_BlurH;
|
|
g_FullScreenQuad.Render();
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ bDOFEnabled ? RTS_COLOR : RTS_COLOR_MS ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_AUX2 ] );
|
|
g_FullScreenQuad.m_bAlphaEnable[0] = true;
|
|
g_FullScreenQuad.m_SrcBlend[0] = D3DBLEND_DESTCOLOR;
|
|
g_FullScreenQuad.m_DestBlend[0] = D3DBLEND_ONE;
|
|
g_FullScreenQuad.m_BlendOp[0] = D3DBLENDOP_REVSUBTRACT;
|
|
g_FullScreenQuad.m_iUsedShader[0] = SSAO_BlurV;
|
|
g_FullScreenQuad.Render();
|
|
g_FullScreenQuad.m_bAlphaEnable[0] = false;
|
|
|
|
// Glow
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX1 ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_COLOR ] );
|
|
g_FullScreenQuad.m_iUsedShader[0] = Extract_InvAlpha;
|
|
g_FullScreenQuad.Render();
|
|
|
|
const int iNumGlowPasses = 3;
|
|
const int iGlowDownsampling = max(2 + g_iResolutionFactorExp, 0);
|
|
|
|
// Blur
|
|
{
|
|
float4Vec[0] = g_fGlow;
|
|
float4Vec[1] = g_fGlow;
|
|
float4Vec[2] = g_fGlow;
|
|
float4Vec[3] = g_fGlow;
|
|
g_d3d_device->SetPixelShaderConstantF( 31, float4Vec, 1 );
|
|
}
|
|
for(int iPass = 0; iPass < iNumGlowPasses; iPass++)
|
|
{
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX2 ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_AUX1 ] );
|
|
float4Vec[0] = d3dpp.BackBufferWidth / (float)(1 << iGlowDownsampling);
|
|
float4Vec[1] = d3dpp.BackBufferHeight / (float)(1 << iGlowDownsampling);
|
|
float4Vec[2] = 1.f / float4Vec[0];
|
|
float4Vec[3] = 1.f / float4Vec[1];
|
|
g_d3d_device->SetPixelShaderConstantF( 0, float4Vec, 1 );
|
|
if(iPass == 0)
|
|
{
|
|
float4Vec[0] = (float)iGlowDownsampling;
|
|
g_d3d_device->SetSamplerState( 0, D3DSAMP_MIPMAPLODBIAS, *((DWORD*)float4Vec) );
|
|
}
|
|
g_FullScreenQuad.m_iUsedShader[0] = BlurH;
|
|
g_FullScreenQuad.Render();
|
|
float4Vec[0] = 0.0f;
|
|
g_d3d_device->SetSamplerState( 0, D3DSAMP_MIPMAPLODBIAS, *((DWORD*)float4Vec) );
|
|
|
|
// Redirect last pass to screen
|
|
if(iPass == iNumGlowPasses - 1)
|
|
{
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ bDOFEnabled ? RTS_COLOR : RTS_COLOR_MS ] );
|
|
g_FullScreenQuad.m_bAlphaEnable[0] = true;
|
|
g_FullScreenQuad.m_SrcBlend[0] = D3DBLEND_ONE;
|
|
g_FullScreenQuad.m_DestBlend[0] = D3DBLEND_ONE;
|
|
g_FullScreenQuad.m_BlendOp[0] = D3DBLENDOP_ADD;
|
|
}
|
|
else
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX1 ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_AUX2 ] );
|
|
g_FullScreenQuad.m_iUsedShader[0] = BlurV;
|
|
g_FullScreenQuad.Render();
|
|
g_FullScreenQuad.m_bAlphaEnable[0] = false;
|
|
float4Vec[0] = (float)d3dpp.BackBufferWidth;
|
|
float4Vec[1] = (float)d3dpp.BackBufferHeight;
|
|
float4Vec[2] = 1.f / float4Vec[0];
|
|
float4Vec[3] = 1.f / float4Vec[1];
|
|
g_d3d_device->SetPixelShaderConstantF( 0, float4Vec, 1 );
|
|
}
|
|
|
|
// Ray
|
|
#ifndef DISABLERAY
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX1 ] );
|
|
g_d3d_device->SetTexture( 0, NULL );
|
|
g_FullScreenQuad.m_iUsedShader[0] = Ray_Mask;
|
|
g_FullScreenQuad.Render();
|
|
|
|
const int iNumRayPasses = 4;
|
|
|
|
// Extrude rays
|
|
for(int iPass = 0; iPass < iNumRayPasses; iPass++)
|
|
{
|
|
//[PS] float passID2exp : register(c23);
|
|
float4Vec[0] = (float)iPass;
|
|
float4Vec[1] = (float)(1 << iPass);
|
|
float4Vec[2] = (float)(iPass == iNumRayPasses - 1);
|
|
g_d3d_device->SetPixelShaderConstantF( 23, float4Vec, 1 );
|
|
|
|
// Redirect last pass to screen
|
|
if(iPass == iNumRayPasses - 1)
|
|
{
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ bDOFEnabled ? RTS_COLOR : RTS_COLOR_MS ] );
|
|
g_FullScreenQuad.m_bAlphaEnable[0] = true;
|
|
g_FullScreenQuad.m_SrcBlend[0] = D3DBLEND_ONE;
|
|
g_FullScreenQuad.m_DestBlend[0] = D3DBLEND_ONE;
|
|
g_FullScreenQuad.m_BlendOp[0] = D3DBLENDOP_ADD;
|
|
}
|
|
else
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ (iPass % 2 == 0) ? RTS_AUX2 : RTS_AUX1 ] );
|
|
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ (iPass % 2 == 0) ? RT_AUX1 : RT_AUX2 ] );
|
|
g_FullScreenQuad.m_iUsedShader[0] = Ray_Extrude;
|
|
g_FullScreenQuad.Render();
|
|
g_FullScreenQuad.m_bAlphaEnable[0] = false;
|
|
}
|
|
#endif
|
|
|
|
// DOF
|
|
if(bDOFEnabled)
|
|
{
|
|
const int iDOFDownsampling = max(2 + g_iResolutionFactorExp, 0);
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX1 ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_COLOR ] );
|
|
g_FullScreenQuad.m_iUsedShader[0] = DOF_Intensity;
|
|
g_FullScreenQuad.Render();
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX2 ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_AUX1 ] );
|
|
g_d3d_device->SetTexture( 4, g_pFullScreenRT[ RT_AUX1 ] );
|
|
float4Vec[0] = d3dpp.BackBufferWidth / (float)(1 << iDOFDownsampling);
|
|
float4Vec[1] = d3dpp.BackBufferHeight / (float)(1 << iDOFDownsampling);
|
|
float4Vec[2] = 1.f / float4Vec[0];
|
|
float4Vec[3] = 1.f / float4Vec[1];
|
|
g_d3d_device->SetPixelShaderConstantF( 0, float4Vec, 1 );
|
|
float4Vec[0] = (float)iDOFDownsampling;
|
|
g_d3d_device->SetSamplerState( 0, D3DSAMP_MIPMAPLODBIAS, *((DWORD*)float4Vec) );
|
|
g_FullScreenQuad.m_iUsedShader[0] = BlurBilH;
|
|
g_FullScreenQuad.Render();
|
|
float4Vec[0] = 0.0f;
|
|
g_d3d_device->SetSamplerState( 0, D3DSAMP_MIPMAPLODBIAS, *((DWORD*)float4Vec) );
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_COLOR ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_AUX2 ] );
|
|
g_d3d_device->SetTexture( 4, g_pFullScreenRT[ RT_AUX1 ] );
|
|
g_FullScreenQuad.m_iUsedShader[0] = BlurBilV;
|
|
g_FullScreenQuad.Render();
|
|
float4Vec[0] = (float)d3dpp.BackBufferWidth;
|
|
float4Vec[1] = (float)d3dpp.BackBufferHeight;
|
|
float4Vec[2] = 1.f / float4Vec[0];
|
|
float4Vec[3] = 1.f / float4Vec[1];
|
|
g_d3d_device->SetPixelShaderConstantF( 0, float4Vec, 1 );
|
|
|
|
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_COLOR_MS ] );
|
|
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_AUX1 ] );
|
|
g_d3d_device->SetTexture( 4, g_pFullScreenRT[ RT_COLOR ] );
|
|
g_FullScreenQuad.m_iUsedShader[0] = DOF;
|
|
g_FullScreenQuad.Render();
|
|
}
|
|
} |