Divergent/mods/Screen Space Shaders/gamedata/shaders/r3/deffer_grass.ps

141 lines
3.6 KiB
PostScript
Raw Normal View History

#if ( defined(MSAA_ALPHATEST_DX10_1_ATOC) || defined(MSAA_ALPHATEST_DX10_1) )
#define EXTEND_F_DEFFER
#endif
#include "common.h"
#include "sload.h"
#include "check_screenspace.h"
static float DITHER_THRESHOLDS[16] =
{
1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
};
// SSS Settings
#ifdef SSFX_FLORAFIX
#include "settings_screenspace_FLORA.h"
#endif
#ifdef ATOC
float4 main ( p_bumped I ) : SV_Target
{
surface_bumped S = sload (I);
S.base.w = (S.base.w-def_aref*0.5f)/(1-def_aref*0.5f);
return S.base;
}
#else // ATOC
#ifdef MSAA_ALPHATEST_DX10_1_ATOC
f_deffer main ( p_bumped I, float4 pos2d : SV_Position )
#else // MSAA_ALPHATEST_DX10_1_ATOC
f_deffer main ( p_bumped I )
#endif // MSAA_ALPHATEST_DX10_1_ATOC
{
f_deffer O;
#if !defined(MSAA_ALPHATEST_DX10_1)
surface_bumped S = sload (I);
#if !( defined(MSAA_ALPHATEST_DX10_1_ATOC) || defined(MSAA_ALPHATEST_DX10_0_ATOC) )
clip (S.base.w-def_aref);
#endif // !( defined(MSAA_ALPHATEST_DX10_1_ATOC) || defined(MSAA_ALPHATEST_DX10_1_ATOC) )
#ifdef MSAA_ALPHATEST_DX10_1_ATOC
float alpha = (S.base.w-def_aref*0.5f)/(1-def_aref*0.5f);
uint mask = alpha_to_coverage ( alpha, pos2d );
#endif // MSAA_ALPHATEST_DX10_1_ATOC
#else // !defined(MSAA_ALPHATEST_DX10_1)
uint mask = 0x0;
surface_bumped S = sload (I,MSAAOffsets[0]*(1.0/16.0));
if( S.base.w-def_aref >= 0 ) mask |= 0x1;
[unroll] for( int i = 1; i < MSAA_SAMPLES; ++i )
{
surface_bumped SI = sload (I,MSAAOffsets[i]*(1.0/16.0));
if( SI.base.w-def_aref >= 0 ) mask |= ( uint(0x1) << i );
}
if( mask == 0x0 )
discard;
#endif // !defined(MSAA_ALPHATEST_DX10_1)
// FLORA FIXES & IMPROVEMENTS - SSS Update 18
// https://www.moddb.com/mods/stalker-anomaly/addons/screen-space-shaders/
//S.normal.xy += float2(0.1f, 0.1f);
S.normal.xy *= max(10.0f * rain_params.y, 3.0f);
// FLORA FIXES & IMPROVEMENTS - SSS Update 22
// https://www.moddb.com/mods/stalker-anomaly/addons/screen-space-shaders/
// Fake UP Normal
float3 fN = mul(m_WV, float3(S.normal.x, 1.0f, S.normal.y));
fN = normalize (fN);
// Terrain Normal ( Engine feed the terrain normals )
float3 Ne = float3(I.M1.z, I.M2.z, I.M3.z) + fN;
Ne = normalize (Ne);
float ms = xmaterial;
S.gloss = def_gloss;
// Dither
float4 Postc = mul(m_P, float4(I.position.xyz, 1));
float2 tc = (Postc.xy / Postc.w) * float2(0.5f, -0.5f) + 0.5f;
float2 dither_uv = tc * screen_res.xy; // Aspect ratio
uint dither_idx = (uint(dither_uv.x) % 4) * 4 + uint(dither_uv.y) % 4;
clip(I.M1.x - DITHER_THRESHOLDS[dither_idx]);
#ifdef SSFX_FLORAFIX
// Material value ( MAT_FLORA )
ms = 0.15f;
// Fake gloss
S.gloss = lerp(ssfx_florafixes_1.x, ssfx_florafixes_1.y, rain_params.y);
#endif
// -----------------------------------------------------------------------
#ifdef USE_LM_HEMI
// float4 lm = tex2D (s_hemi, I.lmh);
float4 lm = s_hemi.Sample( smp_rtlinear, I.lmh);
//float h = dot (lm.rgb,1.h/3.h);
float h = get_hemi(lm);
# ifdef USE_R2_STATIC_SUN
// ms = lm.w;
ms = get_sun(lm);
# endif
#else
float h = I.position.w ;
# ifdef USE_R2_STATIC_SUN
ms = I.tcdh.w ;
# endif
#endif
#ifndef EXTEND_F_DEFFER
O = pack_gbuffer(
float4 (Ne, h),
float4 (I.position.xyz + Ne*S.height*def_virtualh, ms),
float4 (S.base.rgb, S.gloss) );
#else
O = pack_gbuffer(
float4 (Ne, h),
float4 (I.position.xyz + Ne*S.height*def_virtualh, ms),
float4 (S.base.rgb, S.gloss),
mask );
#endif
return O ;
}
#endif // ATOC