Remove twgl

This commit is contained in:
schmelczerandras 2020-07-19 22:15:18 +02:00
parent 13942af41c
commit ac66c91000
16 changed files with 364 additions and 154 deletions

View file

@ -22,53 +22,15 @@ struct Line {
bool isLineEnd;
}[16] lines;
float noise(float x){
return fract(sin(x) * 43758.5453123);
}
float terrain(float x) {
float result = 0.0;
float frequency = 0.01;
float amplitude = 1.0;
for (int i = 0; i < 8; i++) {
result += sin(2.0 * pi * x * frequency - 2.0 * pi * noise(float(i) * 200.0)) * amplitude;
frequency *= 1.5;
amplitude /= 1.2;
}
return result;
}
vec2 random2(vec2 st){
st = vec2( dot(st,vec2(127.1,311.7)),
dot(st,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(st)*43758.5453123);
}
float noise(vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = f*f*(3.0-2.0*f);
return mix( mix( dot( random2(i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),
dot( random2(i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),
mix( dot( random2(i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),
dot( random2(i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);
}
float lineDistance(in vec2 position, in Line line, out float h) {
vec2 pa = position - line.a, ba = line.b - line.a;
h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
vec2 delta = pa - ba*h;
// sign can return 0, double sign prevents this
// sign can return 0, double sign prevents this
float side = sign(sign(dot(delta, line.normal)) - 0.5);
return length(delta) * side + terrain(length(ba * h));
return length(delta) * side;
}
Line endDummyLineFromLine(Line line) {
return Line(line.b, line.b + rotate90deg(line.normal), line.normal, false);
}
@ -140,7 +102,6 @@ void createWorld() {
}
}
uniform vec2 cameraPosition;
uniform vec2 viewBoxSize;
uniform vec2 resolution;
@ -152,6 +113,6 @@ void main() {
vec2 pixelPosition = gl_FragCoord.xy + vec2(0.5);
vec2 position = pixelPosition / resolution * viewBoxSize + cameraPosition;
//fragmentColor = getDistance(position) > 0.0 ? vec4(0.0, 0.0, 0.0, 0.0) : vec4(0.0, 0.0, 0.0, 1.0);
fragmentColor = vec4(vec3(1.0) * clamp(0.0, 1.0, getDistance(position)), 1.0);
}