1
Fork 0

MariENB FO4 3.0.5a

This commit is contained in:
Marisa the Magician 2019-04-07 17:47:39 +02:00
commit 0ac5ca02ac
7 changed files with 132 additions and 120 deletions

View file

@ -1,13 +1,23 @@
/* This shader intentionally left unchanged */
/*
enbadaptation.fx : MariENB3 eye adaptation shader.
(C)2016 Marisa Kirisame, UnSX Team.
Part of MariENB3, the personal ENB of Marisa for Fallout 4.
Released under the GNU GPLv3 (or later).
*/
#include "menbglobaldefs.fx"
float4 AdaptationParameters;
Texture2D TextureCurrent;
Texture2D TexturePrevious;
SamplerState Sampler0
{
Filter = MIN_MAG_MIP_POINT;
Filter = MIN_MAG_MIP_LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
struct VS_INPUT_POST
{
float3 pos : POSITION;
@ -18,86 +28,65 @@ struct VS_OUTPUT_POST
float4 pos : SV_POSITION;
float2 txcoord0 : TEXCOORD0;
};
VS_OUTPUT_POST VS_Quad(VS_INPUT_POST IN,
uniform float sizeX, uniform float sizeY)
VS_OUTPUT_POST VS_Quad( VS_INPUT_POST IN )
{
VS_OUTPUT_POST OUT;
float4 pos;
pos.xyz = IN.pos.xyz;
pos.w = 1.0;
OUT.pos = pos;
float2 offset;
offset.x = sizeX;
offset.y = sizeY;
OUT.txcoord0.xy = IN.txcoord.xy+offset.xy;
OUT.pos = float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
OUT.txcoord0.xy = IN.txcoord.xy;
return OUT;
}
float4 PS_Downsample(VS_OUTPUT_POST IN, float4 v0 : SV_Position0) : SV_Target
/* helper functions */
/* photometric */
#define luminance(x) dot(x,float3(0.2126,0.7152,0.0722))
/* CCIR601 */
//#define luminance(x) dot(x,float3(0.299,0.587,0.114))
float4 PS_Downsample( VS_OUTPUT_POST IN, float4 v0 : SV_Position0 ) : SV_Target
{
float4 res;
float2 pos, coord;
float4 curr = 0.0, currmax = 0.0;
const float scale = 1.0/16.0, step = 1.0/16.0, halfstep = 0.5/16.0;
pos.x = -0.5+halfstep;
for (int x=0; x<16; x++)
{
pos.y = -0.5+halfstep;
for (int y=0; y<16; y++)
{
coord = pos.xy*scale;
float4 tempcurr = TextureCurrent.Sample(Sampler0,
IN.txcoord0.xy+coord.xy);
currmax = max(currmax,tempcurr);
curr += tempcurr;
pos.y += step;
}
pos.x += step;
}
curr /= 256.0;
res = curr;
res = max(res.x,max(res.y,res.z));
float2 coord = IN.txcoord0.xy;
float ssz = 1.0/16.0;
float4 res = float4(0,0,0,0);
int x, y;
[unroll] for ( y=-8; y<8; y++ ) [unroll] for ( x=-8; x<8; x++ )
res += TextureCurrent.Sample(Sampler0,coord+float2(x,y)*ssz);
res /= 256.0;
res = luminance(res.rgb);
res.w = 1.0;
return res;
}
float4 PS_Adaptation(VS_OUTPUT_POST IN, float4 v0 : SV_Position0) : SV_Target
{
float4 res;
float prev = TexturePrevious.Sample(Sampler0,IN.txcoord0.xy).x;
float2 pos;
float curr = 0.0, currmax = 0.0;
const float step = 1.0/16.0, halfstep = 0.5/16.0;
pos.x = halfstep;
for (int x=0; x<16; x++)
float2 coord = IN.txcoord0.xy;
float prev = TexturePrevious.Sample(Sampler0,coord).x;
float ssz = 1.0/16.0;
float4 res = float4(0,0,0,0);
float smpmax = 0.0, smp;
int x, y;
[unroll] for ( y=-8; y<8; y++ ) [unroll] for ( x=-8; x<8; x++ )
{
pos.y = halfstep;
for (int y=0; y<16; y++)
{
float tempcurr = TextureCurrent.Sample(Sampler0,
IN.txcoord0.xy+pos.xy).x;
currmax = max(currmax,tempcurr);
curr += tempcurr;
pos.y += step;
}
pos.x += step;
smp = TextureCurrent.Sample(Sampler0,coord+float2(x,y)*ssz).x;
smpmax = max(smpmax,smp);
res += smp;
}
curr /= 256.0;
curr = lerp(curr,currmax,AdaptationParameters.z);
res = lerp(prev,curr,AdaptationParameters.w);
res = max(res,0.001);
res = min(res,16384.0);
float valmax, valcut;
valmax = max(res.x,max(res.y,res.z));
valcut = max(valmax,AdaptationParameters.x);
valcut = min(valcut,AdaptationParameters.y);
res *= valcut/(valmax+0.000000001);
res /= 256.0;
res = lerp(res,smpmax,AdaptationParameters.z);
res = lerp(prev,res,AdaptationParameters.w);
res = clamp(res,0.0,16384.0);
float vclip = clamp(res.x,AdaptationParameters.x,
AdaptationParameters.y);
res *= vclip/(res+0.000000001);
res.w = 1.0;
return res;
}
technique11 Downsample
{
pass p0
{
SetVertexShader(CompileShader(vs_5_0,VS_Quad(0.0,0.0)));
SetVertexShader(CompileShader(vs_5_0,VS_Quad()));
SetPixelShader(CompileShader(ps_5_0,PS_Downsample()));
}
}
@ -105,7 +94,7 @@ technique11 Draw
{
pass p0
{
SetVertexShader(CompileShader(vs_5_0,VS_Quad(0.0,0.0)));
SetVertexShader(CompileShader(vs_5_0,VS_Quad()));
SetPixelShader(CompileShader(ps_5_0,PS_Adaptation()));
}
}