Is Timer.w broken?

fixing bugs
Post Reply
  • Author
  • Message
Offline
Posts: 12
Joined: 08 Nov 2016, 12:00

Is Timer.w broken?

I'm trying to port a film grain effect I made on ReShade into postpass, it's visually identical, but I can't seem to be able to get the delta time.
The example shaders say:

Code: Select all

//x = generic timer in range 0..1, period of 16777216 ms (4.6 hours), y = average fps, w = frame time elapsed (in seconds)
float4	Timer;
Well I've tried using Timer.w but it seems to be completely stopped. Multiplying up or down didn't do anything either, is this a bug? I've tried using other components of Timer but they didn't help much, average FPS did get me some timed effects...for less than 3 seconds (probably because average FPS), so the effect does seem to work fully except for the timing data.

So, am I doing something wrong?

Here's my code if you wish to test it yourself:

Code: Select all

float fFilmGrain_Intensity <
	string UIName   = "Film Grain Intensity";
	string UIWidget = "spinner";
	float  UIMin    = 0.0;
	float  UIMax    = 1.0;
> = 1.0;

float fFilmGrain_Speed <
	string UIName   = "Film Grain Speed";
	string UIWidget = "spinner";
	float  UIMin    = 0.0;
	float  UIMax    = 100.0;
> = 1.0;

float fFilmGrain_Mean <
	string UIName   = "Film Grain Mean";
	string UIWidget = "spinner";
	float  UIMin    = 0.0;
	float  UIMax    = 1.0;
> = 0.0;

float fFilmGrain_Variance <
	string UIName   = "Film Grain Variance";
	string UIWidget = "spinner";
	float  UIMin    = 0.0;
	float  UIMax    = 1.0;
> = 0.5;

...

float gaussian(float z, float u, float o) {
    // 2.506 ~= sqrt(2 * pi)
    return (1.0 / (o * 2.506)) * exp(-(((z - u) * (z - u)) / (2.0 * (o * o))));
}

float get_film_grain(float2 uv) {
	float t = Timer.w * 0.001 * fFilmGrain_Speed;
	float seed = dot(uv, float2(12.9898, 78.233));
	float noise = frac(sin(seed) * 43758.5453 + t);
	return gaussian(noise, fFilmGrain_Mean, fFilmGrain_Variance * fFilmGrain_Variance);
}

...

// Film Grain
color += (get_film_grain(uv) * (1.0 - color)) * fFilmGrain_Intensity * 0.01;
Once again, Fallout 4 ENB v0.323

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17559
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: Is Timer.w broken?

I think you dont understand what this value mean. It is difference between current and previous frames, if frame rate is constant, this value is constant too, for example framerate=50, Timer.w=0.02 sec.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7

Offline
Posts: 12
Joined: 08 Nov 2016, 12:00

Re: Is Timer.w broken?

Yeah, I'm dumb, I've realized what I need is a generic timer, so Timer.x is what I need, right? I just need a generic value that increments with time.

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17559
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: Is Timer.w broken?

Yes.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7

Offline
Posts: 12
Joined: 08 Nov 2016, 12:00

Re: Is Timer.w broken?

Managed to fix it using Timer.x * 16777.216 (which is the max time * 0.001):

Poor quality but to show it's working (animated): https://gfycat.com/LeanCheapFlyingfox
Here's a screenshot, too:

Image

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17559
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: Is Timer.w broken?

Check if big values of timer (after lot of time passes) do not produce errors in code because of floating point precision. For such cases it is better to use frac or anything similar.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7

Offline
Posts: 12
Joined: 08 Nov 2016, 12:00

Re: Is Timer.w broken?

Maybe frac() would be good yeah, but at some point even it would start being "jumpy". Does the timer wrap back to 0 once it reaches 16777216?
Also maybe too much time would have to pass before we see a lot of jumping/loss of precision, I'll have to test it.

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17559
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: Is Timer.w broken?

It wrap back from 1 to 0. I made 16m limit because its close to float epsilon, but using math on it will degrade precision, so when value is close to max, it should have same values for several frames.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7
Post Reply