Divergent/mods/Enhanced Shaders Color Grading/gamedata/shaders/r3/combine_1.ps

163 lines
3.8 KiB
PostScript

#include "anomaly_shaders.h"
#include "common.h"
#include "lmodel.h"
#include "hmodel.h"
#include "mip_fog.h"
Texture2D s_half_depth;
#include "ssao.ps"
#ifdef HDAO
#define USE_HDAO 1
#endif
#ifdef SM_5
Texture2D<float> s_occ;
#endif // SM_5
#if SSAO_QUALITY <=3
#include "ssdo.ps"
#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 ( screen_res.xy )
#define g_txDepth s_position
#define g_txNormal s_position
#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
float4 L = s_accumulator.Load( int3( I.tc0 * screen_res.xy, 0 ), ISAMPLE );
#endif
// static sun
float mtl = P.w;
#ifdef USE_R2_STATIC_SUN
float sun_occ = P.w*2;
mtl = xmaterial;
L += SRGBToLinear(D.rgb * Ldynamic_color.rgb * sun_occ) * plight_infinity (mtl, P.xyz, N.xyz, D.xyzw, Ldynamic_dir);
#endif
// Calculate SSAO
#ifdef USE_MSAA
int2 texCoord = I.pos2d;
#endif
float3 occ = float3(1.0,1.0,1.0);
#ifdef USE_HDAO
#ifdef SM_5
#if SSAO_QUALITY > 3
occ = s_occ.Sample( smp_nofilter, I.tc0);
#else // SSAO_QUALITY > 3
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
occ = calc_new_hdao( CS_P(P, N, I.tc0, I.tcJ, I.pos2d, ISAMPLE ) );
#else // SSAO_QUALITY > 3
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
occ = calc_hbao( P.z, N, I.tc0, I.pos2d );
#else // USE_HBAO
occ = calc_ssdo(P, N, I.tc0, I.pos2d, ISAMPLE).xxx;
#endif
#endif // USE_HDAO
#ifdef SSAO_QUALITY
occ = compute_colored_ao(occ.x, D.xyz);
#endif
occ = SRGBToLinear(occ); //gamma correct
L.rgb += L.a * SRGBToLinear(D.rgb); //illum in alpha
// hemisphere
float3 hdiffuse, hspecular;
hmodel (hdiffuse, hspecular, mtl, N.w, D, P.xyz, N.xyz);
hdiffuse *= occ;
//hspecular *= occ;
float3 color = L.rgb + hdiffuse.rgb;
color = LinearTosRGB(color); //gamma correct
////////////////////////////////////////////////////////////////////////////////
// here should be distance fog
float3 pos = P.xyz;
float distance = length (pos);
float fog = saturate (distance*fog_params.w + fog_params.x); //
color = Calc_Fog(P.xyz, color);
//color = lerp (color,fog_color,fog); //
//float skyblend = saturate(fog);
float skyblend = 0.5;
skyblend = saturate((fog-skyblend)/(1-skyblend));
skyblend = (skyblend*skyblend);
float tm_scale = I.tc0.w; // interpolated from VS
_out o;
tonemap (o.low, o.high, color, tm_scale ) ;
o.low.a = skyblend ;
o.high.a = skyblend ;
return o;
}