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

76 lines
2.2 KiB
PostScript

/**
* @ Version: SCREEN SPACE SHADERS - UPDATE 20
* @ Description: Non-directional volumetric shader
* @ Modified time: 2024-02-20 07:26
* @ Author: https://www.moddb.com/members/ascii1457
* @ Mod: https://www.moddb.com/mods/stalker-anomaly/addons/screen-space-shaders
*/
// Remember: If you need new textures or samplers, remember to edit both `accum_volumetric.s` and `accum_volumetric_nomsaa.s`
#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
};
float4 m_lmap[2];
//uniform float4 shader_param_6;
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
#ifndef MSAA_OPTIMIZATION
float4 main ( v2p I ) : SV_Target
#else
float4 main ( v2p I, uint iSample : SV_SAMPLEINDEX ) : SV_Target
#endif
{
// Screen UV ( view to uv ) // TODO : Use the Matrix mul from the vertex shader
float4 Postc = mul(m_P, float4(I.vPos, 1));
float2 tc = (Postc.xy / Postc.w) * float2(0.5f, -0.5f) + 0.5f;
// Shadow matrix
float4 P4 = float4(I.vPos, 1);
float4 PS = mul( m_shadow, P4);
PS.xyz /= PS.w;
// Occlusion from light perspective.
float occ = s_smap.SampleCmpLevelZero( smp_smap, PS.xy, PS.z).x;
// Occlusion from player perspective.
float _depth = 0;
#ifndef USE_MSAA
_depth = s_position.Sample(smp_nofilter, tc).z;
#else
_depth = s_position.Load(int3(tc * screen_res.xy, 0), iSample).z;
#endif
_depth = _depth <= SKY_EPS ? 10000 : _depth; // Sky
occ *= _depth < Postc.z ? 0.0f : 1.0f;
// Texture mask
PS.x = dot( P4, m_lmap[0]);
PS.y = dot( P4, m_lmap[1]);
PS.xy /= PS.w;
float4 lightmap = s_lmap.Sample(smp_jitter, PS.xy);
// Attenuate ( Vanilla light attenuation )
float rsqr = dot( I.lightToPos, I.lightToPos); // distance 2 light (squared)
float att = saturate( 1.0f - rsqr * Ldynamic_pos.w ); // q-linear attenuate
// Add extra attenuation when passing through.
att *= saturate(Postc.z * 2.5f);
// Result
float3 result = I.fDensity * occ * att * lightmap * Ldynamic_color;
return float4( result, 0);
}