shuffle shaders

This commit is contained in:
jrkb 2023-05-29 10:08:00 +02:00
parent 0b41ae9f97
commit b107dbf57b
6 changed files with 28 additions and 43 deletions

View file

@ -1,12 +0,0 @@
#version 330 core
in vec2 position;
out vec3 color;
void main() {
float t = (position.y + 1.0) / 2.0;
vec3 bottom = vec3(75.0, 55.0, 201.0) / 255.0;
vec3 top = vec3(0.0, 12.0, 0.0) / 255.0;
color = mix(bottom, top, t);
}

View file

@ -1,15 +0,0 @@
#version 330 core
const vec2 vertices[4] = vec2[4](
vec2(-1.0, -1.0),
vec2( 1.0, -1.0),
vec2(-1.0, 1.0),
vec2( 1.0, 1.0)
);
out vec2 position;
void main() {
position = vertices[gl_VertexID];
gl_Position = vec4(vertices[gl_VertexID], 0.0, 1.0);
}

View file

@ -2,6 +2,7 @@
precision highp float;
precision highp isampler2D;
precision highp sampler2D;
precision highp sampler2DArray;
// Based on: http://wdobbie.com/post/gpu-text-rendering-with-vector-textures/
@ -12,12 +13,20 @@ struct Glyph {
struct Curve {
vec2 p0, p1, p2;
};
// CURVE_SIZE
// is the amount of vec2's in the curve
// we can hardcode this, as we can simply
// count the floats in the struct
// 6 floats => 3 vec2's
#define CURVE_SIZE 3
uniform isampler2D glyphs;
uniform sampler2D curves;
uniform sampler2DArray curves;
ivec3 curvesTextureSize;
int curveBreakPoint;
//uniform sampler2D iChannel0;
//uniform vec4 color;
// Controls for debugging and exploring:
// Size of the window (in pixels) used for 1-dimensional anti-aliasing along each rays.
@ -49,9 +58,14 @@ Glyph loadGlyph(int index) {
Curve loadCurve(int index) {
Curve result;
result.p0 = texelFetch(curves, ivec2(3*index+0, 0), 0).xy;
result.p1 = texelFetch(curves, ivec2(3*index+1, 0), 0).xy;
result.p2 = texelFetch(curves, ivec2(3*index+2, 0), 0).xy;
//int dw = curveBreakPoint; // width including dead space
int dw = curvesTextureSize[0];
int w = dw - (dw % CURVE_SIZE); // effectual width
int ix = (index * CURVE_SIZE) % w;
int iz = ((index * CURVE_SIZE) + 2) / w;
result.p0 = texelFetch(curves, ivec3(ix+0, 0, iz), 0).xy;
result.p1 = texelFetch(curves, ivec3(ix+1, 0, iz), 0).xy;
result.p2 = texelFetch(curves, ivec3(ix+2, 0, iz), 0).xy;
return result;
}
@ -109,25 +123,23 @@ vec2 rotate(vec2 v) {
}
void main() {
//vec4 debug = texture(curves, vec2(uv.x, 0.5));
//ivec4 debug = texture(glyphs, vec2(uv.x, 0.5));
////ivec4 debug = texelFetch(glyphs, ivec2(uv.x * float(textureSize(glyphs, 0).x), 0), 0);
//result = vec4(debug.rgb, 1.0);
Glyph gly = loadGlyph(bufferIndex);
result = vec4((float(gly.start) / 1883.0), (float(gly.count) / 42.0), 0.0, 1.0);
// verify bufferIndex [x]
//result = vec4((float(bufferIndex) / 100.0), 0.0, 0.0, 1.0);
return;
curvesTextureSize = textureSize(curves, 0);
curveBreakPoint = (curvesTextureSize[0] * 2) / 3;
//int w = curvesTextureSize[0]; // 16384 / 2 = 8192
float alpha = 0.0;
// Inverse of the diameter of a pixel in uv units for anti-aliasing.
vec2 inverseDiameter = 1.0 / (antiAliasingWindowSize * fwidth(uv));
vec4 c = color;
Glyph glyph = loadGlyph(bufferIndex);
for (int i = 0; i < glyph.count; i++) {
//if (glyph.start + i > curveBreakPoint) {
//c = vec4(1.0,0.0,0.0,1.0);
//}
Curve curve = loadCurve(glyph.start + i);
vec2 p0 = curve.p0 - uv;
@ -145,7 +157,7 @@ void main() {
}
alpha = clamp(alpha, 0.0, 1.0);
result = color * alpha;
result = vec4(c.rgb, c.a * alpha);
if (enableControlPointsVisualization) {
// Visualize control points.