import the woofer

This commit is contained in:
Haze Weathers 2025-03-01 17:50:05 -05:00
parent 825fee53e2
commit 3e89acfea8
92 changed files with 5783 additions and 0 deletions

View file

@ -0,0 +1,146 @@
shader_type canvas_item;
//the color with the highest priority.
// other colors will be tested based on distance to this
// color to determine which colors take priority for overlaps.
uniform vec3 highestColor = vec3(1.,1.,1.);
//how close two colors should be to be considered "similar".
// can group shapes of visually similar colors, but creates
// some artifacting and should be kept as low as possible.
uniform float similarThreshold = 0.0;
const float scale = 4.0;
const mat3 yuv_matrix = mat3(vec3(0.299, 0.587, 0.114), vec3(-0.169, -0.331, 0.5), vec3(0.5, -0.419, -0.081));
vec3 yuv(vec3 col){
mat3 yuv = transpose(yuv_matrix);
return yuv * col;
}
bool similar(vec4 col1, vec4 col2){
return (col1.a == 0. && col2.a == 0.) || distance(col1, col2) <= similarThreshold;
}
//multiple versions because godot doesn't support function overloading
//note: inner check should ideally check between all permutations
// but this is good enough, and faster
bool similar3(vec4 col1, vec4 col2, vec4 col3){
return similar(col1, col2) && similar(col2, col3);
}
bool similar4(vec4 col1, vec4 col2, vec4 col3, vec4 col4){
return similar(col1, col2) && similar(col2, col3) && similar(col3, col4);
}
bool similar5(vec4 col1, vec4 col2, vec4 col3, vec4 col4, vec4 col5){
return similar(col1, col2) && similar(col2, col3) && similar(col3, col4) && similar(col4, col5);
}
bool higher(vec4 thisCol, vec4 otherCol){
if(similar(thisCol, otherCol)) return false;
if(thisCol.a == otherCol.a){
// return yuv(thisCol.rgb).x > yuv(otherCol.rgb).x;
// return distance(yuv(thisCol.rgb), yuv(highestColor)) < distance(yuv(otherCol.rgb), yuv(highestColor));
return distance(thisCol.rgb, highestColor) < distance(otherCol.rgb, highestColor);
} else {
return thisCol.a > otherCol.a;
}
}
void fragment() {
vec2 size = 1.0/TEXTURE_PIXEL_SIZE+0.00001; //???
vec2 px = UV*size;
vec2 local = floor(mod(px,1.0)*scale);
vec2 localDiff = (local/1.0) - vec2(1.5, 1.5);
vec2 edge = floor(local/(scale/2.0))*(scale/2.0) - vec2(1.0, 1.0);
px = ceil(px);
vec4 baseCol = texture(TEXTURE, px/size);
vec4 col = baseCol;
vec4 c = baseCol;
// vec4 c = texture(TEXTURE, floor(px+(vec2(0.5,0.5)+edge/4.0))/size);
vec2 ot = vec2(edge.x, edge.y * 4.0);
vec4 t = texture(TEXTURE, floor(px+(vec2(0.5,0.5)+ot/4.0))/size);
vec2 otl = vec2(edge.x * 4.0, edge.y * 4.0);
vec4 tl = texture(TEXTURE, floor(px+(vec2(0.5,0.5)+otl/4.0))/size);
vec2 otr = vec2(-edge.x * 4.0, edge.y * 4.0);
vec4 tr = texture(TEXTURE, floor(px+(vec2(0.5,0.5)+otr/4.0))/size);
vec2 ol = vec2(edge.x * 4.0, edge.y);
vec4 l = texture(TEXTURE, floor(px+(vec2(0.5,0.5)+ol/4.0))/size);
vec2 ob = vec2(edge.x, -edge.y * 4.0);
vec4 b = texture(TEXTURE, floor(px+(vec2(0.5,0.5)+ob/4.0))/size);
vec2 obl = vec2(edge.x * 4.0, -edge.y * 4.0);
vec4 bl = texture(TEXTURE, floor(px+(vec2(0.5,0.5)+obl/4.0))/size);
vec2 obr = vec2(-edge.x * 4.0, -edge.y * 4.0);
vec4 br = texture(TEXTURE, floor(px+(vec2(0.5,0.5)+obr/4.0))/size);
vec2 or = vec2(-edge.x * 4.0, edge.y);
vec4 r = texture(TEXTURE, floor(px+(vec2(0.5,0.5)+or/4.0))/size);
vec2 os = vec2(localDiff.x, localDiff.y);
vec4 s = texture(TEXTURE, floor(px+(vec2(0.5,0.5)+os/2.0))/size);
//checkerboard special case
if(similar5(c, tl, tr, bl, br) && similar4(t, r, b, l) && higher(t, c)){
// if(local == vec2(0.,0.)){
// col = l;
// } else if(local == vec2(3.,0.)){
// col = r;
// } else if(local == vec2(0.,3.)){
// col = l;
// } else if(local == vec2(3.,3.)){
// col = r;
// }
} else {
//corner
if(length(localDiff) > 2.1){
if(similar(t, l) && !(similar(tl, c) && !higher(t, c))){
col = t;
} else if(higher(c, l) && higher(c, t) && (similar(tr, c) || similar(bl, c)) && !similar(tl, c)){
if(higher(t, l)){
col = t;
} else {
col = l;
}
}
//edge
} else if(length(localDiff) > 1.58) {
if(similar(t, l)){
if(higher(s, c)){
col = s;
}
}
if(similar3(r, s, tl) && similar3(br, c, l) && higher(s, c)/* && !similar(b, t)*/){
col = t;
}
if(!similar(tl, c) && similar3(r, c, bl) && similar3(tr, t, l) && higher(c, l)){
col = s;
}
if(!similar(tr, c) && similar3(l, c, br) && similar3(tl, s, r) && higher(c, r)){
col = s;
}
if(similar3(b, s, tl) && similar3(br, c, t) && higher(b, c)/* && !similar(r, l)*/){
col = s;
}
if(!similar(tl, c) && similar3(tr, c, b) && similar3(t, l, bl) && higher(c, l)){
col = s;
}
if(!similar(bl, c) && similar3(br, c, t) && similar3(b, s, tl) && higher(c, s)){
col = s;
}
}
}
//set alpha back to full, for manually adjusted pixels
if(col.a > 0.00001){
col.a = 1.0;
}
COLOR = col;
}

View file

@ -0,0 +1 @@
uid://0jlvid7baag0

View file

@ -0,0 +1,345 @@
/*** MIT LICENSE
Copyright (c) 2022 torcado
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
***/
shader_type canvas_item;
//enables 2:1 slopes. otherwise only uses 45 degree slopes
#define SLOPE
//cleans up small detail slope transitions (if SLOPE is enabled)
//if only using for rotation, CLEANUP has negligable effect and should be disabled for speed
//#define CLEANUP
//the color with the highest priority.
// other colors will be tested based on distance to this
// color to determine which colors take priority for overlaps.
uniform vec3 highestColor = vec3(1.,1.,1.);
//how close two colors should be to be considered "similar".
// can group shapes of visually similar colors, but creates
// some artifacting and should be kept as low as possible.
uniform float similarThreshold = 0.0;
uniform float lineWidth = 1.0;
const float scale = 4.0;
const mat3 yuv_matrix = mat3(vec3(0.299, 0.587, 0.114), vec3(-0.169, -0.331, 0.5), vec3(0.5, -0.419, -0.081));
vec3 yuv(vec3 col){
mat3 yuv = transpose(yuv_matrix);
return yuv * col;
}
bool similar(vec4 col1, vec4 col2){
return (col1.a == 0. && col2.a == 0.) || distance(col1, col2) <= similarThreshold;
}
//multiple versions because godot doesn't support function overloading
//note: inner check should ideally check between all permutations
// but this is good enough, and faster
bool similar3(vec4 col1, vec4 col2, vec4 col3){
return similar(col1, col2) && similar(col2, col3);
}
bool similar4(vec4 col1, vec4 col2, vec4 col3, vec4 col4){
return similar(col1, col2) && similar(col2, col3) && similar(col3, col4);
}
bool similar5(vec4 col1, vec4 col2, vec4 col3, vec4 col4, vec4 col5){
return similar(col1, col2) && similar(col2, col3) && similar(col3, col4) && similar(col4, col5);
}
bool higher(vec4 thisCol, vec4 otherCol){
if(similar(thisCol, otherCol)) return false;
if(thisCol.a == otherCol.a){
// return yuv(thisCol.rgb).x > yuv(otherCol.rgb).x;
// return distance(yuv(thisCol.rgb), yuv(highestColor)) < distance(yuv(otherCol.rgb), yuv(highestColor));
return distance(thisCol.rgb, highestColor) < distance(otherCol.rgb, highestColor);
} else {
return thisCol.a > otherCol.a;
}
}
vec4 higherCol(vec4 thisCol, vec4 otherCol){
return higher(thisCol, otherCol) ? thisCol : otherCol;
}
//color distance
float cd(vec4 col1, vec4 col2){
return distance(col1.rgba, col2.rgba);
}
float distToLine(vec2 testPt, vec2 pt1, vec2 pt2, vec2 dir){
vec2 lineDir = pt2 - pt1;
vec2 perpDir = vec2(lineDir.y, -lineDir.x);
vec2 dirToPt1 = pt1 - testPt;
return (dot(perpDir, dir) > 0.0 ? 1.0 : -1.0) * (dot(normalize(perpDir), dirToPt1));
}
//based on down-forward direction
vec4 sliceDist(vec2 point, vec2 mainDir, vec2 pointDir, vec4 ub, vec4 u, vec4 uf, vec4 uff, vec4 b, vec4 c, vec4 f, vec4 ff, vec4 db, vec4 d, vec4 df, vec4 dff, vec4 ddb, vec4 dd, vec4 ddf){
//clamped range prevents inacccurate identity (no change) result, feel free to disable if necessary
#ifdef SLOPE
float minWidth = 0.45;
float maxWidth = 1.142;
#else
float minWidth = 0.0;
float maxWidth = 1.4;
#endif
float _lineWidth = max(minWidth, min(maxWidth, lineWidth));
point = mainDir * (point - 0.5) + 0.5; //flip point
//edge detection
float distAgainst = 4.0*cd(f,d) + cd(uf,c) + cd(c,db) + cd(ff,df) + cd(df,dd);
float distTowards = 4.0*cd(c,df) + cd(u,f) + cd(f,dff) + cd(b,d) + cd(d,ddf);
bool shouldSlice =
(distAgainst < distTowards)
|| (distAgainst < distTowards + 0.001) && !higher(c, f); //equivalent edges edge case
if(similar4(f, d, b, u) && similar4(uf, df, db, ub) && !similar(c, f)){ //checkerboard edge case
shouldSlice = false;
}
if(!shouldSlice) return vec4(-1.0);
//only applicable for very large lineWidth (>1.3)
// if(similar3(c, f, df)){ //don't make slice for same color
// return vec4(-1.0);
// }
float dist = 1.0;
bool flip = false;
vec2 center = vec2(0.5,0.5);
#ifdef SLOPE
if(similar3(f, d, db) && !similar3(f, d, b) && !similar(uf, db)){ //lower shallow 2:1 slant
if(similar(c, df) && higher(c, f)){ //single pixel wide diagonal, dont flip
} else {
//priority edge cases
if(higher(c, f)){
flip = true;
}
if(similar(u, f) && !similar(c, df) && !higher(c, u)){
flip = true;
}
}
if(flip){
dist = _lineWidth-distToLine(point, center+vec2(1.5, -1.0)*pointDir, center+vec2(-0.5, 0.0)*pointDir, -pointDir); //midpoints of neighbor two-pixel groupings
} else {
dist = distToLine(point, center+vec2(1.5, 0.0)*pointDir, center+vec2(-0.5, 1.0)*pointDir, pointDir); //midpoints of neighbor two-pixel groupings
}
//cleanup slant transitions
#ifdef CLEANUP
if(!flip && similar(c, uf) && !(similar3(c, uf, uff) && !similar3(c, uf, ff) && !similar(d, uff))){ //shallow
float dist2 = distToLine(point, center+vec2(2.0, -1.0)*pointDir, center+vec2(-0.0, 1.0)*pointDir, pointDir);
dist = min(dist, dist2);
}
#endif
dist -= (_lineWidth/2.0);
return dist <= 0.0 ? ((cd(c,f) <= cd(c,d)) ? f : d) : vec4(-1.0);
} else if(similar3(uf, f, d) && !similar3(u, f, d) && !similar(uf, db)){ //forward steep 2:1 slant
if(similar(c, df) && higher(c, d)){ //single pixel wide diagonal, dont flip
} else {
//priority edge cases
if(higher(c, d)){
flip = true;
}
if(similar(b, d) && !similar(c, df) && !higher(c, d)){
flip = true;
}
}
if(flip){
dist = _lineWidth-distToLine(point, center+vec2(0.0, -0.5)*pointDir, center+vec2(-1.0, 1.5)*pointDir, -pointDir); //midpoints of neighbor two-pixel groupings
} else {
dist = distToLine(point, center+vec2(1.0, -0.5)*pointDir, center+vec2(0.0, 1.5)*pointDir, pointDir); //midpoints of neighbor two-pixel groupings
}
//cleanup slant transitions
#ifdef CLEANUP
if(!flip && similar(c, db) && !(similar3(c, db, ddb) && !similar3(c, db, dd) && !similar(f, ddb))){ //steep
float dist2 = distToLine(point, center+vec2(1.0, 0.0)*pointDir, center+vec2(-1.0, 2.0)*pointDir, pointDir);
dist = min(dist, dist2);
}
#endif
dist -= (_lineWidth/2.0);
return dist <= 0.0 ? ((cd(c,f) <= cd(c,d)) ? f : d) : vec4(-1.0);
} else
#endif
if(similar(f, d)) { //45 diagonal
if(similar(c, df) && higher(c, f)){ //single pixel diagonal along neighbors, dont flip
if(!similar(c, dd) && !similar(c, ff)){ //line against triple color stripe edge case
flip = true;
}
} else {
//priority edge cases
if(higher(c, f)){
flip = true;
}
if(!similar(c, b) && similar4(b, f, d, u)){
flip = true;
}
}
//single pixel 2:1 slope, dont flip
if((( (similar(f, db) && similar3(u, f, df)) || (similar(uf, d) && similar3(b, d, df)) ) && !similar(c, df))){
flip = true;
}
if(flip){
dist = _lineWidth-distToLine(point, center+vec2(1.0, -1.0)*pointDir, center+vec2(-1.0, 1.0)*pointDir, -pointDir); //midpoints of own diagonal pixels
} else {
dist = distToLine(point, center+vec2(1.0, 0.0)*pointDir, center+vec2(0.0, 1.0)*pointDir, pointDir); //midpoints of corner neighbor pixels
}
//cleanup slant transitions
#ifdef SLOPE
#ifdef CLEANUP
if(!flip && similar3(c, uf, uff) && !similar3(c, uf, ff) && !similar(d, uff)){ //shallow
float dist2 = distToLine(point, center+vec2(1.5, 0.0)*pointDir, center+vec2(-0.5, 1.0)*pointDir, pointDir);
dist = max(dist, dist2);
}
if(!flip && similar3(ddb, db, c) && !similar3(dd, db, c) && !similar(ddb, f)){ //steep
float dist2 = distToLine(point, center+vec2(1.0, -0.5)*pointDir, center+vec2(0.0, 1.5)*pointDir, pointDir);
dist = max(dist, dist2);
}
#endif
#endif
dist -= (_lineWidth/2.0);
return dist <= 0.0 ? ((cd(c,f) <= cd(c,d)) ? f : d) : vec4(-1.0);
}
#ifdef SLOPE
else if(similar3(ff, df, d) && !similar3(ff, df, c) && !similar(uff, d)){ //far corner of shallow slant
if(similar(f, dff) && higher(f, ff)){ //single pixel wide diagonal, dont flip
} else {
//priority edge cases
if(higher(f, ff)){
flip = true;
}
if(similar(uf, ff) && !similar(f, dff) && !higher(f, uf)){
flip = true;
}
}
if(flip){
dist = _lineWidth-distToLine(point, center+vec2(1.5+1.0, -1.0)*pointDir, center+vec2(-0.5+1.0, 0.0)*pointDir, -pointDir); //midpoints of neighbor two-pixel groupings
} else {
dist = distToLine(point, center+vec2(1.5+1.0, 0.0)*pointDir, center+vec2(-0.5+1.0, 1.0)*pointDir, pointDir); //midpoints of neighbor two-pixel groupings
}
dist -= (_lineWidth/2.0);
return dist <= 0.0 ? ((cd(f,ff) <= cd(f,df)) ? ff : df) : vec4(-1.0);
} else if(similar3(f, df, dd) && !similar3(c, df, dd) && !similar(f, ddb)){ //far corner of steep slant
if(similar(d, ddf) && higher(d, dd)){ //single pixel wide diagonal, dont flip
} else {
//priority edge cases
if(higher(d, dd)){
flip = true;
}
if(similar(db, dd) && !similar(d, ddf) && !higher(d, dd)){
flip = true;
}
// if(!higher(d, dd)){
// return vec4(1.0);
// flip = true;
// }
}
if(flip){
dist = _lineWidth-distToLine(point, center+vec2(0.0, -0.5+1.0)*pointDir, center+vec2(-1.0, 1.5+1.0)*pointDir, -pointDir); //midpoints of neighbor two-pixel groupings
} else {
dist = distToLine(point, center+vec2(1.0, -0.5+1.0)*pointDir, center+vec2(0.0, 1.5+1.0)*pointDir, pointDir); //midpoints of neighbor two-pixel groupings
}
dist -= (_lineWidth/2.0);
return dist <= 0.0 ? ((cd(d,df) <= cd(d,dd)) ? df : dd) : vec4(-1.0);
}
#endif
return vec4(-1.0);
}
void fragment() {
vec2 size = 1.0/TEXTURE_PIXEL_SIZE+0.0001; //fix for some sort of rounding error
vec2 px = UV*size;
vec2 local = fract(px);
px = ceil(px);
vec2 pointDir = round(local)*2.0-1.0;
//neighbor pixels
//Up, Down, Forward, and Back
//relative to quadrant of current location within pixel
vec4 uub = texture(TEXTURE, (px+vec2(-1.0,-2.0)*pointDir)/size);
vec4 uu = texture(TEXTURE, (px+vec2( 0.0,-2.0)*pointDir)/size);
vec4 uuf = texture(TEXTURE, (px+vec2( 1.0,-2.0)*pointDir)/size);
vec4 ubb = texture(TEXTURE, (px+vec2(-2.0,-2.0)*pointDir)/size);
vec4 ub = texture(TEXTURE, (px+vec2(-1.0,-1.0)*pointDir)/size);
vec4 u = texture(TEXTURE, (px+vec2( 0.0,-1.0)*pointDir)/size);
vec4 uf = texture(TEXTURE, (px+vec2( 1.0,-1.0)*pointDir)/size);
vec4 uff = texture(TEXTURE, (px+vec2( 2.0,-1.0)*pointDir)/size);
vec4 bb = texture(TEXTURE, (px+vec2(-2.0, 0.0)*pointDir)/size);
vec4 b = texture(TEXTURE, (px+vec2(-1.0, 0.0)*pointDir)/size);
vec4 c = texture(TEXTURE, (px+vec2( 0.0, 0.0)*pointDir)/size);
vec4 f = texture(TEXTURE, (px+vec2( 1.0, 0.0)*pointDir)/size);
vec4 ff = texture(TEXTURE, (px+vec2( 2.0, 0.0)*pointDir)/size);
vec4 dbb = texture(TEXTURE, (px+vec2(-2.0, 1.0)*pointDir)/size);
vec4 db = texture(TEXTURE, (px+vec2(-1.0, 1.0)*pointDir)/size);
vec4 d = texture(TEXTURE, (px+vec2( 0.0, 1.0)*pointDir)/size);
vec4 df = texture(TEXTURE, (px+vec2( 1.0, 1.0)*pointDir)/size);
vec4 dff = texture(TEXTURE, (px+vec2( 2.0, 1.0)*pointDir)/size);
vec4 ddb = texture(TEXTURE, (px+vec2(-1.0, 2.0)*pointDir)/size);
vec4 dd = texture(TEXTURE, (px+vec2( 0.0, 2.0)*pointDir)/size);
vec4 ddf = texture(TEXTURE, (px+vec2( 1.0, 2.0)*pointDir)/size);
vec4 col = c;
//c_orner, b_ack, and u_p slices
// (slices from neighbor pixels will only ever reach these 3 quadrants
vec4 c_col = sliceDist(local, vec2( 1.0, 1.0), pointDir, ub, u, uf, uff, b, c, f, ff, db, d, df, dff, ddb, dd, ddf);
vec4 b_col = sliceDist(local, vec2(-1.0, 1.0), pointDir, uf, u, ub, ubb, f, c, b, bb, df, d, db, dbb, ddf, dd, ddb);
vec4 u_col = sliceDist(local, vec2( 1.0,-1.0), pointDir, db, d, df, dff, b, c, f, ff, ub, u, uf, uff, uub, uu, uuf);
if(c_col.r >= 0.0){
col = c_col;
}
if(b_col.r >= 0.0){
col = b_col;
}
if(u_col.r >= 0.0){
col = u_col;
}
COLOR = col;
}

View file

@ -0,0 +1 @@
uid://c3wn7vy5wqvyv