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

81 lines
2.2 KiB
PostScript
Raw Normal View History

#include "common.h"
//////////////////////////////////////////////////////////////////////////////////////////
float4 MiddleGray;
//////////////////////////////////////////////////////////////////////////////////////////
// perform 4x4 bilinear, 8x8p, the step (C)
// c): 8x8p => 1x1p with exp
// native bilinear
float sample( float2 tc )
{
float4 data = s_image.Sample( smp_rtlinear, tc );
return dot( data, 1.0/4.0 ); // sum components
}
float4 main ( p_filter I ) : SV_Target
{
float4 ratio = float2( 1/screen_res.x,1/screen_res.y).xyxy;
ratio.x = 1;
//ratio.y = 1.77;
//ratio.y = 0.5625;
ratio.y = screen_res.x/screen_res.y;
//ratio.xyzw = ratio.xyxy;
ratio.xyzw = ratio.xyyx;
float4 UVavg = (I.Tex0+I.Tex1+I.Tex2+I.Tex3+I.Tex4+I.Tex5+I.Tex6+I.Tex7)/8;
//adjust for aspect ratio
I.Tex0 = UVavg + ((I.Tex0 - UVavg) * ratio);
I.Tex1 = UVavg + ((I.Tex1 - UVavg) * ratio);
I.Tex2 = UVavg + ((I.Tex2 - UVavg) * ratio);
I.Tex3 = UVavg + ((I.Tex3 - UVavg) * ratio);
I.Tex4 = UVavg + ((I.Tex4 - UVavg) * ratio);
I.Tex5 = UVavg + ((I.Tex5 - UVavg) * ratio);
I.Tex6 = UVavg + ((I.Tex6 - UVavg) * ratio);
I.Tex7 = UVavg + ((I.Tex7 - UVavg) * ratio);
// sample
float4 accum0;
accum0.x = sample(I.Tex0);
accum0.y = sample(I.Tex1);
accum0.z = sample(I.Tex2);
accum0.w = sample(I.Tex3);
float4 accum1;
accum1.x = sample(I.Tex4);
accum1.y = sample(I.Tex5);
accum1.z = sample(I.Tex6);
accum1.w = sample(I.Tex7);
float4 accum2;
accum2.x = sample(I.Tex0.wz);
accum2.y = sample(I.Tex1.wz);
accum2.z = sample(I.Tex2.wz);
accum2.w = sample(I.Tex3.wz);
float4 accum3;
accum3.x = sample(I.Tex4.wz);
accum3.y = sample(I.Tex5.wz);
accum3.z = sample(I.Tex6.wz);
accum3.w = sample(I.Tex7.wz);
// perform accumulation
float4 final;
final.x = dot(accum0,1.0/4.0);
final.y = dot(accum1,1.0/4.0);
final.z = dot(accum2,1.0/4.0);
final.w = dot(accum3,1.0/4.0);
float result = dot(final, 1.0/4.0);
// OK
float scale = MiddleGray.x / (result*MiddleGray.y + MiddleGray.z); // final
float scale_prev = s_tonemap.Sample( smp_nofilter, I.Tex0 ).x;
float rvalue = lerp(scale_prev,scale,MiddleGray.w);
clamp(rvalue, 1.0/128.0, 20.0);
return rvalue;
}