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

77 lines
1.9 KiB
PostScript

#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];
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
s = shadow_hw(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
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
// ----- 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 = 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 *= s_noise.Sample( smp_linear, PS );
t_noise = t_noise*0.5+0.5;
s = max(0, s);
att = max(0, att);
lightmap = max(0, lightmap);
t_noise = max(0, t_noise);
// matches vanilla?
float maxIntens = I.fDensity;
float3 result = maxIntens * s * att;
result *= lightmap;
result *= Ldynamic_color * t_noise;
return float4( result, 0); //srgb
//return float4( SRGBToLinear(result), 0);
}