Triangular Dither
- TreyM
- Topic Author
Less
More
This is a simple port of The Sandvich Maker's Triangular Dither that he wrote for ENB. It's normally used on HDR input, but it can still be useful on LDR content and I find it superior to any other dither shader I've ever used. (original link:
Triangular Dither for ENB
)
Ported and released with permission. There are no UI variables. Just turn it on or off.
The code:
Crosire, I'm submitting a pull request if you'd like to add this one.
Ported and released with permission. There are no UI variables. Just turn it on or off.
The code:
Warning: Spoiler!
////////////////////////////////////////////////////////////
// Triangular Dither //
// By The Sandvich Maker //
// Ported to ReShade by TreyM //
////////////////////////////////////////////////////////////
#include "ReShade.fxh"
uniform float Timer < source = "timer"; >;
#define remap(v, a, b) (((v) - (a)) / ((b) - (a)))
// FUNCTIONS /////////////////////////////////////
float rand21(float2 uv)
{
float2 noise = frac(sin(dot(uv, float2(12.9898, 78.233) * 2.0)) * 43758.5453);
return (noise.x + noise.y) * 0.5;
}
float rand11(float x) { return frac(x * 0.024390243); }
float permute(float x) { return ((34.0 * x + 1.0) * x) % 289.0; }
float3 triDither(float3 color, float2 uv, float timer)
{
static const float bitstep = pow(2.0, 8) - 1.0;
static const float lsb = 1.0 / bitstep;
static const float lobit = 0.5 / bitstep;
static const float hibit = (bitstep - 0.5) / bitstep;
float3 m = float3(uv, rand21(uv + timer)) + 1.0;
float h = permute(permute(permute(m.x) + m.y) + m.z);
float3 noise1, noise2;
noise1.x = rand11(h); h = permute(h);
noise2.x = rand11(h); h = permute(h);
noise1.y = rand11(h); h = permute(h);
noise2.y = rand11(h); h = permute(h);
noise1.z = rand11(h); h = permute(h);
noise2.z = rand11(h);
float3 lo = saturate(remap(color.xyz, 0.0, lobit));
float3 hi = saturate(remap(color.xyz, 1.0, hibit));
float3 uni = noise1 - 0.5;
float3 tri = noise1 - noise2;
return lerp(uni, tri, min(lo, hi)) * lsb;
}
// SHADER ////////////////////////////////////////
float3 PS_TriDither(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float3 color = tex2D(ReShade::BackBuffer, texcoord).rgb;
// Blend
color.rgb += triDither(color.rgb, texcoord, Timer.x);
// Output
return color;
}
// TECHNIQUE /////////////////////////////////////
technique TriDither
{
pass
{
VertexShader = PostProcessVS;
PixelShader = PS_TriDither;
}
}
Crosire, I'm submitting a pull request if you'd like to add this one.
Last edit: 5 years 3 months ago by TreyM.
The following user(s) said Thank You: Tom Yum 72, XIIICaesar, Sinclair, aaronth07, AssassinsDecree, Spellshade, altokitty
Please Log in or Create an account to join the conversation.
- TreyM
- Topic Author
Less
More
I accidentally uploaded the wrong code. It's fixed in the OP now.
Please Log in or Create an account to join the conversation.
- Chavolatra
Less
More
- TreyM
- Topic Author
Less
More
LOL what?
I'm not saying this to be mean or anything, but if you don't know what dithering is for, you probably don't need it. With that said, it can help with color banding in certain situations (less effective on LDR than HDR, but it can still help.)
I'm not saying this to be mean or anything, but if you don't know what dithering is for, you probably don't need it. With that said, it can help with color banding in certain situations (less effective on LDR than HDR, but it can still help.)
Last edit: 5 years 3 months ago by TreyM.
Please Log in or Create an account to join the conversation.
- XIIICaesar
Less
More
5 years 3 months ago - 5 years 3 months ago #5
by XIIICaesar
Replied by XIIICaesar on topic Triangular Dither
Hey TreyM. Love your ENBs. Excited about CFL II too. I tried this out on ReShade & its just a solid black screen when I enable it. No other shaders enabled. Using it on Elder Scrolls Online. Screen resolution is 2560x1440 if that helps any.
Last edit: 5 years 3 months ago by XIIICaesar.
Please Log in or Create an account to join the conversation.
- TreyM
- Topic Author
Less
More
Is ES:O DX9 or DX11?
Edit: Interesting... It works on OGL and DX9, but not DX11...
Edit 2: Fixed in OP
Edit: Interesting... It works on OGL and DX9, but not DX11...
Edit 2: Fixed in OP
Last edit: 5 years 3 months ago by TreyM.
Please Log in or Create an account to join the conversation.
- XIIICaesar
Less
More
Thats it. No black screen anymore. Although I still have banding coming through using Triangular Dither that I didn't with deband. Maybe I've just got a lot of banding Anyways thanks dude. I've got it at the bottom of my load order so it loads almost last.
Please Log in or Create an account to join the conversation.
- TreyM
- Topic Author
Less
More
Dither doesn't fix banding. It's meant to prevent it. Debanding is to remove banding lol.
You should be using dither BEFORE effects that cause banding, not after.
You should be using dither BEFORE effects that cause banding, not after.
The following user(s) said Thank You: jas01, XE007
Please Log in or Create an account to join the conversation.