Welcome, Guest.
Username: Password: Remember me

TOPIC: Eye Adaptation

Eye Adaptation 1 year 10 months ago #1

  • Deriest
  • Deriest's Avatar
  • Offline
  • Posts: 26
  • Thank you received: 12
Hello, I haven't had much time to test this on any games because I spend most of my time on a Mac but I was wondering if eye adaptation could be implemented into Reshade if it isn't already in it. As I said I haven't tried Reshade with any games yet so I can't know if it has eye adaptation implemented or not. I don't really know much about writing shaders but here is something that I was planning on trying the next time I get home to my pc.
float4  adaptPass (in float4 pos : SV_Position, in float2 texcoord : TEXCOORD0) : SV_Target
{
    float4  Lum             =   tex2D(samplerBloom4, 0.5);
            Lum.w           =   max(Lum.x, max(Lum.y, Lum.z));
            
    float4  Color           =   tex2D(samplerColor, texcoord);
            Color.w         =   max(Color.x, max(Color.y, Color.z));        
            
    float   adaptLum        =   Lum.w;
    float   adaptCol        =   Color.w;
    
    if  (adaptCol > adaptLum)
    {
        float   difference  =   adaptCol / adaptLum;
        float3  brightness  =   pow(color.xyz, difference);
    }
    
    if  (adaptCol < adaptLum)
    {
        float   difference  =   adaptLum / adaptCol;
        float3  brightness  =   color.xyz + difference;
    }
    
    //      color.xyz       =   lerp(color.xyz, brightness, timer);
            color.xyz       =   lerp(color.xyz, brightness, smoothstep(0, timeleft, timer));
            color.w         =   1.0;
return      color;
}

I want to learn this so if there is anything someone wants to point out to me, feel free to do so.
The administrator has disabled public write access.

Eye Adaptation 1 year 10 months ago #2

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2437
  • Thank you received: 1384
Looks good. I'd recommend you to start with MasterEffect as a base, because it is setup similar to ENB (so you have that samplerBloom4 sampler already created).
Cheers, crosire =)
The administrator has disabled public write access.

Eye Adaptation 1 year 10 months ago #3

  • Deriest
  • Deriest's Avatar
  • Offline
  • Posts: 26
  • Thank you received: 12
Thanks for the reply. I managed to get some testing done and it doesn't work very well. The changing in brightness happens correctly but it flickers always. I wanted to make it fade like normal eye adaptation but I think that has do do with the timer and I don't really understand how that works.
The administrator has disabled public write access.

Eye Adaptation 1 year 10 months ago #4

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2437
  • Thank you received: 1384
In that case you'll need access to previous frames, so to fade between them smoothly, which is not yet possible with ReShade. It's on the TODO list though =)
Cheers, crosire =)
The administrator has disabled public write access.

Eye Adaptation 1 year 10 months ago #5

  • Deriest
  • Deriest's Avatar
  • Offline
  • Posts: 26
  • Thank you received: 12
Cool thanks. So far I am really enjoying this. Keep up the good work. :cheer:
The administrator has disabled public write access.
The following user(s) said Thank You: crosire

Eye Adaptation 1 year 10 months ago #6

  • Deriest
  • Deriest's Avatar
  • Offline
  • Posts: 26
  • Thank you received: 12
I saw the thread about previous frame access and I have been trying to figure out how to make this eye adaptation thing happen. I render the previous frame to its own texture at the end of my technique but I am having difficulty figuring out how to get the fade working. I was hoping maybe someone could help explain to me the meaning of these timers.

Is frametime the number of milliseconds that have passed while compiling the current frame or the number of milliseconds it took for the previous frame?
Is timer counting total milliseconds since game started or since current frame started rendering?

Sorry for these questions if they are dumb but the extent of my programming knowledge is from mods like this which I have only been messing with for under a year.
The administrator has disabled public write access.

Eye Adaptation 1 year 10 months ago #7

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2437
  • Thank you received: 1384
There are (alrmost) no dumb questions =)
To answer yours, the following timers are currently available in ReShade:
  • date | Four component vector containing: year, month (1 - 12), day of month (1 - 32) and time in seconds since midnight
  • frametime | Time in milliseconds it took for the previous frame to complete (including post processing)
  • timer | Time in milliseconds since game start
  • timeleft | Time in milliseconds that is left until the current technique timeout is reached
You can watch the value of date, frametime and timer in the statistics overlay by the way. Simply add "#pragma reshade showstatistics" anywhere to your shader to enable it.
Cheers, crosire =)
Last Edit: 1 year 10 months ago by crosire.
The administrator has disabled public write access.
The following user(s) said Thank You: Deriest

Eye Adaptation 1 year 10 months ago #8

  • Deriest
  • Deriest's Avatar
  • Offline
  • Posts: 26
  • Thank you received: 12
Thanks for the reply and for clearing that up for me.
The administrator has disabled public write access.

Eye Adaptation 1 year 10 months ago #9

  • Deriest
  • Deriest's Avatar
  • Offline
  • Posts: 26
  • Thank you received: 12
I got it working but it is more like an automatic exposure adjustment than true eye adaptation. I'll have to wait until we gain access to more than just the previous frame and current frame to create true eye adaptation but for now it will work. It just needs some tweaking to actually be useful.
The administrator has disabled public write access.

Eye Adaptation 1 year 10 months ago #10

Oh this would be awesome, i know this effect from crysis 1 and it was never used by crytek :D i just activated it and optimized it abit...
i wish this feature in reshade aswell B)
The administrator has disabled public write access.

Eye Adaptation 1 year 9 months ago #11

  • Deriest
  • Deriest's Avatar
  • Offline
  • Posts: 26
  • Thank you received: 12
Sorry to bump such an old thread but I still haven't been able to get realistic eye adaptation. It is more of a smooth fade between the two frames than a delay. I have been using
(1 - timeleft) * adaptSpeed
for the timer to blend between the two frames but when I read about adaptation something called delta time is always used. Is that the same as one of the timers in reshade or will I have to calculate it myself and if so then how?
The administrator has disabled public write access.

Eye Adaptation 1 year 9 months ago #12

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2437
  • Thank you received: 1384
"delta time" or Δt is the expression for a time difference. In computer graphics it usually expresses the time it took for the last frame to complete, which you can retrieve using ReShade's "frametime" timer.
Cheers, crosire =)
The administrator has disabled public write access.
The following user(s) said Thank You: Deriest

Eye Adaptation 1 year 9 months ago #13

  • Deriest
  • Deriest's Avatar
  • Offline
  • Posts: 26
  • Thank you received: 12
Ah ok, thanks for the reply and for putting up with my lack of knowledge.
The administrator has disabled public write access.

Eye Adaptation 1 year 4 months ago #14

Hi,

Sorry for raising this thread even though it hasn't been posted to for about 4.5 months, but I have a question about this, and I'm hoping Deriest is still around and can answer it, or that someone else might be able to answer it for me...

given the code line:
float4  Lum             =   tex2D(samplerBloom4, 0.5);

Why is the second parameter for the tex2D function merely 0.5? I thought it required a full texture coordinate, which would be a float2, not a single float value. Does the system assume a coordinate of (0.5, 0.5) if it only receives the one float value?

I'd appreciate clarification on that please.

Thanks,
Drake Phoenix
The administrator has disabled public write access.

Eye Adaptation 1 year 4 months ago #15

  • Ganossa
  • Ganossa's Avatar
  • Offline
  • 최정장군
  • Posts: 790
  • Thank you received: 838
Correct, under the assumption that blur and one coordinate is enough for a scene brightness estimation. Its cheap, but far from accurate. ;)
The administrator has disabled public write access.
The following user(s) said Thank You: DrakePhoenix

Eye Adaptation 1 year 4 months ago #16

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2437
  • Thank you received: 1384
DrakePhoenix wrote:
Why is the second parameter for the tex2D function merely 0.5? I thought it required a full texture coordinate, which would be a float2, not a single float value. Does the system assume a coordinate of (0.5, 0.5) if it only receives the one float value?
ReShade supports implicit vector casting from a smaller size vector (in this case a single component one, a scalar) to a bigger size vector (in this case a two component one). It will automatically expand the last value in the vector to the remaining components of the bigger size vector. This means:
float3 val3 = 5; // val3 == float3(5, 5, 5)
float4 val4 = float2(1, 2); // val4 == float4(1, 2, 2, 2)
So "tex2D(..., 0.5)" is equivalent to "tex2D(..., float2(0.5, 0.5))" and "tex2D(..., 0.5.xx)".
Cheers, crosire =)
Last Edit: 1 year 4 months ago by crosire.
The administrator has disabled public write access.
The following user(s) said Thank You: DrakePhoenix

Eye Adaptation 1 year 4 months ago #17

Thank you both.

I was actually wondering this morning if it worked similar to the way copying from a couple of cells in MS Excel or OpenOffice Calc and then pasting into a selected set of cells that is larger than the original source. In that case it starts over with the first value and repeats through it. So, for example, if you copy 2 cells (1, 2) and paste into 4 cells you would get a result of 1, 2, 1, 2.

So it's good to know not only that it will implicitly cast, but also the manner in which it does so.

Thanks again,
Drake Phoenix
The administrator has disabled public write access.

Eye Adaptation 1 year 4 months ago #18

Oh, sorry, one other thing...

I'm curious as to how the samplerBloomX samplers work. I know they are based on sampling from texBloomX. And for some reason texBloom1 and texBloom2 are identical. But texBloom3 divides the buffer dimensions by 2, texBloom4 divides by 4, and texBloom5 divides by 8.

Is this basically that you take the buffer texture, and then down-size it to fit into the smaller dimensions (which would lose detail), in order to deliberately blur the texture and then output the blurred texture as the result?

Thanks,
Drake Phoenix
The administrator has disabled public write access.

Eye Adaptation 1 year 4 months ago #19

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2437
  • Thank you received: 1384
DrakePhoenix wrote:
I'm curious as to how the samplerBloomX samplers work. I know they are based on sampling from texBloomX. And for some reason texBloom1 and texBloom2 are identical. But texBloom3 divides the buffer dimensions by 2, texBloom4 divides by 4, and texBloom5 divides by 8.
That would be a question for Marty, since these originate from his code (ported from ENB) AFAIK.
Cheers, crosire =)
Last Edit: 1 year 4 months ago by crosire.
The administrator has disabled public write access.