Skip to content

Commit

Permalink
noteBase is now just SDF Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
LumpBloom7 committed Nov 17, 2024
1 parent 057388c commit abfe2cf
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ layout(location = 3) in highp vec4 v_TexRect;

layout(location = 0) out vec4 o_Colour;

vec4 sdfToShape(in float dist, in float borderThickness, in float shadowThickness){
vec4 sdfToShape(in float dist, in float borderThickness, in float shadowThickness, in bool glow){
vec3 shadowColor = glow ? vec3(1) : vec3(0);
float shadowAlpha = glow ? 0.75: 0.6;

Expand All @@ -34,7 +34,7 @@ vec4 sdfToShape(in float dist, in float borderThickness, in float shadowThicknes
return shadowPart + fillPart;
}

vec4 sdfFill(in float dist, in float borderThickness, in float shadowThickness){
vec4 sdfFill(in float dist, in float borderThickness, in float shadowThickness, in bool glow){
vec3 shadowColor = glow ? vec3(1) : vec3(0);
float shadowAlpha = glow ? 0.75: 0.6;

Expand Down
5 changes: 3 additions & 2 deletions osu.Game.Rulesets.Sentakki/Resources/Shaders/sh_chevron.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SENTAKKI_CHEVRON_FS
#define SENTAKKI_CHEVRON_FS

#include "sh_SDFUtils.fs"

layout(std140, set = 0, binding = 0) uniform m_shapeParameters
{
float thickness;
Expand All @@ -10,7 +12,6 @@ layout(std140, set = 0, binding = 0) uniform m_shapeParameters
bool fanChevron;
};

#include "sh_noteBase.fs"

float sdPolygon( in vec2 p, in vec2 origin, in vec2[6] v )
{
Expand Down Expand Up @@ -101,7 +102,7 @@ void main(void) {
ringSDF = fanChev(p, c,size - vec2(shadeRadius + borderThickness) * 2, borderThickness);
else ringSDF = chev(p, c,size - vec2(shadeRadius + borderThickness) * 2, borderThickness);

vec4 r = sdfFill(ringSDF, borderThickness, shadeRadius);
vec4 r = sdfFill(ringSDF, borderThickness, shadeRadius, glow);
o_Colour = r;
}
#endif
12 changes: 6 additions & 6 deletions osu.Game.Rulesets.Sentakki/Resources/Shaders/sh_hexNote.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SENTAKKI_HEX_NOTE_FS
#define SENTAKKI_HEX_NOTE_FS

#include "sh_SDFUtils.fs"

layout(std140, set = 0, binding = 0) uniform m_shapeParameters
{
float thickness;
Expand All @@ -9,8 +11,6 @@ layout(std140, set = 0, binding = 0) uniform m_shapeParameters
bool glow;
};

#include "sh_noteBase.fs"

// SDF that makes a rounded hexagon
// Adapted from the Star shader provided at https://iquilezles.org/articles/distfunctions2d/
float roundedHexSDF(in vec2 p, in vec2 origin, in float h, in float r)
Expand Down Expand Up @@ -65,15 +65,15 @@ void main(void) {
float h = size.y - size.x;

float hex = roundedHexSDF(p, c, h, radius);
float dotDown = circleSDF(p, c + vec2(0, h * 0.5), borderThickness/4 - 1.5 );
float dotDown = circleSDF(p, c + vec2(0, h * 0.5), borderThickness/4 - 1.5);
float dotUp = circleSDF(p, c -vec2(0, h * 0.5), borderThickness/4 - 1.5);

vec4 dotDownShape = sdfToShape(dotDown, borderThickness, 0);
vec4 dotUpShape = sdfToShape(dotUp, borderThickness, 0);
vec4 dotDownShape = sdfToShape(dotDown, borderThickness, 0, false);
vec4 dotUpShape = sdfToShape(dotUp, borderThickness, 0, false);

vec4 r2 = max(dotDownShape - dotUpShape, vec4(0,0,0,0)) + dotUpShape;

vec4 r = sdfToShape(hex, borderThickness, shadeRadius) + r2;
vec4 r = sdfToShape(hex, borderThickness, shadeRadius, glow) + r2;

o_Colour = r;
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Sentakki/Resources/Shaders/sh_ringNote.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SENTAKKI_RING_FS
#define SENTAKKI_RING_FS

#include "sh_SDFUtils.fs"

layout(std140, set = 0, binding = 0) uniform m_shapeParameters
{
float thickness;
Expand All @@ -9,8 +11,6 @@ layout(std140, set = 0, binding = 0) uniform m_shapeParameters
bool glow;
};

#include "sh_noteBase.fs"

void main(void) {
vec2 resolution = v_TexRect.zw - v_TexRect.xy;
vec2 pixelPos = (v_TexCoord - v_TexRect.xy) / resolution;
Expand All @@ -28,7 +28,7 @@ void main(void) {
float dotSDF = circleSDF(p,c, borderThickness / 4 - 1.5);
float ringSDF = circleSDF(p, c, radius);

vec4 r = sdfToShape(ringSDF, borderThickness, shadeRadius) + sdfToShape(dotSDF, borderThickness, 0);
vec4 r = sdfToShape(ringSDF, borderThickness, shadeRadius, glow) + sdfToShape(dotSDF, borderThickness, 0, false);
o_Colour = r;
}

Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Sentakki/Resources/Shaders/sh_starNote.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SENTAKKI_STAR_NOTE_FS
#define SENTAKKI_STAR_NOTE_FS

#include "sh_SDFUtils.fs"

layout(std140, set = 0, binding = 0) uniform m_shapeParameters
{
float thickness;
Expand All @@ -9,8 +11,6 @@ layout(std140, set = 0, binding = 0) uniform m_shapeParameters
bool glow;
};

#include "sh_noteBase.fs"

// signed distance to a n-star polygon, with external angle w
float sdStar(in vec2 p, in vec2 origin, in float r, in float n, in float w)
{
Expand Down Expand Up @@ -57,7 +57,7 @@ void main(void) {

float star = sdStar(p, c, radius, 5, 0.6);

vec4 r = sdfToShape(star, borderThickness * 0.75, shadeRadius);
vec4 r = sdfToShape(star, borderThickness * 0.75, shadeRadius, glow);

o_Colour = r;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SENTAKKI_CHEVRON_FS
#define SENTAKKI_CHEVRON_FS

#include "sh_SDFUtils.fs"

layout(std140, set = 0, binding = 0) uniform m_shapeParameters
{
float thickness;
Expand All @@ -11,8 +13,6 @@ layout(std140, set = 0, binding = 0) uniform m_shapeParameters
bool shadowOnly;
};

#include "sh_noteBase.fs"

float sdTriangle( in vec2 p, in vec2 p0, in vec2 p1, in vec2 p2 )
{
vec2 e0 = p1-p0, e1 = p2-p1, e2 = p0-p2;
Expand Down Expand Up @@ -73,8 +73,8 @@ void main(void) {
if(shadowOnly)
o_Colour = sdfShadow(ringSDF, borderThickness, shadeRadius);
else if(fillTriangle)
o_Colour = sdfFill(ringSDF, borderThickness, shadeRadius);
o_Colour = sdfFill(ringSDF, borderThickness, shadeRadius, glow);
else
o_Colour = sdfToShape(ringSDF, borderThickness, shadeRadius);
o_Colour = sdfToShape(ringSDF, borderThickness, shadeRadius, glow);
}
#endif

0 comments on commit abfe2cf

Please sign in to comment.