Skip to content

Commit

Permalink
HOTFIX Regression on zigzag
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanmcdonald committed Jun 27, 2021
1 parent 1fe7d01 commit fca65ce
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 43 deletions.
33 changes: 21 additions & 12 deletions shader/brush/zigzag2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@
// https://github.com/lachlanmcdonald/magicavoxel-shaders
// Copyright (c) 2021 Lachlan McDonald
//
// xs brush/zigzag2 [Direction] [Width A] [Width B]
// xs brush/zigzag2 [Direction] [Width A] [Width B] [Color A] [Color B]
//
// xs_begin
// author : '@lachlanmcdonald'
// arg : { id = '0' name = 'Direction' value = '0' range = '0 3' step = '1' decimal = '0' }
// arg : { id = '1' name = 'Width A' value = '2' var = 'width_a' range = '1 256' step = '1' decimal = '0' }
// arg : { id = '2' name = 'Width B' value = '2' var = 'width_b' range = '1 256' step = '1' decimal = '0' }
// arg : { id = '1' name = 'Width A' value = '2' range = '1 256' step = '1' decimal = '0' }
// arg : { id = '2' name = 'Width B' value = '2' range = '1 256' step = '1' decimal = '0' }
// arg : { id = '3' name = 'Color A' value = '1' range = '0 255' step = '1' decimal = '0' }
// arg : { id = '4' name = 'Color B' value = '9' range = '0 255' step = '1' decimal = '0' }
// xs_end

int direction = int(i_args[0]);
float width_a = i_args[1];
float width_b = i_args[2];
float color_a = i_args[3];
float color_b = i_args[4];

float map(vec3 v) {
v = floor(v);

if (direction == 1) {
v.y = -v.y;
} else if (direction == 2) {
Expand All @@ -24,20 +32,21 @@ float map(vec3 v) {
}

float size = width_a + width_b;
vec3 c = floor(v / size);
vec3 ic = floor(v - c * size);
float row = floor(v.y / size);
float col = floor(v.x / size);
vec2 k = v.xy - vec2(col, row) * size;

if (mod(c.x + c.y, 2.0) == 0.0) {
if (any(lessThan(ic.xy, vec2(width_a)))) {
return color_sel(0.0);
if (mod(row + col, 2.0) == 0.0) {
if (k.x < width_a && k.y < width_a) {
return color_a;
} else {
return i_num_color_sels < 2 ? 0.0 : color_sel(1.0);
return color_b;
}
} else {
if (all(lessThan(ic.xy, vec2(width_a)))) {
return color_sel(0.0);
if (k.x < width_a || k.y < width_a) {
return color_a;
} else {
return i_num_color_sels < 2 ? 0.0 : color_sel(1.0);
return color_b;
}
}
}
11 changes: 7 additions & 4 deletions shader/brush/zigzag3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
// https://github.com/lachlanmcdonald/magicavoxel-shaders
// Copyright (c) 2021 Lachlan McDonald
//
// xs brush/zigzag3 [Direction] [Width A] [Width B] [Width C]
// xs brush/zigzag3 [Direction] [Width A] [Width B] [Width C] [Color A] [Color B] [Color C]
//
// xs_begin
// author : '@lachlanmcdonald'
// arg : { id = '0' name = 'Direction' value = '0' range = '0 3' step = '1' decimal = '0' }
// arg : { id = '1' name = 'Width A' value = '2' var = 'width_a' range = '1 256' step = '1' decimal = '0' }
// arg : { id = '2' name = 'Width B' value = '2' var = 'width_b' range = '1 256' step = '1' decimal = '0' }
// arg : { id = '3' name = 'Width C' value = '2' var = 'width_c' range = '1 256' step = '1' decimal = '0' }
// arg : { id = '1' name = 'Width A' value = '2' range = '1 256' step = '1' decimal = '0' }
// arg : { id = '2' name = 'Width B' value = '2' range = '1 256' step = '1' decimal = '0' }
// arg : { id = '3' name = 'Width C' value = '2' range = '1 256' step = '1' decimal = '0' }
// arg : { id = '4' name = 'Color A' value = '1' range = '0 255' step = '1' decimal = '0' }
// arg : { id = '5' name = 'Color B' value = '9' range = '0 255' step = '1' decimal = '0' }
// arg : { id = '6' name = 'Color C' value = '18' range = '0 255' step = '1' decimal = '0' }
// xs_end

int direction = int(i_args[0]);
Expand Down
24 changes: 12 additions & 12 deletions shader/brush/zigzag.txt → shader/brush/zigzag_range.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@
// https://github.com/lachlanmcdonald/magicavoxel-shaders
// Copyright (c) 2021 Lachlan McDonald
//
// xs brush/zigzag [Direction] [Width]
// xs brush/zigzag_range [Direction] [Width] [Color A] [Color B]
//
// xs_begin
// author : '@lachlanmcdonald'
// arg : { id = '0' name = 'Direction' value = '0' range = '0 3' step = '1' decimal = '0' }
// arg : { id = '1' name = 'Width' value = '2' range = '1 256' step = '1' decimal = '0' }
// arg : { id = '2' name = 'Color A' value = '1' range = '0 255' step = '1' decimal = '0' }
// arg : { id = '3' name = 'Color B' value = '9' range = '0 255' step = '1' decimal = '0' }
// xs_end

int direction = int(i_args[0]);
float width = i_args[1];

float roundf(float f) {
return f >= 0.5 ? ceil(f) : floor(f);
}

float pal_mix(float p) {
float f = roundf(mix(0.0, float(i_num_color_sels), p));
return color_sel(f);
}
float pal_min = i_args[2];
float pal_max = i_args[3];

float map(vec3 v) {
v = floor(v);
Expand All @@ -34,11 +29,16 @@ float map(vec3 v) {
v.x = -v.x;
}

float size = floor(float(i_num_color_sels) * width);
float size = floor((max(pal_max, pal_min) - min(pal_max, pal_min) + 1.0) * width);
float row = floor(v.y / size);
float col = floor(v.x / size);
vec2 k = v.xy - vec2(col, row) * size;

float p = mod(row + col, 2.0) == 0.0 ? min(k.x, k.y) : max(k.x, k.y);
return color_sel(floor(p / width));

if (pal_min > pal_max) {
return pal_min - floor(p / width);
} else {
return pal_min + floor(p / width);
}
}
48 changes: 33 additions & 15 deletions shaders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,6 @@ shaders:
value: 1
- name: Seed
type: seed
brush/zigzag:
params:
- decimal: 0
name: Direction
range: 0 3
step: 1
value: 0
- name: Width
type: size
value: 2
brush/zigzag2:
params:
- decimal: 0
Expand All @@ -303,12 +293,16 @@ shaders:
value: 0
- name: Width A
type: size
var: width_a
value: 2
- name: Width B
type: size
var: width_b
value: 2
- name: Color A
type: colorA
value: 1
- name: Color B
type: colorB
value: 9
brush/zigzag3:
params:
- decimal: 0
Expand All @@ -317,17 +311,39 @@ shaders:
step: 1
value: 0
- name: Width A
var: width_a
type: size
value: 2
- name: Width B
var: width_b
type: size
value: 2
- name: Width C
var: width_c
type: size
value: 2
- name: Color A
type: colorA
value: 1
- name: Color B
type: colorB
value: 9
- name: Color C
type: colorB
value: 18
brush/zigzag_range:
params:
- decimal: 0
name: Direction
range: 0 3
step: 1
value: 0
- name: Width
type: size
value: 2
- name: Color A
type: colorA
value: 1
- name: Color B
type: colorB
value: 9
case:
params:
- name: Color
Expand Down Expand Up @@ -521,11 +537,13 @@ shaders:
value: 1
types:
colorA:
name: Color A
decimal: 0
range: 0 255
step: 1
value: 1
colorB:
name: Color B
decimal: 0
range: 0 255
step: 1
Expand Down

0 comments on commit fca65ce

Please sign in to comment.