Shader Programming Discussion
- NoMansReshade
- Topic Author
THIS IS NOT A REQUEST THREAD!!!!!
Enjoy!
Please Log in or Create an account to join the conversation.
- NoMansReshade
- Topic Author
For example:
float3 ACESFilm( float3 x )
{
float a = 0.98f; //Slope
float b = 0.3f; // Toe
float c = 0.22f; // Shoulder
float d = 0.0f; // Black Clip
float e = 0.025f; // White Clip
return saturate((x * (a * x + b)) / (x * (c * x + d) + e));
}
This is the base code for the "ACE Filmic Tonemapping" algorithm. Then you compare that to something like "Hable Tonemapping" and you realize it looks very similar.
float hA = 0.15;
float hB = 0.50;
float hC = 0.10;
float hD = 0.20;
float hE = 0.02;
float hF = 0.30;
return ((x*(hA*x+hC*hB)+hD*hE) / (x*(hA*x+hB)+hD*hF)) - hE/hF;
And this is interesting because of how different they look...
Case and point...
The reason I even bring this up is because I wonder about different tonemapping algorithms, and how they function. I know that there is only so much you can do with a couple of pixels and some color ranges, but still.
There seems to be a big craze recently on these forums from not only me, but other members as well, about "Reverse Tonemapping"... Well this is exactly what I wanted to talk about briefly: "Reverse" or "Inverse" tonemapping is the simple idea of reversing the effects of a game's tonemapping algorithm, effectively giving you access to colors that weren't there... However, if any of you understand how "HDR" works, you'll know that "Inverse" tonemapping is far from magical, and can't bring back color accuracy. Because what ends up happening in practically every game on the planet, is that the game's output color depth is limited to 8-bit. Some games go above that, but this very rarely happens. Because of this, we're stuck with what's known as "Color Banding", aka this shit:
Yeah... not pretty to look at. Anyways, to sum up a long post; Tonemapping is cool, inverse tonemapping is intriguing. I'm far from a professional shader programmer, but from what I've learned thus far, it's an art form. An art form disregarded by most.
Please Log in or Create an account to join the conversation.
- NoMansReshade
- Topic Author
This screenshot is from the game "Portal 2"
VS ACES Filmic Tonemapping:
Very pretty... but it can get buggy very easily
Here is the code (Used for magic bloom):
float3 i_Uncharted2Tonemap(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float3 x = blur(ReShade::BackBuffer, texcoord, 2.0 * fBloom_Radius);
float A = 0.15f * fBloom_Threshold;
float B = 0.50f * fBloom_Threshold;
float C = 0.10f * fBloom_Threshold;
float D = 0.20f * fBloom_Threshold;
float E = 0.02f + fBloom_Threshold;
float F = 0.30f * fBloom_Threshold;
return saturate((x/(A/x-C/B)-D/E) / pow(x/(A/x-B)-D/F+E*F, 0.001));
}
Hable seems to be more accurate color wise. But I will continue to do some more testing.
Edit:
Okay, Hable is like 50000x better than ACES in terms of inverse tonemapping...
I'm in bloom heaven
Please Log in or Create an account to join the conversation.
- MaxG3D
2. Could you please make a super dumbed down tutorial on how to achieve that?
3. Is it possible to use it for other effects than bloom, like DOF or Motion Blur?
Please Log in or Create an account to join the conversation.
- Marty McFly
Please Log in or Create an account to join the conversation.
- NoMansReshade
- Topic Author
@Marty Thanks for the heads up! As soon as I figure out how to use WolframAlpha, I should be good to go Until then, I'll take your other suggestions into account, thanks!
Please Log in or Create an account to join the conversation.
- MaxG3D
float3 i_Uncharted2Tonemap(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float3 x = blur(ReShade::BackBuffer, texcoord, 2.0 * fBloom_Radius);
float A = 0.30;
float B = 0.50;
float C = 0.10;
float D = 0.10;
float E = fBloom_Radius
float F = 0.30;
float W = 5.60;
float4 res = float4(i_Uncharted2Tonemap.rgb, W);
return (saturate ((x/(A/x-C/B)-D/E) / pow(x/(A/x-B)-D/F+E*F, 0.001))*res.w);
}
Please Log in or Create an account to join the conversation.
- Marty McFly
Also, as the exact tonemapper is almost never known and we want a generic solution (it's ReShade after all), you can take any tonemapper. A simple pow(color, contrast) before the inversed tonemap is enough to control how strongly the inversed tonemapper boosts colors.
Please Log in or Create an account to join the conversation.
- MaxG3D
Please Log in or Create an account to join the conversation.
- NoMansReshade
- Topic Author
Please Log in or Create an account to join the conversation.
- Marty McFly
MaxG3D wrote: You must have missed the link from the previous post, for some reason this forums doesn't highlight links at all. I simply copied the code from Enbeffect Kingeric explenation, and replaced it with ReShade counterparts.
But you did it the wrong way, man
@NoMansReShade: well, as long as you only do it on bloom, it doesn't really matter. I do tonemap(inv(color)+bloom) so if there's no bloom, the original color must be there. Otherwise you mess up the colors.
Please Log in or Create an account to join the conversation.
- NoMansReshade
- Topic Author
The chapter that came to my attention was "27.2 Extracting Object Positions from the Depth Buffer"
I remember suggesting in a thread that the depth buffer could possibly be used to "Fake" motion vectors.
My question is: Could this be translated to Reshade? And if so, how hard would it be to achieve?
It seems pretty self explanatory from looking at the examples they gave... So there must be something
I'm missing.
Please Log in or Create an account to join the conversation.
- Marty McFly
Well, that's just how it works, reconstructing world position from image goes per depth buffer, texcoord and projection matrices. That's the standard way to do that in pixel shaders (I don't even know of any other one), it's no secret trick. I did that in GTASA to draw water surface (height map tracing) in ENB. Given the above projection matrices. With ReShade, all I can do is reconstruct the positions of objects relative to camera, by faking FoV value. But this has no object memory, so a shader cannot identify and track objects over several frames.
Please Log in or Create an account to join the conversation.
- luluco250
Is it possible to add a texture to another without running into the "no read/write on the same texture" issue? (can't use backbuffer in this case)
For example, I'm building a shader for combining various HDR effects (using inverse tonemapping), so we can have HDR bloom, DoF etc.
Because of the I/O limitation, I have to use two HDR textures, but I was wondering if I could use pass blending to, for example, blend the bloom textures with one of the HDR textures WITHOUT having to write to another one (aka avoiding ping-pong).
This is to allow all effects to be pilled up together in order to have correct adaptation and tonemap in the end.
Please Log in or Create an account to join the conversation.
- Marty McFly
Please Log in or Create an account to join the conversation.
- luluco250
Setting SrcBlend to ZERO did make the image black though.
BlendEnable = true;
BlendOp = ADD;
SrcBlend = ONE;
DestBlend = ONE;
Please Log in or Create an account to join the conversation.
- Marty McFly
AlphaBlendEnable = true;
SrcBlend = One;
DestBlend = One;
Assuming AlphaBlendEnable (HLSL) and BlendEnable (ReShade FX) are the same thing, maybe all you need to do is removing BlendOp.
Please Log in or Create an account to join the conversation.
- crosire
Please Log in or Create an account to join the conversation.
- MaxG3D
Hey, is there any follow up on the HDR bloom research that you've showed off? That stuff looks pretty amazing
Please Log in or Create an account to join the conversation.