diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-03-18 16:25:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-18 16:25:38 +0200 |
commit | c3600612a83442eeadf99a1602ab07537b071b66 (patch) | |
tree | 1d88bdedd4c00c332fa4f4e7f78b9c0ee842a2a9 /src/main/resources/assets/libgui/shaders | |
parent | 91e4e6401089d6dc5b92589fa1fb1501b7217cf0 (diff) | |
download | LibGui-c3600612a83442eeadf99a1602ab07537b071b66.tar.gz LibGui-c3600612a83442eeadf99a1602ab07537b071b66.tar.bz2 LibGui-c3600612a83442eeadf99a1602ab07537b071b66.zip |
Improve tiled NinePatchBackgroundPainter performance (#185)
* Improve tiled NinePatchBackgroundPainter performance
* Use Fabric API's CoreShaderRegistrationCallback
* Switch to LibNinePatch release build
* Rename libgui:tiled -> libgui:tiled_rectangle
* Fix grammar
Diffstat (limited to 'src/main/resources/assets/libgui/shaders')
3 files changed, 67 insertions, 0 deletions
diff --git a/src/main/resources/assets/libgui/shaders/core/tiled_rectangle.fsh b/src/main/resources/assets/libgui/shaders/core/tiled_rectangle.fsh new file mode 100644 index 0000000..15e3185 --- /dev/null +++ b/src/main/resources/assets/libgui/shaders/core/tiled_rectangle.fsh @@ -0,0 +1,32 @@ +#version 150 + +uniform sampler2D Sampler0; +uniform vec4 ColorModulator; + +uniform vec2 LibGuiRectanglePos; +uniform vec2 LibGuiTileDimensions; +uniform vec4 LibGuiTileUvs; + +in vec2 vertexPosition; +out vec4 fragColor; + +float lerp(float time, float a, float b) { + return (1 - time) * a + time * b; +} + +vec2 getTextureCoords(vec2 pos) { + float deltaX = mod(pos.x - LibGuiRectanglePos.x, LibGuiTileDimensions.x) / LibGuiTileDimensions.x; + float deltaY = mod(pos.y - LibGuiRectanglePos.y, LibGuiTileDimensions.y) / LibGuiTileDimensions.y; + return vec2( + lerp(deltaX, LibGuiTileUvs.x, LibGuiTileUvs.z), + lerp(deltaY, LibGuiTileUvs.y, LibGuiTileUvs.w) + ); +} + +void main() { + vec4 color = texture(Sampler0, getTextureCoords(vertexPosition)); + if (color.a < 0.1) { + discard; + } + fragColor = color * ColorModulator; +} diff --git a/src/main/resources/assets/libgui/shaders/core/tiled_rectangle.json b/src/main/resources/assets/libgui/shaders/core/tiled_rectangle.json new file mode 100644 index 0000000..2ca0af3 --- /dev/null +++ b/src/main/resources/assets/libgui/shaders/core/tiled_rectangle.json @@ -0,0 +1,20 @@ +{ + "blend": { + "func": "add", + "srcrgb": "srcalpha", + "dstrgb": "1-srcalpha" + }, + "vertex": "libgui:tiled_rectangle", + "fragment": "libgui:tiled_rectangle", + "attributes": ["Position"], + "samplers": [{ "name": "Sampler0" }], + "uniforms": [ + { "name": "ModelViewMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, + { "name": "ProjMat", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] }, + { "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] }, + { "name": "LibGuiRectanglePos", "type": "float", "count": 2, "values": [ 0.0, 0.0 ] }, + { "name": "LibGuiTileDimensions", "type": "float", "count": 2, "values": [ 0.0, 0.0 ] }, + { "name": "LibGuiTileUvs", "type": "float", "count": 4, "values": [ 0.0, 0.0, 1.0, 1.0 ] }, + { "name": "LibGuiPositionMatrix", "type": "matrix4x4", "count": 16, "values": [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ] } + ] +} diff --git a/src/main/resources/assets/libgui/shaders/core/tiled_rectangle.vsh b/src/main/resources/assets/libgui/shaders/core/tiled_rectangle.vsh new file mode 100644 index 0000000..6a1209d --- /dev/null +++ b/src/main/resources/assets/libgui/shaders/core/tiled_rectangle.vsh @@ -0,0 +1,15 @@ +#version 150 + +in vec3 Position; + +uniform mat4 ModelViewMat; +uniform mat4 ProjMat; +uniform mat4 LibGuiPositionMatrix; + +out vec2 vertexPosition; + +void main() { + gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0); + vec4 rawPos = inverse(LibGuiPositionMatrix) * vec4(Position, 1.0); + vertexPosition = rawPos.xy; +} |