-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the repeat moving background shader.
Co-authored-by: WebFreak001 <[email protected]>
- Loading branch information
1 parent
173718d
commit d5d0c3c
Showing
2 changed files
with
54 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 24 additions & 21 deletions
45
osu.Framework.Font/Resources/Shaders/sh_RepeatMovingBackground.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,43 @@ | ||
// see : https://github.com/kiwipxl/GLSL-shaders/blob/master/repeat.glsl | ||
#include "sh_CustomizedShaderGlobalUniforms.h" | ||
#include "sh_Utils.h" | ||
|
||
varying vec2 v_TexCoord; | ||
varying vec4 v_Colour; | ||
varying mediump vec4 v_TexRect; | ||
layout(location = 1) in lowp vec4 v_Colour; | ||
layout(location = 2) in highp vec2 v_TexCoord; | ||
layout(location = 3) in highp vec4 v_TexRect; | ||
|
||
uniform lowp sampler2D m_Sampler; | ||
layout(set = 2, binding = 0) uniform lowp texture2D m_RepeatTexture; | ||
layout(set = 2, binding = 1) uniform lowp sampler m_RepeatSampler; | ||
|
||
uniform mediump vec2 g_TexSize; | ||
uniform lowp sampler2D g_RepeatSample; | ||
uniform vec2 g_RepeatSampleCoord; | ||
uniform vec2 g_RepeatSampleSize; | ||
uniform vec2 g_DisplaySize; | ||
uniform vec2 g_DisplayBorder; | ||
uniform vec2 g_Speed; | ||
uniform float g_Time; | ||
uniform float g_Mix; | ||
layout(std140, set = 3, binding = 0) uniform m_RepeatMovingBackgroundParameters | ||
{ | ||
mediump vec2 g_RepeatSampleCoord; | ||
mediump vec2 g_RepeatSampleSize; | ||
mediump vec2 g_DisplaySize; | ||
mediump vec2 g_DisplayBorder; | ||
mediump vec2 g_Speed; | ||
mediump float g_Mix; | ||
}; | ||
|
||
float mod(float a, int b) { | ||
return a - (float(b) * floor(a/float(b))); | ||
} | ||
layout(set = 1, binding = 0) uniform lowp texture2D m_Texture; | ||
layout(set = 1, binding = 1) uniform lowp sampler m_Sampler; | ||
|
||
layout(location = 0) out vec4 o_Colour; | ||
|
||
void main(void) { | ||
// calculate how many times texture should be repeated. | ||
vec2 repeat = g_TexSize / (g_DisplaySize + g_DisplayBorder); | ||
|
||
// get the repeat texture coordinate. | ||
float repeatTexCoordX = mod(v_TexCoord.x * repeat.x + g_Speed.x * g_Time, 1); | ||
float repeatTexCoordY = mod(v_TexCoord.y * repeat.y + g_Speed.y * g_Time, 1); | ||
float repeatTexCoordX = mod(v_TexCoord.x * repeat.x + g_Speed.x * g_Time, 1.0); | ||
float repeatTexCoordY = mod(v_TexCoord.y * repeat.y + g_Speed.y * g_Time, 1.0); | ||
vec2 repeatTexCoord = vec2(repeatTexCoordX, repeatTexCoordY) / g_DisplaySize * (g_DisplaySize + g_DisplayBorder); | ||
|
||
// because repeat texture will be the size of 1024*1024, so should make a conversion to get the target area of the texture. | ||
vec2 fixedTexCoord = repeatTexCoord * g_RepeatSampleSize + g_RepeatSampleCoord; | ||
|
||
// get point colour from sample. | ||
vec4 texColor = texture2D(m_Sampler, v_TexCoord); | ||
vec4 repeatSampleColor = v_Colour * vec4(texture2D(g_RepeatSample, fixedTexCoord).xyz, texColor.a); | ||
gl_FragColor = toSRGB(mix(texColor, repeatSampleColor, g_Mix)); | ||
vec4 texColor = texture(sampler2D(m_Texture, m_Sampler), v_TexCoord); | ||
vec4 repeatSampleColor = v_Colour * vec4(texture(sampler2D(m_RepeatTexture, m_RepeatSampler), fixedTexCoord).xyz, texColor.a); | ||
o_Colour = toSRGB(mix(texColor, repeatSampleColor, g_Mix)); | ||
} |