Eye Adaption

  • Posts: 262
2 years 2 months ago - 1 year 4 weeks ago #1 by brussell
Description:
This shader lightens or darkens the image depending on the average screen brightness, thus mimicking exposure adaption from cameras/eyes (hence the name).

Example Video

This shader is part of the offical reshade shaders repository.
For the latest updates visit my repository github.com/brussell1/Shaders

Changelog:
Warning: Spoiler! [ Click to expand ]
The following user(s) said Thank You: Marty McFly, Insomnia, Martigen, DeMondo, luluco250, Qsimil, andrew, MakeNX, Ryukou36, GP-Unity and 7 other people also said thanks.

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

  • Posts: 1221
2 years 2 months ago #2 by Marty McFly
Interesting. To simulate adaptation before tonemapping (instead of untonemapping and retonemapping, try to protect white tones by reducing the darkening for those pixels. That'll retain most of the image fidelity.
The following user(s) said Thank You: brussell

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

  • Posts: 201
2 years 2 months ago #3 by kaicooper
wow thats somthing..perfect

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

  • Posts: 262
2 years 2 months ago #4 by brussell
Changelog 30.01.2018:
-added parameters for black and white protection
-fixed dynamic adaption calculations
-adaption speed now (almost) fps independent
-some code optimisations
The following user(s) said Thank You: Qsimil

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

  • Posts: 142
2 years 2 months ago #5 by Insomnia
I have to say I really, really like this shader. :) Thanks for sharing!

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

  • Posts: 262
2 years 2 months ago #6 by brussell
Changelog 08.02.2018:
-simplified adaption calculation
-added saturation parameters

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

  • Posts: 433
2 years 1 month ago - 2 years 1 month ago #7 by Martigen

brussell wrote: Changelog 08.02.2018:
-simplified adaption calculation
-added saturation parameters

Thank you brussel. Just one suggestion: please stop adding a default key and setting it enabled, this screws up profiles, and perhaps call it something more informative :) So for eg:
technique LightAdaptionRussel

Thanks :)

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

  • Posts: 56
2 years 1 month ago #8 by Rudy102
Thanks a lot. It's a really useful shader. One question, any chances for version with UI ?

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

  • Posts: 262
2 years 1 month ago #9 by brussell

Rudy102 wrote: Thanks a lot. It's a really useful shader. One question, any chances for version with UI ?

Yes. Soon. :)

btw:
Changelog 14.02.2018:
-simpler, more efficient code, less parameters
-better saturation calculation
-toggable brightening and darkening
The following user(s) said Thank You: Rudy102

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

  • Posts: 56
2 years 1 month ago #10 by Rudy102
What a nice update, thank you kindly :)

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

  • Posts: 262
2 years 1 month ago - 2 years 1 month ago #11 by brussell
I've added the GUI-version to the initial post. I will also try to add it to the official shader repository soon.
The following user(s) said Thank You: GP-Unity

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

  • Posts: 85
2 years 1 month ago #12 by moriz1
one quick thing:

your luma averaging function isn't actually giving you an average - it is merely reporting the last luma value that the shader happens to sample. every time you reload the shader, it will give you a different luma value, even if the scene does not change in any way.

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

  • Posts: 3671
2 years 1 month ago #13 by crosire
Nope. It's correct. It works by using ReShade's mipmap generation to do the averaging and then simply samples the result from the lowest mipmap.
The following user(s) said Thank You: brussell

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

  • Posts: 85
2 years 1 month ago - 2 years 1 month ago #14 by moriz1
if that's the case, shouldn't the calculated luma value be the same every time you hit reload? with my test scene (which is a completely static scene), this luma value fluctuates every time i reload.

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

  • Posts: 262
2 years 1 month ago #15 by brussell
I can't reproduce this behavior. And even if the first frame after a reload somehow has a luma of 0 or 1, it should settle after a few seconds (depending on AdaptionSpeed).

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

  • Posts: 85
2 years 1 month ago - 2 years 1 month ago #16 by moriz1
my mistake. apparently i didn't set the mipmap level correctly (i was trying out the sampling algorithm in a different shader), so it must be sampling that isn't actually a 1x1 texture.

i did however, notice that the luma value changes if i alt-tab in and out of the game window. doing this will cause the calculated luma to rise by about 0.05 in my test scene. not sure what that was about.

btw, this is the code i'm using to display the luma on screen:
float res = -0.1;

int line0[14] = { __L, __u, __m, __a, __Space, __C, __u, __r, __r, __e, __n, __t, __Colon, __Space };	//Luma Current: %d

DrawText_String(float2(100.0, 132.0), 32, 1, texcoord, line0, 14, res);
DrawText_Digit(DrawText_Shift(float2(100.0, 132.0), int2(14, 0), 32, 1), 32, 1, texcoord, 3, avglum, res);
if ( res != -0.1)
	return res;

you need to include "DrawText.fxh" for this to work. this code snippet will print "Luma Current: ####" on the top left corner of the screen.

EDIT: is it a good idea to use gamma correction? i've been using:
float CalcLuma(float3 color) {
	if (GammaCorrectionEnable) {
    	return pow((color.r*2 + color.b + color.g*3) / 6, 1/2.2);
	}
	
	return (color.r*2 + color.b + color.g*3) / 6;
}

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

  • Posts: 262
2 years 1 month ago - 2 years 1 month ago #17 by brussell

moriz1 wrote: i did however, notice that the luma value changes if i alt-tab in and out of the game window. doing this will cause the calculated luma to rise by about 0.05 in my test scene. not sure what that was about.

btw, this is the code i'm using to display the luma on screen:

float res = -0.1;

int line0[14] = { __L, __u, __m, __a, __Space, __C, __u, __r, __r, __e, __n, __t, __Colon, __Space };	//Luma Current: %d

DrawText_String(float2(100.0, 132.0), 32, 1, texcoord, line0, 14, res);
DrawText_Digit(DrawText_Shift(float2(100.0, 132.0), int2(14, 0), 32, 1), 32, 1, texcoord, 3, avglum, res);
if ( res != -0.1)
	return res;

you need to include "DrawText.fxh" for this to work. this code snippet will print "Luma Current: ####" on the top left corner of the screen.


There seems to be a bug(?) in the DrawTextDigit function. Even if you choose a fixed value like this
DrawText_Digit(DrawText_Shift(float2(100.0, 132.0), int2(14, 0), 32, 1), 32, 1, texcoord, 3, 1, res);
,something like 1.09 gets displayed.

EDIT: is it a good idea to use gamma correction? i've been using:

float CalcLuma(float3 color) {
	if (GammaCorrectionEnable) {
    	return pow((color.r*2 + color.b + color.g*3) / 6, 1/2.2);
	}
	
	return (color.r*2 + color.b + color.g*3) / 6;
}


No, not necessary.

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

  • Posts: 15
1 year 10 months ago #18 by PureEvilWindom
can this effect combined with vignette ? so if you face bright light you simulate human eyes that half closed to reduce light.

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

  • Posts: 262
1 year 10 months ago #19 by brussell

PureEvilWindom wrote: can this effect combined with vignette ? so if you face bright light you simulate human eyes that half closed to reduce light.


Sure. How about that: i.imgur.com/fJsqNji.gifv
I've also tried to mimic some glare-through-eye lids-effect recently: i.imgur.com/ROF4BEW.gifv
If there's more resonance I will add it.
The following user(s) said Thank You: PureEvilWindom, Meddy

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

  • Posts: 123
1 year 10 months ago #20 by Chavolatra
OMG, it is vey nice =)

post this fast

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