Files
REM-Mod/FLARDATA/Shader/bloomUpsample.fs
2024-10-18 22:02:26 +02:00

47 lines
1.7 KiB
GLSL

//This shader file is part of FLAR - Advanced Renderer for Freelancer by Schmackbolzen
//If you use the supplied shader files you may not modify them unless you state in them what you changed
//and also mention the source or who the author is.
//
//PBR bloom upsample shader for FLAR by Schmackbolzen based on code from https://learnopengl.com/Guest-Articles/2022/Phys.-Based-Bloom
//The only bug fix is using different filter radii for each direction since the texture is not square
#version 330
uniform sampler2D srcTexture;
uniform float filterRadiusX;
uniform float filterRadiusY;
in vec2 texCoord;
layout (location = 0) out vec3 upsample;
void main()
{
float x = filterRadiusX;
float y = filterRadiusY;
// Take 9 samples around current texel:
// a - b - c
// d - e - f
// g - h - i
// === ('e' is the current texel) ===
vec3 a = texture(srcTexture, vec2(texCoord.x - x, texCoord.y + y)).rgb;
vec3 b = texture(srcTexture, vec2(texCoord.x, texCoord.y + y)).rgb;
vec3 c = texture(srcTexture, vec2(texCoord.x + x, texCoord.y + y)).rgb;
vec3 d = texture(srcTexture, vec2(texCoord.x - x, texCoord.y)).rgb;
vec3 e = texture(srcTexture, vec2(texCoord.x, texCoord.y)).rgb;
vec3 f = texture(srcTexture, vec2(texCoord.x + x, texCoord.y)).rgb;
vec3 g = texture(srcTexture, vec2(texCoord.x - x, texCoord.y - y)).rgb;
vec3 h = texture(srcTexture, vec2(texCoord.x, texCoord.y - y)).rgb;
vec3 i = texture(srcTexture, vec2(texCoord.x + x, texCoord.y - y)).rgb;
// Apply weighted distribution, by using a 3x3 tent filter:
// 1 | 1 2 1 |
// -- * | 2 4 2 |
// 16 | 1 2 1 |
upsample = e*4.0;
upsample += (b+d+f+h)*2.0;
upsample += (a+c+g+i);
upsample *= 1.0 / 16.0;
}