1091 lines
37 KiB
C++
1091 lines
37 KiB
C++
#include "defines.h"
|
||
|
||
#include "shader.h"
|
||
#include "globals.h"
|
||
|
||
#include "Renderpipe.h"
|
||
|
||
extern float g_fLogoIntensity;
|
||
extern D3DXCOLOR g_FadeColor;
|
||
|
||
extern bool bLowDetail;
|
||
|
||
void Renderpipe::PrepareDefaultRenderStates(RenderTargetSurfaceIndices colorSurface,
|
||
RenderTargetSurfaceIndices depthSurface,
|
||
RenderTargetIndices linearDepthTexture)
|
||
{
|
||
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[ linearDepthTexture ] );
|
||
// samplerCube envSampler : register(s6);
|
||
if(colorSurface < RTS_ENVCUBE1 || colorSurface > RTS_ENVCUBE6)
|
||
{
|
||
g_d3d_device->SetSamplerState( 6, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
|
||
g_d3d_device->SetSamplerState( 6, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
|
||
g_d3d_device->SetSamplerState( 6, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
|
||
g_d3d_device->SetSamplerState( 6, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
|
||
g_d3d_device->SetSamplerState( 6, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );
|
||
g_d3d_device->SetSamplerState( 6, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP );
|
||
g_d3d_device->SetTexture( 6, g_pCubeRT[ RT_ENVCUBE ] );
|
||
}
|
||
else
|
||
g_d3d_device->SetTexture( 6, NULL );
|
||
// samplerCube envIntSampler : register(s7);
|
||
if(colorSurface < RTS_ENVCUBEINT1 || colorSurface > RTS_ENVCUBEINT6)
|
||
{
|
||
g_d3d_device->SetSamplerState( 7, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
|
||
g_d3d_device->SetSamplerState( 7, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
|
||
g_d3d_device->SetSamplerState( 7, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
|
||
g_d3d_device->SetSamplerState( 7, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
|
||
g_d3d_device->SetSamplerState( 7, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );
|
||
g_d3d_device->SetSamplerState( 7, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP );
|
||
g_d3d_device->SetTexture( 7, g_pCubeRT[ RT_ENVCUBEINT ] );
|
||
}
|
||
else
|
||
g_d3d_device->SetTexture( 7, NULL );
|
||
|
||
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[ colorSurface ] );
|
||
g_d3d_device->SetDepthStencilSurface( g_pFullScreenRTS[ depthSurface ] );
|
||
}
|
||
|
||
void Renderpipe::PrepareWithoutPostProcessing(RenderTargetSurfaceIndices colorSurface, RenderTargetSurfaceIndices depthSurface)
|
||
{
|
||
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[ colorSurface ] );
|
||
g_d3d_device->SetDepthStencilSurface( g_pFullScreenRTS[ depthSurface ] );
|
||
}
|
||
|
||
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_AUX_DS ] );
|
||
}
|
||
|
||
void Renderpipe::PreparePreRenderStates(RenderTargetSurfaceIndices colorSurface, RenderTargetSurfaceIndices depthSurface)
|
||
{
|
||
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[ colorSurface ] );
|
||
g_d3d_device->SetDepthStencilSurface( g_pFullScreenRTS[ depthSurface ] );
|
||
}
|
||
|
||
void Renderpipe::PrepareFullScreenQuadRenderStates(RenderTargetIndices linearDepthTexture,
|
||
RenderTargetIndices colorTexture)
|
||
{
|
||
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[ colorTexture ] );
|
||
// 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[ linearDepthTexture ] );
|
||
// 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->SetSamplerState( 3, D3DSAMP_ADDRESSW, 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->SetSamplerState( 4, D3DSAMP_ADDRESSW, D3DTADDRESS_CLAMP );
|
||
g_d3d_device->SetTexture( 4, NULL );
|
||
g_d3d_device->SetTexture( 5, NULL );
|
||
g_d3d_device->SetTexture( 6, NULL );
|
||
g_d3d_device->SetTexture( 7, NULL );
|
||
g_d3d_device->SetTexture( 8, 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, UINT nEnvXY, UINT nEnvBlurXY, D3DMULTISAMPLE_TYPE multiSampleType)
|
||
{
|
||
unsigned int nMaxEnvXY = max(nEnvXY, nEnvBlurXY);
|
||
unsigned int nMaxX = max( nScreenX, max(nShadowXY, nMaxEnvXY) );
|
||
unsigned int nMaxY = max( nScreenY, max(nShadowXY, nMaxEnvXY) );
|
||
|
||
// 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);
|
||
g_d3d_device->CreateTexture( nScreenX,
|
||
nScreenY,
|
||
1,
|
||
D3DUSAGE_RENDERTARGET,
|
||
D3DFMT_R32F,
|
||
D3DPOOL_DEFAULT,
|
||
&(g_pFullScreenRT[ RT_REFLECTION_DEPTH ]),
|
||
NULL);
|
||
g_d3d_device->CreateTexture( nScreenX,
|
||
nScreenY,
|
||
1,
|
||
D3DUSAGE_RENDERTARGET,
|
||
D3DFMT_A8R8G8B8,
|
||
D3DPOOL_DEFAULT,
|
||
&(g_pFullScreenRT[ RT_REFLECTION ]),
|
||
NULL);
|
||
g_d3d_device->CreateTexture( nEnvXY,
|
||
nEnvXY,
|
||
1,
|
||
D3DUSAGE_RENDERTARGET,
|
||
D3DFMT_R32F,
|
||
D3DPOOL_DEFAULT,
|
||
&(g_pFullScreenRT[ RT_CUBE_DEPTH ]),
|
||
NULL);
|
||
g_d3d_device->CreateCubeTexture( nEnvXY,
|
||
0,
|
||
D3DUSAGE_RENDERTARGET | D3DUSAGE_AUTOGENMIPMAP,
|
||
D3DFMT_A16B16G16R16F,
|
||
D3DPOOL_DEFAULT,
|
||
&(g_pCubeRT[ RT_ENVCUBE ]),
|
||
NULL);
|
||
g_d3d_device->CreateCubeTexture( nEnvBlurXY,
|
||
0,
|
||
D3DUSAGE_RENDERTARGET | D3DUSAGE_AUTOGENMIPMAP,
|
||
D3DFMT_A16B16G16R16F,
|
||
D3DPOOL_DEFAULT,
|
||
&(g_pCubeRT[ RT_ENVCUBEINT ]),
|
||
NULL);
|
||
|
||
// Multi-sampled depth surface erzeugen
|
||
g_d3d_device->CreateRenderTarget( nScreenX,
|
||
nScreenY,
|
||
D3DFMT_R32F,
|
||
multiSampleType,
|
||
0,
|
||
FALSE,
|
||
&(g_pFullScreenRTS[ RTS_DEPTH_MS ]),
|
||
NULL);
|
||
g_nFullScreenResX[ RTS_DEPTH_MS ] = nScreenX;
|
||
g_nFullScreenResY[ RTS_DEPTH_MS ] = nScreenY;
|
||
|
||
// Back Buffer holen
|
||
g_d3d_device->GetRenderTarget( 0, &(g_pFullScreenRTS[ RTS_COLOR_MS ]) );
|
||
g_nFullScreenResX[ RTS_COLOR_MS ] = nScreenX;
|
||
g_nFullScreenResY[ RTS_COLOR_MS ] = nScreenY;
|
||
|
||
// Depth-stencil Buffer holen
|
||
g_d3d_device->GetDepthStencilSurface( &(g_pFullScreenRTS[ RTS_DEFAULT_DS ]) );
|
||
g_nFullScreenResX[ RTS_DEFAULT_DS ] = nScreenX;
|
||
g_nFullScreenResY[ RTS_DEFAULT_DS ] = nScreenY;
|
||
|
||
// Non-multi-sampled depth-stencil surface erzeugen
|
||
g_d3d_device->CreateDepthStencilSurface( nMaxX,
|
||
nMaxY,
|
||
D3DFMT_D24S8,
|
||
D3DMULTISAMPLE_NONE,
|
||
0,
|
||
TRUE,
|
||
&(g_pFullScreenRTS[ RTS_AUX_DS ]),
|
||
NULL);
|
||
g_nFullScreenResX[ RTS_AUX_DS ] = nMaxX;
|
||
g_nFullScreenResY[ RTS_AUX_DS ] = nMaxY;
|
||
|
||
g_d3d_device->CreateDepthStencilSurface( nMaxEnvXY,
|
||
nMaxEnvXY,
|
||
D3DFMT_D24S8,
|
||
D3DMULTISAMPLE_NONE,
|
||
0,
|
||
FALSE,
|
||
&(g_pFullScreenRTS[ RTS_CUBE_DS ]),
|
||
NULL);
|
||
g_nFullScreenResX[ RTS_CUBE_DS ] = nMaxEnvXY;
|
||
g_nFullScreenResY[ RTS_CUBE_DS ] = nMaxEnvXY;
|
||
|
||
// Texture Surfaces holen
|
||
if( g_pFullScreenRT[ RT_DEPTH ] != NULL )
|
||
{
|
||
g_pFullScreenRT[ RT_DEPTH ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_DEPTH ]) );
|
||
g_nFullScreenResX[ RTS_DEPTH ] = nScreenX;
|
||
g_nFullScreenResY[ RTS_DEPTH ] = nScreenY;
|
||
}
|
||
if( g_pFullScreenRT[ RT_COLOR ] != NULL )
|
||
{
|
||
g_pFullScreenRT[ RT_COLOR ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_COLOR ]) );
|
||
g_nFullScreenResX[ RTS_COLOR ] = nScreenX;
|
||
g_nFullScreenResY[ RTS_COLOR ] = nScreenY;
|
||
}
|
||
if( g_pFullScreenRT[ RT_AUX1 ] != NULL )
|
||
{
|
||
g_pFullScreenRT[ RT_AUX1 ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_AUX1 ]) );
|
||
g_nFullScreenResX[ RTS_AUX1 ] = nScreenX;
|
||
g_nFullScreenResY[ RTS_AUX1 ] = nScreenY;
|
||
}
|
||
if( g_pFullScreenRT[ RT_AUX2 ] != NULL )
|
||
{
|
||
g_pFullScreenRT[ RT_AUX2 ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_AUX2 ]) );
|
||
g_nFullScreenResX[ RTS_AUX2 ] = nScreenX;
|
||
g_nFullScreenResY[ RTS_AUX2 ] = nScreenY;
|
||
}
|
||
if( g_pFullScreenRT[ RT_SHADOW ] != NULL )
|
||
{
|
||
g_pFullScreenRT[ RT_SHADOW ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_SHADOW ]) );
|
||
g_nFullScreenResX[ RTS_SHADOW ] = nShadowXY;
|
||
g_nFullScreenResY[ RTS_SHADOW ] = nShadowXY;
|
||
}
|
||
if( g_pFullScreenRT[ RT_REFLECTION_DEPTH ] != NULL )
|
||
{
|
||
g_pFullScreenRT[ RT_REFLECTION_DEPTH ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_REFLECTION_DEPTH ]) );
|
||
g_nFullScreenResX[ RTS_REFLECTION_DEPTH ] = nScreenX;
|
||
g_nFullScreenResY[ RTS_REFLECTION_DEPTH ] = nScreenY;
|
||
}
|
||
if( g_pFullScreenRT[ RT_REFLECTION ] != NULL )
|
||
{
|
||
g_pFullScreenRT[ RT_REFLECTION ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_REFLECTION ]) );
|
||
g_nFullScreenResX[ RTS_REFLECTION ] = nScreenX;
|
||
g_nFullScreenResY[ RTS_REFLECTION ] = nScreenY;
|
||
}
|
||
if( g_pFullScreenRT[ RT_CUBE_DEPTH ] != NULL )
|
||
{
|
||
g_pFullScreenRT[ RT_CUBE_DEPTH ]->GetSurfaceLevel( 0, &(g_pFullScreenRTS[ RTS_CUBE_DEPTH ]) );
|
||
g_nFullScreenResX[ RTS_CUBE_DEPTH ] = nEnvXY;
|
||
g_nFullScreenResY[ RTS_CUBE_DEPTH ] = nEnvXY;
|
||
}
|
||
if( g_pCubeRT[ RT_ENVCUBE ] != NULL )
|
||
{
|
||
for(int i = 0; i < 6; i++)
|
||
{
|
||
int iRTS = RTS_ENVCUBE1 + i;
|
||
|
||
g_pCubeRT[ RT_ENVCUBE ]->GetCubeMapSurface( (D3DCUBEMAP_FACES)i, 0, &(g_pFullScreenRTS[ iRTS ]) );
|
||
g_nFullScreenResX[ iRTS ] = nEnvXY;
|
||
g_nFullScreenResY[ iRTS ] = nEnvXY;
|
||
}
|
||
}
|
||
if( g_pCubeRT[ RT_ENVCUBEINT ] != NULL )
|
||
{
|
||
for(int i = 0; i < 6; i++)
|
||
{
|
||
int iRTS = RTS_ENVCUBEINT1 + i;
|
||
|
||
g_pCubeRT[ RT_ENVCUBEINT ]->GetCubeMapSurface( (D3DCUBEMAP_FACES)i, 0, &(g_pFullScreenRTS[ iRTS ]) );
|
||
g_nFullScreenResX[ iRTS ] = nEnvBlurXY;
|
||
g_nFullScreenResY[ iRTS ] = nEnvBlurXY;
|
||
}
|
||
}
|
||
}
|
||
|
||
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++ )
|
||
{
|
||
if( IsObjInScene( (ObjectIndices)i ) )
|
||
{
|
||
g_Objects[ i ].Render();
|
||
}
|
||
}
|
||
|
||
if( IsObjInScene( OI_SKY ) || IsObjInScene( OI_SKY_CUBEMAP ) || IsObjInScene( OI_SKY_CAVE ) )
|
||
{
|
||
g_SkyBox.RenderSky();
|
||
}
|
||
}
|
||
|
||
void Renderpipe::FullRenderPass()
|
||
{
|
||
bool bOcean = IsObjInScene( OI_OCEAN );
|
||
bool bSSAO = ( IsObjInScene( OI_SKY_CUBEMAP ) || IsObjInScene( OI_CAVE_FIRST ) ) && (!bLowDetail);
|
||
|
||
#if defined(MESHTESTER)
|
||
bOcean = false;
|
||
#endif
|
||
|
||
// Check whether under water
|
||
bool bSubmerged = (g_Camera.m_vec3Pos.y < g_OceanWater.m_fWaterLevel);
|
||
|
||
// Reflexion
|
||
if(bOcean && !bSubmerged)
|
||
RenderReflection();
|
||
|
||
// Render
|
||
RenderScene(g_matView, g_matProjection, g_Camera.m_vec3Pos, g_CamFront,
|
||
RTS_COLOR_MS, RTS_COLOR, RTS_DEPTH_MS, RTS_DEPTH, RTS_DEFAULT_DS, RT_DEPTH);
|
||
RenderPostProcessing(bSubmerged, bOcean, bSSAO);
|
||
}
|
||
|
||
void Renderpipe::CubeRenderPass()
|
||
{
|
||
// Loop over cube faces
|
||
for(int i = 0; i < 6; i++)
|
||
{
|
||
// Shadow splits aktualisieren
|
||
g_PSSM.UpdateSplits(g_LightDir, g_Environment.m_ViewMatrix[i], g_Environment.m_ProjMatrix[i]);
|
||
|
||
// Render
|
||
RenderTargetSurfaceIndices colorSurface = (RenderTargetSurfaceIndices)(RTS_ENVCUBE1 + i);
|
||
RenderScene(g_Environment.m_ViewMatrix[i], g_Environment.m_ProjMatrix[i],
|
||
g_Environment.m_ViewPos[i], g_Environment.m_ViewDir[i],
|
||
colorSurface, colorSurface, RTS_CUBE_DEPTH, RTS_CUBE_DEPTH, RTS_CUBE_DS, RT_CUBE_DEPTH);
|
||
}
|
||
}
|
||
|
||
void Renderpipe::CubeBlurPass()
|
||
{
|
||
const float MaxAngle = D3DXToRadian(180.0f);
|
||
const float NumRounds = 139.0f;
|
||
const int NumSteps = 512;
|
||
float WeightSum = 325.81241f / 512 * NumSteps;
|
||
|
||
// Post-processing beginnen
|
||
Renderpipe::PrepareFullScreenQuadRenderStates();
|
||
|
||
// Blur
|
||
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;
|
||
g_FullScreenQuad.m_iUsedShader[0] = TexGen_CubeBlur;
|
||
|
||
// Loop over cube faces
|
||
for(int i = 0; i < 6; i++)
|
||
{
|
||
int iRTS = RTS_ENVCUBEINT1 + i;
|
||
|
||
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ (RenderTargetSurfaceIndices)iRTS ] );
|
||
g_d3d_device->SetTexture( 4, g_pCubeRT[ RT_ENVCUBE ] );
|
||
|
||
// Face loeschen
|
||
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET, 0, 1.0f, 0 );
|
||
|
||
// Set screen resoluton
|
||
Shader::SetResolution(g_nFullScreenResX[iRTS], g_nFullScreenResY[iRTS]);
|
||
|
||
float fWeightSum = 0.0f;
|
||
|
||
for(int j = 0; j < NumSteps; j++)
|
||
{
|
||
float fStep = (float)j / (NumSteps - 1);
|
||
float fRotAngleAngle = NumRounds * c_2PI * fStep;
|
||
// float fRotAngleAngle = 0.2f; // g_Random.genFloat(0.0f, c_2PI);
|
||
float fRotAngle = MaxAngle * fStep;
|
||
// float fRotAngle = g_Random.genFloat(0.0f, MaxAngle);
|
||
|
||
D3DXMATRIX mRotX, mRotY, mCube;
|
||
D3DXMatrixRotationX(&mRotX, cos(fRotAngleAngle) * fRotAngle);
|
||
D3DXMatrixRotationY(&mRotY, sin(fRotAngleAngle) * fRotAngle);
|
||
D3DXMatrixMultiply(&mCube, &mRotX, &mRotY);
|
||
D3DXMatrixMultiply(&mCube, &g_Environment.m_LocalMatrix[i], &mCube);
|
||
|
||
//[PS] float3x3 g_mCubeMatrix : register(c40);
|
||
g_d3d_device->SetPixelShaderConstantF( 40, (float*)&mCube, 3 );
|
||
|
||
float float4Vec[4];
|
||
|
||
//[PS] float g_fCubeWeight : register(c43);
|
||
float4Vec[0] = cos( c_PI / 2 * fRotAngle / MaxAngle );
|
||
fWeightSum += float4Vec[0];
|
||
float4Vec[0] /= WeightSum;
|
||
g_d3d_device->SetPixelShaderConstantF( 43, float4Vec, 1 );
|
||
|
||
// Blur
|
||
g_FullScreenQuad.Render();
|
||
}
|
||
|
||
WeightSum = fWeightSum;
|
||
}
|
||
|
||
g_FullScreenQuad.m_bAlphaEnable[0] = false;
|
||
}
|
||
|
||
void Renderpipe::RenderScene(const D3DXMATRIX &mView, const D3DXMATRIX &mProj,
|
||
const D3DXVECTOR3 &vCamPos, const D3DXVECTOR3 &vCamDir,
|
||
RenderTargetSurfaceIndices colorSurfaceMS, RenderTargetSurfaceIndices colorSurface,
|
||
RenderTargetSurfaceIndices linearDepthSurfaceMS, RenderTargetSurfaceIndices linearDepthSurface,
|
||
RenderTargetSurfaceIndices depthSurface, RenderTargetIndices linearDepthTexture)
|
||
{
|
||
/***********************************************************************************/
|
||
// vorbereitender Renderdurchlauf
|
||
|
||
//Pre-pass Renderstati
|
||
Renderpipe::PreparePreRenderStates(linearDepthSurfaceMS, depthSurface);
|
||
|
||
// Bildschirm loeschen
|
||
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0 );
|
||
|
||
// Set screen resoluton
|
||
Shader::SetResolution(g_nFullScreenResX[linearDepthSurfaceMS], g_nFullScreenResY[linearDepthSurfaceMS]);
|
||
|
||
// Set camera
|
||
Shader::SetCamera(mView, mProj, vCamPos, vCamDir);
|
||
|
||
//alle Renderpipes ausfueheren mit pre-pass Renderstati
|
||
for( int i= 0; i < ObjectCount; i++ )
|
||
{
|
||
if( IsObjInScene( (ObjectIndices)i ) )
|
||
{
|
||
g_Objects[ i ].PreRender();
|
||
}
|
||
}
|
||
|
||
if( IsObjInScene( OI_SKY ) || IsObjInScene( OI_SKY_CUBEMAP ) || IsObjInScene( OI_SKY_CAVE ) )
|
||
{
|
||
g_SkyBox.RenderSkyDepth();
|
||
}
|
||
|
||
#ifndef DISABLEFLUIDS
|
||
if( IsObjInScene( OI_FLUIDS ) )
|
||
{
|
||
for (int i = 0; i < FI_Count; ++i)
|
||
{
|
||
if (!g_FluidParticleSystem[i].IsVisible)
|
||
continue;
|
||
g_FluidContext.RenderParticleDepth(g_FluidParticleSystem[i]);
|
||
}
|
||
}
|
||
#endif
|
||
|
||
// Tiefe in Textur kopieren
|
||
if(linearDepthSurface != linearDepthSurfaceMS)
|
||
g_d3d_device->StretchRect( g_pFullScreenRTS[ linearDepthSurfaceMS ], NULL,
|
||
g_pFullScreenRTS[ linearDepthSurface ], NULL, D3DTEXF_NONE );
|
||
|
||
/***********************************************************************************/
|
||
// Schatten-Renderdurchlauf
|
||
|
||
// Schatten l<>schen
|
||
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_AUX2 ] );
|
||
g_d3d_device->SetDepthStencilSurface(NULL);
|
||
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET, 0xffffffff, 1.0f, 0 );
|
||
|
||
// Shadow splits rendern
|
||
for(int iSplit = g_PSSM.m_iSplitCount; iSplit-- > 0; )
|
||
{
|
||
//Shadow-pass Renderstati
|
||
Renderpipe::PrepareShadowRenderStates();
|
||
|
||
// Schattentiefen loeschen
|
||
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0 );
|
||
|
||
D3DXMATRIX matSplitVP;
|
||
|
||
// Set shadow camera
|
||
Shader::SetCamera(g_PSSM.m_ViewMatrices[iSplit], g_PSSM.m_ProjMatrices[iSplit],
|
||
g_PSSM.m_ViewPos[iSplit], g_PSSM.m_ViewDir[iSplit],
|
||
&matSplitVP);
|
||
|
||
// Set screen resoluton
|
||
Shader::SetResolution(g_nFullScreenResX[RTS_SHADOW], g_nFullScreenResY[RTS_SHADOW]);
|
||
|
||
//alle Renderpipes ausfueheren mit pre-pass Renderstati
|
||
for( int i= 0; i < ObjectCount; i++ )
|
||
{
|
||
if( IsObjInScene( (ObjectIndices)i ) )
|
||
{
|
||
g_Objects[ i ].PreRender();
|
||
}
|
||
}
|
||
|
||
// Pre-processing beginnen
|
||
Renderpipe::PrepareFullScreenQuadRenderStates(linearDepthTexture);
|
||
|
||
// Reset camera
|
||
Shader::SetCamera(mView, mProj, vCamPos, vCamDir);
|
||
|
||
// Set screen resoluton
|
||
Shader::SetResolution(g_nFullScreenResX[RTS_AUX2], g_nFullScreenResY[RTS_AUX2]);
|
||
|
||
float float4Vec[4];
|
||
|
||
//[PS] float split : register(c23);
|
||
float4Vec[0] = (float)iSplit;
|
||
g_d3d_device->SetPixelShaderConstantF( 23, float4Vec, 1 );
|
||
|
||
//[PS] float4x4 shadowVP : register(c24);
|
||
D3DXMatrixTranspose(&matSplitVP, &matSplitVP);
|
||
g_d3d_device->SetPixelShaderConstantF( 24, (float*)&matSplitVP, 4 );
|
||
|
||
//[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_nFullScreenResX[ RTS_SHADOW ];
|
||
float4Vec[3] = (float)g_nFullScreenResY[ RTS_SHADOW ];
|
||
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();
|
||
|
||
// Schatten blurren
|
||
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(colorSurfaceMS, depthSurface, linearDepthTexture);
|
||
|
||
// Bildschirm loeschen
|
||
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET , 0xff20b0f0, 1.0f, 0 );
|
||
|
||
// Set screen resoluton
|
||
Shader::SetResolution(g_nFullScreenResX[colorSurfaceMS], g_nFullScreenResY[colorSurfaceMS]);
|
||
|
||
//alle Renderpipes ausfueheren mit normalen Renderstati
|
||
for( int i= 0; i < ObjectCount; i++ )
|
||
{
|
||
if( IsObjInScene( (ObjectIndices)i ) )
|
||
{
|
||
g_Objects[ i ].Render();
|
||
}
|
||
}
|
||
|
||
if( IsObjInScene( OI_SKY ) || IsObjInScene( OI_SKY_CUBEMAP ) || IsObjInScene( OI_SKY_CAVE ) )
|
||
{
|
||
g_SkyBox.RenderSky();
|
||
}
|
||
}
|
||
|
||
void Renderpipe::RenderPostProcessing(bool bSubmerged, bool bOcean, bool bSSAO)
|
||
{
|
||
// Set screen resoluton
|
||
Shader::SetResolution(g_nFullScreenResX[RTS_COLOR_MS], g_nFullScreenResY[RTS_COLOR_MS]);
|
||
|
||
if(bOcean && bSubmerged)
|
||
{
|
||
// Farbe in Textur kopieren
|
||
g_d3d_device->StretchRect( g_pFullScreenRTS[ RTS_COLOR_MS ], NULL,
|
||
g_pFullScreenRTS[ RTS_COLOR ], NULL, D3DTEXF_NONE );
|
||
|
||
// Water
|
||
g_Ocean.RenderWater(true);
|
||
}
|
||
|
||
// Post-processing beginnen
|
||
Renderpipe::PrepareFullScreenQuadRenderStates();
|
||
|
||
#ifndef DISABLEDOF
|
||
bool bDOFEnabled = (g_Camera.m_fDOF >= 0.0f);
|
||
#else
|
||
bool bDOFEnabled = false;
|
||
#endif
|
||
|
||
float float4Vec[4];
|
||
|
||
if(bSSAO)
|
||
{
|
||
// 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_COLOR ] );
|
||
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[ RTS_COLOR_MS ] );
|
||
g_d3d_device->SetTexture( 0, g_pFullScreenRT[ RT_COLOR ] );
|
||
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;
|
||
}
|
||
|
||
if(bOcean)
|
||
{
|
||
// Shadows
|
||
g_d3d_device->SetTexture( 4, g_pFullScreenRT[ RT_AUX2 ] );
|
||
|
||
// Don't break glow
|
||
g_d3d_device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
|
||
g_d3d_device->SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_ZERO);
|
||
g_d3d_device->SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_ONE);
|
||
g_d3d_device->SetRenderState(D3DRS_BLENDOPALPHA, D3DBLENDOP_ADD);
|
||
|
||
// Underwater filter
|
||
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_COLOR_MS ] );
|
||
g_FullScreenQuad.m_bAlphaEnable[0] = true;
|
||
g_FullScreenQuad.m_SrcBlend[0] = D3DBLEND_SRCALPHA;
|
||
g_FullScreenQuad.m_DestBlend[0] = D3DBLEND_SRCCOLOR;
|
||
g_FullScreenQuad.m_BlendOp[0] = D3DBLENDOP_ADD;
|
||
g_FullScreenQuad.m_iUsedShader[0] = Underwater_Filter;
|
||
g_FullScreenQuad.Render();
|
||
g_FullScreenQuad.m_bAlphaEnable[0] = false;
|
||
|
||
// Underwater
|
||
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_COLOR_MS ] );
|
||
g_FullScreenQuad.m_bAlphaEnable[0] = true;
|
||
g_FullScreenQuad.m_SrcBlend[0] = D3DBLEND_ONE;
|
||
g_FullScreenQuad.m_DestBlend[0] = D3DBLEND_INVSRCALPHA;
|
||
g_FullScreenQuad.m_BlendOp[0] = D3DBLENDOP_ADD;
|
||
g_FullScreenQuad.m_iUsedShader[0] = Underwater;
|
||
g_FullScreenQuad.Render();
|
||
g_FullScreenQuad.m_bAlphaEnable[0] = false;
|
||
|
||
// Don't break alpha blending
|
||
g_d3d_device->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE);
|
||
|
||
//Pre-pass Renderstati
|
||
Renderpipe::PreparePreRenderStates();
|
||
|
||
// Water depth
|
||
g_Ocean.RenderWaterDepth(bSubmerged);
|
||
|
||
if(!bSubmerged)
|
||
{
|
||
// Farbe in Textur kopieren
|
||
g_d3d_device->StretchRect( g_pFullScreenRTS[ RTS_COLOR_MS ], NULL,
|
||
g_pFullScreenRTS[ RTS_COLOR ], NULL, D3DTEXF_NONE );
|
||
|
||
//normale Renderstati
|
||
Renderpipe::PrepareDefaultRenderStates();
|
||
|
||
// Water
|
||
g_Ocean.RenderWater(false);
|
||
}
|
||
|
||
// Tiefe in Textur kopieren
|
||
g_d3d_device->StretchRect( g_pFullScreenRTS[ RTS_DEPTH_MS ], NULL,
|
||
g_pFullScreenRTS[ RTS_DEPTH ], NULL, D3DTEXF_NONE );
|
||
}
|
||
|
||
// Fluid
|
||
#ifndef DISABLEFLUIDS
|
||
if( IsObjInScene( OI_FLUIDS ) )
|
||
{
|
||
for (int i = 0; i < FI_Count; ++i)
|
||
{
|
||
if (!g_FluidParticleSystem[i].IsVisible)
|
||
continue;
|
||
|
||
// Farbe in Textur kopieren
|
||
g_d3d_device->StretchRect( g_pFullScreenRTS[ RTS_COLOR_MS ], NULL,
|
||
g_pFullScreenRTS[ RTS_COLOR ], NULL, D3DTEXF_NONE );
|
||
|
||
// Partikel rendern
|
||
Renderpipe::PrepareDefaultRenderStates();
|
||
g_FluidContext.Begin(g_Fluid);
|
||
|
||
g_FluidContext.RenderParticles(g_FluidParticleSystem[i]);
|
||
|
||
g_FluidContext.End();
|
||
|
||
// Fluid rendern
|
||
Renderpipe::PrepareDefaultRenderStates();
|
||
g_FluidContext.Display(g_Fluid);
|
||
}
|
||
}
|
||
#endif
|
||
|
||
// 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();
|
||
|
||
// 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(3 + g_iResolutionFactorExp, 0);
|
||
|
||
// Blur
|
||
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
|
||
if( (!bOcean || !bSubmerged) && !bLowDetail)
|
||
{
|
||
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();
|
||
}
|
||
|
||
// Logo
|
||
if(g_fLogoIntensity > 0.001f)
|
||
{
|
||
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_COLOR_MS ] );
|
||
float4Vec[0] = g_fLogoIntensity;
|
||
g_d3d_device->SetPixelShaderConstantF( 50, float4Vec, 1 );
|
||
g_FullScreenQuad.m_bAlphaEnable[0] = true;
|
||
g_FullScreenQuad.m_SrcBlend[0] = D3DBLEND_ONE;
|
||
g_FullScreenQuad.m_DestBlend[0] = D3DBLEND_INVSRCALPHA;
|
||
g_FullScreenQuad.m_BlendOp[0] = D3DBLENDOP_ADD;
|
||
g_FullScreenQuad.m_iUsedShader[0] = Overlay_Logo;
|
||
g_FullScreenQuad.Render();
|
||
g_FullScreenQuad.m_bAlphaEnable[0] = false;
|
||
}
|
||
|
||
// Fade
|
||
if(g_FadeColor.a > 0.001f)
|
||
{
|
||
g_d3d_device->SetRenderTarget( 0, g_pFullScreenRTS[ RTS_COLOR_MS ] );
|
||
g_d3d_device->SetPixelShaderConstantF( 51, (float*) &g_FadeColor, 1 );
|
||
g_FullScreenQuad.m_bAlphaEnable[0] = true;
|
||
g_FullScreenQuad.m_SrcBlend[0] = D3DBLEND_ONE;
|
||
g_FullScreenQuad.m_DestBlend[0] = D3DBLEND_INVSRCALPHA;
|
||
g_FullScreenQuad.m_BlendOp[0] = D3DBLENDOP_ADD;
|
||
g_FullScreenQuad.m_iUsedShader[0] = Overlay_Fade;
|
||
g_FullScreenQuad.Render();
|
||
g_FullScreenQuad.m_bAlphaEnable[0] = false;
|
||
}
|
||
}
|
||
|
||
void Renderpipe::RenderReflection()
|
||
{
|
||
// Set reflection camera
|
||
Shader::SetCamera(g_OceanWater.m_ViewMatrix, g_OceanWater.m_ProjMatrix,
|
||
g_OceanWater.m_ViewPos, g_OceanWater.m_ViewDir );
|
||
|
||
/***********************************************************************************/
|
||
// vorbereitender Reflexions-Renderdurchlauf
|
||
|
||
// Set screen resoluton
|
||
Shader::SetResolution(g_nFullScreenResX[RTS_REFLECTION_DEPTH], g_nFullScreenResY[RTS_REFLECTION_DEPTH]);
|
||
|
||
//Pre-pass Renderstati
|
||
Renderpipe::PreparePreRenderStates(RTS_REFLECTION_DEPTH, RTS_AUX_DS);
|
||
g_d3d_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW );
|
||
|
||
// 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++ )
|
||
{
|
||
if( IsObjInScene( (ObjectIndices)i ) )
|
||
{
|
||
g_Objects[ i ].PreRender();
|
||
}
|
||
}
|
||
|
||
if( IsObjInScene( OI_SKY ) || IsObjInScene( OI_SKY_CUBEMAP ) || IsObjInScene( OI_SKY_CAVE ) )
|
||
{
|
||
g_SkyBox.RenderSkyDepth(true);
|
||
}
|
||
|
||
/***********************************************************************************/
|
||
// normaler Reflexions-Renderdurchlauf
|
||
|
||
// Set screen resoluton
|
||
Shader::SetResolution(g_nFullScreenResX[RTS_REFLECTION], g_nFullScreenResY[RTS_REFLECTION]);
|
||
|
||
//normale Renderstati
|
||
Renderpipe::PrepareDefaultRenderStates(RTS_REFLECTION, RTS_AUX_DS);
|
||
g_d3d_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW );
|
||
|
||
// 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++ )
|
||
{
|
||
if( IsObjInScene( (ObjectIndices)i ) )
|
||
{
|
||
g_Objects[ i ].Render();
|
||
}
|
||
}
|
||
|
||
if( IsObjInScene( OI_SKY ) || IsObjInScene( OI_SKY_CUBEMAP ) || IsObjInScene( OI_SKY_CAVE ) )
|
||
{
|
||
g_SkyBox.RenderSky(true);
|
||
}
|
||
|
||
// Reset camera
|
||
Shader::SetCamera(g_matView, g_matProjection,
|
||
g_Camera.m_vec3Pos, g_CamFront);
|
||
}
|