Adding Luminance Consideration from SSAO.fx to Comic.fx (and other shaders)

1 year 1 month ago - 1 year 1 month ago #1 by sheno1346
Many shaders have the issue where they will show through bright transparency effects like sparks/electricity/explosions. Marty McFly's SSAO shader fixes this with a customizable "luminance consideration" setting that accounts for bright areas on the screen and doesn't display the shader there.

I was hoping someone could walk me through how to add this to Comic.fx as it has a similar issue, and that could also serve as baseline for possibly adding luminance consideration to other shaders that need it. I have a vague knowledge of reshade but have done ini mods for other games like Doom so I could pick it up pretty quick.


Here's an example of SSAO with luminance consideration OFF and ON:

Last edit: 1 year 1 month ago by sheno1346.

Please Log in or Create an account to join the conversation.

1 year 1 month ago - 1 year 1 month ago #2 by Daemonjax
It should be pretty straight forward.

I don't use comic and never plan to (otherwise I'd just post the finished code), but it'd go something like this for it to cut off if the lum value for the pixel is above a specific value (between 0 and 1):

1) create a uniform or #define for a float value (let's call it CUTOFF_LUM_VALUE).
2) calculate the lum_value of the current pixel: this formula is fine: (0.2126*RED + 0.7152*GREEN + 0.0722*BLUE)
3) find the line of code near the end of the shader that returns the new rgb color value and do the lum test there. If it's less than CUTOFF_LUM_VALUE then it just operates normally, otherwise it returns the original pixel color.

If you don't want it to simply cutoff, you can experiment with lerping the original and new pixel color based on the difference between lum_value and CUTOFF_LUM_VALUE (or a function that takes both as an argument and does something a little more complicated).

In the end it'll just be like 5 lines of code added total (unless you want to do some complicated calculation based on lum_value and CUTOFF_LUM_VALUE). 

The above is the same for ANY shader, really (like ambient occlusion, debanding, antialiasing, whatever) -- and can be further generalized for adding anything new to any shader:

a) create a test
b) test it against current pixel
c) finally based on the result of that test either return the original color, the modified color, or a completely new color from an interpolation (lerp or whatever) between the original color and the modified color
Last edit: 1 year 1 month ago by Daemonjax.

Please Log in or Create an account to join the conversation.