Eye Adaptation

  • Deriest
  • Topic Author
More
9 years 3 months ago #1 by Deriest Eye Adaptation was created by Deriest
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.

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

  • crosire
More
9 years 3 months ago #2 by crosire Replied by crosire on topic Eye Adaptation
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).

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

  • Deriest
  • Topic Author
More
9 years 3 months ago #3 by Deriest Replied by Deriest on topic Eye Adaptation
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.

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

  • crosire
More
9 years 3 months ago #4 by crosire Replied by crosire on topic Eye Adaptation
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 =)

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

  • Deriest
  • Topic Author
More
9 years 3 months ago #5 by Deriest Replied by Deriest on topic Eye Adaptation
Cool thanks. So far I am really enjoying this. Keep up the good work. :cheer:
The following user(s) said Thank You: crosire

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

  • Deriest
  • Topic Author
More
9 years 2 months ago #6 by Deriest Replied by Deriest on topic Eye Adaptation
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.

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

  • crosire
More
9 years 2 months ago - 9 years 2 months ago #7 by crosire Replied by crosire on topic Eye Adaptation
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.
Last edit: 9 years 2 months ago by crosire.
The following user(s) said Thank You: Deriest

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

  • Deriest
  • Topic Author
More
9 years 2 months ago #8 by Deriest Replied by Deriest on topic Eye Adaptation
Thanks for the reply and for clearing that up for me.

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

  • Deriest
  • Topic Author
More
9 years 2 months ago #9 by Deriest Replied by Deriest on topic Eye Adaptation
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.

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

  • CryZENx
More
9 years 2 months ago #10 by CryZENx Replied by CryZENx on topic Eye Adaptation
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)

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

  • Deriest
  • Topic Author
More
9 years 1 month ago #11 by Deriest Replied by Deriest on topic Eye Adaptation
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?

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

  • crosire
More
9 years 1 month ago #12 by crosire Replied by crosire on topic Eye Adaptation
"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.
The following user(s) said Thank You: Deriest

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

  • Deriest
  • Topic Author
More
9 years 1 month ago #13 by Deriest Replied by Deriest on topic Eye Adaptation
Ah ok, thanks for the reply and for putting up with my lack of knowledge.

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

  • DrakePhoenix
More
8 years 9 months ago #14 by DrakePhoenix Replied by DrakePhoenix on topic Eye Adaptation
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

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

  • Ganossa
More
8 years 9 months ago #15 by Ganossa Replied by Ganossa on topic Eye Adaptation
Correct, under the assumption that blur and one coordinate is enough for a scene brightness estimation. Its cheap, but far from accurate. ;)
The following user(s) said Thank You: DrakePhoenix

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

  • crosire
More
8 years 9 months ago - 8 years 9 months ago #16 by crosire Replied by crosire on topic Eye Adaptation

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)".
Last edit: 8 years 9 months ago by crosire.
The following user(s) said Thank You: DrakePhoenix

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

  • DrakePhoenix
More
8 years 9 months ago #17 by DrakePhoenix Replied by DrakePhoenix on topic Eye Adaptation
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

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

  • DrakePhoenix
More
8 years 9 months ago #18 by DrakePhoenix Replied by DrakePhoenix on topic Eye Adaptation
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

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

  • crosire
More
8 years 9 months ago - 8 years 9 months ago #19 by crosire Replied by crosire on topic Eye Adaptation

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.
Last edit: 8 years 9 months ago by crosire.

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

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.