-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathCombiner.fragment
74 lines (45 loc) · 2 KB
/
Combiner.fragment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#version 420
#include "Includes/Configuration.include"
in vec2 texcoord;
uniform sampler2D currentComputation;
uniform sampler2D lastFrame;
uniform sampler2D lastPosition;
uniform sampler2D positionBuffer;
uniform sampler2D velocityBuffer;
uniform int temporalProjXOffs;
uniform mat4 lastMVP;
uniform mat4 currentMVP;
uniform vec3 cameraPosition;
void main() {
// Fetch screen size, so we don't have to pass it as a shader input
ivec2 screenSize = textureSize(positionBuffer, 0);
// Screen coordinate (as int vec)
ivec2 screenCoord = ivec2(texcoord * vec2(screenSize.x, screenSize.y));
// Screen coordinate (half resolution only)
ivec2 computationCoord = ivec2( screenCoord.x/2, screenCoord.y);
vec3 position = texture(positionBuffer, texcoord).rgb;
// The last computed value (half resolution only, but up-to-date)
vec3 lastComputedValue = texelFetch(currentComputation, computationCoord, 0).rgb;
vec2 velocity = texture(velocityBuffer, texcoord).rg / 255.0;
vec2 lastFrameTexcoord = texcoord - velocity;
vec3 oldProjectedColor = texture(lastFrame, lastFrameTexcoord).rgb;
vec3 oldProjectedPos = texture(lastPosition, lastFrameTexcoord).rgb;
float distanceToCamera = distance(cameraPosition, position);
float reliability = 1.0 - (distance(oldProjectedPos, position) / distanceToCamera * 200.0);
// reliability = 1.0;
// Fetch the up-to-date position from the buffer
// vec4 position = vec4(texelFetch(positionBuffer, screenCoord, 0).rgb, 1);
vec3 result;
// if (distance(finalValue, vec3(1,0,0)) < 0.0001) {
// finalValue = lastComputedValue.rgb;
// // finalValue = lastFrameValue.rgb;
// }
// // result.xyz = vec3(finalValue);
result = mix(lastComputedValue, oldProjectedColor, saturate(reliability));
// If we have a newer value, use this
if (screenCoord.x % 2 == 1-temporalProjXOffs) {
result = lastComputedValue;
// result = vec4(0,1,0,1);
}
gl_FragColor = vec4( result, 1 );
}