How can i implement the Range Function from the Blur and Sharp effect?
Posted: 19 Mar 2024, 22:05
I want to implement the range function from the Blur and Sharp effects that are in enbpostpass to a Chromatic Abberation shader. I have made multiple tries but couldn't get it to work.
Chromatic Abberation Effect :
float3 PS_ChromaticAberration(VS_OUTPUT_POST IN, float4 vPos : SV_Position0) : SV_Target
{
float3 color, colorInput = TextureColor.Sample(Sampler0, IN.txcoord0.xy).rgb;
float2 pixeloffset = ScreenSize.y;
pixeloffset.y *= ScreenSize.z;
color.r = TextureColor.Sample(Sampler0, IN.txcoord0.xy + (pixeloffset * float2(ChromaticAberrationPositionX1, ChromaticAberrationPositionY1))).r;
color.g = colorInput.g;
color.b = TextureColor.Sample(Sampler0, IN.txcoord0.xy - (pixeloffset * float2(ChromaticAberrationPositionX1, ChromaticAberrationPositionY1))).b;
return lerp(colorInput, color, ChromaticAberrationIntensity1);
}
Blur Effect :
float4 PS_Blur(VS_OUTPUT_POST IN, float4 vPos : SV_Position0) : SV_Target
{
float4 res;
float4 color;
float4 centercolor;
float2 pixeloffset = ScreenSize.y;
pixeloffset.y *= ScreenSize.z;
centercolor = TextureColor.Sample(Sampler0, IN.txcoord0.xy);
color = 0.0;
float2 offsets[4]=
{
float2(-1.0,-1.0),
float2(-1.0, 1.0),
float2( 1.0,-1.0),
float2( 1.0, 1.0),
};
for (int i = 0; i < 4; i++)
{
float2 coord = offsets.xy * pixeloffset.xy * BlurRange1 + IN.txcoord0.xy;
color += TextureColor.Sample(Sampler1, coord.xy);
}
color.xyz += centercolor.xyz;
color *= 0.2;
res.xyz = lerp(centercolor.xyz, color, BlurIntensity1);
res.w = 1.0;
return res;
}
Chromatic Abberation Effect :
float3 PS_ChromaticAberration(VS_OUTPUT_POST IN, float4 vPos : SV_Position0) : SV_Target
{
float3 color, colorInput = TextureColor.Sample(Sampler0, IN.txcoord0.xy).rgb;
float2 pixeloffset = ScreenSize.y;
pixeloffset.y *= ScreenSize.z;
color.r = TextureColor.Sample(Sampler0, IN.txcoord0.xy + (pixeloffset * float2(ChromaticAberrationPositionX1, ChromaticAberrationPositionY1))).r;
color.g = colorInput.g;
color.b = TextureColor.Sample(Sampler0, IN.txcoord0.xy - (pixeloffset * float2(ChromaticAberrationPositionX1, ChromaticAberrationPositionY1))).b;
return lerp(colorInput, color, ChromaticAberrationIntensity1);
}
Blur Effect :
float4 PS_Blur(VS_OUTPUT_POST IN, float4 vPos : SV_Position0) : SV_Target
{
float4 res;
float4 color;
float4 centercolor;
float2 pixeloffset = ScreenSize.y;
pixeloffset.y *= ScreenSize.z;
centercolor = TextureColor.Sample(Sampler0, IN.txcoord0.xy);
color = 0.0;
float2 offsets[4]=
{
float2(-1.0,-1.0),
float2(-1.0, 1.0),
float2( 1.0,-1.0),
float2( 1.0, 1.0),
};
for (int i = 0; i < 4; i++)
{
float2 coord = offsets.xy * pixeloffset.xy * BlurRange1 + IN.txcoord0.xy;
color += TextureColor.Sample(Sampler1, coord.xy);
}
color.xyz += centercolor.xyz;
color *= 0.2;
res.xyz = lerp(centercolor.xyz, color, BlurIntensity1);
res.w = 1.0;
return res;
}