add game&rawdata

This commit is contained in:
Vasily Petrov 2026-06-17 23:06:51 +03:00
parent 0133cd976c
commit 49b34b5546
45731 changed files with 709831 additions and 0 deletions

View file

@ -0,0 +1,78 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
//////////////////////////////////////////////////////////////////////////////////////////
// This is the basic primitive used by convex, volumetric lights
// for example spot-lights, one face of the omni lights, etc.
//////////////////////////////////////////////////////////////////////////////////////////
// following options are available to configure compilation:
// USE_LMAP
// USE_LMAPXFORM
// USE_SHADOW
//////////////////////////////////////////////////////////////////////////////////////////
uniform float4 m_lmap [2] ;
//float4 main( float4 tc : TEXCOORD0, float4 tcJ : TEXCOORD1 ) : SV_Target
#ifdef MSAA_OPTIMIZATION
#ifdef GBUFFER_OPTIMIZATION
float4 main( p_volume I, float4 pos2d : SV_Position, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main( p_volume I, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#endif
#else
#ifdef GBUFFER_OPTIMIZATION
float4 main( p_volume I, float4 pos2d : SV_Position ) : SV_Target
#else
float4 main( p_volume I ) : SV_Target
#endif
#endif
{
// float4 _P = tex2Dproj (s_position, tc);
// float4 _N = tex2Dproj (s_normal, tc);
float2 tcProj = I.tc.xy / I.tc.w;
gbuffer_data gbd = gbuffer_load_data( GLD_P(tcProj, pos2d, ISAMPLE) );
#ifdef GBUFFER_OPTIMIZATION
// Emulate virtual offset
gbd.P += gbd.N*0.015f;
#endif // GBUFFER_OPTIMIZATION
float4 _P = float4( gbd.P, gbd.mtl );
float4 _N = float4( gbd.N, gbd.hemi );
float m = xmaterial ;
# ifndef USE_R2_STATIC_SUN
m = _P.w ;
# endif
// ----- light-model
float rsqr;
float4 light = plight_local( m, _P, _N, Ldynamic_pos, Ldynamic_pos.w, rsqr );
// ----- shadow
float4 P4 = float4( _P.x, _P.y, _P.z, 1);
float4 PS = mul( m_shadow, P4 );
float s = 1.h;
#ifdef USE_SHADOW
#ifdef USE_SJITTER
s = shadowtest( PS, I.tcJ );
#else
s = shadow( PS );
#endif
#endif
// ----- lightmap
float4 lightmap= 1.h;
#ifdef USE_LMAP
#ifdef USE_LMAPXFORM
PS.x = dot( P4, m_lmap[0] );
PS.y = dot( P4, m_lmap[1] );
#endif
//lightmap= tex2Dproj (s_lmap, PS); //
// Can use linear with mip point
lightmap = s_lmap.Sample( smp_rtlinear, PS.xy / PS.w ); //
#endif
return blendp ( Ldynamic_color * light * s * lightmap, I.tc );
}

View file

@ -0,0 +1,7 @@
#include "common.h"
//float4 main ( p_flat I ) : SV_Target
float4 main() : SV_Target
{
return float4 (1,1,1,1)*16.0h;
}

View file

@ -0,0 +1,7 @@
#include "common.h"
//float4 main ( p_flat I ) : SV_Target
float4 main() : SV_Target
{
return float4 (1,1,1,0)*1.0h;
}

View file

@ -0,0 +1,43 @@
#include "common.h"
#include "lmodel.h"
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
// Note: this is a float-sphere
uniform float3 direction;
#ifdef MSAA_OPTIMIZATION
#ifdef GBUFFER_OPTIMIZATION
float4 main ( float4 tc:TEXCOORD0, float4 pos2d : SV_Position, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main ( float4 tc:TEXCOORD0, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#endif
#else
#ifdef GBUFFER_OPTIMIZATION
float4 main ( float4 tc:TEXCOORD0, float4 pos2d : SV_Position ) : SV_Target
#else
float4 main ( float4 tc:TEXCOORD0 ) : SV_Target
#endif
#endif
{
// float4 _P = tex2Dproj (s_position, tc);
// float4 _N = tex2Dproj (s_normal, tc);
float2 tcProj = tc.xy / tc.w;
gbuffer_data gbd = gbuffer_load_data( GLD_P(tcProj, pos2d, ISAMPLE) );
//float4 _P = s_position.Sample( smp_nofilter, tcProj );
//float4 _N = s_normal.Sample( smp_nofilter, tcProj );
float4 _P = float4( gbd.P, gbd.mtl );
float4 _N = float4( gbd.N, gbd.hemi );
float3 L2P = _P.xyz - Ldynamic_pos.xyz; // light2point
float3 L2P_N = normalize ( L2P ); // light2point
float rsqr = dot ( L2P, L2P ); // distance 2 light (squared)
float att = saturate ( 1 - rsqr*Ldynamic_pos.w );// q-linear attenuate
float light = saturate ( dot( -L2P_N, _N.xyz ) );
float hemi = saturate ( dot( L2P_N, direction ) );
// Final color
return blendp( float4( Ldynamic_color.xyz * att * light * hemi, 0 ), tc );
}

View file

@ -0,0 +1 @@
#include "accum_indirect.ps"

View file

@ -0,0 +1,2 @@
#undef MSAA_OPTIMIZATION
#include "accum_indirect.ps"

View file

@ -0,0 +1,7 @@
#include "common.h"
float4 main ( float4 P: POSITION ) : SV_Position
{
return mul ( m_WVP, P );
}
FXVS;

View file

@ -0,0 +1,2 @@
#define USE_SHADOW
#include "accum_base.ps"

View file

@ -0,0 +1,2 @@
#include "accum_omni_normal.ps"

View file

@ -0,0 +1,3 @@
#undef MSAA_OPTIMIZATION
#include "accum_omni_normal.ps"

View file

@ -0,0 +1,4 @@
#define USE_SHADOW
#define USE_LMAP
#include "accum_base.ps"

View file

@ -0,0 +1,2 @@
#include "accum_omni_transluent.ps"

View file

@ -0,0 +1,2 @@
#undef MSAA_OPTIMIZATION
#include "accum_omni_transluent.ps"

View file

@ -0,0 +1,39 @@
#include "common.h"
#include "lmodel.h"
// TODO: DX10: Move to Load
#ifdef MSAA_OPTIMIZATION
#ifdef GBUFFER_OPTIMIZATION
float4 main ( float4 tc:TEXCOORD0, float4 pos2d : SV_Position, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main ( float4 tc:TEXCOORD0, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#endif
#else
#ifdef GBUFFER_OPTIMIZATION
float4 main ( float4 tc:TEXCOORD0, float4 pos2d : SV_Position ) : SV_Target
#else
float4 main ( float4 tc:TEXCOORD0 ) : SV_Target
#endif
#endif
{
const float bias_mul = 0.999f;
// Sample the fat framebuffer:
// float4 _P = tex2Dproj (s_position, tc);
// float4 _N = tex2Dproj (s_normal, tc);
float2 tcProj = tc.xy / tc.w;
gbuffer_data gbd = gbuffer_load_data( GLD_P(tcProj, pos2d, ISAMPLE) );
float4 _P = float4( gbd.P,gbd.mtl );
float4 _N = float4( gbd.N,gbd.hemi );
float m = xmaterial ;
# ifndef USE_R2_STATIC_SUN
m = _P.w ;
# endif
float rsqr;
float4 light = plight_local( m, _P, _N, Ldynamic_pos, Ldynamic_pos.w, rsqr );
return blendp( Ldynamic_color * light, tc);
}

View file

@ -0,0 +1 @@
#include "accum_omni_unshadowed.ps"

View file

@ -0,0 +1,2 @@
#undef MSAA_OPTIMIZATION
#include "accum_omni_unshadowed.ps"

View file

@ -0,0 +1,4 @@
#define USE_SHADOW
#define USE_LMAP
#include "accum_base.ps"

View file

@ -0,0 +1 @@
#include "accum_spot_fullsize.ps"

View file

@ -0,0 +1,3 @@
#undef MSAA_OPTIMIZATION
#include "accum_spot_fullsize.ps"

View file

@ -0,0 +1,5 @@
#define USE_LMAP
#define USE_LMAPXFORM
#define USE_SHADOW
#include "accum_base.ps"

View file

@ -0,0 +1 @@
#include "accum_spot_normal.ps"

View file

@ -0,0 +1,3 @@
#undef MSAA_OPTIMIZATION
#include "accum_spot_normal.ps"

View file

@ -0,0 +1,3 @@
#define USE_LMAP
#include "accum_base.ps"

View file

@ -0,0 +1,2 @@
#include "accum_spot_unshadowed.ps"

View file

@ -0,0 +1,3 @@
#undef MSAA_OPTIMIZATION
#include "accum_spot_unshadowed.ps"

View file

@ -0,0 +1,59 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
/*
struct _input
{
float2 tc : TEXCOORD0;
float4 tcJ : TEXCOORD1;
float2 LT : TEXCOORD2;
float2 RT : TEXCOORD3;
float2 LB : TEXCOORD4;
float2 RB : TEXCOORD5;
};
*/
#ifdef MSAA_OPTIMIZATION
#ifdef GBUFFER_OPTIMIZATION
float4 main ( p_aa_AA_sun I, float4 pos2d : SV_Position, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main ( p_aa_AA_sun I, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#endif
#else
#ifdef GBUFFER_OPTIMIZATION
float4 main ( p_aa_AA_sun I, float4 pos2d : SV_Position ) : SV_Target
#else
float4 main ( p_aa_AA_sun I ) : SV_Target
#endif
#endif
{
gbuffer_data gbd = gbuffer_load_data( GLD_P(I.tc, pos2d, ISAMPLE) );
// float4 _P = tex2D (s_position, I.tc);
// float4 _N = tex2D (s_normal, I.tc);
float4 _P = float4( gbd.P, gbd.mtl );
float4 _N = float4( gbd.N, gbd.hemi );
// ----- light-model
float m = xmaterial ;
# ifndef USE_R2_STATIC_SUN
m = _P.w ;
# endif
float4 light = plight_infinity( m, _P, _N, Ldynamic_dir );
// ----- shadow
float4 s_sum;
// s_sum.x = tex2D ( s_smap, I.LT).x;
// s_sum.y = tex2D ( s_smap, I.RT).y;
// s_sum.z = tex2D ( s_smap, I.LB).z;
// s_sum.w = tex2D ( s_smap, I.RB).w;
s_sum.x = s_smap.Sample( smp_nofilter, I.LT).x;
s_sum.y = s_smap.Sample( smp_nofilter, I.RT).y;
s_sum.z = s_smap.Sample( smp_nofilter, I.LB).z;
s_sum.w = s_smap.Sample( smp_nofilter, I.RB).w;
// float s = dot ( s_sum, 1.h/4.h);
float s = ((s_sum.x+s_sum.y)+(s_sum.z+s_sum.w))*(1.h/4.h);
return Ldynamic_color * light * s;
}

View file

@ -0,0 +1,21 @@
#include "common.h"
//////////////////////////////////////////////////////////////////////////////////////////
uniform float4x4 m_texgen;
#ifdef USE_SJITTER
uniform float4x4 m_texgen_J;
#endif
//////////////////////////////////////////////////////////////////////////////////////////
// Vertex
v2p_volume main ( float4 P: POSITION )
{
v2p_volume O;
O.hpos = mul( m_WVP, P );
O.tc = mul( m_texgen, P );
#ifdef USE_SJITTER
O.tcJ = mul( m_texgen_J, P );
#endif
return O;
}
FXVS;

View file

@ -0,0 +1,103 @@
#include "common.h"
#include "lmodel.h"
#ifdef USE_MINMAX_SM
#define SM_MINMAX
#endif
#if SUN_QUALITY>2
#define ULTRA_SHADOWS_ON
#endif // SUN_QUALITY>2
#ifdef ULTRA_SHADOWS_ON
#define USE_ULTRA_SHADOWS
#endif
#include "shadow.h"
uniform float3 view_shadow_proj;
#ifdef USE_SUNFILTER
#ifdef MSAA_OPTIMIZATION
float4 main ( v2p_volume I, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main ( v2p_volume I ) : SV_Target
#endif
{
//float4 _P = tex2D( s_position, tc );
gbuffer_data gbd = gbuffer_load_data( GLD_P(I.tc, I.hpos, ISAMPLE) );
#ifdef GBUFFER_OPTIMIZATION
// Emulate virtual offset
gbd.P += gbd.N*0.015f;
#endif // GBUFFER_OPTIMIZATION
float4 _P = float4( gbd.P, 1.f);
float4 PS = mul( m_shadow, _P );
float s = shadowtest_sun( PS, I.tcJ ) * sunmask( _P );
return s;
}
#else
#ifdef MSAA_OPTIMIZATION
float4 main ( v2p_volume I, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main ( v2p_volume I ) : SV_Target
#endif
{
//float4 _P = tex2D( s_position, tc );
//float4 _N = tex2D( s_normal, tc );
gbuffer_data gbd = gbuffer_load_data( GLD_P(I.tc.xy/I.tc.w, I.hpos, ISAMPLE) );
#ifdef GBUFFER_OPTIMIZATION
// Emulate virtual offset
gbd.P += gbd.N*0.015f;
#endif // GBUFFER_OPTIMIZATION
float4 _P = float4( gbd.P, gbd.mtl );
float4 _N = float4( gbd.N, gbd.hemi );
// ----- light-model
float m = xmaterial;
# ifndef USE_R2_STATIC_SUN
m = _P.w;
# endif
float4 light = plight_infinity ( m, _P, _N, Ldynamic_dir );
// ----- shadow
float4 P4 = float4( _P.x, _P.y, _P.z, 1.f);
float4 PS = mul( m_shadow, P4 );
float s = sunmask( P4 );
#if defined (USE_SJITTER) || SUN_QUALITY==2 // Hight quality
s *= shadow_high(PS); //shadowtest_sun( PS, float4(0,0,0,0) );
#else
#ifdef SM_MINMAX
#ifdef USE_SJITTER
s *= shadow_dx10_1( PS, I.tcJ, I.hpos.xy );
#else
s *= shadow( PS );
#endif
#else
s *= shadow( PS );
#endif
#endif
// Far edge fading code
float2 tc_f = (PS.xy/PS.w)-float2(0.5f,0.5f);
// Fade only fron edges
tc_f *= step( -dot( tc_f, view_shadow_proj.xy ), 0 );
tc_f = abs( tc_f );
float border = 0.4f;
float fac_x = 1.f-saturate( ( tc_f.x - border )/(0.5f-border));
float fac_y = 1.f-saturate( ( tc_f.y - border )/(0.5f-border));
s += ((1-s)*(1-fac_x*fac_y));
//\ Far edge fading code
return blend( Ldynamic_color * light * s/*float4( 1.f, 0.2f, 0.2f, 1.f)*/, I.tc );
}
#endif

View file

@ -0,0 +1,3 @@
#undef MSAA_OPTIMIZATION
#include "accum_sun_far.ps"

View file

@ -0,0 +1,3 @@
#undef MSAA_OPTIMIZATION
#include "accum_sun_far.ps"

View file

@ -0,0 +1,36 @@
#include "common.h"
// TODO: DX10: move to load instead of sample (will need to provide integer texture coordinates)
#define EPS (0.9f/255.f)
//#define EPS (40.f/255.f)
#define CLIP_THRESHOLD (1.0f/255.f)
#ifdef MSAA_OPTIMIZATION
#ifdef GBUFFER_OPTIMIZATION
float4 main ( p_TL I, float4 pos2d : SV_Position, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main ( p_TL I, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#endif
#else
#ifdef GBUFFER_OPTIMIZATION
float4 main ( p_TL I, float4 pos2d : SV_Position ) : SV_Target
#else
float4 main ( p_TL I ) : SV_Target
#endif
#endif
{
// Sample the fat framebuffer:
//float4 NH = tex2D( s_normal, I.Tex0);
gbuffer_data gbd = gbuffer_load_data( GLD_P(I.Tex0, pos2d, ISAMPLE) );
float4 NH = float4( gbd.N, gbd.hemi );
float L = NH.w * dot( Ldynamic_dir, (float3)NH ) + EPS; // Use hemisphere as approximation of max light
//float L = dot( Ldynamic_dir, (float3)NH ) + EPS; // Use hemisphere as approximation of max light
// L = 1;
clip(L-CLIP_THRESHOLD);
return float4( L, L, L, L );
}

View file

@ -0,0 +1 @@
#include "accum_sun_mask.ps"

View file

@ -0,0 +1,2 @@
#undef MSAA_OPTIMIZATION
#include "accum_sun_mask.ps"

View file

@ -0,0 +1 @@
#include "accum_sun.ps"

View file

@ -0,0 +1,89 @@
#include "common.h"
#include "lmodel.h"
#ifdef USE_MINMAX_SM
#define SM_MINMAX
#endif
#if SUN_QUALITY>2
#define ULTRA_SHADOWS_ON
#endif // SUN_QUALITY>2
#ifdef ULTRA_SHADOWS_ON
#define USE_ULTRA_SHADOWS
#endif
#include "shadow.h"
#ifdef USE_SUNFILTER
#ifdef MSAA_OPTIMIZATION
float4 main ( v2p_volume I, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main ( v2p_volume I ) : SV_Target
#endif
{
//float4 _P = tex2D( s_position, tc );
gbuffer_data gbd = gbuffer_load_data( GLD_P(I.tc, I.hpos, ISAMPLE) );
#ifdef GBUFFER_OPTIMIZATION
// Emulate virtual offset
gbd.P += gbd.N*0.015f;
#endif // GBUFFER_OPTIMIZATION
float4 _P = float4( gbd.P, 1.f);
float4 PS = mul( m_shadow, _P );
float s = shadowtest_sun( PS, I.tcJ ) * sunmask( _P );
return s;
}
#else
#ifdef MSAA_OPTIMIZATION
float4 main ( v2p_volume I, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main ( v2p_volume I ) : SV_Target
#endif
{
//float4 _P = tex2D( s_position, tc );
//float4 _N = tex2D( s_normal, tc );
gbuffer_data gbd = gbuffer_load_data( GLD_P(I.tc.xy/I.tc.w, I.hpos, ISAMPLE) );
#ifdef GBUFFER_OPTIMIZATION
// Emulate virtual offset
gbd.P += gbd.N*0.015f;
#endif // GBUFFER_OPTIMIZATION
float4 _P = float4( gbd.P, gbd.mtl );
float4 _N = float4( gbd.N, gbd.hemi );
// ----- light-model
float m = xmaterial;
# ifndef USE_R2_STATIC_SUN
m = _P.w;
# endif
float4 light = plight_infinity ( m, _P, _N, Ldynamic_dir );
// ----- shadow
float4 P4 = float4( _P.x, _P.y, _P.z, 1.f);
float4 PS = mul( m_shadow, P4 );
float s = sunmask( P4 );
#if defined (USE_SJITTER) || SUN_QUALITY==2 // Hight quality
s *= shadow_high(PS); //shadowtest_sun( PS, float4(0,0,0,0) );
#else
#ifdef SM_MINMAX
#ifdef USE_SJITTER
s *= shadow_dx10_1( PS, I.tcJ, I.hpos.xy );
#else
s *= shadow( PS );
#endif
#else
s *= shadow( PS );
#endif
#endif
return blend( Ldynamic_color * light * s/*float4( 1.f, 0.2f, 0.2f, 1.f)*/, I.tc );
}
#endif

View file

@ -0,0 +1 @@
#include "accum_sun_near.ps"

View file

@ -0,0 +1,2 @@
#define USE_MINMAX_SM
#include "accum_sun_near.ps"

View file

@ -0,0 +1,2 @@
#undef USE_MINMAX_SM
#include "accum_sun_near.ps"

View file

@ -0,0 +1,3 @@
#undef MSAA_OPTIMIZATION
#include "accum_sun_near.ps"

View file

@ -0,0 +1,4 @@
#undef MSAA_OPTIMIZATION
#define USE_MINMAX_SM
#include "accum_sun_near.ps"

View file

@ -0,0 +1,4 @@
#undef MSAA_OPTIMIZATION
#undef USE_MINMAX_SM
#include "accum_sun_near.ps"

View file

@ -0,0 +1,99 @@
#include "common.h"
#include "lmodel.h"
#include "shadow.h"
#ifndef ISAMPLE
#define ISAMPLE 0
#endif
#ifdef USE_SUNFILTER
#ifdef GBUFFER_OPTIMIZATION
#ifdef MSAA_OPTIMIZATION
float4 main ( float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1, float4 Color : COLOR, float4 pos2d : SV_Position, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main ( float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1, float4 Color : COLOR, float4 pos2d : SV_Position ) : SV_Target
#endif
#else
#ifdef MSAA_OPTIMIZATION
float4 main ( float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1, float4 Color : COLOR, uint iSample : SV_SAMPLEINDEX) : SV_Target
#else
float4 main ( float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1, float4 Color : COLOR ) : SV_Target
#endif
#endif
{
//float4 _P = tex2D( s_position, tc );
#ifdef GBUFFER_OPTIMIZATION
#ifdef MSAA_OPTIMIZATION
gbuffer_data gbd = gbuffer_load_data( tc, pos2d, iSample );
#else
gbuffer_data gbd = gbuffer_load_data( tc, pos2d, ISAMPLE );
#endif
#else
#ifdef MSAA_OPTIMIZATION
gbuffer_data gbd = gbuffer_load_data( tc, iSample );
#else
gbuffer_data gbd = gbuffer_load_data( tc, ISAMPLE );
#endif
#endif
float4 _P = float4( gbd.P, 1.f);
float4 PS = mul( m_shadow, _P );
float s = shadowtest_sun( PS, tcJ ) * sunmask( _P );
return s;
}
#else
#ifdef GBUFFER_OPTIMIZATION
#ifdef MSAA_OPTIMIZATION
float4 main ( float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1, float4 Color : COLOR, float4 pos2d : SV_Position, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main ( float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1, float4 Color : COLOR, float4 pos2d : SV_Position ) : SV_Target
#endif
#else
#ifdef MSAA_OPTIMIZATION
float4 main ( float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main ( float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1 ) : SV_Target
#endif
#endif
{
//float4 _P = tex2D( s_position, tc );
//float4 _N = tex2D( s_normal, tc );
#ifdef GBUFFER_OPTIMIZATION
#ifdef MSAA_OPTIMIZATION
gbuffer_data gbd = gbuffer_load_data( tc, pos2d, iSample );
#else
gbuffer_data gbd = gbuffer_load_data( tc, pos2d, ISAMPLE );
#endif
#else
#ifdef MSAA_OPTIMIZATION
gbuffer_data gbd = gbuffer_load_data( tc, iSample );
#else
gbuffer_data gbd = gbuffer_load_data( tc, ISAMPLE );
#endif
#endif
float4 _P = float4( gbd.P, gbd.mtl );
float4 _N = float4( gbd.N, gbd.hemi );
// ----- light-model
float m = xmaterial;
# ifndef USE_R2_STATIC_SUN
m = _P.w;
# endif
float4 light = plight_infinity ( m, _P, _N, Ldynamic_dir );
// ----- shadow
float4 P4 = float4( _P.x, _P.y, _P.z, 1.f);
float4 PS = mul( m_shadow, P4 );
float s = sunmask( P4 );
#ifdef USE_SJITTER
s *= shadowtest_sun( PS, tcJ );
#else
s *= shadow( PS );
#endif
return blend( Ldynamic_color * light * s, tc );
}
#endif

View file

@ -0,0 +1,2 @@
#undef MSAA_OPTIMIZATION
#include "accum_sun.ps"

View file

@ -0,0 +1,21 @@
#include "common.h"
//////////////////////////////////////////////////////////////////////////////////////////
uniform float4x4 m_texgen;
#ifdef USE_SJITTER
uniform float4x4 m_texgen_J;
#endif
//////////////////////////////////////////////////////////////////////////////////////////
// Vertex
v2p_volume main ( float4 P: POSITION )
{
v2p_volume O;
O.hpos = mul( m_WVP, P );
O.tc = mul( m_texgen, P );
#ifdef USE_SJITTER
O.tcJ = mul( m_texgen_J, P );
#endif
return O;
}
FXVS;

View file

@ -0,0 +1,95 @@
#include "common.h"
#include "shadow.h"
#ifndef ISAMPLE
#define ISAMPLE 0
#endif
struct v2p
{
float3 lightToPos : TEXCOORD0; // light center to plane vector
float3 vPos : TEXCOORD1; // position in camera space
float fDensity : TEXCOORD2; // plane density along Z axis
// float2 tNoise : TEXCOORD3; // projective noise
};
uniform float4 m_lmap [2];
Texture2D s_noise;
#define USE_LMAP
#define USE_LMAPXFORM
#define USE_SHADOW
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
#ifndef MSAA_OPTIMIZATION
float4 main ( v2p I ) : SV_Target
#else
float4 main ( v2p I, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#endif
{
// ----- shadow
float4 P4 = float4(I.vPos, 1);
float4 PS = mul( m_shadow, P4);
float s = 1.h;
#ifdef USE_SHADOW
// #ifdef USE_SJITTER
// s = shadowtest (PS,tcJ);
// #else
// TODO: DX10: Use lower quality shadow test
s = shadow(PS);
// #endif
#endif
// ----- lightmap
float4 lightmap = 1.h;
#ifdef USE_LMAP
#ifdef USE_LMAPXFORM
PS.x = dot( P4, m_lmap[0]);
PS.y = dot( P4, m_lmap[1]);
#endif
// lightmap = tex2Dproj(s_lmap, PS); //
lightmap = s_lmap.Sample(smp_rtlinear, PS.xy/PS.w); //
#endif
// ----- attenuate
float rsqr = dot( I.lightToPos, I.lightToPos); // distance 2 light (squared)
float att = saturate( 1 - rsqr * Ldynamic_pos.w ); // q-linear attenuate
//float att = saturate( 1 - (rsqr * Ldynamic_pos.w)*(rsqr * Ldynamic_pos.w) ); // q-linear attenuate
//float att = 10*(1/(1+0.1*rsqr));
//float att = 1.0h/rsqr;
//float att = 1.0h/rsqr-Ldynamic_pos.w;
//float att = 5*(sqrt(1.0h/rsqr)-sqrt(Ldynamic_pos.w));
// ----- noise
PS.xy /= PS.w;
float time = timers.z*0.1;
PS.xy /= 3;
PS.x += time;
// TODO: DX10: Can use sampler with point mip filter
//float4 t_noise = tex2D(s_noise,PS);
float4 t_noise = s_noise.Sample( smp_linear, PS );
PS.x -= time;
PS.y -= time*0.70091;
// TODO: DX10: Can use sampler with point mip filter
//t_noise *= tex2D(s_noise,PS);
t_noise *= s_noise.Sample( smp_linear, PS );
//t_noise *= 4;
t_noise = t_noise*0.5+0.5;
// out
//float maxIntens = 1.0h/100.0h;
//float maxIntens = 1.0h/40.0h;
//float maxIntens = 1.0h/10.0h;
float maxIntens = I.fDensity;
float3 result = maxIntens * s * att;
result *= lightmap;
result *= Ldynamic_color * t_noise;
// result = maxIntens;
// result *= lightmap;
// result = 0.1h;
// result = 0.0h;
return float4( result, 0);
}

View file

@ -0,0 +1,21 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_volumetric", "accum_volumetric")
: fog (false)
: zb (true,false)
: blend (true,blend.one,blend.one)
-- : aref (true,0)
: sorting (2, false)
-- TODO: Implement sampler states
-- shader:sampler ("s_lmap") :texture (t_base): clamp()
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_noise") :texture("fx\\fx_noise") : f_linear ()
shader:dx10texture ("s_lmap", t_base)
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_noise", "fx\\fx_noise")
shader:dx10sampler ("smp_rtlinear")
shader:dx10sampler ("smp_linear")
-- shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,44 @@
#include "common.h"
cbuffer VolumetricLights
{
float3 vMinBounds;
float3 vMaxBounds;
float4 FrustumClipPlane[6];
}
struct v2p
{
float3 lightToPos : TEXCOORD0; // light center to plane vector
float3 vPos : TEXCOORD1; // position in camera space
float fDensity : TEXCOORD2; // plane density alon Z axis
// float2 tNoise : TEXCOORD3; // projective noise
float3 clip0 : SV_ClipDistance0;
float3 clip1 : SV_ClipDistance1;
float4 hpos : SV_Position;
};
v2p main ( float3 P : POSITION )
{
v2p o;
float4 vPos;
vPos.xyz = lerp( vMinBounds, vMaxBounds, P); // Position in camera space
vPos.w = 1;
o.hpos = mul (m_P, vPos); // xform, input in camera coordinates
o.lightToPos = vPos.xyz - Ldynamic_pos.xyz;
o.vPos = vPos;
// o.fDensity = (vMaxBounds.z-vMinBounds.z)/2000.0h;
// o.fDensity = (vMaxBounds.z-vMinBounds.z)/2000.0h*2;
o.fDensity = 1.0h/40.0h;
// o.fDensity = 1.0h/20.0h;
for (int i=0; i<3; ++i)
{
o.clip0[i] = dot( o.hpos, FrustumClipPlane[i]);
o.clip1[i] = dot( o.hpos, FrustumClipPlane[i+3]);
}
return o;
}

View file

@ -0,0 +1 @@
#include "accum_volumetric.ps"

View file

@ -0,0 +1,2 @@
#undef MSAA_OPTIMIZATION
#include "accum_volumetric.ps"

View file

@ -0,0 +1,21 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_volumetric", "accum_volumetric")
: fog (false)
: zb (true,false)
: blend (true,blend.one,blend.one)
-- : aref (true,0)
: sorting (2, false)
-- TODO: Implement sampler states
-- shader:sampler ("s_lmap") :texture (t_base): clamp()
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_noise") :texture("fx\\fx_noise") : f_linear ()
shader:dx10texture ("s_lmap", t_base)
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_noise", "fx\\fx_noise")
shader:dx10sampler ("smp_rtlinear")
shader:dx10sampler ("smp_linear")
-- shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1 @@
#include "accum_volumetric.vs"

View file

@ -0,0 +1,226 @@
#include "common.h"
#undef ULTRA_SHADOWS_ON
#undef USE_ULTRA_SHADOWS
#define RAY_PATH 2.0h
#define JITTER_TEXTURE_SIZE 64.0f
#define JITTER_SUN_SHAFTS
#ifdef SUN_SHAFTS_QUALITY
#if SUN_SHAFTS_QUALITY==1
#define FILTER_LOW
#define RAY_SAMPLES 20
#elif SUN_SHAFTS_QUALITY==2
#define FILTER_LOW
#define RAY_SAMPLES 20
#elif SUN_SHAFTS_QUALITY==3
#define FILTER_LOW
#define RAY_SAMPLES 40
#endif
#endif
#ifndef FILTER_LOW
#ifdef USE_MINMAX_SM
#define SM_MINMAX
#endif
#endif
#include "shadow.h"
float4 volume_range; // x - near plane, y - far plane
float4 sun_shafts_intensity;
uniform float4 screen_res;
#ifdef MSAA_OPTIMIZATION
//#ifdef GBUFFER_OPTIMIZATION
//float4 main (float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1, float4 pos2d : SV_Position, uint iSample : SV_SAMPLEINDEX ) : SV_Target
//#else
float4 main (v2p_volume I, uint iSample : SV_SAMPLEINDEX ) : SV_Target
//#endif
#else
//#ifdef GBUFFER_OPTIMIZATION
//float4 main (float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1, float4 pos2d : SV_Position ) : SV_Target
//#else
float4 main (v2p_volume I) : SV_Target
//#endif
#endif
{
float2 tc = I.tc.xy/I.tc.w;
float4 pos2d = I.hpos;
gbuffer_data gbd = gbuffer_load_data( GLD_P(tc, pos2d, ISAMPLE) );
#ifndef SUN_SHAFTS_QUALITY
return float4(0,0,0,0);
#else // SUN_SHAFTS_QUALITY
//float3 P = tex2D(s_position, tc).xyz;
float3 P = gbd.P;
#ifndef JITTER_SUN_SHAFTS
// Fixed ray length, fixed step dencity
// float3 direction = (RAY_PATH/RAY_SAMPLES)*normalize(P);
// Variable ray length, variable step dencity
float3 direction = P/RAY_SAMPLES;
#else // JITTER_SUN_SHAFTS
// float2 tcJ = I.tcJ;
// Variable ray length, variable step dencity, use jittering
//float4 J0 = tex2D (jitter0,tcJ);
float4 J0 = jitter0.Sample( smp_jitter, tc*screen_res.x*1.f/JITTER_TEXTURE_SIZE );
float coeff = (RAY_SAMPLES - 1*J0.x)/(RAY_SAMPLES*RAY_SAMPLES);
float3 direction = P*coeff;
// float3 direction = P/(RAY_SAMPLES+(J0.x*4-2));
#endif // JITTER_SUN_SHAFTS
float depth = P.z;
float deltaDepth = direction.z;
float4 current = mul (m_shadow,float4(P,1));
float4 delta = mul (m_shadow, float4(direction,0));
float res = 0;
float max_density = sun_shafts_intensity;
float density = max_density/RAY_SAMPLES;
if (depth<0.0001)
res = max_density;
[unroll]
for ( int i=0; i<RAY_SAMPLES; ++i )
{
if (depth>0.3)
{
#ifndef FILTER_LOW
#ifndef SM_MINMAX
res += density*shadow( current );
#else
res += density*shadow_dx10_1_sunshafts(current, pos2d.xy );
#endif
#else // FILTER_LOW
res += density*sample_hw_pcf(current, float4(0,0,0,0));
#endif // FILTER_LOW
}
depth -= deltaDepth;
current -= delta;
}
float fSturation = -Ldynamic_dir.z;
// Normalize dot product to
fSturation = 0.5*fSturation+0.5;
// Map saturation to 0.2..1
fSturation = 0.80*fSturation+0.20;
res *= fSturation;
return res*Ldynamic_color;
#endif // SUN_SHAFTS_QUALITY
}
/*
#ifdef GBUFFER_OPTIMIZATION
float4 main (float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1, float4 pos2d : SV_Position ) : SV_Target
#else
float4 main (float2 tc : TEXCOORD0, float2 tcJ : TEXCOORD1 ) : SV_Target
#endif
{
#ifdef GBUFFER_OPTIMIZATION
gbuffer_data gbd = gbuffer_load_data( tc, pos2d );
#else
gbuffer_data gbd = gbuffer_load_data( tc );
#endif
#ifndef SUN_SHAFTS_QUALITY
return float4(0,0,0,0);
#else // SUN_SHAFTS_QUALITY
//float3 P = tex2D(s_position, tc).xyz;
float3 P = gbd.P;
#ifndef JITTER_SUN_SHAFTS
// Fixed ray length, fixed step dencity
// float3 direction = (RAY_PATH/RAY_SAMPLES)*normalize(P);
// Variable ray length, variable step dencity
float3 direction = P/RAY_SAMPLES;
#else // JITTER_SUN_SHAFTS
// Variable ray length, variable step dencity, use jittering
//float4 J0 = tex2D (jitter0,tcJ);
float4 J0 = jitter0.Sample( smp_jitter, tc*screen_res.x*1.f/JITTER_TEXTURE_SIZE );
float coeff = (RAY_SAMPLES - 1*J0.x)/(RAY_SAMPLES*RAY_SAMPLES);
float3 direction = P*coeff;
// float3 direction = P/(RAY_SAMPLES+(J0.x*4-2));
#endif // JITTER_SUN_SHAFTS
float depth = P.z;
float deltaDepth = direction.z;
float4 current = mul (m_shadow,float4(P,1));
float4 delta = mul (m_shadow, float4(direction,0));
float res = 0;
float max_density = sun_shafts_intensity;
float density = max_density/RAY_SAMPLES;
if (depth<0.0001)
res = max_density;
float OrigDepth = depth;
////////////////////////////////
//
// const float ExC = 0.3;
// const float IntCorrection = 3;
// density /= ExC;
// density *= IntCorrection;
// float IntegralMul = exp(ExC*(length(P)/RAY_SAMPLES));
// float Integral = exp(-ExC*(length(P)))*(1-1/IntegralMul);
// if (depth<0.0001)
// res *= (IntCorrection/ExC)
// *( exp( -ExC*100/20) - exp( -ExC*100) );
[unroll]
for ( int i=0; i<RAY_SAMPLES; ++i )
{
if (depth>0.3)
{
//res *= extinct;
//if (i<5)
res += density*shadow(current);
//else
//res += Integral*density*sample_hw_pcf(current, float4(0,0,0,0));
//res += density*sample_hw_pcf(current, float4(0,0,0,0));
}
depth -= deltaDepth;
current -= delta;
//Integral *= IntegralMul;
}
// if (OrigDepth<0.0001)
// res = max_density;
// else
// res *= density;
float fSturation = -Ldynamic_dir.z;
// Normalize dot product to
fSturation = 0.5*fSturation+0.5;
// Map saturation to 0.2..1
fSturation = 0.80*fSturation+0.20;
res *= fSturation;
return res*Ldynamic_color;
#endif // SUN_SHAFTS_QUALITY
}
*/

View file

@ -0,0 +1,21 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("stub_notransform_2uv", "accum_volumetric_sun_normal")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_smap_minmax", "$user$smap_depth_minmax");
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,2 @@
#define USE_MINMAX_SM
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,21 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_sun", "accum_volumetric_sun_minmax")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_smap_minmax", "$user$smap_depth_minmax");
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1 @@
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,2 @@
#define ISAMPLE 0
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,20 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_sun", "accum_volumetric_sun_msaa0")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,2 @@
#define ISAMPLE 1
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,20 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_sun", "accum_volumetric_sun_msaa1")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,2 @@
#define ISAMPLE 2
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,20 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_sun", "accum_volumetric_sun_msaa2")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,2 @@
#define ISAMPLE 3
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,20 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_sun", "accum_volumetric_sun_msaa3")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,2 @@
#define ISAMPLE 4
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,20 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_sun", "accum_volumetric_sun_msaa4")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,2 @@
#define ISAMPLE 5
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,20 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_sun", "accum_volumetric_sun_msaa5")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,2 @@
#define ISAMPLE 6
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,20 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_sun", "accum_volumetric_sun_msaa6")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,2 @@
#define ISAMPLE 7
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,20 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_sun", "accum_volumetric_sun_msaa7")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,2 @@
#undef MSAA_OPTIMIZATION
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,21 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_sun", "accum_volumetric_sun_nomsaa")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_smap_minmax", "$user$smap_depth_minmax");
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,21 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("accum_sun", "accum_volumetric_sun_minmax")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
: sorting (2, false)
-- TODO: DX10: Implement for near and far phase.
-- TODO: DX10: Setup samplers.
-- shader:sampler ("s_smap") :texture ("null")
-- shader:sampler ("s_position") :texture ("$user$position")
-- shader:sampler ("jitter0") :texture ("$user$jitter_0") : f_none ()
shader:dx10texture ("s_smap", "null")
shader:dx10texture ("s_smap_minmax", "$user$smap_depth_minmax");
shader:dx10texture ("s_position", "$user$position")
shader:dx10texture ("jitter0", "$user$jitter_0")
shader:dx10sampler ("smp_nofilter")
shader:dx10sampler ("smp_jitter")
shader:dx10sampler ("smp_smap")
end

View file

@ -0,0 +1,3 @@
#unfdef USE_MINMAX_SM
#include "accum_volumetric_sun.ps"

View file

@ -0,0 +1,19 @@
#include "common.h"
struct v2p
{
float2 tc0: TEXCOORD0; // base
// float2 tc1: TEXCOORD1; // lmap
float4 c0: COLOR0; // sun
};
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
float4 main( v2p I ) : SV_Target
{
// float4 t_base = tex2D (s_base,I.tc0);
float4 t_base = s_base.Sample( smp_base, I.tc0 );
// out
return float4 (t_base.r,t_base.g,t_base.b,t_base.a * I.c0.a);
}

View file

@ -0,0 +1,24 @@
#include "common.h"
struct vf
{
float2 tc0 : TEXCOORD0; // base
float4 c0 : COLOR0; // color
float4 hpos : SV_Position;
};
vf main (v_static v)
{
vf o;
o.hpos = mul (m_WVP, v.P); // xform, input in world coords
o.tc0 = unpack_tc_base(v.tc,v.T.w,v.B.w); // copy tc
// calculate fade
float3 dir_v = normalize (mul(m_WV,v.P));
float3 norm_v = normalize (mul(m_WV,unpack_normal(v.Nh).zyx));
float fade = abs (dot(dir_v,norm_v));
o.c0 = fade;
return o;
}

View file

@ -0,0 +1,33 @@
#include "common.h"
/*
struct v2p
{
float2 tc0: TEXCOORD0; // Texture coordinates (for sampling maps)
float2 tc1: TEXCOORD1; // Texture coordinates (for sampling maps)
float2 tc2: TEXCOORD2; // Texture coordinates (for sampling maps)
float2 tc3: TEXCOORD3; // Texture coordinates (for sampling maps)
};
*/
uniform float4 b_params;
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
float4 main ( p_build I ) : SV_Target
{
// hi-rgb.base-lum
// float3 s0 = tex2D (s_image, I.tc0);
// float3 s1 = tex2D (s_image, I.tc1);
// float3 s2 = tex2D (s_image, I.tc2);
// float3 s3 = tex2D (s_image, I.tc3);
float3 s0 = s_image.Sample( smp_rtlinear, I.Tex0);
float3 s1 = s_image.Sample( smp_rtlinear, I.Tex1);
float3 s2 = s_image.Sample( smp_rtlinear, I.Tex2);
float3 s3 = s_image.Sample( smp_rtlinear, I.Tex3);
float3 avg = ( (s0+s1) + (s2+s3) )/2;
float hi = dot( avg, 1.h )-b_params.x ; // assume def_hdr equal to 3.0
return float4( avg, hi );
}

View file

@ -0,0 +1,69 @@
#include "common.h"
/*
struct v2p
{
float2 tc0: TEXCOORD0; // Central
float4 tc1: TEXCOORD1; // -1,+1
float4 tc2: TEXCOORD2; // -2,+2
float4 tc3: TEXCOORD3; // -3,+3
float4 tc4: TEXCOORD4; // -4,+4
float4 tc5: TEXCOORD5; // -5,+5
float4 tc6: TEXCOORD6; // -6,+6
float4 tc7: TEXCOORD7; // -7,+7
};
*/
//////////////////////////////////////////////////////////////////////////////////////////
uniform float4 weight[2];
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
// Separable gauss filter: 2*7 + 1 + 7*2 = 29 samples
// Samples: 0-central, -1, -2,..., -7, 1, 2,... 7
// Approximated i-count: 15t + 15a + 7a(d) + 1(out) = 38, HLSL compiled to 38 :)
float4 main ( p_filter I ) : SV_Target
{
// central
//float4 accum = weight[1].w * tex2D (s_bloom, I.tc0);
float4 accum = weight[1].w * s_bloom.Sample(smp_rtlinear, I.Tex0);
// left (7)
// right (7) - no swizles on 'texld', so this is dep-read infact
// accum += weight[0].x * tex2D (s_bloom, I.tc1.xy);
// accum += weight[0].x * tex2D (s_bloom, I.tc1.wz);
accum += weight[0].x * s_bloom.Sample(smp_rtlinear, I.Tex1.xy);
accum += weight[0].x * s_bloom.Sample(smp_rtlinear, I.Tex1.wz);
// accum += weight[0].y * tex2D (s_bloom, I.tc2.xy);
// accum += weight[0].y * tex2D (s_bloom, I.tc2.wz);
accum += weight[0].y * s_bloom.Sample(smp_rtlinear, I.Tex2.xy);
accum += weight[0].y * s_bloom.Sample(smp_rtlinear, I.Tex2.wz);
// accum += weight[0].z * tex2D (s_bloom, I.tc3.xy);
// accum += weight[0].z * tex2D (s_bloom, I.tc3.wz);
accum += weight[0].z * s_bloom.Sample(smp_rtlinear, I.Tex3.xy);
accum += weight[0].z * s_bloom.Sample(smp_rtlinear, I.Tex3.wz);
// accum += weight[0].w * tex2D (s_bloom, I.tc4.xy);
// accum += weight[0].w * tex2D (s_bloom, I.tc4.wz);
accum += weight[0].w * s_bloom.Sample(smp_rtlinear, I.Tex4.xy);
accum += weight[0].w * s_bloom.Sample(smp_rtlinear, I.Tex4.wz);
// accum += weight[1].x * tex2D (s_bloom, I.tc5.xy);
// accum += weight[1].x * tex2D (s_bloom, I.tc5.wz);
accum += weight[1].x * s_bloom.Sample(smp_rtlinear, I.Tex5.xy);
accum += weight[1].x * s_bloom.Sample(smp_rtlinear, I.Tex5.wz);
// accum += weight[1].y * tex2D (s_bloom, I.tc6.xy);
// accum += weight[1].y * tex2D (s_bloom, I.tc6.wz);
accum += weight[1].y * s_bloom.Sample(smp_rtlinear, I.Tex6.xy);
accum += weight[1].y * s_bloom.Sample(smp_rtlinear, I.Tex6.wz);
// accum += weight[1].z * tex2D (s_bloom, I.tc7.xy);
// accum += weight[1].z * tex2D (s_bloom, I.tc7.wz);
accum += weight[1].z * s_bloom.Sample(smp_rtlinear, I.Tex7.xy);
accum += weight[1].z * s_bloom.Sample(smp_rtlinear, I.Tex7.wz);
// OK
return accum;
}

View file

@ -0,0 +1,27 @@
#include "common.h"
/*
struct v2p
{
float2 tc0: TEXCOORD0; // base
float2 tc1: TEXCOORD1; // base
float2 tc2: TEXCOORD2; // base
float2 tc3: TEXCOORD3; // base
};
*/
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
float4 main( p_build I ) : SV_Target
{
// float4 t_0 = tex2D (s_bloom,I.tc0);
// float4 t_1 = tex2D (s_bloom,I.tc1);
// float4 t_2 = tex2D (s_bloom,I.tc2);
// float4 t_3 = tex2D (s_bloom,I.tc3);
float4 t_0 = s_image.Sample( smp_rtlinear, I.Tex0);
float4 t_1 = s_image.Sample( smp_rtlinear, I.Tex1);
float4 t_2 = s_image.Sample( smp_rtlinear, I.Tex2);
float4 t_3 = s_image.Sample( smp_rtlinear, I.Tex3);
// out
return ( (t_0+t_1) + (t_2+t_3) ) / 2;
}

View file

@ -0,0 +1,42 @@
#include "common.h"
/*
struct v2p
{
float4 tc0: TEXCOORD0; // Central
float4 tc1: TEXCOORD1; // -1,+1
float4 tc2: TEXCOORD2; // -2,+2
float4 tc3: TEXCOORD3; // -3,+3
float4 tc4: TEXCOORD4; // -4,+4
float4 tc5: TEXCOORD5; // -5,+5
float4 tc6: TEXCOORD6; // -6,+6
float4 tc7: TEXCOORD7; // -7,+7
};
*/
//////////////////////////////////////////////////////////////////////////////////////////
#define LUMINANCE_BASE 0.0001h
float luminance (float2 tc)
{
//float3 source = tex2D(s_image,tc);
float3 source = s_image.Sample( smp_rtlinear, tc );
return dot( source, LUMINANCE_VECTOR*def_hdr );
}
//////////////////////////////////////////////////////////////////////////////////////////
// perform 2x2=4s convolution, working on 4x4=16p area
// that means 256x256 source will be scaled to (256/4)x(256/4) = 64x64p
// a): 256x256 => 64x64p with log
// b): 64x64p => 8x8p
// c): 8x8p => 1x1p with exp
float4 main( p_build I ) : SV_Target
{
// first 8 bilinear samples (8x4 = 32 pixels)
float4 final;
final.x = luminance(I.Tex0);
final.y = luminance(I.Tex1);
final.z = luminance(I.Tex2);
final.w = luminance(I.Tex3);
// OK
return final ;
}

View file

@ -0,0 +1,58 @@
#include "common.h"
struct v2p
{
float4 tc0: TEXCOORD0; // Central
float4 tc1: TEXCOORD1; // -1,+1
float4 tc2: TEXCOORD2; // -2,+2
float4 tc3: TEXCOORD3; // -3,+3
float4 tc4: TEXCOORD4; // -4,+4
float4 tc5: TEXCOORD5; // -5,+5
float4 tc6: TEXCOORD6; // -6,+6
float4 tc7: TEXCOORD7; // -7,+7
};
//////////////////////////////////////////////////////////////////////////////////////////
// perform 4x4 bilinear, 8x8p, the step (B)
// b): 64x64p => 8x8p
float sample (float2 tc)
{
// float4 data = tex2D(s_image,tc);
float4 data = s_image.Sample( smp_rtlinear, tc );
return dot( data, 1.h/4.h ); // sum components
}
float4 main( p_filter I ) : SV_Target
{
// sample
float4 accum0;
accum0.x = sample(I.Tex0);
accum0.y = sample(I.Tex1);
accum0.z = sample(I.Tex2);
accum0.w = sample(I.Tex3);
float4 accum1;
accum1.x = sample(I.Tex4);
accum1.y = sample(I.Tex5);
accum1.z = sample(I.Tex6);
accum1.w = sample(I.Tex7);
float4 accum2;
accum2.x = sample(I.Tex0.wz);
accum2.y = sample(I.Tex1.wz);
accum2.z = sample(I.Tex2.wz);
accum2.w = sample(I.Tex3.wz);
float4 accum3;
accum3.x = sample(I.Tex4.wz);
accum3.y = sample(I.Tex5.wz);
accum3.z = sample(I.Tex6.wz);
accum3.w = sample(I.Tex7.wz);
// perform accumulation
float4 final;
final.x = dot(accum0,1.h/4.h);
final.y = dot(accum1,1.h/4.h);
final.z = dot(accum2,1.h/4.h);
final.w = dot(accum3,1.h/4.h);
// OK
return final;
}

View file

@ -0,0 +1,74 @@
#include "common.h"
/*
struct v2p
{
float4 tc0: TEXCOORD0; // Central
float4 tc1: TEXCOORD1; // -1,+1
float4 tc2: TEXCOORD2; // -2,+2
float4 tc3: TEXCOORD3; // -3,+3
float4 tc4: TEXCOORD4; // -4,+4
float4 tc5: TEXCOORD5; // -5,+5
float4 tc6: TEXCOORD6; // -6,+6
float4 tc7: TEXCOORD7; // -7,+7
};
*/
//////////////////////////////////////////////////////////////////////////////////////////
uniform float4 MiddleGray;
//////////////////////////////////////////////////////////////////////////////////////////
// perform 4x4 bilinear, 8x8p, the step (C)
// c): 8x8p => 1x1p with exp
// native bilinear
float sample( float2 tc )
{
// float4 data = tex2D(s_image,tc);
float4 data = s_image.Sample( smp_rtlinear, tc );
return dot( data, 1.h/4.h ); // sum components
}
float4 main ( p_filter I ) : SV_Target
{
// sample
float4 accum0;
accum0.x = sample(I.Tex0);
accum0.y = sample(I.Tex1);
accum0.z = sample(I.Tex2);
accum0.w = sample(I.Tex3);
float4 accum1;
accum1.x = sample(I.Tex4);
accum1.y = sample(I.Tex5);
accum1.z = sample(I.Tex6);
accum1.w = sample(I.Tex7);
float4 accum2;
accum2.x = sample(I.Tex0.wz);
accum2.y = sample(I.Tex1.wz);
accum2.z = sample(I.Tex2.wz);
accum2.w = sample(I.Tex3.wz);
float4 accum3;
accum3.x = sample(I.Tex4.wz);
accum3.y = sample(I.Tex5.wz);
accum3.z = sample(I.Tex6.wz);
accum3.w = sample(I.Tex7.wz);
// perform accumulation
float4 final;
final.x = dot(accum0,1/4.h);
final.y = dot(accum1,1/4.h);
final.z = dot(accum2,1/4.h);
final.w = dot(accum3,1/4.h);
float result = dot(final, 1/4.h);
// OK
float scale = MiddleGray.x / (result*MiddleGray.y + MiddleGray.z); // final
// float scale_prev = tex2D (s_tonemap,I.tc0).x;
float scale_prev = s_tonemap.Sample( smp_nofilter, I.Tex0 ).x;
float rvalue = lerp (scale_prev,scale,MiddleGray.w);
// clamp (rvalue, 1.f/8.f, 2.0f);
clamp (rvalue, 1.f/128.f, 20.0f);
return rvalue ;
}

View file

@ -0,0 +1,29 @@
#include "common.h"
struct v2p
{
float4 color : COLOR0; // rgb. intensity, for SM3 - tonemap prescaled
float2 tc0 : TEXCOORD0;
float2 tc1 : TEXCOORD1;
};
//uniform sampler2D s_clouds0 : register(s0);
//uniform sampler2D s_clouds1 : register(s1);
Texture2D s_clouds0 : register(t0);
Texture2D s_clouds1 : register(t1);
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
float4 main ( v2p I ) : SV_Target
{
// float4 s0 = tex2D (s_clouds0,I.tc0);
// float4 s1 = tex2D (s_clouds1,I.tc1);
float4 s0 = s_clouds0.Sample( smp_base, I.tc0 );
float4 s1 = s_clouds1.Sample( smp_base, I.tc1 );
float4 mix = I.color * (s0 + s1) ;
float4 rgb = mix ;
// return float4 (rgb.rgb, I.color.a);
return rgb;
}

View file

@ -0,0 +1,21 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("clouds","clouds")
: fog (false)
-- TODO: DX10: Check if this is ok.
-- : zb (true,false)
: zb (false,false)
: sorting (3, true)
: blend (true, blend.srcalpha,blend.invsrcalpha)
-- TODO: DX10: implement sampler setup
-- shader:sampler ("s_clouds0") :texture ("null") : wrap() : f_anisotropic()
-- shader:sampler ("s_clouds1") :texture ("null") : wrap() : f_anisotropic()
-- shader:sampler ("s_tonemap") :texture ("$user$tonemap")
shader:dx10texture ("s_clouds0", "null")
shader:dx10texture ("s_clouds1", "null")
shader:dx10texture ("s_tonemap", "$user$tonemap")
shader:dx10sampler ("smp_base")
-- shader:dx10sampler ("smp_linear")
end

View file

@ -0,0 +1,44 @@
#include "common.h"
#include "shared\cloudconfig.h"
struct vi
{
float4 p : POSITION;
float4 dir : COLOR0; // dir0,dir1(w<->z)
float4 color : COLOR1; // rgb. intensity
};
struct vf
{
float4 color : COLOR0; // rgb. intensity, for SM3 - tonemap-prescaled, HI-res
float2 tc0 : TEXCOORD0;
float2 tc1 : TEXCOORD1;
float4 hpos : SV_Position;
};
vf main (vi v)
{
vf o;
o.hpos = mul (m_WVP, v.p); // xform, input in world coords
// if (length(float3(v.p.x,0,v.p.z))>CLOUD_FADE) o.color.w = 0 ;
// generate tcs
float2 d0 = v.dir.xy*2-1;
float2 d1 = v.dir.wz*2-1;
float2 _0 = v.p.xz * CLOUD_TILE0 + d0*timers.z*CLOUD_SPEED0;
float2 _1 = v.p.xz * CLOUD_TILE1 + d1*timers.z*CLOUD_SPEED1;
o.tc0 = _0; // copy tc
o.tc1 = _1; // copy tc
o.color = v.color ; // copy color, low precision, cannot prescale even by 2
o.color.w *= pow (v.p.y,25);
// float scale = tex2Dlod (s_tonemap,float4(.5,.5,.5,.5)).x ;
float scale = s_tonemap.Load( int3(0,0,0) ).x;
// float scale = s_tonemap.Load( int3(1,1,0) ).x;
o.color.rgb *= scale ; // high precision
return o;
}

View file

@ -0,0 +1,251 @@
#include "common.h"
//#define USE_SUPER_SPECULAR
//#define USE_ORIGINAL_SSAO
//#define HBAO_WORLD_JITTER
#include "lmodel.h"
#include "hmodel.h"
uniform Texture2D s_half_depth;
//#include "ssao_blur.ps"
#ifdef HDAO
#define USE_HDAO 1
#endif
#ifdef SM_5
Texture2D<float> s_occ;
#endif // SM_5
//#ifdef SSAO_QUALITY
//#undef SSAO_QUALITY
//#define SSAO_QUALITY 4
//#endif
#if SSAO_QUALITY <=3
#include "ssao.ps"
//#ifdef SM_5
//#undef SM_5
//#endif
#else
#ifndef USE_HDAO
#define USE_HDAO
#endif
#endif
#ifdef USE_HDAO
#if SSAO_QUALITY > 3
#include "ssao_hdao_new.ps"
#endif
#define USE_HDAO_CODE
#if SSAO_QUALITY <=3
#define g_f2RTSize ( pos_decompression_params2.xy )
//#define g_f2RTSize float2( 1280.0f, 1024.0f )
#ifdef GBUFFER_OPTIMIZATION
#define g_txDepth s_position
#define g_txNormal s_position
#else
#define g_txDepth s_position
#define g_txNormal s_normal
#endif
#include "ssao_hdao.ps"
#endif
#else // USE_HDAO
#ifdef USE_HBAO
#include "ssao_hbao.ps"
#endif // USE_HBAO
#endif // USE_HDAO
struct _input
{
float4 tc0 : TEXCOORD0; // tc.xy, tc.w = tonemap scale
float2 tcJ : TEXCOORD1; // jitter coords
float4 pos2d : SV_Position;
};
struct _out
{
float4 low : SV_Target0;
float4 high : SV_Target1;
};
// TODO: DX10: Replace Sample with Load
#ifndef MSAA_OPTIMIZATION
_out main ( _input I )
#else
_out main ( _input I, uint iSample : SV_SAMPLEINDEX )
#endif
{
gbuffer_data gbd = gbuffer_load_data( GLD_P(I.tc0, I.pos2d, ISAMPLE) );
// Sample the buffers:
float4 P = float4( gbd.P, gbd.mtl ); // position.(mtl or sun)
float4 N = float4( gbd.N, gbd.hemi ); // normal.hemi
float4 D = float4( gbd.C, gbd.gloss ); // rgb.gloss
#ifndef USE_MSAA
float4 L = s_accumulator.Sample( smp_nofilter, I.tc0); // diffuse.specular
#else
# ifdef GBUFFER_OPTIMIZATION
float4 L = s_accumulator.Load( int3( I.pos2d.xy, 0 ), ISAMPLE); // diffuse.specular
# else
float4 L = s_accumulator.Load( int3( I.tc0 * pos_decompression_params2.xy, 0 ), ISAMPLE );
# endif
#endif
#ifdef USE_SUPER_SPECULAR
{
float ds = dot( D.rgb, 1.h/3.h );
D.w = max( D.w, ds*ds/8.h );
}
#endif
#ifdef FORCE_GLOSS
D.w = FORCE_GLOSS;
#endif
#ifdef USE_GAMMA_22
D.rgb = ( D.rgb*D.rgb ); // pow(2.2)
#endif
// static sun
float mtl = P.w;
#ifdef USE_R2_STATIC_SUN
float sun_occ = P.w*2;
mtl = xmaterial;
L += Ldynamic_color * sun_occ * plight_infinity (mtl, P.xyz, N.xyz, Ldynamic_dir);
#endif
// hemisphere
float3 hdiffuse, hspecular;
// Calculate SSAO
#ifdef USE_MSAA
# ifdef GBUFFER_OPTIMIZATION
int2 texCoord = I.pos2d;
# else
int2 texCoord = int2( I.tc0 * pos_decompression_params2.xy );
# endif
#endif
/*#ifdef USE_SSAO_BLUR
# ifndef USE_MSAA
float occ = ssao_blur_ps(I.tc0);
# else
float occ = ssao_blur_ps( texCoord, ISAMPLE );
# endif*/
#ifdef USE_HDAO
#ifdef SM_5
#if SSAO_QUALITY > 3
float occ = s_occ.Sample( smp_nofilter, I.tc0);
#else // SSAO_QUALITY > 3
float occ = calc_hdao( CS_P(P, N, I.tc0, I.tcJ, I.pos2d, ISAMPLE ) );
#endif // SSAO_QUALITY > 3
#else // SM_5
#if SSAO_QUALITY > 3
float occ = calc_new_hdao( CS_P(P, N, I.tc0, I.tcJ, I.pos2d, ISAMPLE ) );
#else // SSAO_QUALITY > 3
float occ = calc_hdao( CS_P(P, N, I.tc0, I.tcJ, I.pos2d, ISAMPLE ) );
#endif // SSAO_QUALITY > 3
#endif // SM_5
#else // USE_HDAO
#ifdef USE_HBAO
float occ = calc_hbao( P.z, N, I.tc0, I.pos2d );
#else // USE_HBAO
float occ = calc_ssao( CS_P(P, N, I.tc0, I.tcJ, I.pos2d, ISAMPLE ) );
#endif
#endif // USE_HDAO
hmodel (hdiffuse, hspecular, mtl, N.w, D.w, P.xyz, N.xyz);
// hmodel (hdiffuse, hspecular, mtl, 1, D.w, P.xyz, N.xyz);
// hdiffuse*=hdiffuse; //. high contrast hemi
// hdiffuse*=(D.rgb*0.8 + 0.2h); // rise texture contrast for diffuse lighting
// hdiffuse = 0.8;
// hdiffuse *= (occ*(D.rgb + .1h));
hdiffuse *= occ;
hspecular *= occ;
float4 light = float4 (L.rgb + hdiffuse, L.w) ;
float4 C = D*light ; // rgb.gloss * light(diffuse.specular)
// float3 spec = (C.rgb*.5h + .5h)*C.w + hspecular + hspecular + hspecular; // replicated specular
float3 spec = C.www + hspecular; // replicated specular
#ifdef USE_SUPER_SPECULAR
spec = (C.rgb*.5h + .5h)*C.w + hspecular ;
#endif
// float3 color = C.rgb + D.rgb*spec ;
// float3 color = C.rgb + (D.rgb*spec+spec)/0.5h;
float3 color = C.rgb + spec ;
// float3 color = C.rgb + D.rgb*spec+hspecular+hspecular ; // More realistic and contrast specular - Ugrumiy edition
////////////////////////////////////////////////////////////////////////////////
/// For Test ///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#ifdef DBG_TEST_NMAP
//. hemi + sun + lighting + specular
color = hdiffuse + L.rgb + N;
#endif
#ifdef DBG_TEST_NMAP_SPEC
//. hemi + sun + lighting + specular
color = hdiffuse + L.rgb + N + spec;
#endif
#ifdef DBG_TEST_LIGHT
//. hemi + sun + lighting + specular
color = hdiffuse + L.rgb;
#endif
#ifdef DBG_TEST_LIGHT_SPEC
//. hemi + sun + lighting + specular
color = hdiffuse + L.rgb + spec;
#endif
#ifdef DBG_TEST_SPEC
//. only lighting and specular
color = spec;
#endif
////////////////////////////////////////////////////////////////////////////////
// here should be distance fog
float3 pos = P.xyz;
float distance = length (pos);
float fog = saturate (distance*fog_params.w + fog_params.x); //
color = lerp (color,fog_color,fog); //
float skyblend = saturate (fog*fog);
#ifdef DBG_TMAPPING
color = D.xyz;
#endif
float tm_scale = I.tc0.w; // interpolated from VS
#ifdef USE_SUPER_SPECULAR
color = spec - hspecular ;
#endif
// color = N; //show normals
// color = D.xyz;
// color
//float3 color = (0.5 * (sign( gbd.N - gbd.N_org ) + 1.0 ) );
//color = float3( abs( gbd.hemi - gbd.hemi_org), 0, abs( gbd.mtl - gbd.mtl_org) );
//color = abs( gbd.N - gbd.N_org );
// color = occ; // holger test
//color = gbd.N;
_out o;
tonemap (o.low, o.high, color, tm_scale ) ;
o.low.a = skyblend ;
o.high.a = skyblend ;
// o.low = skyblend;
// o.hight = 0;
//o.low = float4(gbd.P,1);
//o.low = float4( 1.0f, 0.0f, 0.0f, 1.0f );
return o;
}

View file

@ -0,0 +1,27 @@
#include "common.h"
struct _in
{
float4 P : POSITIONT; // xy=pos, zw=tc0
float2 tcJ : TEXCOORD0; // jitter coords
};
struct v2p
{
float4 tc0 : TEXCOORD0; // tc.xy, tc.w = tonemap scale
float2 tcJ : TEXCOORD1; // jitter coords
float4 hpos: SV_Position;
};
//////////////////////////////////////////////////////////////////////////////////////////
// Vertex
v2p main ( _in I )
{
v2p O;
O.hpos = float4 (I.P.x, -I.P.y, 0, 1);
float scale = s_tonemap.Load(int3(0,0,0)).x;
O.tc0 = float4 (I.P.zw, scale, scale);
O.tcJ = I.tcJ;
return O;
}
FXVS;

View file

@ -0,0 +1 @@
#include "combine_1.ps"

View file

@ -0,0 +1,2 @@
#undef MSAA_OPTIMIZATION
#include "combine_1.ps"

View file

@ -0,0 +1,125 @@
#include "common.h"
#include "mblur.h"
/*
struct v2p
{
float4 tc0: TEXCOORD0; // Center
float4 tc1: TEXCOORD1; // LT
float4 tc2: TEXCOORD2; // RB
float4 tc3: TEXCOORD3; // RT
float4 tc4: TEXCOORD4; // LB
float4 tc5: TEXCOORD5; // Left / Right
float4 tc6: TEXCOORD6; // Top / Bottom
};
*/
//////////////////////////////////////////////////////////////////////////////////////////
Texture2D s_distort;
uniform float4 e_barrier; // x=norm(.8f), y=depth(.1f), z=clr
uniform float4 e_weights; // x=norm, y=depth, z=clr
uniform float4 e_kernel; // x=norm, y=depth, z=clr
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
#ifdef GBUFFER_OPTIMIZATION
float4 main ( v_aa_AA I, float4 pos2d : SV_POSITION ) : SV_Target
#else
float4 main ( v_aa_AA I ) : SV_Target
#endif
{
#ifdef GBUFFER_OPTIMIZATION
gbuffer_data gbd0 = gbuffer_load_data(I.Tex0, pos2d);
gbuffer_data gbd1 = gbuffer_load_data_offset(I.Tex0,I.Tex1, pos2d);
gbuffer_data gbd2 = gbuffer_load_data_offset(I.Tex0,I.Tex2, pos2d);
gbuffer_data gbd3 = gbuffer_load_data_offset(I.Tex0,I.Tex3, pos2d);
gbuffer_data gbd4 = gbuffer_load_data_offset(I.Tex0,I.Tex4, pos2d);
#else
gbuffer_data gbd0 = gbuffer_load_data(I.Tex0);
gbuffer_data gbd1 = gbuffer_load_data(I.Tex1);
gbuffer_data gbd2 = gbuffer_load_data(I.Tex2);
gbuffer_data gbd3 = gbuffer_load_data(I.Tex3);
gbuffer_data gbd4 = gbuffer_load_data(I.Tex4);
#endif
// Normal discontinuety filter
//float3 nc = tex2D (s_normal, I.tc0);
float3 nc = gbd0.N;
float4 nd;
// nd.x = dot (nc, (float3)tex2D(s_normal,I.tc1));
// nd.y = dot (nc, (float3)tex2D(s_normal,I.tc2));
// nd.z = dot (nc, (float3)tex2D(s_normal,I.tc3));
// nd.w = dot (nc, (float3)tex2D(s_normal,I.tc4));
nd.x = dot (nc, (float3)( gbd1 ).N);
nd.y = dot (nc, (float3)( gbd2 ).N);
nd.z = dot (nc, (float3)( gbd3 ).N);
nd.w = dot (nc, (float3)( gbd4 ).N);
nd -= e_barrier.x ;
nd = step (0,nd); // bw
float ne = saturate (dot(nd,e_weights.x));
// Opposite coords
float4 tc5r = I.Tex5.wzyx;
float4 tc6r = I.Tex6.wzyx;
#ifdef GBUFFER_OPTIMIZATION
gbuffer_data gbd5 = gbuffer_load_data_offset(I.Tex0,I.Tex5, pos2d);
gbuffer_data gbd6 = gbuffer_load_data_offset(I.Tex0,I.Tex6, pos2d);
gbuffer_data gbd5r = gbuffer_load_data_offset(I.Tex0,tc5r, pos2d);
gbuffer_data gbd6r = gbuffer_load_data_offset(I.Tex0,tc6r, pos2d);
#else
gbuffer_data gbd5 = gbuffer_load_data(I.Tex5);
gbuffer_data gbd6 = gbuffer_load_data(I.Tex6);
gbuffer_data gbd5r = gbuffer_load_data(tc5r);
gbuffer_data gbd6r = gbuffer_load_data(tc6r);
#endif
// Depth filter : compute gradiental difference: (c-sample1)+(c-sample1_opposite)
// float4 dc = tex2D (s_position, I.tc0);
float4 dc = float4( gbd0.P, gbd0.mtl );
float4 dd;
// dd.x = (float)tex2D(s_position,I.tc1).z + (float)tex2D(s_position,I.tc2).z;
// dd.y = (float)tex2D(s_position,I.tc3).z + (float)tex2D(s_position,I.tc4).z;
// dd.z = (float)tex2D(s_position,I.tc5).z + (float)tex2D(s_position,tc5r).z;
// dd.w = (float)tex2D(s_position,I.tc6).z + (float)tex2D(s_position,tc6r).z;
dd.x = (float)gbd1.P.z
+ (float)gbd2.P.z;
dd.y = (float)gbd3.P.z
+ (float)gbd4.P.z;
dd.z = (float)gbd5.P.z
+ (float)gbd5r.P.z;
dd.w = (float)gbd6.P.z
+ (float)gbd6r.P.z;
dd = abs(2*dc.z-dd)-e_barrier.y;
dd = step (dd,0); // bw
float de = saturate (dot(dd,e_weights.y));
// weight
float w = (1-de*ne)*e_kernel.x; // 0 - no aa, 1=full aa
#ifdef USE_DISTORT
// float4 distort = tex2D (s_distort, I.tc0);
float4 distort = s_distort.Sample( smp_nofilter, I.Tex0);
float2 doffs = (distort.xy-.5h)*def_distort;
float2 center = I.Tex0 + doffs;
#else
float2 center = I.Tex0;
#endif
// Smoothed color
// (a-c)*w + c = a*w + c(1-w)
float2 offset = center * (1-w);
// float4 s0 = tex2D (s_image, offset + I.tc1*w);
// float4 s1 = tex2D (s_image, offset + I.tc2*w);
// float4 s2 = tex2D (s_image, offset + I.tc3*w);
// float4 s3 = tex2D (s_image, offset + I.tc4*w);
float4 s0 = s_image.Sample( smp_rtlinear, offset + I.Tex1*w);
float4 s1 = s_image.Sample( smp_rtlinear, offset + I.Tex2*w);
float4 s2 = s_image.Sample( smp_rtlinear, offset + I.Tex3*w);
float4 s3 = s_image.Sample( smp_rtlinear, offset + I.Tex4*w);
float3 final = mblur( center, dc, (s0+s1+s2+s3)/4.h );
// return combine_bloom(final,tex2D (s_bloom, I.tc0));
return combine_bloom( final, s_bloom.Sample( smp_rtlinear, I.Tex0));
}

View file

@ -0,0 +1,3 @@
#define USE_DISTORT //- shader defined
#include "combine_2_AA.ps"

View file

@ -0,0 +1,114 @@
#include "common.h"
#include "mblur.h"
#include "dof.h"
/*
struct v2p
{
float4 tc0: TEXCOORD0; // Center
float4 tc1: TEXCOORD1; // LT
float4 tc2: TEXCOORD2; // RB
float4 tc3: TEXCOORD3; // RT
float4 tc4: TEXCOORD4; // LB
float4 tc5: TEXCOORD5; // Left / Right
float4 tc6: TEXCOORD6; // Top / Bottom
};
*/
//////////////////////////////////////////////////////////////////////////////////////////
#ifndef USE_MSAA
Texture2D s_distort;
#define EPSDEPTH 0.001
#else
Texture2DMS<float4, MSAA_SAMPLES> s_distort;
#define EPSDEPTH 0.001
#endif
uniform float4 e_barrier; // x=norm(.8f), y=depth(.1f), z=clr
uniform float4 e_weights; // x=norm, y=depth, z=clr
uniform float4 e_kernel; // x=norm, y=depth, z=clr
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
struct c2_out
{
float4 Color : SV_Target;
#ifdef USE_MSAA
float Depth : SV_Depth;
#endif
};
c2_out main( v2p_aa_AA I )
{
c2_out res;
res.Color = float4(0,0,0,0);
/*
#ifdef USE_MSAA
[unroll] for( int iSample = 0; iSample < MSAA_SAMPLES; ++iSample )
{
#else // USE_MSAA
int iSample = 0;
#endif
*/
int iSample = 0;
#ifdef GBUFFER_OPTIMIZATION
gbuffer_data gbd = gbuffer_load_data(I.Tex0, I.HPos, iSample );
#else
gbuffer_data gbd = gbuffer_load_data(I.Tex0, iSample );
#endif
#ifdef USE_DISTORT
// float depth = tex2D (s_position, I.tc0).z;
// float4 distort = tex2D (s_distort, I.tc0);
float depth = gbd.P.z;
#ifndef USE_MSAA
float4 distort = s_distort.Sample(smp_nofilter, I.Tex0);
#else // USE_MSAA
float4 distort = s_distort.Load( int3( I.Tex0 * pos_decompression_params2.xy, 0 ), iSample );
#endif // USE_MSAA
float2 offset = (distort.xy-(127.0h/255.0h))*def_distort; // fix newtral offset
float2 center = I.Tex0 + offset;
#ifdef GBUFFER_OPTIMIZATION
gbuffer_data gbdx = gbuffer_load_data_offset(I.Tex0, center, I.HPos, iSample );
#else
gbuffer_data gbdx = gbuffer_load_data_offset(I.Tex0, center, iSample);
#endif
// float depth_x = tex2D (s_position, center).z ;
float depth_x = gbdx.P.z;
if ((depth_x+EPSDEPTH)<depth) center = I.Tex0; // discard new sample
#else // USE_DISTORT
float2 center = I.Tex0;
#endif
//float3 img = tex2D (s_image, center);
float3 img = dof(center);
// float4 bloom = tex2D (s_bloom, center);
float4 bloom = s_bloom.Sample( smp_rtlinear, center);
// img = mblur (center,tex2D(s_position,I.tc0),img.rgb);
// img = mblur( center, s_position.Sample( smp_nofilter, tc0), img.rgb);
img = mblur( center, ( gbd ).P, img.rgb);
#ifdef USE_DISTORT
float3 blurred = bloom*def_hdr ;
img = lerp (img,blurred,distort.z);
#endif
/*
#ifdef USE_MSAA
res += combine_bloom( img, bloom ) / MSAA_SAMPLES;
}
#else
res += combine_bloom( img, bloom );
#endif
*/
res.Color += combine_bloom( img, bloom );
#ifdef USE_MSAA
float4 ptp = mul(m_P, float4(gbd.P, 1));
res.Depth = ptp.w==0?1:ptp.z/ptp.w;
#endif
return res;
}

View file

@ -0,0 +1,3 @@
#define USE_DISTORT //- shader defined
#include "combine_2_NAA.ps"

View file

@ -0,0 +1,44 @@
#include "common.h"
// Igor: used for volumetric light
#ifndef USE_MSAA
Texture2D s_vollight;
#else
Texture2DMS<float4, MSAA_SAMPLES> s_vollight;
#endif
struct _input
{
float4 tc0 : TEXCOORD0; // tc.xy, tc.w = tonemap scale
};
struct _out
{
float4 low : SV_Target0;
float4 high : SV_Target1;
};
// TODO: DX10: Use load instead of sample
_out main( _input I )
{
// final tone-mapping
float tm_scale = I.tc0.w; // interpolated from VS
_out o;
float4 color;
#ifndef USE_MSAA
color = s_vollight.Load(int3(I.tc0.xy*pos_decompression_params2.xy, 0));
#else // USE_MSAA
color = s_vollight.Load(int3(I.tc0.xy*pos_decompression_params2.xy, 0), 0);
[unroll] for(int iSample = 1; iSample < MSAA_SAMPLES; ++iSample)
{
color += s_vollight.Load(int3(I.tc0*pos_decompression_params2.xy, 0), iSample);
}
color /= MSAA_SAMPLES;
#endif // USE_MSAA
tonemap(o.low, o.high, color, tm_scale );
return o;
}

View file

@ -0,0 +1,16 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("combine_1", "combine_volumetric")
: fog (false)
: zb (false,false)
: blend (true,blend.one,blend.one)
-- : aref (true,0) -- enable to save bandwith?
: sorting (2, false)
-- TOD0: DX10: Implement samplers
-- shader:sampler ("s_vollight") :texture ("$user$generic2")
-- shader:sampler ("s_tonemap") :texture ("$user$tonemap")
shader:dx10texture ("s_vollight", "$user$generic2")
shader:dx10texture ("s_tonemap", "$user$tonemap")
shader:dx10sampler ("smp_nofilter")
end

View file

@ -0,0 +1,105 @@
#ifndef COMMON_H
#define COMMON_H
#include "shared\common.h"
#include "common_defines.h"
#include "common_policies.h"
#include "common_iostructs.h"
#include "common_samplers.h"
#include "common_cbuffers.h"
#include "common_functions.h"
// #define USE_SUPER_SPECULAR
#ifdef USE_R2_STATIC_SUN
# define xmaterial float(1.0h/4.h)
#else
# define xmaterial float(L_material.w)
#endif
/*
//////////////////////////////////////////////////////////////////////////////////////////
// *** options
// #define DBG_TEST_NMAP
// #define DBG_TEST_NMAP_SPEC
// #define DBG_TEST_SPEC
// #define DBG_TEST_LIGHT
// #define DBG_TEST_LIGHT_SPEC
// #define USE_GAMMA_22
// #define USE_SJITTER
// #define USE_SUNFILTER
// #define USE_FETCH4
// #define USE_MBLUR //- HW-options defined
// #define USE_HWSMAP //- HW-options defined
// #define USE_HWSMAP_PCF //- nVidia GF3+, R600+
// #define USE_BRANCHING //- HW-options defined
// #define USE_VTF //- HW-options defined, VertexTextureFetch
// #define FP16_FILTER //- HW-options defined
// #define FP16_BLEND //- HW-options defined
//
// #define USE_PARALLAX //- shader defined
// #define USE_TDETAIL //- shader defined
// #define USE_LM_HEMI //- shader defined
// #define USE_DISTORT //- shader defined
// #define USE_SUNMASK //- shader defined
// #define DBG_TMAPPING
//////////////////////////////////////////////////////////////////////////////////////////
uniform float4 J_direct [6];
uniform float4 J_spot [6];
float2 calc_detail (float3 w_pos) {
float dtl = distance (w_pos,eye_position)*dt_params.w;
dtl = min (dtl*dtl, 1);
float dt_mul = 1 - dtl; // dt* [1 .. 0 ]
float dt_add = .5 * dtl; // dt+ [0 .. 0.5]
return float2 (dt_mul,dt_add);
}
//////////////////////////////////////////////////////////////////////////////////////////
#ifdef USE_HWSMAP
#else
struct v_shadow_direct_aref
{
float4 hpos: POSITION; // Clip-space position (for rasterization)
float depth: TEXCOORD0; // Depth
float2 tc0: TEXCOORD1; // Diffuse map for aref
};
struct v_shadow_direct
{
float4 hpos: POSITION; // Clip-space position (for rasterization)
float depth: TEXCOORD0; // Depth
};
#endif
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
struct p_screen {
float4 hpos : POSITION;
float2 tc0 : TEXCOORD0; // Texture coordinates (for sampling maps)
};
//////////////////////////////////////////////////////////////////////////////////////////
float3 v_hemi_wrap (float3 n, float w) { return L_hemi_color*(w + (1-w)*n.y); }
float3 v_sun_wrap (float3 n, float w) { return L_sun_color*(w+(1-w)*dot(n,-L_sun_dir_w)); }
*/
#define FXPS technique _render{pass _code{PixelShader=compile ps_3_0 main();}}
#define FXVS technique _render{pass _code{VertexShader=compile vs_3_0 main();}}
#endif

View file

@ -0,0 +1,21 @@
#ifndef common_cbuffers_h_included
#define common_cbuffers_h_included
#ifndef MSAA_OPTIMIZATION
// Used by dynamic lights and volumetric effects
cbuffer dynamic_light
{
float4 Ldynamic_color; // dynamic light color (rgb1) - spot/point/sun
float4 Ldynamic_pos; // dynamic light pos+1/range(w) - spot/point
float4 Ldynamic_dir; // dynamic light direction - sun
}
#else
cbuffer dynamic_light
{
float4 Ldynamic_color; // dynamic light color (rgb1) - spot/point/sun
float4 Ldynamic_pos; // dynamic light pos+1/range(w) - spot/point
float4 Ldynamic_dir; // dynamic light direction - sun
}
#endif
#endif // common_cbuffers_h_included

View file

@ -0,0 +1,24 @@
#ifndef common_defines_h_included
#define common_defines_h_included
//////////////////////////////////////////////////////////////////////////////////////////
// Defines //
#define def_gloss float(2.f /255.f)
#define def_aref float(200.f/255.f)
#define def_dbumph float(0.333f)
#define def_virtualh float(0.05f) // 5cm
#define def_distort float(0.05f) // we get -0.5 .. 0.5 range, this is -512 .. 512 for 1024, so scale it
#define def_hdr float(9.h) // hight luminance range float(3.h)
#define def_hdr_clip float(0.75h) //
#define LUMINANCE_VECTOR float3(0.3f, 0.38f, 0.22f)
//////////////////////////////////////////////////////////////////////////////////////////
#ifndef SMAP_size
#define SMAP_size 1024
#endif
#define PARALLAX_H 0.02
#define parallax float2(PARALLAX_H, -PARALLAX_H/2)
//////////////////////////////////////////////////////////////////////////////////////////
#endif // common_defines_h_included

Some files were not shown because too many files have changed in this diff Show more