-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SUTK] Added rounded rectangel rendering (SUTK::RenderRectFillRound)
- Loading branch information
Showing
17 changed files
with
983 additions
and
26 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
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
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
156 changes: 156 additions & 0 deletions
156
shaders/presets/no_standalone_use/sdf_template.template
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 |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#sl version 2023 | ||
#sb version 2023 | ||
|
||
[Name("SDFRoundedRectShader")] | ||
Shader | ||
{ | ||
Properties | ||
{ | ||
[Stage(fragment, vertex)] | ||
[Set(material_set, material_properties)] | ||
uniform Parameters | ||
{ | ||
vec4 color; | ||
PARAMETERS_HERE | ||
} parameters; | ||
} | ||
|
||
Layout | ||
{ | ||
[Rate(per_vertex)] | ||
[MeshLayout(sge_optimal)] | ||
[Attribute(position)] | ||
vec3 position; | ||
} | ||
|
||
RenderPass | ||
{ | ||
SubPass | ||
{ | ||
[NoParse] | ||
GraphicsPipeline | ||
{ | ||
rasterization | ||
{ | ||
// in SUTK (geometry compilation) we need this to be counterclockwise | ||
frontface = counterclockwise | ||
} | ||
|
||
colorBlend | ||
{ | ||
attachment | ||
{ | ||
blendenable = true | ||
} | ||
} | ||
} | ||
|
||
[NoParse] | ||
GLSL | ||
{ | ||
#stage vertex | ||
|
||
#version 450 | ||
|
||
#include <v3d.h> | ||
|
||
layout(SGE_UNIFORM_BUFFER_LAYOUT, set = CAMERA_SET, binding = CAMERA_PROPERTIES_BINDING) uniform CameraInfo cameraInfo; | ||
layout(SGE_UNIFORM_BUFFER_LAYOUT, set = OBJECT_SET, binding = TRANSFORM_BINDING) uniform ObjectInfo objectInfo; | ||
|
||
layout(SGE_UNIFORM_BUFFER_LAYOUT, set = GLOBAL_SET, binding = SCREEN_BINDING) uniform ScreenInfo | ||
{ | ||
uvec2 resolution; | ||
uvec2 dpi; | ||
uvec2 size; | ||
mat4 matrix; | ||
} screenInfo; | ||
|
||
layout(location = POSITION_LOCATION) in vec3 position; | ||
|
||
void main() | ||
{ | ||
vec4 clipPos = screenInfo.matrix * objectInfo.transform * vec4(position, 1); | ||
clipPos.y = -clipPos.y; | ||
gl_Position = clipPos; | ||
} | ||
|
||
#stage fragment | ||
|
||
#version 450 | ||
|
||
#include <v3d.h> | ||
|
||
layout(SGE_UNIFORM_BUFFER_LAYOUT, set = MATERIAL_SET, binding = MATERIAL_PROPERTIES_BINDING) uniform Parameters | ||
{ | ||
vec4 color; | ||
PARAMETERS_HERE | ||
} parameters; | ||
|
||
layout(SGE_UNIFORM_BUFFER_LAYOUT, set = OBJECT_SET, binding = TRANSFORM_BINDING) uniform ObjectInfo objectInfo; | ||
|
||
layout(SGE_UNIFORM_BUFFER_LAYOUT, set = GLOBAL_SET, binding = SCREEN_BINDING) uniform ScreenInfo | ||
{ | ||
uvec2 resolution; | ||
uvec2 dpi; | ||
uvec2 size; | ||
mat4 matrix; | ||
} screenInfo; | ||
|
||
layout(location = 0) out vec4 color; | ||
|
||
vec4 convertToCenterOrigin(vec4 coord) | ||
{ | ||
return vec4(coord.x - screenInfo.size.x * 0.5, screenInfo.size.y * 0.5 - coord.y, coord.z, coord.w); | ||
} | ||
|
||
float realizeWidth(float width) | ||
{ | ||
uvec2 win_size = screenInfo.size; | ||
return width + win_size.x * 0.5; | ||
} | ||
|
||
float realizeHeight(float height) | ||
{ | ||
uvec2 win_size = screenInfo.size; | ||
return win_size.y * 0.5 - height; | ||
} | ||
|
||
vec2 realizeSize(vec2 size) | ||
{ | ||
uvec2 win_size = screenInfo.size; | ||
float size_x = size.x + win_size.x * 0.5; | ||
float size_y = win_size.y * 0.5 - size.y; | ||
return vec2(size_x, size_y); | ||
} | ||
|
||
float peekFn(float x, float sharpness) | ||
{ | ||
return (1.0 / (sharpness * sharpness * x * x + 1)); | ||
} | ||
|
||
float sdf(vec2 fragCoord) | ||
{ | ||
PARAMETERS_UNPACK_HERE | ||
|
||
// Signed Distance Function Definition | ||
|
||
float alpha = 1.0f; | ||
|
||
SDF_FN_BODY_HERE | ||
|
||
return alpha; | ||
} | ||
|
||
void main() | ||
{ | ||
vec4 fragCoord = gl_FragCoord; | ||
fragCoord = convertToCenterOrigin(fragCoord); | ||
|
||
float alpha = sdf(fragCoord.xy); | ||
|
||
color = vec4(1.0, 1.0, 1.0, alpha) * parameters.color; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.