99 lines
3.2 KiB
PostScript
99 lines
3.2 KiB
PostScript
/**
|
|
* @ Version: SCREEN SPACE SHADERS - UPDATE 22
|
|
* @ Description: Bloom - Combine
|
|
* @ Modified time: 2024-11-05 11:31
|
|
* @ Author: https://www.moddb.com/members/ascii1457
|
|
* @ Mod: https://www.moddb.com/mods/stalker-anomaly/addons/screen-space-shaders
|
|
*/
|
|
|
|
#include "screenspace_common.h"
|
|
|
|
Texture2D s_ssfx_bloom;
|
|
Texture2D s_starburst;
|
|
Texture2D s_bloom_lens;
|
|
Texture2D s_ssfx_lensdirt;
|
|
|
|
uniform float4 ssfx_bloom_1; // Threshold, Exposure, Emmisive, Sky
|
|
uniform float4 ssfx_bloom_2; // Blur Radius, Vibrance, Lens, Dirt
|
|
uniform float4 mask_control;
|
|
|
|
//uniform float4 shader_param_6;
|
|
|
|
float3 UnchartedToneMapping(float3 col, float exposure)
|
|
{
|
|
static const float A = 0.15;
|
|
static const float B = 0.50;
|
|
static const float C = 0.10;
|
|
static const float D = 0.20;
|
|
static const float E = 0.02;
|
|
static const float F = 0.30;
|
|
static const float W = 11.2;
|
|
static const float white = 1.0 / (((W * (A * W + C * B) + D * E) / (W * (A * W + B) + D * F)) - E / F);
|
|
|
|
col *= exposure;
|
|
col = ((col * (A * col + C * B) + D * E) / (col * (A * col + B) + D * F)) - E / F;
|
|
col *= white;
|
|
|
|
return col;
|
|
}
|
|
|
|
float4 main ( p_screen I ) : SV_Target
|
|
{
|
|
|
|
// Bloom ///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
float4 bloom = 0;
|
|
|
|
bloom.r = s_ssfx_bloom.Sample(smp_rtlinear, I.tc0.xy + (float2(4.5f, 5.3f) / screen_res.xy)).r;
|
|
bloom.ga = s_ssfx_bloom.Sample(smp_rtlinear, I.tc0.xy).ga;
|
|
bloom.b = s_ssfx_bloom.Sample(smp_rtlinear, I.tc0.xy - (float2(3.2f, 4.1f) / screen_res.xy)).b;
|
|
|
|
// Adjust intensity
|
|
bloom = pow( abs( bloom ), 0.5f );
|
|
|
|
// Some extra bloom for emissive ( `bloom.a` is only Emissive )
|
|
bloom.rgb = saturate(bloom.rgb * (1.0f + bloom.a));
|
|
|
|
// Tonemap
|
|
bloom.rgb = UnchartedToneMapping(bloom.rgb, ssfx_bloom_1.y);
|
|
bloom.rgb = vibrance( bloom.rgb, ssfx_bloom_2.y );
|
|
|
|
// Lens Flares /////////////////////////////////////////////////////////////////////////////
|
|
|
|
float aspect = screen_res.x / screen_res.y;
|
|
|
|
// Starburst
|
|
float sOffset = dot(m_V[0], float3(0,0,1)) + dot(m_V[1], float3(0,1,0)) * 2; // Camera Angle
|
|
|
|
// Radial UV
|
|
float2 cUV = I.tc0.xy - 0.5f;
|
|
float cUV_len = length(cUV);
|
|
float radial = acos(cUV.x / cUV_len) * 2.0f;
|
|
float starburst = s_starburst.Sample(smp_linear, radial.xx + sOffset).r;
|
|
starburst *= s_starburst.Sample(smp_linear, radial.xx - sOffset).r;
|
|
//starburst = saturate(starburst + (1.0f - smoothstep(0.0, 0.5, d)));
|
|
|
|
// Lens flares
|
|
float3 Flares = 0;
|
|
|
|
Flares.r = s_bloom_lens.Sample(smp_rtlinear, I.tc0.xy + (float2(18.5f, 21.1f) / screen_res.xy)).r;
|
|
Flares.g = s_bloom_lens.Sample(smp_rtlinear, I.tc0.xy).g;
|
|
Flares.b = s_bloom_lens.Sample(smp_rtlinear, I.tc0.xy - (float2(12.5f, 18.1f) / screen_res.xy)).b;
|
|
|
|
Flares = saturate(Flares * starburst * ssfx_bloom_2.z);
|
|
|
|
// Adjust brightness
|
|
Flares *= 0.5f / (0.5f + Flares) * mask_control.x;
|
|
|
|
// COMBINE /////////////////////////////////////////////////////////////////////////////////
|
|
|
|
bloom.rgb = blend_soft(bloom.rgb, Flares);
|
|
|
|
// Dirt Layer
|
|
float3 MaskDirt = s_ssfx_lensdirt.Sample(smp_rtlinear, I.tc0.xy) * saturate(bloom.rgb + bloom.aaa);
|
|
MaskDirt *= 2.5f * ssfx_bloom_2.w * saturate(mask_control.x);
|
|
|
|
bloom.rgb = blend_soft(bloom.rgb, MaskDirt.rgb);
|
|
|
|
return float4(bloom.rgb, 1);
|
|
} |