Compare commits

...

6 Commits

Author SHA1 Message Date
Dean Herbert
7416892e34 Merge pull request #227 from EVAST9919/triangles-v2
Implement TriangleBorder shader
2022-11-24 15:03:23 +09:00
Andrei Zavatski
3653f7477d Remove toSRGB colour conversion 2022-11-23 16:12:46 +03:00
Andrei Zavatski
abc3834535 Expose thickness uniform 2022-11-21 10:20:05 +03:00
Dean Herbert
3dad98e20c Merge pull request #228 from OliBomby/streams-icon
Create Streams icon
2022-11-18 16:18:17 +09:00
OliBomby
d9409e12f0 Create streams.png 2022-11-18 07:58:27 +01:00
Andrei Zavatski
979b1027e6 Implement TriangleBorder shader 2022-11-13 15:27:44 +03:00
2 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
#define HIGH_PRECISION_VERTEX
#include "sh_Utils.h"
#include "sh_Masking.h"
varying highp vec2 v_TexCoord;
uniform lowp sampler2D m_Sampler;
uniform mediump float thickness;
highp float dstToLine(highp vec2 start, highp vec2 end, highp vec2 pixelPos)
{
highp float lineLength = distance(end, start);
if (lineLength < 0.001)
return distance(pixelPos, start);
highp vec2 a = (end - start) / lineLength;
highp vec2 closest = clamp(dot(a, pixelPos - start), 0.0, distance(end, start)) * a + start; // closest point on a line from given position
return distance(closest, pixelPos);
}
bool insideTriangle(highp vec2 pixelPos)
{
bool inLeftPart = pixelPos.x < 0.5 && pixelPos.x > 0.5 * (1.0 - pixelPos.y);
bool inRightPart = pixelPos.x > 0.5 && pixelPos.x < 0.5 * (1.0 + pixelPos.y);
return inLeftPart || inRightPart;
}
void main(void)
{
highp vec2 resolution = v_TexRect.zw - v_TexRect.xy;
highp vec2 pixelPos = (v_TexCoord - v_TexRect.xy) / resolution;
highp float texelSize = max(abs(dFdx(pixelPos.x)), abs(dFdy(pixelPos.y))) * 1.5;
if (!insideTriangle(pixelPos))
{
gl_FragColor = vec4(0.0);
return;
}
highp float dst1 = dstToLine(vec2(0.0, 1.0), vec2(1.0), pixelPos);
highp float dst2 = dstToLine(vec2(1.0), vec2(0.5, 0.0), pixelPos);
highp float dst3 = dstToLine(vec2(0.0, 1.0), vec2(0.5, 0.0), pixelPos);
highp float dst = min(min(dst1, dst2), dst3);
lowp float alpha = dst < texelSize ? dst / texelSize : smoothstep(texelSize, 0.0, dst - thickness);
lowp vec4 col = getRoundedColor(texture2D(m_Sampler, v_TexCoord), v_TexCoord);
gl_FragColor = vec4(col.rgb, col.a * alpha);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B