Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 330
- in vec2 TexCoord;
- out vec3 Color;
- uniform sampler2D Input;
- uniform sampler2D BlockTexCoord;
- uniform sampler2D Normals;
- uniform sampler2D WorldPos;
- uniform sampler2D TemporalSampling;
- uniform mat4 ProjectionMatrix;
- uniform mat4 ViewMatrix;
- uniform bool Vertical;
- const int Pixels = 16;
- void main() {
- vec2 TextureSize = vec2(textureSize(Input, 0));
- vec2 TexelSize = 1.0 / TextureSize;
- float TotalPixelsFound = 0.0;
- vec3 CurrentInput = texture(Input, TexCoord).xyz;
- float CurrentTemporalSampling = texture(TemporalSampling, TexCoord).x;
- Color = texture(Normals, TexCoord).xyz == vec3(0.) ? CurrentInput : vec3(0.);
- if (Color.r > 0.001 || Color.g > 0.001 || Color.b > 0.001)
- return;
- vec4 CurrentWorldPosition = texture(WorldPos, TexCoord);
- vec3 WorldPosPositive = texture(WorldPos, TexCoord + vec2(!Vertical ? TexelSize.x : 0.0, Vertical ? TexelSize.y : 0.0)).xyz;
- vec3 WorldPosNegative = texture(WorldPos, TexCoord - vec2(!Vertical ? TexelSize.x : 0.0, Vertical ? TexelSize.y : 0.0)).xyz;
- vec3 RayDirectionPositive = normalize(WorldPosPositive - CurrentWorldPosition.xyz);
- vec3 RayDirectionNegative = normalize(WorldPosPositive - CurrentWorldPosition.xyz);
- vec4 NewWorldPositionPositive = vec4(CurrentWorldPosition.xyz + RayDirectionPositive*0.5, 1.);
- vec4 NewWorldPositionNegative = vec4(CurrentWorldPosition.xyz + RayDirectionNegative*0.5, 1.);
- vec4 NDCPositive = ProjectionMatrix * ViewMatrix * NewWorldPositionPositive;
- vec2 TCPositive = (NDCPositive.xy / NDCPositive.w) * 0.5 + 0.5;
- vec4 NDCNegative = ProjectionMatrix * ViewMatrix * NewWorldPositionPositive;
- vec2 TCNegative = (NDCNegative.xy / NDCNegative.w) * 0.5 + 0.5;
- int RangeNegative = min(max(Vertical ? int(floor(abs(TCNegative.y - TexCoord.y) * TextureSize.y)) : int(floor(abs(TCNegative.x - TexCoord.x) * TextureSize.x)), int(ceil(mix(10.0, 7.0, CurrentTemporalSampling)))), int(ceil(mix(32.0, 24.0, CurrentTemporalSampling))));
- int RangePositive = min(max(Vertical ? int(floor(abs(TCPositive.y - TexCoord.y) * TextureSize.y)) : int(floor(abs(TCPositive.x - TexCoord.x) * TextureSize.x)), int(ceil(mix(10.0, 7.0, CurrentTemporalSampling)))), int(ceil(mix(32.0, 24.0, CurrentTemporalSampling))));
- float PowerCoef = mix(0.025, 0.05, CurrentTemporalSampling);
- vec4 PrevWorldPos = CurrentWorldPosition;
- float PixelAddon = 0.0;
- float Power = 1.0;
- for (int Pixel = -1; Pixel > RangeNegative; Pixel--) {
- Power -= PowerCoef;
- vec2 Addon = vec2(!Vertical ? TexelSize.x * Pixel : 0., Vertical ? TexelSize.y * Pixel : 0.);
- vec2 NC = TexCoord + Addon;
- vec4 ThisWorldPos = texture(WorldPos, NC);
- if (abs(ThisWorldPos.x - PrevWorldPos.x) > 0.6 || abs(ThisWorldPos.y - PrevWorldPos.y) > 0.6 || abs(ThisWorldPos.z - PrevWorldPos.z) > 0.6 || abs(ThisWorldPos.a - PrevWorldPos.a) > 0.1)
- break;
- PrevWorldPos = ThisWorldPos;
- vec3 c = texture(Input, NC).rgb;
- Color += texture(Input, NC).rgb * Power;
- PixelAddon += 1.0 * Power;
- }
- PrevWorldPos = CurrentWorldPosition;
- Power = 1.0;
- for (int Pixel = 1; Pixel < RangePositive; Pixel++) {
- Power -= PowerCoef;
- vec2 Addon = vec2(!Vertical ? TexelSize.x * Pixel : 0., Vertical ? TexelSize.y * Pixel : 0.);
- vec2 NC = TexCoord + Addon;
- vec4 ThisWorldPos = texture(WorldPos, NC);
- if (abs(ThisWorldPos.x - PrevWorldPos.x) > 0.6 || abs(ThisWorldPos.y - PrevWorldPos.y) > 0.6 || abs(ThisWorldPos.z - PrevWorldPos.z) > 0.6 || abs(ThisWorldPos.a - PrevWorldPos.a) > 0.1)
- break;
- PrevWorldPos = ThisWorldPos;
- //float Power = pow(PowerCoef, Pixel);
- vec3 c = texture(Input, NC).rgb;
- Color += texture(Input, NC).rgb * Power;
- PixelAddon += 1.0 * Power;
- }
- Color = PixelAddon < 0.1 ? CurrentInput : Color / PixelAddon;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement