Added New Mods and Profiles Folders

This is a complete rebuild of the modpack, with all new mods and updates for 1.5.3 of Anomaly.
This commit is contained in:
2025-01-14 05:07:53 -05:00
parent 85c665b107
commit 376b4b9689
21217 changed files with 546254 additions and 0 deletions
@@ -0,0 +1,220 @@
#include "anomaly_shaders.h"
#include "common.h"
#include "night_vision.h"
#include "lmodel.h"
#include "hmodel.h"
Texture2D s_half_depth;
#include "ssao.ps"
#ifdef HDAO
#define USE_HDAO 1
#endif
#ifdef SM_5
Texture2D<float> s_occ;
#endif // SM_5
#if SSAO_QUALITY <=3
#include "ssdo.ps"
#else
#ifndef USE_HDAO
#define USE_HDAO
#endif
#endif
#ifdef USE_HDAO
#if SSAO_QUALITY > 3
#include "ssao_hdao_new.ps"
#endif
#define USE_HDAO_CODE
#if SSAO_QUALITY <=3
#define g_f2RTSize ( screen_res.xy )
#define g_txDepth s_position
#define g_txNormal s_position
#include "ssao_hdao.ps"
#endif
#else // USE_HDAO
#ifdef USE_HBAO
#include "ssao_hbao.ps"
#endif // USE_HBAO
#endif // USE_HDAO
struct _input
{
float4 tc0 : TEXCOORD0; // tc.xy, tc.w = tonemap scale
float2 tcJ : TEXCOORD1; // jitter coords
float4 pos2d : SV_Position;
};
struct _out
{
float4 low : SV_Target0;
float4 high : SV_Target1;
};
// TODO: DX10: Replace Sample with Load
#ifndef MSAA_OPTIMIZATION
_out main ( _input I )
#else
_out main ( _input I, uint iSample : SV_SAMPLEINDEX )
#endif
{
gbuffer_data gbd = gbuffer_load_data( GLD_P(I.tc0, I.pos2d, ISAMPLE) );
// Sample the buffers:
float4 P = float4( gbd.P, gbd.mtl ); // position.(mtl or sun)
float4 N = float4( gbd.N, gbd.hemi ); // normal.hemi
float4 D = float4( gbd.C, gbd.gloss ); // rgb.gloss
#ifndef USE_MSAA
float4 L = s_accumulator.Sample( smp_nofilter, I.tc0); // diffuse.specular
#else
float4 L = s_accumulator.Load( int3( I.tc0 * screen_res.xy, 0 ), ISAMPLE );
#endif
if (abs(P.w - MAT_FLORA) <= 0.05) {
// Reapply distance factor to fix overtly glossy plants in distance
// Unfortunately some trees etc don't seem to use the same detail shader
float fAtten = 1 - smoothstep(0, 50, P.z);
D.a *= (fAtten * fAtten);
}
// static sun
float mtl = P.w;
#ifdef USE_R2_STATIC_SUN
float sun_occ = P.w*2;
mtl = xmaterial;
L += SRGBToLinear(D.rgb * Ldynamic_color.rgb * sun_occ) * plight_infinity (mtl, P.xyz, N.xyz, D.xyzw, Ldynamic_dir);
#endif
// Calculate SSAO
#ifdef USE_MSAA
int2 texCoord = I.pos2d;
#endif
float3 occ = float3(1.0,1.0,1.0);
#ifdef USE_HDAO
#ifdef SM_5
#if SSAO_QUALITY > 3
occ = s_occ.Sample( smp_nofilter, I.tc0);
#else // SSAO_QUALITY > 3
occ = calc_hdao( CS_P(P, N, I.tc0, I.tcJ, I.pos2d, ISAMPLE ) );
#endif // SSAO_QUALITY > 3
#else // SM_5
#if SSAO_QUALITY > 3
occ = calc_new_hdao( CS_P(P, N, I.tc0, I.tcJ, I.pos2d, ISAMPLE ) );
#else // SSAO_QUALITY > 3
occ = calc_hdao( CS_P(P, N, I.tc0, I.tcJ, I.pos2d, ISAMPLE ) );
#endif // SSAO_QUALITY > 3
#endif // SM_5
#else // USE_HDAO
#ifdef USE_HBAO
occ = calc_hbao( P.z, N, I.tc0, I.pos2d );
#else // USE_HBAO
occ = calc_ssdo(P, N, I.tc0, I.pos2d, ISAMPLE).xxx;
#endif
#endif // USE_HDAO
#ifdef SSAO_QUALITY
occ = compute_colored_ao(occ.x, D.xyz);
#endif
occ = SRGBToLinear(occ); //gamma correct
L.rgb += L.a * SRGBToLinear(D.rgb); //illum in alpha
// hemisphere
float3 hdiffuse, hspecular;
hmodel (hdiffuse, hspecular, mtl, N.w, D, P.xyz, N.xyz);
hdiffuse *= occ;
//hspecular *= occ;
float3 color = L.rgb + hdiffuse.rgb;
color = LinearTosRGB(color); //gamma correct
//// SOME NVG SHIT ////
float lua_param_nvg_generation = floor(shader_param_8.x); // 1, 2, or 3
float lua_param_nvg_num_tubes = frac(shader_param_8.x) * 10.0f; // 1, 2, 4, 1.1, or 1.2
float lua_param_nvg_gain_current = floor(shader_param_8.y) / 10.0f;
float lua_param_vignette_current = floor(shader_param_8.z) / 100.0f;
// NVG reduces gloss to 0 inside mask
D.a *= (1.0 - compute_lens_mask(aspect_ratio_correction(I.tc0), lua_param_nvg_num_tubes));
//// END NVG SHIT ////
////////////////////////////////////////////////////////////////////////////////
// here should be distance fog
float3 pos = P.xyz;
float distance = length (pos);
float fog = saturate (distance*fog_params.w + fog_params.x); //
color = lerp (color,fog_color,fog); //
float skyblend = saturate (fog*fog);
float tm_scale = I.tc0.w; // interpolated from VS
_out o;
/////////// BEEFS NVGS CHANGES ///////////
if (lua_param_nvg_generation > 0.0f && compute_lens_mask(aspect_ratio_correction(I.tc0), lua_param_nvg_num_tubes) == 1.0f)
{
float lua_param_nvg_gain_offset = floor(shader_param_8.w) / 10.0f;
tonemap(o.low, o.high, color, 10.0f * lua_param_nvg_gain_offset);
// Turn split tonemapping data to YUV and discard UV
o.low.r = dot(o.low.rgb, luma_conversion_coeff);
o.high.r = dot(o.high.rgb, luma_conversion_coeff);
o.low.r *= 4.0f;
o.high.r *= 4.0f;
// Turn s_accumulator data in to YUV and discard UV
o.low.g = pow(dot(L.rgb, luma_conversion_coeff),2.0f)*1.3f;
o.high.g = o.low.g;
// Turn albedo into YUV and discard UV
o.low.b = dot(D.rgb, luma_conversion_coeff);
o.high.b = o.low.b;
o.low *= lua_param_nvg_gain_current;
o.high *= lua_param_nvg_gain_current;
// Extra
o.low.a = skyblend;
o.high.a = skyblend;
// APPLY VIGNETTE
float vignette = calc_vignette(lua_param_nvg_num_tubes, I.tc0, lua_param_vignette_current+0.02);
o.high = clamp(o.high,0.0,1.0);
o.low= clamp(o.low,0.0,1.0);
o.high.rgb *= vignette;
o.low.rgb *= vignette;
}
else
{
tonemap(o.low, o.high, color, tm_scale);
o.low.a = skyblend;
o.high.a = skyblend;
}
return o;
}
@@ -0,0 +1,96 @@
#include "common.h"
#include "anomaly_shaders.h"
#include "night_vision.h"
//////////////////////////////////////////////////////////////////////////////////////////
#ifndef USE_MSAA
Texture2D s_distort;
#define EPSDEPTH 0.001
#else
#ifndef SM_5
Texture2DMS<float4,MSAA_SAMPLES> s_distort;
#else
Texture2DMS<float4> s_distort;
#endif
#define EPSDEPTH 0.001
#endif
//////////////////////////////////////////////////////////////////////////////////////////
float4 e_barrier; // x=norm(.8f), y=depth(.1f), z=clr
float4 e_weights; // x=norm, y=depth, z=clr
float4 e_kernel; // x=norm, y=depth, z=clr
//////////////////////////////////////////////////////////////////////////////////////////
#include "mblur.h"
#include "img_corrections.h"
#include "tonemapping.h"
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
struct c2_out
{
float4 Color : SV_Target;
#ifdef USE_MSAA
float Depth : SV_Depth;
#endif
};
c2_out main( v2p_aa_AA I )
{
c2_out res;
res.Color = float4(0,0,0,0);
int iSample = 0;
gbuffer_data gbd = gbuffer_load_data(I.Tex0, I.HPos, iSample );
float depth = gbd.P.z;
#ifdef USE_DISTORT
#ifndef USE_MSAA
float4 distort = s_distort.Sample(smp_nofilter, I.Tex0);
#else // USE_MSAA
float4 distort = s_distort.Load( int3( I.Tex0 * screen_res.xy, 0 ), iSample );
#endif // USE_MSAA
float2 offset = (distort.xy-(127.0h/255.0h))*def_distort; // fix newtral offset
float2 center = I.Tex0 + offset;
gbuffer_data gbdx = gbuffer_load_data_offset(I.Tex0, center, I.HPos, iSample);
float depth_x = gbdx.P.z;
if ((depth_x+EPSDEPTH)<depth) center = I.Tex0; // discard new sample
#else // USE_DISTORT
float2 center = I.Tex0;
#endif
float3 img = s_image.Load(int3(center.xy * screen_res.xy, 0),0);
float4 bloom = s_bloom.Sample(smp_rtlinear,center);
img = mblur( center, ( gbd ).P, img.rgb);
float lua_param_nvg_generation = floor(shader_param_8.x); // 1, 2, or 3
float lua_param_nvg_num_tubes = frac(shader_param_8.x) * 10.0f; // 1, 2, 4, 1.1, or 1.2
// NVG CHANGE TO PREVENT WEIRD COLORS, ONLY APPLY BLOOM WHEN WE'RE NOT IN NVG MASK
if (lua_param_nvg_generation < 0.01f && compute_lens_mask(aspect_ratio_correction(I.Tex0), lua_param_nvg_num_tubes) == 0.0f)
{
img = blend_soft(img, bloom.xyz*bloom.w);
}
if (tnmp_onoff == 1.0)
{
img = Uncharted2ToneMapping(img);
}
img = img_corrections(img);
#ifdef USE_DISTORT
float3 blurred = bloom*def_hdr ;
img = lerp (img,blurred,distort.z);
#endif
res.Color = float4(img,1.0);
#ifdef USE_MSAA
float4 ptp = mul(m_P, float4(gbd.P, 1));
res.Depth = ptp.w==0?1:ptp.z/ptp.w;
#endif
return res;
}
@@ -0,0 +1,453 @@
#include "common.h"
uniform float4 shader_param_8;
uniform float4 shader_param_7;
///////////////////////////////////////////////////////
// BEEF'S SHADER BASED NIGHT VISION EFFECT //
///////////////////////////////////////////////////////
// Huge credit TO LVutner from Anomaly Discord, who //
// literally taught me everything I know, to Sky4Ace //
// who's simple_blur function I've adapted for this //
// shader, and to Meltac, who provided some advice //
// and inspiration for developing this shader. //
///////////////////////////////////////////////////////
// Note: You are free to distribute and adapt this //
// Shader and any components, just please provide //
// credit to myself and/or the above individuals. I //
// have provided credit for individual functions and //
// their original authors where applicable. - BEEF //
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
// USER SETTINGS HERE
///////////////////////////////////////////////////////
//////// GLOBAL SETTINGS(ALL GENERATIONS)////////
#define sky_brightness_factor float (1.0f) // Sky brightness factor. If your sky is too bright, decrease this slightly, if too dim, increase this slightly.
// NVG CRT & NOISE VALUES
//(BE AWARE THAT NOISE AND SCINTILLATION SCALE WITH NVG GAIN)
#define gen_1_crt_effect_factor float(0.05) // Default 0.05 - How much CRT effect to add to NVG image (0 = none, 1 = max).
#define gen_1_nvg_noise_factor float (0.15) // Default 0.15 - How much noise to add to NVG image. (0 = none, 0.5 = insane)
#define gen_1_scintillation_constant float (0.999f) // Default 0.999 - The closer the number is to 1.00000, the less scintillation effect.
#define gen_1_luma_sharpen_factor float(0.0f) // Default 0.0 - How much luma sharpen is added in. (0 = none, 1 = max)
#define gen_2_crt_effect_factor float(0.07) // Default 0.07 - How much CRT effect to add to NVG image (0 = none, 1 = max).
#define gen_2_nvg_noise_factor float (0.1) // Default 0.15 - How much noise to add to NVG image. (0 = none, 0.5 = insane)
#define gen_2_scintillation_constant float (0.9991f) // Default 0.9991 - The closer the number is to 1.00000, the less scintillation effect.
#define gen_2_luma_sharpen_factor float(0.25f) // Default 0.25f - How much luma sharpen is added in. (0 = none, 1 = max)
#define gen_3_crt_effect_factor float(0.1) // Default 0.1 - How much CRT effect to add to NVG image (0 = none, 1 = max).
#define gen_3_nvg_noise_factor float (0.08) // Default 0.15 - How much noise to add to NVG image. (0 = none, 0.5 = insane)
#define gen_3_scintillation_constant float (0.9992f) // Default 0.9992 - The closer the number is to 1.00000, the less scintillation effect.
#define gen_3_luma_sharpen_factor float(0.5f) // Default 0.5 - How much luma sharpen is added in. (0 = none, 1 = max)
// NVG COLOR OPTIONS:
#define gen_1_saturation_color float3 (0.7,1,0.6) // Gen1 NVG color - it defines the max amount of color from 0 to 1 using (Red,Green,Blue)
#define gen_2_saturation_color float3 (0.5,1,0.4) // Gen1 NVG color - it defines the max amount of color from 0 to 1 using (Red,Green,Blue)
#define gen_3_saturation_color float3 (0.2,1,0.9) // Gen1 NVG color - it defines the max amount of color from 0 to 1 using (Red,Green,Blue)
// EXAMPLE COLOR SCHEMES:
// (0.7,1,0.6) - gen 1 soft green
// (0.5,1,0.4) - gen 2 hard green
// (0.2,1,0.9) - gen 3 blueish
// (1.0,1.0,1.0) - black and white
// (1.0,0.7,0.1) - yellow or amber color
///////////////////////////////////////////////////////
// PROBABLY DON'T CHANGE STUFF BELOW HERE UNLESS YOU KNOW WHAT YOU'RE DOING
///////////////////////////////////////////////////////
// Constants
#define tube_radius float (frac(shader_param_7.y))
#define single_tube_centered float2(0.5f, -0.5f + (floor(shader_param_7.x) / 100))
#define single_tube_offset_left float2(0.25f, -0.5f + (floor(shader_param_7.x) / 100)) // Single tube screen position (0.5, 0.5 is centered)
#define single_tube_offset_right float2(0.75f, -0.5f + (floor(shader_param_7.x) / 100)) // Single tube screen position (0.5, 0.5 is centered)
#define dual_tube_offset_1 float2(0.25f, -0.5f + (floor(shader_param_7.x) / 100)) // Offset for dual tube left eye
#define dual_tube_offset_2 float2(0.75f, -0.5f + (floor(shader_param_7.x) / 100)) // Offset for dual tube right eye
#define quad_tube_offset_1 float2(0.05f, -0.5f + (floor(shader_param_7.x) / 100)) // Offset for quad tube left outer tube
#define quad_tube_offset_2 float2(0.3f, -0.5f + (floor(shader_param_7.x) / 100)) // Offset for quad tube left inner tube
#define quad_tube_offset_3 float2(0.7f, -0.5f + (floor(shader_param_7.x) / 100)) // Offset for quad tube right inner tube
#define quad_tube_offset_4 float2(0.95f, -0.5f + (floor(shader_param_7.x) / 100)) // Offset for quad tube right outer tube
#define luma_conversion_coeff float3 (0.299, 0.587, 0.114)// When we convert to YUV, these are the coefficients for Y (since we discard UV)
#define farthest_depth float (25.0f) // The farthest far place that we can reach in regards to DOF effects
// LUA PACKING
// local x_1 = tostring(nvg_generation) -- Generation (1,2,3) - outputs 1.x to 3.x
// local x_2 = tostring(nvg_num_tubes) -- Num Tubes (1,2,4,11,12) outputs x.1, x.2, x.4, x.11, or x.12
// local y_1 = tostring(math.floor(nvg_gain_current * 10)) -- Gain Adjust (0.1 to 3) -- outputs 1.y to 30.y in 1. increment
// local y_2 = tostring(math.floor(nvg_washout_thresh * 10)) -- Washout Thresh (0.0 - 0.9) - outputs y.0 to y.9 in .1 increment
// local z_1 = tostring(math.floor(vignette_current * 100)) -- Vignette Amount (0.0 to 1.0) outputs 0.z to 100.z in 1. increment
// local z_2 = tostring(math.floor(glitch_power * 10)) -- Glitch Power (0.0 - 0.9) - outputs z.0 to z.9 in .1 increment
// local w_1 = tostring((math.floor(nvg_gain_offset * 10)) ) -- Gain Offset (0.5 to 3.0) - outputs 5.w to 30.w in 1. increment
// local w_2 = tostring(nvg_mode) -- Mode (0,1) - outputs w.0 or w.1 depending on mode
// SHADER UNPACKING
// float lua_param_nvg_generation = floor(shader_param_8.x); // 1, 2, or 3
// float lua_param_nvg_num_tubes = frac(shader_param_8.x) * 10.0f; // 1, 2, 4, 1.1, or 1.2
// float lua_param_nvg_gain_current = floor(shader_param_8.y) / 10.0f; // 0.0 to 3.0
// float lua_param_nvg_washout_thresh = frac(shader_param_8.y); // 0.0 to 0.9
// float lua_param_vignette_current = floor(shader_param_8.z) / 100.0f; // 0.0 to 1.0
// float lua_param_glitch_power = frac(shader_param_8.z); // 0.0 to 0.9
// float lua_param_nvg_gain_offset = floor(shader_param_8.w) / 10.0f; // 0.5 to 3.0
// float lua_param_nvg_mode = frac(shader_param_8.w) * 10; // 0 to 9 in 1.0 increment
// mode 0: blurred background (default)
// mode 1: black background
// mode 2: image overlay
// mode 3: no changes (clear vision)
// float lua_param_flip_down = floor(shader_param_7.x);
// float lua_param_nvg_radius = frac(shader_param_7.y);
///////////////////////////////////////////////////////
// DEFINE NVG MASK (Credit to LVutner for huge assistance in designing the functions)
///////////////////////////////////////////////////////
float compute_lens_mask(float2 masktc, float num_tubes)
{
float lua_param_flip_down = floor(shader_param_7.x);
lua_param_flip_down = clamp(5 - (lua_param_flip_down / 20.0f),1.0f,5.0f);
masktc.y = masktc.y * lua_param_flip_down;
if (num_tubes > 0.99f && num_tubes < 1.01f) // One tube centered
{
return step(distance(masktc,single_tube_centered), tube_radius);
}
else if (num_tubes > 1.09f && num_tubes < 1.11f) // One tube left offset
{
return step(distance(masktc,single_tube_offset_left), tube_radius);
}
else if (num_tubes > 1.19f && num_tubes < 1.21f) // One tube right offset
{
return step(distance(masktc,single_tube_offset_right), tube_radius);
}
else if (num_tubes > 1.99f && num_tubes < 2.01f) // Two tubes
{
if ( (step(distance(masktc,dual_tube_offset_1), tube_radius) == 1) || (step(distance(masktc,dual_tube_offset_2), tube_radius) == 1))
{
return 1.0f;
}
else
{
return 0.0f;
}
}
else if (num_tubes > 3.99f && num_tubes < 4.01f) // Four Tubes
{
if (((step(distance(masktc,quad_tube_offset_1), tube_radius) == 1) || (step(distance(masktc,quad_tube_offset_2), tube_radius) == 1)) || ((step(distance(masktc,quad_tube_offset_3), tube_radius) == 1) || (step(distance(masktc,quad_tube_offset_4), tube_radius) == 1)))
{
return 1.0f;
}
else
{
return 0.0f;
}
}
else
{
return 0.0f;
}
}
///////////////////////////////////////////////////////
// ASPECT RATIO CORRECTION (Credit LVutner)
///////////////////////////////////////////////////////
float2 aspect_ratio_correction (float2 tc)
{
tc.x -= 0.5f;
tc.x *= (screen_res.x / screen_res.y);
tc.x += 0.5f;
return tc;
}
///////////////////////////////////////////////////////
// CRT EFFECT (adapted from MattiasCRT on ShaderToy, credit Mattias)
///////////////////////////////////////////////////////
float2 curve_texturecoords(float2 curved_tc)
{
curved_tc = (curved_tc - 0.5) * 2.0;
curved_tc *= 1.1;
curved_tc.x *= 1.0 + pow((abs(curved_tc.y) / 5.0), 2.0);
curved_tc.y *= 1.0 + pow((abs(curved_tc.x) / 4.0), 2.0);
curved_tc = (curved_tc / 2.0) + 0.5;
curved_tc = curved_tc *0.92 + 0.04;
return curved_tc;
}
float3 make_crt_ified(float3 fragColor, float2 tc )
{
//float2 screen_res = screen_res.xy; // define screen res variable
float2 uv = curve_texturecoords(tc);
float3 col;
float x = sin(0.3*timers.x+uv.y*21.0)*sin(0.7*timers.x+uv.y*29.0)*sin(0.3+0.33*timers.x+uv.y*31.0)*0.0017;
col.r = fragColor.r;
col.g = fragColor.g;
col.b = fragColor.b;
col.r += 0.08f * fragColor.r;
col.g += 0.05f * fragColor.g;
col.b += 0.08f * fragColor.b;
col = clamp(col*0.6+0.4*col*col*1.0,0.0,1.0);
float vig = (0.0 + 1.0*16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y));
col *= float(pow(abs(vig),0.3));
col *= float3(0.95,1.05,0.95);
col *= 2.8;
float scans = clamp( 0.35+0.35*sin(uv.y*screen_res.y*2.0), 0.0, 1.0);
float s = pow(scans,1.7);
col = col*float( 0.4+0.7*s) ;
col *= 1.0+0.01*sin(110.0*timers.x);
if (uv.x < 0.0 || uv.x > 1.0)
col *= 0.0;
if (uv.y < 0.0 || uv.y > 1.0)
col *= 0.0;
col*=1.0-0.65*float(clamp(((tc.x % 2.0)-1.0)*2.0,0.0f,1.0f));
float comp = smoothstep( 0.1, 0.9, sin(timers.x) );
fragColor = col;
return fragColor;
}
///////////////////////////////////////////////////////
// VIGNETTE CALCULATOR (USED IN NVG AS WELL AS BLOOM PHASES TO DARKEN EDGES OF SHIT)
///////////////////////////////////////////////////////
float calc_vignette (float num_tubes, float2 tc, float vignette_amount)
{
float vignette;
float2 corrected_texturecoords = aspect_ratio_correction(tc);
float lua_param_flip_down = floor(shader_param_7.x);
lua_param_flip_down = clamp(5 - (lua_param_flip_down / 20.0f),1.0f,5.0f);
corrected_texturecoords.y = corrected_texturecoords.y * lua_param_flip_down;
if (num_tubes > 0.99f && num_tubes < 1.01f)
{
float gen1_vignette = pow(smoothstep(tube_radius,tube_radius-vignette_amount, distance(corrected_texturecoords,single_tube_centered)),3);
vignette = 1.0 - (1.0 - gen1_vignette); // apply vignette
}
else if (num_tubes > 1.09f && num_tubes < 1.11f)
{
float gen1_vignette = pow(smoothstep(tube_radius,tube_radius-vignette_amount, distance(corrected_texturecoords,single_tube_offset_left)),3);
vignette = 1.0 - (1.0 - gen1_vignette); // apply vignette
}
else if (num_tubes > 1.19f && num_tubes < 1.21f)
{
float gen1_vignette = pow(smoothstep(tube_radius,tube_radius-vignette_amount, distance(corrected_texturecoords,single_tube_offset_right)),3);
vignette = 1.0 - (1.0 - gen1_vignette); // apply vignette
}
else if (num_tubes > 1.99f && num_tubes < 2.01f)
{
float gen2_vignette_1 = pow(smoothstep(tube_radius,tube_radius-vignette_amount, distance(corrected_texturecoords,dual_tube_offset_1)),3);
float gen2_vignette_2 = pow(smoothstep(tube_radius,tube_radius-vignette_amount, distance(corrected_texturecoords,dual_tube_offset_2)),3);
vignette = 1.0 - ((1.0 - gen2_vignette_1) * (1.0 - gen2_vignette_2)); // apply vignette
}
else if (num_tubes > 3.99f && num_tubes < 4.01f)
{
float gen3_vignette_1 = pow(smoothstep(tube_radius,tube_radius-vignette_amount, distance(corrected_texturecoords,quad_tube_offset_1)),3);
float gen3_vignette_2 = pow(smoothstep(tube_radius,tube_radius-vignette_amount, distance(corrected_texturecoords,quad_tube_offset_2)),3);
float gen3_vignette_3 = pow(smoothstep(tube_radius,tube_radius-vignette_amount, distance(corrected_texturecoords,quad_tube_offset_3)),3);
float gen3_vignette_4 = pow(smoothstep(tube_radius,tube_radius-vignette_amount, distance(corrected_texturecoords,quad_tube_offset_4)),3);
vignette = 1.0 - ((1.0 - gen3_vignette_1) * (1.0 - gen3_vignette_2) * (1.0 - gen3_vignette_3) * (1.0 - gen3_vignette_4)); // apply vignette
}
return vignette;
}
///// blur functions
float IGN_calc(float2 uv)
{
uv = frac(uv);
float f = 0.06711056 * uv.x + 0.00583715 * uv.y;
return 6.28*(frac(52.9829189 * frac(f)));
}
float2x2 rot(float a)
{
float c;
float s;
sincos(a,s,c);
return float2x2 (c, s, -s, c);
}
///////////////////////////////////////////////////////
// LUMA SHARPEN (adapted from Simple Luma Sharpen on ShaderToy, credit xwize)
///////////////////////////////////////////////////////
float3 YUVFromRGB( float3 color)
{
return float3 (color.r * 0.299 + color.g * 0.587 + color.b * 0.114,
color.r * -0.147 + color.g * -0.289 + color.b * 0.436,
color.r * 0.615 + color.g * -0.515 + color.b * -0.100);
}
float3 RGBFromYUV ( float3 color)
{
return float3 (color.r * 1.0 + color.b * 1.140,
color.r * 1.0 + color.g * -0.395 + color.b * 0.581 ,
color.r * 1.0 + color.g * 2.032);
}
float extractLuma(float3 c)
{
return (c.r * 0.299 + c.g * 0.587 + c.b * 0.114);
}
float3 luma_sharpen(float3 image, float2 uv)
{
float3 yuv = YUVFromRGB(image);
float2 imgSize = screen_res.xy;
float accumY = 0.0;
for(int i = -1; i <= 1; ++i) {
for(int j = -1; j <= 1; ++j) {
float2 offset = float2(i,j) / imgSize;
float s = extractLuma(s_blur_2.SampleLevel(smp_rtlinear,uv + offset,0).rrr);
float notCentre = min(float(i*i + j*j),1.0);
accumY += s * (9.0 - notCentre*10.0);
}
}
accumY /= 9.0;
float gain = 0.9;
accumY = (accumY + yuv.x)*gain;
image = RGBFromYUV (float3(accumY,yuv.y,yuv.z)); // sharpened
return image;
}
///////////////////////////////////////////////////////
// DEPTH BLUR - LITERALLY BLURS THE DEPTH VALUE IN S_POSITION
///////////////////////////////////////////////////////
float blurred_depth (float2 tc)
{
float Pi = 6.28318530718; // Pi*2
float Directions = 12.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)
float Quality = 4.0; // BLUR QUALITY (Default 4.0 - More is better but slower)
float Size = 6;
float2 Radius = Size/screen_res.xy;
// how far away is the center of our COC
float center_depth = s_position.Load( int3( (tc)*screen_res.xy, 0 ), 0 ).z;
if (center_depth == 0) { center_depth = 10000; }
// set our average depth to be center depth
float depth_average = 0;
// where we store the depth_sample
float depth_sample;
// where we store the weighted value from sample
float depth_tap;
// where we store our weighted
float weight = 0.0;
// where we store the total weighted
float total_weight = 0.0;
// Blur calculations
for(float i=1.0; i<=Quality; i++) // how far away are we
{
for( float d=0.0; d<Pi; d+=Pi/Directions) // where are we around the circle
{
// pull depth at our sample point
depth_sample = s_position.Load( int3( ((tc+float2(cos(d),sin(d))*Radius*i) * screen_res.xy), 0 ), 0 ).z;
// if we hit the sky, give it a depth of 10k
if (depth_sample == 0) {depth_sample = 10000.0f; }
// if the point we hit is closer than our (center? average), then that point should add blurring to our centerpoint
if (depth_sample <= center_depth )
{
weight = Quality - pow((i - 1),0.5);
depth_average += depth_sample * weight;
total_weight += weight;
}
// but if the point we hit is farther than our (center? average?) then that point should not be adding blur to our centerpoint
}
}
depth_average /= total_weight;
return depth_average;
}
////////////////////////////////////////////////////////////////////
//////// GLITCH EFFECT /////////////////
float3 glitchEffect( float3 image, float2 tc, float power)
{
//tc.y = 1.0 - tc.y;
float time = fmod(timers.x, 32.0); // + modelmat[0].x + modelmat[0].z;
float GLITCH = saturate(power);
float rnd0 = rand(timers.x);
float r0 = saturate((1.0-GLITCH)*0.7 + rnd0);
float rnd1 = rand(floor(tc.x*10.0f * r0) / (10.0f * r0) * time);
float r1 = 0.5 - (0.5 * GLITCH) + rnd1;
r1 = 1.0 - max( 0.0, r1);
float rnd2 = rand(floor(tc.y*40.0f * r1) / (40.0f * r1) * time);
float r2 = saturate(rnd2);
float rnd3 = rand(floor(tc.y*10.0f * r0) / (10.0f * r0) * time);
float r3 = (1.0 - saturate(rnd3 + 0.8)) - 0.1f;
float pxrnd = rand( dot(tc.x,tc.y) + time );
float test_result;
if (rnd0 > 0.5f)
{ test_result = 1.0f; }
else
{test_result = -1.0f; }
float ofs = 0.05 * r2 * GLITCH * test_result;
ofs += 0.5 * pxrnd * ofs;
tc.y += 0.1 * r3 * GLITCH;
int NUM_SAMPLES = 10;
float RCP_NUM_SAMPLES_F = 1.0 / (float)NUM_SAMPLES;
float3 sum = 0.0f;
float3 wsum = 0.0f;
float t0 = 0.0f;
for( int i=0; i<NUM_SAMPLES; ++i )
{
float t = (float)i * RCP_NUM_SAMPLES_F;
tc.x = saturate(tc.x + ofs * t);
float3 samplecol = s_blur_2.SampleLevel(smp_rtlinear, tc, 0).rgb;
// float3 s = spectrum_offset( t );
// samplecol *= s;
sum += samplecol;
wsum += 1.0f;
}
return sum.rgb /= wsum;
}
@@ -0,0 +1,163 @@
///////////////////////////////////////////////////////
// BEEF'S SHADER BASED NIGHT VISION EFFECT //
///////////////////////////////////////////////////////
// Huge credit TO LVutner from Anomaly Discord, who //
// literally taught me everything I know, to Sky4Ace //
// who's simple_blur function I've adapted for this //
// shader, and to Meltac, who provided some advice //
// and inspiration for developing this shader. //
///////////////////////////////////////////////////////
// Note: You are free to distribute and adapt this //
// Shader and any components, just please provide //
// credit to myself and/or the above individuals. I //
// have provided credit for individual functions and //
// their original authors where applicable. - BEEF //
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
// STEP 0 - GLOBAL DEFINITIONS AND INCLUDES
///////////////////////////////////////////////////////
#include "night_vision.h"
#include "common.h"
float3 bokeh_pass_3 (float image, float2 tc)
{
float Pi = 6.28318530718; float blur_directions = 8.0; float blur_quality = 4.0; float blur_radius = 5; float3 color = 0.0f; float3 color_average = 0.0f;
float light_avgs = 0.0f; float weight = 0.0f; float total_weight = 0.0f;
for(float i=1.0; i<=blur_quality; i++) { for( float d=0.0; d<Pi; d+=Pi/blur_directions) {
color = s_blur_8.SampleLevel(smp_rtlinear, tc + (float2(cos(d),sin(d))*blur_radius*i/screen_res.xy),0).rgb;
color += s_blur_4.SampleLevel(smp_rtlinear, tc + (float2(cos(d),sin(d))*blur_radius*i/screen_res.xy),0).rgb;
if (color.g > 0.0f) { color.g *= 1.0f; light_avgs += 1.0f;} else {light_avgs += 0.5;} color_average += color; } } image = color_average.g / light_avgs;
return image;
}
float4 main(p_screen I) : SV_Target
{
///////////////////////////////////////////////////////
// STEP 0 - LOCAL DEFINITIONS
///////////////////////////////////////////////////////
// TC vars
float2 corrected_texturecoords = aspect_ratio_correction(I.tc0);
///////////////////////////////////////////////////////
// STEP 0 - MAIN SAMPLES
///////////////////////////////////////////////////////
float3 image = s_image.Sample(smp_rtlinear, I.tc0).xyz;
///////////////////////////////////////////////////////
// STEP 0 - MAIN FUNCTION
///////////////////////////////////////////////////////
float3 half_res_blur = s_blur_2.Sample(smp_rtlinear, I.tc0).rgb;
float lua_param_nvg_num_tubes = frac(shader_param_8.x) * 10.0f;
if (compute_lens_mask(corrected_texturecoords, lua_param_nvg_num_tubes) == 1) // see if we're inside the lens mask
{
// GRAB SAMPLES FOR NVG SHADER
float3 eighth_res_bloom = s_blur_8.Sample(smp_rtlinear, I.tc0).rgb;
float3 quarter_res_bloom = s_blur_4.Sample(smp_rtlinear, I.tc0).rgb;
float4 jitter = float4(
frac(sin(dot(I.tc0, float2(12.0, 78.0) + (timers.x) )) * 12345.0),
frac(sin(dot(I.tc0-fmod(I.tc0,float2(3.0,3.0)/screen_res.xy), float2(12.0, 78.0) + (timers.x) )) * 22738.0),
frac(sin(dot(I.tc0-fmod(I.tc0,float2(3.0,3.0)/screen_res.xy), float2(12.0, 78.0) + (timers.x) )) * 78372.0),
frac(sin(dot(I.tc0, float2(12.0, 78.0) + (timers.x) )) * 37857.0));
//float depth = s_position.Load(int3(I.tc0 * screen_res.xy,0),0).z; // Sample the depth buffer in a better way
//float depth = pow(blurred_depth(I.tc0),2)*1000;
float depth = blurred_depth(I.tc0);
//image.r = lerp(half_res_blur.r,image.r,0.6f);
//image = pow(image,0.75);
image = lerp(image,half_res_blur,clamp(1-smoothstep(0,15,depth),0.4,1)); // NEAR BLUR
if (depth < 1000)
{
float light_att = pow(1.0f-(smoothstep(5,300,depth)),0.5); // Distance from full brightness to full black
if ((image.r+image.g) < 0.9f)
{
image.r *= (light_att+0.1f); //Apply light attenuation (plus offset to prevent sky turning black)
}
}
// GLITCH EFFECT -- TO DO
float lua_param_glitch_power = fmod(shader_param_8.z,1.0f);
if (lua_param_glitch_power > 0.0f)
{
image = lerp(image, glitchEffect(image, I.tc0, lua_param_glitch_power),0.9);
}
// APPLY BLOOM / WASHOUT
float addon = bokeh_pass_3( (eighth_res_bloom.g + quarter_res_bloom.g),I.tc0);
float addon_hard = max(addon - 0.7,0.0) * 2.0f;
float addon_soft = (max(half_res_blur.g - 0.6,0.0f) / 0.6) / 1.0f;
// addon = max(addon - 0.01,0) * 3;
image = image + (float3)addon_soft + (float3)addon_hard;
// image *= 3;
// APPLY CRT EFFECT
image = lerp(image,make_crt_ified(half_res_blur, I.tc0),gen_1_crt_effect_factor); // Adds a CRT effect that I think looks better than draw_scanlines
// APPLY NOISE
float lua_param_nvg_gain_current = floor(shader_param_8.y) / 10.0f;
image.r += jitter.y * (gen_1_nvg_noise_factor * (pow(lua_param_nvg_gain_current,0.5) )); // Add the noise to the image
// APPLY SCINTILLATION EFFECT
if (jitter.z > (gen_1_scintillation_constant - ( (1.0-gen_1_scintillation_constant) * (lua_param_nvg_gain_current - 1.0f) ) ) )
{ image.r = 1.0f; }
// APPLY IMAGE COLOR CORRECTION AND MAKE BRIGHT SPOTS WHITE
image.rgb = saturate(image.r) * gen_1_saturation_color;
if (image.g >= 0.95)
{
image.rgb = pow(image.ggg,2);
}
// APPLY VIGNETTE
float lua_param_vignette_current = floor(shader_param_8.z) / 100.0f;
float vignette = calc_vignette(lua_param_nvg_num_tubes, I.tc0, lua_param_vignette_current);
image = clamp(image,0.0,1.0);
image *= vignette;
// RETURN THE RESULTING IMAGE
return float4(image, 1.0);
}
///////////////////////////////////////////////////////
// OUTSIDE NVG CIRCLES OF EFFECT - If the absolute distance from screen center is farther than circle_radius, then we'll run the other shader effects below
///////////////////////////////////////////////////////
else
{
float lua_param_nvg_mode = frac(shader_param_8.w) * 10;
if (abs(lua_param_nvg_mode-0.0) <= 0.01) // mode 0 - blur
{
image = half_res_blur;
image = clamp(image,0.0,1.0);
}
else if (abs(lua_param_nvg_mode-1.0) <= 0.01) // mode 1 - black
{
image = float3(0.0,0.0,0.0);
}
else if (abs(lua_param_nvg_mode-2.0) <= 0.01) // mode 2 - image overlay
{
image = clamp(image,0.0,1.0);
}
else if (abs(lua_param_nvg_mode-3.0) <= 0.01) // mode 3 - no changes (clear vision)
{
image = clamp(image,0.0,1.0);
}
// RETURN THE RESULTING IMAGE
return float4(image, 1.0);
}
}
@@ -0,0 +1,161 @@
///////////////////////////////////////////////////////
// BEEF'S SHADER BASED NIGHT VISION EFFECT //
///////////////////////////////////////////////////////
// Huge credit TO LVutner from Anomaly Discord, who //
// literally taught me everything I know, to Sky4Ace //
// who's simple_blur function I've adapted for this //
// shader, and to Meltac, who provided some advice //
// and inspiration for developing this shader. //
///////////////////////////////////////////////////////
// Note: You are free to distribute and adapt this //
// Shader and any components, just please provide //
// credit to myself and/or the above individuals. I //
// have provided credit for individual functions and //
// their original authors where applicable. - BEEF //
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
// STEP 0 - GLOBAL DEFINITIONS AND INCLUDES
///////////////////////////////////////////////////////
#include "night_vision.h"
#include "common.h"
float3 bokeh_pass_3 (float image, float2 tc)
{
float Pi = 6.28318530718; float blur_directions = 8.0; float blur_quality = 4.0; float blur_radius = 5; float3 color = 0.0f; float3 color_average = 0.0f;
float light_avgs = 0.0f; float weight = 0.0f; float total_weight = 0.0f;
for(float i=1.0; i<=blur_quality; i++) { for( float d=0.0; d<Pi; d+=Pi/blur_directions) {
color = s_blur_8.SampleLevel(smp_rtlinear, tc + (float2(cos(d),sin(d))*blur_radius*i/screen_res.xy),0).rgb;
color += s_blur_4.SampleLevel(smp_rtlinear, tc + (float2(cos(d),sin(d))*blur_radius*i/screen_res.xy),0).rgb;
if (color.g > 0.0f) { color.g *= 1.0f; light_avgs += 1.0f;} else {light_avgs += 0.5;} color_average += color; } } image = color_average.g / light_avgs;
return image;
}
float4 main(p_screen I) : SV_Target
{
///////////////////////////////////////////////////////
// STEP 0 - LOCAL DEFINITIONS
///////////////////////////////////////////////////////
// TC vars
float2 corrected_texturecoords = aspect_ratio_correction(I.tc0);
///////////////////////////////////////////////////////
// STEP 0 - MAIN SAMPLES
///////////////////////////////////////////////////////
float3 image = s_image.Sample(smp_rtlinear, I.tc0).xyz;
///////////////////////////////////////////////////////
// STEP 0 - MAIN FUNCTION
///////////////////////////////////////////////////////
float3 half_res_blur = s_blur_2.Sample(smp_rtlinear, I.tc0).rgb;
float lua_param_nvg_num_tubes = frac(shader_param_8.x) * 10.0f;
if (compute_lens_mask(corrected_texturecoords, lua_param_nvg_num_tubes) == 1) // see if we're inside the lens mask
{
// GRAB SAMPLES FOR NVG SHADER
float3 eighth_res_bloom = s_blur_8.Sample(smp_rtlinear, I.tc0).rgb;
float3 quarter_res_bloom = s_blur_4.Sample(smp_rtlinear, I.tc0).rgb;
float4 jitter = float4(
frac(sin(dot(I.tc0, float2(12.0, 78.0) + (timers.x) )) * 12345.0),
frac(sin(dot(I.tc0-fmod(I.tc0,float2(3.0,3.0)/screen_res.xy), float2(12.0, 78.0) + (timers.x) )) * 22738.0),
frac(sin(dot(I.tc0-fmod(I.tc0,float2(3.0,3.0)/screen_res.xy), float2(12.0, 78.0) + (timers.x) )) * 78372.0),
frac(sin(dot(I.tc0, float2(12.0, 78.0) + (timers.x) )) * 37857.0));
//float depth = s_position.Load(int3(I.tc0 * screen_res.xy,0),0).z; // Sample the depth buffer in a better way
//float depth = pow(blurred_depth(I.tc0),2)*1000;
float depth = blurred_depth(I.tc0);
//image.r = lerp(half_res_blur.r,image.r,0.6f);
//image = pow(image,0.75);
image = lerp(image,half_res_blur,clamp(1-smoothstep(0,15,depth),0.4,1)); // NEAR BLUR
if (depth < 1000)
{
float light_att = pow(1.0f-(smoothstep(5,300,depth)),0.5); // Distance from full brightness to full black
if ((image.r+image.g) < 0.9f)
{
image.r *= (light_att+0.1f); //Apply light attenuation (plus offset to prevent sky turning black)
}
}
// GLITCH EFFECT -- TO DO
float lua_param_glitch_power = fmod(shader_param_8.z,1.0f);
if (lua_param_glitch_power > 0.0f)
{
image = lerp(image, glitchEffect(image, I.tc0, lua_param_glitch_power),0.9);
}
// APPLY BLOOM / WASHOUT
float addon = bokeh_pass_3( (eighth_res_bloom.g + quarter_res_bloom.g),I.tc0);
float addon_hard = max(addon - 0.7,0.0) * 2.0f;
float addon_soft = (max(half_res_blur.g - 0.6,0.0f) / 0.6) / 1.0f;
// addon = max(addon - 0.01,0) * 3;
image = image + (float3)addon_soft + (float3)addon_hard;
// image *= 3;
// APPLY CRT EFFECT
image = lerp(image,make_crt_ified(half_res_blur, I.tc0),gen_2_crt_effect_factor); // Adds a CRT effect that I think looks better than draw_scanlines
// APPLY NOISE
float lua_param_nvg_gain_current = floor(shader_param_8.y) / 10.0f;
image.r += jitter.y * (gen_2_nvg_noise_factor * (pow(lua_param_nvg_gain_current,0.5) )); // Add the noise to the image
// APPLY SCINTILLATION EFFECT
if (jitter.z > (gen_2_scintillation_constant - ( (1.0-gen_2_scintillation_constant) * (lua_param_nvg_gain_current - 1.0f) ) ) )
{ image.r = 1.0f; }
// APPLY IMAGE COLOR CORRECTION AND MAKE BRIGHT SPOTS WHITE
image.rgb = saturate(image.r) * gen_2_saturation_color;
if (image.g >= 0.95)
{
image.rgb = pow(image.ggg,2);
}
// APPLY VIGNETTE
float lua_param_vignette_current = floor(shader_param_8.z) / 100.0f;
float vignette = calc_vignette(lua_param_nvg_num_tubes, I.tc0, lua_param_vignette_current);
image = clamp(image,0.0,1.0);
image *= vignette;
// RETURN THE RESULTING IMAGE
return float4(image, 1.0);
}
///////////////////////////////////////////////////////
// OUTSIDE NVG CIRCLES OF EFFECT - If the absolute distance from screen center is farther than circle_radius, then we'll run the other shader effects below
///////////////////////////////////////////////////////
else
{
float lua_param_nvg_mode = frac(shader_param_8.w) * 10;
if (abs(lua_param_nvg_mode-0.0) <= 0.01) // mode 0 - blur
{
image = half_res_blur;
image = clamp(image,0.0,1.0);
}
else if (abs(lua_param_nvg_mode-1.0) <= 0.01) // mode 1 - black
{
image = float3(0.0,0.0,0.0);
}
else if (abs(lua_param_nvg_mode-2.0) <= 0.01) // mode 2 - image overlay
{
image = clamp(image,0.0,1.0);
}
else if (abs(lua_param_nvg_mode-3.0) <= 0.01) // mode 3 - no changes (clear vision)
{
image = clamp(image,0.0,1.0);
}
// RETURN THE RESULTING IMAGE
return float4(image, 1.0);
}
}
@@ -0,0 +1,161 @@
///////////////////////////////////////////////////////
// BEEF'S SHADER BASED NIGHT VISION EFFECT //
///////////////////////////////////////////////////////
// Huge credit TO LVutner from Anomaly Discord, who //
// literally taught me everything I know, to Sky4Ace //
// who's simple_blur function I've adapted for this //
// shader, and to Meltac, who provided some advice //
// and inspiration for developing this shader. //
///////////////////////////////////////////////////////
// Note: You are free to distribute and adapt this //
// Shader and any components, just please provide //
// credit to myself and/or the above individuals. I //
// have provided credit for individual functions and //
// their original authors where applicable. - BEEF //
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
// STEP 0 - GLOBAL DEFINITIONS AND INCLUDES
///////////////////////////////////////////////////////
#include "night_vision.h"
#include "common.h"
float3 bokeh_pass_3 (float image, float2 tc)
{
float Pi = 6.28318530718; float blur_directions = 8.0; float blur_quality = 4.0; float blur_radius = 5; float3 color = 0.0f; float3 color_average = 0.0f;
float light_avgs = 0.0f; float weight = 0.0f; float total_weight = 0.0f;
for(float i=1.0; i<=blur_quality; i++) { for( float d=0.0; d<Pi; d+=Pi/blur_directions) {
color = s_blur_8.SampleLevel(smp_rtlinear, tc + (float2(cos(d),sin(d))*blur_radius*i/screen_res.xy),0).rgb;
color += s_blur_4.SampleLevel(smp_rtlinear, tc + (float2(cos(d),sin(d))*blur_radius*i/screen_res.xy),0).rgb;
if (color.g > 0.0f) { color.g *= 1.0f; light_avgs += 1.0f;} else {light_avgs += 0.5;} color_average += color; } } image = color_average.g / light_avgs;
return image;
}
float4 main(p_screen I) : SV_Target
{
///////////////////////////////////////////////////////
// STEP 0 - LOCAL DEFINITIONS
///////////////////////////////////////////////////////
// TC vars
float2 corrected_texturecoords = aspect_ratio_correction(I.tc0);
///////////////////////////////////////////////////////
// STEP 0 - MAIN SAMPLES
///////////////////////////////////////////////////////
float3 image = s_image.Sample(smp_rtlinear, I.tc0).xyz;
///////////////////////////////////////////////////////
// STEP 0 - MAIN FUNCTION
///////////////////////////////////////////////////////
float3 half_res_blur = s_blur_2.Sample(smp_rtlinear, I.tc0).rgb;
float lua_param_nvg_num_tubes = frac(shader_param_8.x) * 10.0f;
if (compute_lens_mask(corrected_texturecoords, lua_param_nvg_num_tubes) == 1) // see if we're inside the lens mask
{
// GRAB SAMPLES FOR NVG SHADER
float3 eighth_res_bloom = s_blur_8.Sample(smp_rtlinear, I.tc0).rgb;
float3 quarter_res_bloom = s_blur_4.Sample(smp_rtlinear, I.tc0).rgb;
float4 jitter = float4(
frac(sin(dot(I.tc0, float2(12.0, 78.0) + (timers.x) )) * 12345.0),
frac(sin(dot(I.tc0-fmod(I.tc0,float2(3.0,3.0)/screen_res.xy), float2(12.0, 78.0) + (timers.x) )) * 22738.0),
frac(sin(dot(I.tc0-fmod(I.tc0,float2(3.0,3.0)/screen_res.xy), float2(12.0, 78.0) + (timers.x) )) * 78372.0),
frac(sin(dot(I.tc0, float2(12.0, 78.0) + (timers.x) )) * 37857.0));
//float depth = s_position.Load(int3(I.tc0 * screen_res.xy,0),0).z; // Sample the depth buffer in a better way
//float depth = pow(blurred_depth(I.tc0),2)*1000;
float depth = blurred_depth(I.tc0);
//image.r = lerp(half_res_blur.r,image.r,0.6f);
image = pow(image,0.85);
image = lerp(image,half_res_blur,clamp(1-smoothstep(0,15,depth),0.2,1)); // NEAR BLUR
if (depth < 1000)
{
float light_att = pow(1.0f-(smoothstep(5,300,depth)),0.5); // Distance from full brightness to full black
if ((image.r+image.g) < 0.9f)
{
image.r *= (light_att+0.1f); //Apply light attenuation (plus offset to prevent sky turning black)
}
}
// GLITCH EFFECT -- TO DO
float lua_param_glitch_power = fmod(shader_param_8.z,1.0f);
if (lua_param_glitch_power > 0.0f)
{
image = lerp(image, glitchEffect(image, I.tc0, lua_param_glitch_power),0.9);
}
// APPLY BLOOM / WASHOUT
float addon = bokeh_pass_3( (eighth_res_bloom.g + quarter_res_bloom.g),I.tc0);
float addon_hard = max(addon - 0.7,0.0) * 2.0f;
float addon_soft = (max(half_res_blur.g - 0.6,0.0f) / 0.6) / 1.0f;
// addon = max(addon - 0.01,0) * 3;
image = image + (float3)addon_soft + (float3)addon_hard;
// image *= 3;
// APPLY CRT EFFECT
image = lerp(image,make_crt_ified(half_res_blur, I.tc0),gen_3_crt_effect_factor); // Adds a CRT effect that I think looks better than draw_scanlines
// APPLY NOISE
float lua_param_nvg_gain_current = floor(shader_param_8.y) / 10.0f;
image.r += jitter.y * (gen_3_nvg_noise_factor * (pow(lua_param_nvg_gain_current,0.5) )); // Add the noise to the image
// APPLY SCINTILLATION EFFECT
if (jitter.z > (gen_3_scintillation_constant - ( (1.0-gen_3_scintillation_constant) * (lua_param_nvg_gain_current - 1.0f) ) ) )
{ image.r = 1.0f; }
// APPLY IMAGE COLOR CORRECTION AND MAKE BRIGHT SPOTS WHITE
image.rgb = saturate(image.r) * gen_3_saturation_color;
if (image.g >= 0.95)
{
image.rgb = pow(image.ggg,2);
}
// APPLY VIGNETTE
float lua_param_vignette_current = floor(shader_param_8.z) / 100.0f;
float vignette = calc_vignette(lua_param_nvg_num_tubes, I.tc0, lua_param_vignette_current);
image = clamp(image,0.0,1.0);
image *= vignette;
// RETURN THE RESULTING IMAGE
return float4(image, 1.0);
}
///////////////////////////////////////////////////////
// OUTSIDE NVG CIRCLES OF EFFECT - If the absolute distance from screen center is farther than circle_radius, then we'll run the other shader effects below
///////////////////////////////////////////////////////
else
{
float lua_param_nvg_mode = frac(shader_param_8.w) * 10;
if (abs(lua_param_nvg_mode-0.0) <= 0.01) // mode 0 - blur
{
image = half_res_blur;
image = clamp(image,0.0,1.0);
}
else if (abs(lua_param_nvg_mode-1.0) <= 0.01) // mode 1 - black
{
image = float3(0.0,0.0,0.0);
}
else if (abs(lua_param_nvg_mode-2.0) <= 0.01) // mode 2 - image overlay
{
image = clamp(image,0.0,1.0);
}
else if (abs(lua_param_nvg_mode-3.0) <= 0.01) // mode 3 - no changes (clear vision)
{
image = clamp(image,0.0,1.0);
}
// RETURN THE RESULTING IMAGE
return float4(image, 1.0);
}
}
@@ -0,0 +1,113 @@
#include "common.h"
#include "night_vision.h"
float4 blur_params;
float4 main(p_screen I) : SV_Target
{
// Defines
float3 image;
const float GAUSS_SIGMA = 2.5;
const int support = int(GAUSS_SIGMA * 1.5);
float lua_param_nvg_generation = floor(shader_param_8.x); // 1, 2, or 3
float lua_param_nvg_num_tubes = frac(shader_param_8.x) * 10.0f;
float lua_param_nvg_washout_thresh = frac(shader_param_8.y);
float lua_param_vignette_current = floor(shader_param_8.z) / 100.0f;
if (lua_param_nvg_generation > 0.0f && compute_lens_mask(aspect_ratio_correction(I.tc0), lua_param_nvg_num_tubes) == 1.0f) // if NVGs are enabled ...
{
// HALF RES BLUR - PASS 1 - R = LUMA, G = LIGHTMAP, B = NORMALIZED DEPTH OUT TO FARTHEST_DEPTH (defined in night_vision.h)
if (blur_params.x == 1 && blur_params.z == (screen_res.x / 2.0f))
{
image = float3(s_image.Sample(smp_rtlinear, I.tc0).rg,saturate(s_position.Load( int3( (I.tc0)*screen_res.xy, 0 ), 0 ).z / farthest_depth));
if (image.b == 0.0f) { image.b = 1.0f; } float scale = 0.05f; scale *= (IGN_calc(I.tc0/2.0*screen_res.xy)); float3 total = 0.0f; float divisor = 0.0f;
float total_depth = image.b; float divisor_depth = 1.0f; float r = 1.0f; float2x2 G = rot(2.399996); float2 offset = float2(scale,scale);
for (int i = 0; i < 16; ++i) {
r += 1.0f / r; offset = mul(offset, G); float3 color = s_image.SampleLevel(smp_rtlinear, I.tc0 + (offset * (r - 1.0f) * 1.0f/screen_res.xy),0).rgb;
color.b = saturate(s_position.Load( int3( (I.tc0*screen_res.xy) + (offset * (r - 1.0f)), 0 ), 0 ).z / (farthest_depth));
if (color.b == 0.0f) { color.b = 1.0f; } float weight = 1.0f; total.rg += color.rg * weight; divisor += weight; if (color.b <= image.b - 0.04)
{ total_depth += color.b; divisor_depth += weight; }
}
image = float3(max((total.rg / divisor),0),max((total_depth / divisor_depth),0));
float vignette = calc_vignette(lua_param_nvg_num_tubes, I.tc0, lua_param_vignette_current); image = clamp(image,0.0,1.0); image *= vignette;
return float4(image, 1.0f);
}
// HALF RES BLUR - PASS 2 - R = LUMA, G = LIGHTMAP, B = BLURRED DEPTH
else if (blur_params.x == 0 && blur_params.z == (screen_res.x / 2.0f)) // half-res fixed DOF blur pass 2
{
image = s_image.Sample(smp_rtlinear, I.tc0).rgb; float scale = 0.3f; float center_depth = image.b; scale *= (IGN_calc(I.tc0/2.0*screen_res.xy));
float3 total = 0.0f; float divisor = 0.0f; float r = 1.0f; float2x2 G = rot(2.399996); float2 offset = float2(scale,scale);
for (int i = 0; i < 24; ++i) { r += 1.0f / r; offset = mul(offset, G);
float falloff = saturate( ( 1.2f * center_depth ) - log(center_depth * 6.4f) - ( 0.4f * pow(center_depth, 2.3f) ) );
float3 color = s_image.SampleLevel(smp_rtlinear, I.tc0 + (offset * (falloff) * (r - 1.02f) * 1.0f/screen_res.xy),0).rgb;
float weight = 1.0f; total += color * weight; divisor += weight;
}
image = max((total.rgb / divisor),0);
float vignette = calc_vignette(lua_param_nvg_num_tubes, I.tc0, lua_param_vignette_current); image = clamp(image,0.0,1.0); image *= vignette;
return float4(image, 1.0f);
}
// QUARTER RES BLUR - PASS 1 - R = LUMA, G = LIGHTMAP, B = ALBEDO
else if (blur_params.x == 1 && blur_params.z == (screen_res.x / 4))
{
float general_threshold = 0.05f; float light_thresh = lua_param_nvg_washout_thresh; float Pi = 6.28318530718; float blur_directions = 12.0; float blur_quality = 6.0;
float blur_radius = 1.5; float3 color = 0.0f; float3 color_average = s_image.Sample(smp_rtlinear, I.tc0).rgb; float weight = 0.0f;
float light_avgs = 0.0f;
for(float i=1.0; i<= blur_quality; i++) { for( float d=0.0; d<Pi; d+=Pi/blur_directions) {
color = s_image.SampleLevel(smp_rtlinear, I.tc0 + (float2(cos(d),sin(d))*blur_radius*i/screen_res.xy),0).rgb; color.rb *= color.rb;
color.rb = saturate((color.rb - general_threshold) / (1.0f - general_threshold)); color.g = saturate((color.g - light_thresh) / (1.0f - light_thresh));
if (color.g > 0.0f) { color.g *= 8.0f; light_avgs += 1.0f;} else {light_avgs += 0.1 * i;}
color.rb = sqrt(color.rb); color_average += color; } }
image.rb = color_average.rb / (blur_directions*blur_quality); image.g = color_average.g / light_avgs;
return float4(image, 1.0f);
}
// QUARTER RES BLUR - PASS 2 - R = LUMA, G = LIGHTMAP, B = ALBEDO
else if (blur_params.x == 0 && blur_params.z == (screen_res.x / 4)) // quarter and eighth res circular bokeh pass 2
{
float Pi = 6.28318530718; float blur_directions = 16.0; float blur_quality = 4.0; float blur_radius = 4; float3 color = 0.0f;
float3 color_average = s_image.Sample(smp_rtlinear, I.tc0).rgb; float light_avgs = 0.0f; float weight = 0.0f; float total_weight = 0.0f;
for(float i=1.0; i<= blur_quality; i++) { for( float d=0.0; d<Pi; d+=Pi/blur_directions) {
color = s_image.SampleLevel(smp_rtlinear, I.tc0 + (float2(cos(d),sin(d))*blur_radius*i/screen_res.xy),0).rgb;
if (color.g > 0.0f) { color.g *= 4.0f; light_avgs += 1.0f;} else {light_avgs += 0.1 * i;} color_average += color; } }
image.rb = color_average.rb / (blur_directions*blur_quality); image.g = color_average.g / light_avgs;
return float4(image, 1.0f);
}
// EIGHTH RES BLUR - PASS 1 - R = LUMA, G = LIGHTMAP, B = ALBEDO
else if (blur_params.x == 1 && blur_params.z == (screen_res.x / 8)) // quarter and eighth res circular bokeh pass 1
{
float general_threshold = 0.05f; float light_thresh = lua_param_nvg_washout_thresh; float Pi = 6.28318530718; float blur_directions = 12.0; float blur_quality = 4.0;
float blur_radius = 1; float3 color = 0.0f; float3 color_average = s_image.Sample(smp_rtlinear, I.tc0).rgb; float weight = 0.0f; float total_weight = 0.0f;
float light_avgs = 0.0f;
for(float i=1.0; i<= blur_quality; i++) { for( float d=0.0; d<Pi; d+=Pi/blur_directions) {
color = s_image.SampleLevel(smp_rtlinear, I.tc0 + (float2(cos(d),sin(d))*blur_radius*i/screen_res.xy),0).rgb; color.rb *= color.rb;
color.rb = saturate((color.rb - general_threshold) / (1.0f - general_threshold)); color.g = saturate((color.g - light_thresh) / (1.0f - light_thresh));
if (color.g > 0.0f) { color.g *= 8.0f; light_avgs += 1.0f;} else {light_avgs += 0.1 * i;} color.rb = sqrt(color.rb); color_average += color; } }
image.rb = color_average.rb / (blur_directions*blur_quality); image.g = color_average.g / light_avgs;
return float4(image, 1.0f);
}
// EIGHTH RES BLUR - PASS 2 - R = LUMA, G = LIGHTMAP, B = ALBEDO
else if (blur_params.x == 0 && blur_params.z == (screen_res.x / 8)) // quarter and eighth res circular bokeh pass 2
{
float Pi = 6.28318530718; float blur_directions = 16.0; float blur_quality = 4.0; float blur_radius = 4; float3 color = 0.0f;
float3 color_average = s_image.Sample(smp_rtlinear, I.tc0).rgb; float light_avgs = 0.0f; float weight = 0.0f; float total_weight = 0.0f;
for(float i=1.0; i<= blur_quality; i++) { for( float d=0.0; d<Pi; d+=Pi/blur_directions) {
color = s_image.SampleLevel(smp_rtlinear, I.tc0 + (float2(cos(d),sin(d))*blur_radius*i/screen_res.xy),0).rgb;
if (color.g > 0.0f) { color.g *= 4.0f; light_avgs += 1.0f;} else {light_avgs += 0.1 * i;} color_average += color; } }
image.rb = color_average.rb / (blur_directions*blur_quality); image.g = color_average.g / light_avgs;
return float4(image, 1.0f);
}
}
// OTHERWISE, DO NORMAL BLUR
float scale = 0.3f; scale *= (IGN_calc(I.tc0/2.0*screen_res.xy)); float3 total = s_image.Sample(smp_rtlinear, I.tc0).rgb; float divisor = 1.0f;
float r = 0.9f; float2x2 G = rot(2.399996); float2 offset = float2(scale,scale);
for (int i = 0; i < 16; ++i) {r += 1.0f / r; offset = mul(offset, G);
float3 color = s_image.SampleLevel(smp_rtlinear, I.tc0 + (offset * (r - 1.0f) * 1.0f/screen_res.xy),0).rgb; float weight = 1.0f;
total += color * weight; divisor += weight; } image = max((total / divisor),0);
return float4(image, 1.0f);
}
@@ -0,0 +1,64 @@
#include "common.h"
#include "night_vision.h"
struct v2p
{
float4 factor : COLOR0; // for SM3 - factor.rgb - tonemap-prescaled
float3 tc0 : TEXCOORD0;
float3 tc1 : TEXCOORD1;
float4 sv : SV_Position;
};
struct _out
{
float4 low : SV_Target0;
float4 high : SV_Target1;
};
TextureCube s_sky0 :register(t0);
TextureCube s_sky1 :register(t1);
//////////////////////////////////////////////////////////////////////////////////////////
// Pixel
_out main( v2p I )
{
float3 s0 = s_sky0.Sample( smp_rtlinear, I.tc0 );
float3 s1 = s_sky1.Sample( smp_rtlinear, I.tc1 );
float3 sky = lerp (s0,s1,I.factor.w);
sky *= I.factor.rgb;
// final tone-mapping
_out o;
tonemap(o.low, o.high, sky, 1 ) ; //factor contains tonemapping
float2 texturecoord = I.sv.xy / screen_res.xy;
float2 texturecoord_2 = I.sv.xy / screen_res.xy;
float lua_param_nvg_generation = floor(shader_param_8.x); // 1, 2, or 3
float lua_param_nvg_num_tubes = frac(shader_param_8.x) * 10.0f; // 1, 2, 4, 1.1, or 1.2
float lua_param_nvg_gain_current = floor(shader_param_8.y) / 10.0f;
float lua_param_vignette_current = floor(shader_param_8.z) / 100.0f;
if (lua_param_nvg_generation > 0 && ((compute_lens_mask(aspect_ratio_correction(texturecoord), lua_param_nvg_num_tubes) == 1.0f || compute_lens_mask(aspect_ratio_correction(texturecoord_2), lua_param_nvg_num_tubes) == 1.0f)))
{
o.low.r = dot(o.low.rgb * 5.0f, luma_conversion_coeff);
o.high.r = dot(o.high.rgb * 5.0f, luma_conversion_coeff);
o.low.gb = 0.0f;
o.high.gb = 0.0f;
o.low *= lua_param_nvg_gain_current * sky_brightness_factor;
o.high *= lua_param_nvg_gain_current * sky_brightness_factor;
o.high = clamp(o.high,0.0,1.0);
o.low= clamp(o.low,0.0,1.0);
float vignette = calc_vignette(lua_param_nvg_num_tubes, texturecoord, lua_param_vignette_current);
float vignette_2 = calc_vignette(lua_param_nvg_num_tubes, texturecoord_2, lua_param_vignette_current);
o.low *= (vignette * vignette_2);
o.high *= (vignette * vignette_2);
}
return o;
}