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

87 lines
2.3 KiB
PostScript

#include "common.h"
#include "lmodel.h"
#include "shadow.h"
// Check Screen Space Shaders modules & addons
#include "check_screenspace.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
//////////////////////////////////////////////////////////////////////////////////////////
float4 m_lmap[2];
#ifdef MSAA_OPTIMIZATION
float4 main(p_volume I, float4 pos2d : SV_Position, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#else
float4 main(p_volume I, float4 pos2d : SV_Position ) : SV_Target
#endif
{
float2 tcProj = I.tc.xy / I.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 );
float4 _C = float4(gbd.C, gbd.gloss );
float m = xmaterial ;
#ifndef USE_R2_STATIC_SUN
m = _P.w;
#endif
// FLORA FIXES & IMPROVEMENTS - SSS Update 14.2
// Fix Flora ilumination ( Align normal to light )
#ifdef SSFX_FLORAFIX
if(abs(m - MAT_FLORA) <= 0.05)
{
_N.rgb = -normalize(_P - Ldynamic_pos.xyz);
_C.w *= 0.3f;
}
#endif
// ----- light-model
float rsqr;
float4 light = plight_local(m, _P, _N, _C, Ldynamic_pos, Ldynamic_pos.w, rsqr );
// ----- shadow
float3 Offset = 0;
#ifdef SSFX_SHADOWS
// Biasing ( Use the nDotL from plight_local... )
float bias_int = (1.0 - saturate(dot(_N, -normalize(_P - Ldynamic_pos.xyz)))) * rsqr * Ldynamic_pos.w;
Offset = _N * (0.025f + bias_int * ssfx_shadow_bias.x);
#endif
float4 P4 = float4(_P.xyz + Offset, 1);
float4 PS = mul(m_shadow, P4 );
float s = 1.h;
#ifdef USE_SHADOW
s = shadow( PS );
#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
// Can use linear with mip point
lightmap = s_lmap.SampleLevel(smp_rtlinear, PS.xy / PS.w, 0 );
#endif
#ifdef SSFX_ENHANCED_SHADERS
return float4(SRGBToLinear(Ldynamic_color.rgb * lightmap.rgb * s.xxx),1) * light;
#else
return float4( Ldynamic_color * light * s * lightmap);
#endif
}