Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TPHD] Add bloom graphic pack #642

Merged
merged 12 commits into from
Oct 15, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#version 430
#extension GL_ARB_texture_gather : enable
#extension GL_ARB_separate_shader_objects : enable


// shader 49865bd2e62efda1: tints the bloom mask and applies it to the frame


#ifdef VULKAN
#define ATTR_LAYOUT(__vkSet, __location) layout(set = __vkSet, location = __location)
#define UNIFORM_BUFFER_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(set = __vkSet, binding = __vkLocation, std140)
#define TEXTURE_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(set = __vkSet, binding = __vkLocation)
#define GET_FRAGCOORD() vec4(gl_FragCoord.xy*uf_fragCoordScale.xy,gl_FragCoord.z, 1.0/gl_FragCoord.w)

#else
#define ATTR_LAYOUT(__vkSet, __location) layout(location = __location)
#define UNIFORM_BUFFER_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(binding = __glLocation, std140)
#define TEXTURE_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(binding = __glLocation)
#define GET_FRAGCOORD() vec4(gl_FragCoord.xy*uf_fragCoordScale,gl_FragCoord.zw)

#endif

#ifdef VULKAN
layout(set = 1, binding = 1) uniform ufBlock
{
uniform ivec4 uf_remappedPS[1]; // holds area specific bloom tint color
uniform vec4 uf_fragCoordScale;
};

#else
uniform ivec4 uf_remappedPS[1]; // holds area specific bloom tint color
uniform vec2 uf_fragCoordScale;

#endif

TEXTURE_LAYOUT(0, 1, 0) uniform sampler2D textureUnitPS0; // bloom mask created in 6e2f31b2b2fcab1f
layout(location = 0) in vec4 passParameterSem0; // pixel coord
layout(location = 0) out vec4 passPixelColor0; // pixel color, alpha = blend of original pixel -> used to dampen non-bloom areas in shadow world


// more compatible interpolation
float mixf(float x, float y, float a)
{
return x * (1.0 - a) + y * a;
}


void main()
{
// get pixel coord
vec2 coord = passParameterSem0.xy;

// get bloom mask
vec3 mask = texture(textureUnitPS0, coord).xyz;

// get area specific color tint
vec4 tint = vec4(0.0);
tint.x = intBitsToFloat(uf_remappedPS[0].x);
tint.y = intBitsToFloat(uf_remappedPS[0].y);
tint.z = intBitsToFloat(uf_remappedPS[0].z);
tint.w = intBitsToFloat(uf_remappedPS[0].w);

// get luminance of tint: removes color, keeps intended brightness
float tintLuminance = dot(tint.xyz, vec3(0.299, 0.587, 0.114)); // percieved approximation

// apply custom tint color
tint.x = mixf(tintLuminance, tint.x, $bloom_tint_strength);
tint.y = mixf(tintLuminance, tint.y, $bloom_tint_strength);
tint.z = mixf(tintLuminance, tint.z, $bloom_tint_strength);

// apply tint on mask
vec4 outColor = vec4(0.0);
outColor.x = mask.x * tint.x;
outColor.y = mask.y * tint.y;
outColor.z = mask.z * tint.z;

// custom brightness reduction, only in shadow world below 1.0
outColor.w = mixf(1.0, tint.w, $shadow_world_darkening);

// export
passPixelColor0 = vec4(outColor.x, outColor.y, outColor.z, outColor.w);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#version 430
#extension GL_ARB_texture_gather : enable
#extension GL_ARB_separate_shader_objects : enable


// shader 5f422bf63e25be7f: desaturates colors (shadow world only)
// desaturates the image by shifting colors towards the red channel
// used in shadow world only, as far as tested
// grading values always seem to be: 1.0, 1.0, 1.0, ~0.33


#ifdef VULKAN
#define ATTR_LAYOUT(__vkSet, __location) layout(set = __vkSet, location = __location)
#define UNIFORM_BUFFER_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(set = __vkSet, binding = __vkLocation, std140)
#define TEXTURE_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(set = __vkSet, binding = __vkLocation)
#define GET_FRAGCOORD() vec4(gl_FragCoord.xy*uf_fragCoordScale.xy,gl_FragCoord.z, 1.0/gl_FragCoord.w)

layout(set = 1, binding = 1) uniform ufBlock
{
uniform ivec4 uf_remappedPS[1]; // grading
};

#else
#define ATTR_LAYOUT(__vkSet, __location) layout(location = __location)
#define UNIFORM_BUFFER_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(binding = __glLocation, std140)
#define TEXTURE_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(binding = __glLocation)
#define GET_FRAGCOORD() vec4(gl_FragCoord.xy*uf_fragCoordScale,gl_FragCoord.zw)

uniform ivec4 uf_remappedPS[1]; // grading

#endif


TEXTURE_LAYOUT(0, 1, 0) uniform sampler2D textureUnitPS0; // frame
layout(location = 0) in vec4 passParameterSem1; // pixel coordinate
layout(location = 0) out vec4 passPixelColor0; // output. w is alpha, overlayed


// more compatible interpolation
float mixf(float x, float y, float a)
{
return x * (1.0 - a) + y * a;
}


void main()
{
// get texel color
vec2 coord = passParameterSem1.xy;
vec3 texel = texture(textureUnitPS0, coord).xyz;

// get grading
vec4 grading = vec4(0.0);
grading.x = intBitsToFloat(uf_remappedPS[0].x); // 1.0
grading.y = intBitsToFloat(uf_remappedPS[0].y); // 1.0
grading.z = intBitsToFloat(uf_remappedPS[0].z); // 1.0
grading.w = intBitsToFloat(uf_remappedPS[0].w); // alpha, ~0.33

// shift towards red channel
vec4 color = vec4(0.0);
color.x = texel.x * grading.x; // red * 1.0
color.y = texel.x * grading.y; // red * 1.0
color.z = texel.x * grading.z; // red * 1.0
color.w = mixf(0.0, grading.w, $shadow_world_desaturation); // apply custom strength

// export
passPixelColor0 = vec4(color.x, color.y, color.z, color.w);


// test current grading colors
//passPixelColor0 = vec4(grading.x, grading.y, grading.z, 1.0);

// test current grading alpha
//passPixelColor0 = vec4(grading.w, grading.w, grading.w, 1.0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#version 430
#extension GL_ARB_texture_gather : enable
#extension GL_ARB_separate_shader_objects : enable


// shader 6e2f31b2b2fcab1f: creates bloom mask


#ifdef VULKAN
#define ATTR_LAYOUT(__vkSet, __location) layout(set = __vkSet, location = __location)
#define UNIFORM_BUFFER_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(set = __vkSet, binding = __vkLocation, std140)
#define TEXTURE_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(set = __vkSet, binding = __vkLocation)
#define GET_FRAGCOORD() vec4(gl_FragCoord.xy*uf_fragCoordScale.xy,gl_FragCoord.z, 1.0/gl_FragCoord.w)

#else
#define ATTR_LAYOUT(__vkSet, __location) layout(location = __location)
#define UNIFORM_BUFFER_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(binding = __glLocation, std140)
#define TEXTURE_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(binding = __glLocation)
#define GET_FRAGCOORD() vec4(gl_FragCoord.xy*uf_fragCoordScale,gl_FragCoord.zw)

#endif

#ifdef VULKAN
layout(set = 1, binding = 1) uniform ufBlock
{
uniform ivec4 uf_remappedPS[1]; // mask threshold
uniform vec4 uf_fragCoordScale;
};

#else
uniform ivec4 uf_remappedPS[1]; // mask threshold
uniform vec2 uf_fragCoordScale;

#endif

TEXTURE_LAYOUT(0, 1, 0) uniform sampler2D textureUnitPS0; // frame
layout(location = 0) out vec4 passPixelColor0; // outputs to a texture used by c612390d4c70f430, 95a5a89d62998e0d and 49865bd2e62efda1


void main()
{
// get mask threshold data
float cutoff = intBitsToFloat(uf_remappedPS[0].x); // ~0.39: 0-1, higher = less glowing pixels
float contrast = intBitsToFloat(uf_remappedPS[0].y); // 4.5: higher = sharper edges

// get texture coordinate of this pixel
vec4 coord = GET_FRAGCOORD();
coord.x = coord.x * intBitsToFloat(0x3b088889); // align to scale/grid?
KoB-Kirito marked this conversation as resolved.
Show resolved Hide resolved
coord.y = coord.y * intBitsToFloat(0x3b72b9d6);

// get color of this pixel
vec3 color = texture(textureUnitPS0, vec2(coord.x, coord.y)).xyz;

// calculate luminance = percieved brightness
float luminance = dot(color, vec3(0.299, 0.587, 0.114)); // percieved approximation

// apply threshold, removes dark areas from the mask
luminance = contrast * (luminance - cutoff) * $bloom_strength; // apply custom strength

// apply to color and clamp
color.x = clamp(luminance * color.x, 0.0, 1.0);
color.y = clamp(luminance * color.y, 0.0, 1.0);
color.z = clamp(luminance * color.z, 0.0, 1.0);

// export
passPixelColor0 = vec4(color.x, color.y, color.z, 0.0);
}
Loading