shuffle shaders
This commit is contained in:
parent
0b41ae9f97
commit
b107dbf57b
6 changed files with 28 additions and 43 deletions
|
@ -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);
|
|
||||||
}
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -2,6 +2,7 @@
|
||||||
precision highp float;
|
precision highp float;
|
||||||
precision highp isampler2D;
|
precision highp isampler2D;
|
||||||
precision highp sampler2D;
|
precision highp sampler2D;
|
||||||
|
precision highp sampler2DArray;
|
||||||
|
|
||||||
// Based on: http://wdobbie.com/post/gpu-text-rendering-with-vector-textures/
|
// Based on: http://wdobbie.com/post/gpu-text-rendering-with-vector-textures/
|
||||||
|
|
||||||
|
@ -12,12 +13,20 @@ struct Glyph {
|
||||||
struct Curve {
|
struct Curve {
|
||||||
vec2 p0, p1, p2;
|
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 isampler2D glyphs;
|
||||||
uniform sampler2D curves;
|
uniform sampler2DArray curves;
|
||||||
|
ivec3 curvesTextureSize;
|
||||||
|
int curveBreakPoint;
|
||||||
|
//uniform sampler2D iChannel0;
|
||||||
//uniform vec4 color;
|
//uniform vec4 color;
|
||||||
|
|
||||||
|
|
||||||
// Controls for debugging and exploring:
|
// Controls for debugging and exploring:
|
||||||
|
|
||||||
// Size of the window (in pixels) used for 1-dimensional anti-aliasing along each rays.
|
// 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 loadCurve(int index) {
|
||||||
Curve result;
|
Curve result;
|
||||||
result.p0 = texelFetch(curves, ivec2(3*index+0, 0), 0).xy;
|
//int dw = curveBreakPoint; // width including dead space
|
||||||
result.p1 = texelFetch(curves, ivec2(3*index+1, 0), 0).xy;
|
int dw = curvesTextureSize[0];
|
||||||
result.p2 = texelFetch(curves, ivec2(3*index+2, 0), 0).xy;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,25 +123,23 @@ vec2 rotate(vec2 v) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
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);
|
curvesTextureSize = textureSize(curves, 0);
|
||||||
result = vec4((float(gly.start) / 1883.0), (float(gly.count) / 42.0), 0.0, 1.0);
|
curveBreakPoint = (curvesTextureSize[0] * 2) / 3;
|
||||||
|
//int w = curvesTextureSize[0]; // 16384 / 2 = 8192
|
||||||
// verify bufferIndex [x]
|
|
||||||
//result = vec4((float(bufferIndex) / 100.0), 0.0, 0.0, 1.0);
|
|
||||||
return;
|
|
||||||
|
|
||||||
float alpha = 0.0;
|
float alpha = 0.0;
|
||||||
|
|
||||||
// Inverse of the diameter of a pixel in uv units for anti-aliasing.
|
// Inverse of the diameter of a pixel in uv units for anti-aliasing.
|
||||||
vec2 inverseDiameter = 1.0 / (antiAliasingWindowSize * fwidth(uv));
|
vec2 inverseDiameter = 1.0 / (antiAliasingWindowSize * fwidth(uv));
|
||||||
|
|
||||||
|
vec4 c = color;
|
||||||
|
|
||||||
Glyph glyph = loadGlyph(bufferIndex);
|
Glyph glyph = loadGlyph(bufferIndex);
|
||||||
for (int i = 0; i < glyph.count; i++) {
|
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);
|
Curve curve = loadCurve(glyph.start + i);
|
||||||
|
|
||||||
vec2 p0 = curve.p0 - uv;
|
vec2 p0 = curve.p0 - uv;
|
||||||
|
@ -145,7 +157,7 @@ void main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
alpha = clamp(alpha, 0.0, 1.0);
|
alpha = clamp(alpha, 0.0, 1.0);
|
||||||
result = color * alpha;
|
result = vec4(c.rgb, c.a * alpha);
|
||||||
|
|
||||||
if (enableControlPointsVisualization) {
|
if (enableControlPointsVisualization) {
|
||||||
// Visualize control points.
|
// Visualize control points.
|
Loading…
Reference in a new issue