mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Pass a transformation matrix in CommonRotation shaders instead of an angle
This will allow us to implement shearing more easily. Also, for the non-SmearRotxel shaders, normalize their pivot in GDScript, before passing it to the script. Should probably be faster this way
This commit is contained in:
parent
25f7192573
commit
e15b207993
|
@ -1,22 +1,14 @@
|
|||
uniform sampler2D selection_tex : filter_nearest;
|
||||
uniform vec2 pivot_pixel;
|
||||
uniform float angle;
|
||||
uniform vec2 pivot;
|
||||
uniform mat2 transformation_matrix;
|
||||
|
||||
vec2 rotate(vec2 uv, vec2 pivot, float ratio) {
|
||||
vec2 rotate(vec2 uv, float ratio) {
|
||||
// Scale and center image
|
||||
uv.x -= pivot.x;
|
||||
uv.x *= ratio;
|
||||
uv.x += pivot.x;
|
||||
uv.x = (uv.x - pivot.x) * ratio + pivot.x;
|
||||
uv -= pivot;
|
||||
|
||||
// Rotate image
|
||||
uv -= pivot;
|
||||
mat3 transformation = mat3(
|
||||
vec3(cos(angle), -sin(angle), 0.0),
|
||||
vec3(sin(angle), cos(angle), 0.0),
|
||||
vec3(0.0, 0.0, 1.0)
|
||||
);
|
||||
|
||||
uv = (transformation * vec3(uv, 1.0)).xy;
|
||||
uv *= transformation_matrix;
|
||||
uv.x /= ratio;
|
||||
uv += pivot;
|
||||
|
||||
|
|
|
@ -8,10 +8,9 @@ void fragment() {
|
|||
vec4 original = texture(TEXTURE, UV);
|
||||
vec2 tex_size = 1.0 / TEXTURE_PIXEL_SIZE; // Texture size in real pixel coordinates
|
||||
vec2 pixelated_uv = floor(UV * tex_size) / (tex_size - 1.0); // Pixelate UV to fit resolution
|
||||
vec2 pivot = pivot_pixel / tex_size; // Normalize pivot position
|
||||
float ratio = tex_size.x / tex_size.y; // Resolution ratio
|
||||
|
||||
vec2 rotated_uv = rotate(pixelated_uv, pivot, ratio);
|
||||
vec2 rotated_uv = rotate(pixelated_uv, ratio);
|
||||
vec4 rotated_color = texture(TEXTURE, rotated_uv); // Rotated image
|
||||
COLOR = mix_rotated_and_original(rotated_color, original, UV, rotated_uv, TEXTURE_PIXEL_SIZE);
|
||||
}
|
||||
|
|
|
@ -292,15 +292,14 @@ void fragment()
|
|||
{
|
||||
vec4 original = texture(TEXTURE, UV);
|
||||
vec2 size = 1.0 / TEXTURE_PIXEL_SIZE;
|
||||
vec2 pivot = pivot_pixel / size; // Normalize pivot position
|
||||
float ratio = size.x / size.y; // Resolution ratio
|
||||
vec2 pixelated_uv = floor(UV * size) / (size - 1.0); // Pixelate UV to fit resolution
|
||||
vec2 rotated_uv;
|
||||
if (preview) {
|
||||
rotated_uv = rotate(pixelated_uv, pivot, ratio);
|
||||
rotated_uv = rotate(pixelated_uv, ratio);
|
||||
}
|
||||
else {
|
||||
rotated_uv = rotate(UV, pivot, ratio);
|
||||
rotated_uv = rotate(UV, ratio);
|
||||
}
|
||||
vec4 c = scale(TEXTURE, rotated_uv, TEXTURE_PIXEL_SIZE);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ uniform sampler2D selection_tex : filter_nearest;
|
|||
uniform float initial_angle = 0.0;
|
||||
uniform float ending_angle = 0.0;
|
||||
uniform float tolerance : hint_range(0.0, 255.0) = 100.0;
|
||||
uniform vec2 origin = vec2(0.0, 0.0);
|
||||
uniform vec2 pivot = vec2(0.0, 0.0);
|
||||
uniform vec2 position = vec2(0.0, 0.0);
|
||||
|
||||
bool similarColors(vec4 c1, vec4 c2) {
|
||||
|
@ -16,7 +16,7 @@ bool similarColors(vec4 c1, vec4 c2) {
|
|||
|
||||
vec4 rotate(sampler2D tex, vec2 uv, vec2 tex_pixel_size) {
|
||||
vec4 color = vec4(0.0);
|
||||
vec2 center = origin / tex_pixel_size;
|
||||
vec2 center = pivot / tex_pixel_size;
|
||||
vec2 size = 1.0 / tex_pixel_size;
|
||||
vec2 coord = uv / tex_pixel_size + position;
|
||||
int dx = 3 * (int(coord.x) - int(center.x));
|
||||
|
@ -113,7 +113,7 @@ vec4 rotate(sampler2D tex, vec2 uv, vec2 tex_pixel_size) {
|
|||
// The exact same as rotate, but had to be re-defined due to https://github.com/godotengine/godot/issues/75935
|
||||
vec4 rotate_uniform(sampler2D tex, vec2 uv, vec2 tex_pixel_size) {
|
||||
vec4 color = vec4(0.0);
|
||||
vec2 center = origin / tex_pixel_size;
|
||||
vec2 center = pivot / tex_pixel_size;
|
||||
vec2 size = 1.0 / tex_pixel_size;
|
||||
vec2 coord = uv / tex_pixel_size + position;
|
||||
int dx = 3 * (int(coord.x) - int(center.x));
|
||||
|
|
|
@ -275,15 +275,14 @@ void fragment() {
|
|||
vec2 size = 1.0/TEXTURE_PIXEL_SIZE+0.0001; //fix for some sort of rounding error
|
||||
// Pixelorama edit
|
||||
vec4 original = texture(TEXTURE, UV);
|
||||
vec2 pivot = pivot_pixel / size; // Normalize pivot position
|
||||
float ratio = size.x / size.y; // Resolution ratio
|
||||
vec2 pixelated_uv = floor(UV * size) / (size - 1.0); // Pixelate UV to fit resolutio
|
||||
vec2 rotated_uv;
|
||||
if (preview) {
|
||||
rotated_uv = rotate(pixelated_uv, pivot, ratio);
|
||||
rotated_uv = rotate(pixelated_uv, ratio);
|
||||
}
|
||||
else {
|
||||
rotated_uv = rotate(UV, pivot, ratio);
|
||||
rotated_uv = rotate(UV, ratio);
|
||||
}
|
||||
vec2 px = rotated_uv * size;
|
||||
vec2 local = fract(px);
|
||||
|
|
|
@ -99,17 +99,16 @@ func commit_action(cel: Image, _project := Global.current_project) -> void:
|
|||
if _type_is_shader():
|
||||
var shader := rotxel_shader
|
||||
var params := {
|
||||
"angle": angle, "selection_tex": selection_tex, "pivot_pixel": pivot, "preview": true
|
||||
"transformation_matrix": Transform2D(angle, Vector2.ZERO),
|
||||
"selection_tex": selection_tex,
|
||||
"pivot": pivot / Vector2(cel.get_size()),
|
||||
"preview": true
|
||||
}
|
||||
match type_option_button.get_selected_id():
|
||||
ROTXEL_SMEAR:
|
||||
params = {
|
||||
"initial_angle": init_angle,
|
||||
"ending_angle": angle,
|
||||
"tolerance": tolerance_slider.value,
|
||||
"selection_tex": selection_tex,
|
||||
"origin": pivot / Vector2(cel.get_size()),
|
||||
}
|
||||
params["ending_angle"] = angle
|
||||
params["initial_angle"] = init_angle
|
||||
params["tolerance"] = tolerance_slider.value
|
||||
CLEANEDGE:
|
||||
shader = DrawingAlgos.clean_edge_shader
|
||||
OMNISCALE:
|
||||
|
|
Loading…
Reference in a new issue