1
0
mirror of https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git synced 2025-01-05 00:53:36 +08:00

ShaderIncl files refactored

This commit is contained in:
Digvijaysinh Gohil 2024-08-06 16:23:43 +05:30
parent 21213d657e
commit d72153b7c4
5 changed files with 127 additions and 134 deletions

View File

@ -1,9 +1,9 @@
vec3 contrast(vec3 input, float contrast){
vec3 contrast(vec3 input, float contrast) {
float midpoint = pow(0.5, 2.2);
return (input - midpoint) * contrast + midpoint;
}
vec3 hue(vec3 input, float offset, int range_index){
vec3 hue(vec3 input, float offset, int range_index) {
// RGB to HSV
vec4 k = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(input.bg, k.wz), vec4(input.gb, k.xy), step(input.b, input.g));
@ -31,17 +31,17 @@ vec3 hue(vec3 input, float offset, int range_index){
return rgb;
}
vec3 replace_color(vec3 input, vec3 from, vec3 to, float range, float fuzziness){
vec3 replace_color(vec3 input, vec3 from, vec3 to, float range, float fuzziness) {
float dist = distance(from, input);
return mix(to, input, clamp((dist - range) / max(fuzziness, 1.0e-5), 0.0, 1.0));
}
vec3 saturation(vec3 input, float saturation){
vec3 saturation(vec3 input, float saturation) {
float luma = dot(input, vec3(0.2126729, 0.7151522, 0.0721750));
return luma + saturation * (input - vec3(luma));
}
vec3 white_balance(vec3 input, float temperature, float tint){
vec3 white_balance(vec3 input, float temperature, float tint) {
float t1 = temperature * 10.0 / 6.0;
float t2 = tint * 10.0 / 6.0;
@ -78,7 +78,7 @@ vec3 white_balance(vec3 input, float temperature, float tint){
return LMS_2_LIN_MAT * lms;
}
vec4 color_mask(vec3 input, vec3 mask_color, float range, float fuzziness){
vec4 color_mask(vec3 input, vec3 mask_color, float range, float fuzziness) {
float dist = distance(mask_color, input);
return vec4(clamp(1. - (dist - range) / max(fuzziness, 1e-5), 0., 1.));
}

View File

@ -1,11 +1,11 @@
vec3 node_scale_world(mat4 model_matrix){
vec3 _axis_x = model_matrix[0].xyz;
vec3 _axis_y = model_matrix[1].xyz;
vec3 _axis_z = model_matrix[2].xyz;
vec3 node_scale_world(mat4 model_matrix) {
vec3 axis_x = model_matrix[0].xyz;
vec3 axis_y = model_matrix[1].xyz;
vec3 axis_z = model_matrix[2].xyz;
float _scale_x = length(_axis_x);
float _scale_y = length(_axis_y);
float _scale_z = length(_axis_z);
float scale_x = length(axis_x);
float scale_y = length(axis_y);
float scale_z = length(axis_z);
return vec3(_scale_x, _scale_y, _scale_z);
return vec3(scale_x, scale_y, scale_z);
}

View File

@ -40,112 +40,112 @@ float smoothmax(float a, float b, float t) {
return mix(b, a, h) + t * h * (1. - h);
}
vec3 vector_transform_world_to_local(mat4 model_matrix, vec3 vector){
vec3 vector_transform_world_to_local(mat4 model_matrix, vec3 vector) {
return (inverse(model_matrix) * vec4(vector, 1.0)).xyz;
}
vec3 vector_transform_world_to_view(mat4 view_matrix, vec3 vector){
vec3 vector_transform_world_to_view(mat4 view_matrix, vec3 vector) {
return (view_matrix * vec4(vector, 1.0)).xyz;
}
vec3 vector_transform_world_to_screen(mat4 view_matrix, mat4 projection_matrix, vec3 vector){
vec3 vector_transform_world_to_screen(mat4 view_matrix, mat4 projection_matrix, vec3 vector) {
vec3 vector_view = vector_transform_world_to_view(view_matrix, vector);
return (projection_matrix * vec4(vector_view, 1.0)).xyz;
}
vec3 vector_transform_world_to_tangent(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
vec3 vector_transform_world_to_tangent(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
vec3 vector_local = vector_transform_world_to_local(model_matrix, vector);
return local_to_tangent_matrix * vector_local;
}
vec3 vector_transform_local_to_world(mat4 model_matrix, vec3 vector){
vec3 vector_transform_local_to_world(mat4 model_matrix, vec3 vector) {
return (model_matrix * vec4(vector, 1.0)).xyz;
}
vec3 vector_transform_local_to_view(mat4 model_matrix, mat4 view_matrix, vec3 vector){
vec3 vector_transform_local_to_view(mat4 model_matrix, mat4 view_matrix, vec3 vector) {
vec3 vector_world = vector_transform_local_to_world(model_matrix, vector);
return (view_matrix * vec4(vector_world, 1.0)).xyz;
}
vec3 vector_transform_local_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 vector){
vec3 vector_transform_local_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 vector) {
vec3 vector_view = vector_transform_local_to_view(model_matrix, view_matrix, vector);
return (projection_matrix * vec4(vector_view, 1.0)).xyz;
}
vec3 vector_transform_local_to_tangent(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
vec3 vector_transform_local_to_tangent(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
return local_to_tangent_matrix * vector;
}
vec3 vector_transform_view_to_world(mat4 inv_view_matrix, vec3 vector){
vec3 vector_transform_view_to_world(mat4 inv_view_matrix, vec3 vector) {
return (inv_view_matrix * vec4(vector, 1.0)).xyz;;
}
vec3 vector_transform_view_to_local(mat4 inv_view_matrix, mat4 model_matrix, vec3 vector){
vec3 vector_transform_view_to_local(mat4 inv_view_matrix, mat4 model_matrix, vec3 vector) {
vec3 vector_world = vector_transform_view_to_world(inv_view_matrix, vector);
return vector_transform_world_to_local(model_matrix, vector_world);
}
vec3 vector_transform_view_to_screen(mat4 projection_matrix, vec3 vector){
vec3 vector_transform_view_to_screen(mat4 projection_matrix, vec3 vector) {
return (projection_matrix * vec4(vector, 1.0)).xyz;
}
vec3 vector_transform_view_to_tangent(mat4 inv_view_matrix, mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
vec3 vector_transform_view_to_tangent(mat4 inv_view_matrix, mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
vec3 vector_local = vector_transform_view_to_local(inv_view_matrix, model_matrix, vector);
return vector_transform_local_to_tangent(normal, binormal, tangent, vector_local);
}
vec3 vector_transform_screen_to_view(mat4 inv_projection_matrix, vec3 vector){
vec3 vector_transform_screen_to_view(mat4 inv_projection_matrix, vec3 vector) {
return (inv_projection_matrix * vec4(vector, 1.0)).xyz;;
}
vec3 vector_transform_screen_to_local(mat4 inv_projection_matrix, mat4 inv_view_matrix, mat4 model_matrix, vec3 vector){
vec3 vector_transform_screen_to_local(mat4 inv_projection_matrix, mat4 inv_view_matrix, mat4 model_matrix, vec3 vector) {
vec3 vector_view = vector_transform_screen_to_view(inv_projection_matrix, vector);
return vector_transform_view_to_local(inv_view_matrix, model_matrix, vector_view);
}
vec3 vector_transform_screen_to_world(mat4 inv_projection_matrix, mat4 inv_view_matrix, vec3 vector){
vec3 vector_transform_screen_to_world(mat4 inv_projection_matrix, mat4 inv_view_matrix, vec3 vector) {
vec3 vector_view = vector_transform_screen_to_view(inv_projection_matrix, vector);
return vector_transform_view_to_world(inv_view_matrix, vector_view);
}
vec3 vector_transform_screen_to_tangent(mat4 inv_projection_matrix, mat4 inv_view_matrix, mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
vec3 vector_transform_screen_to_tangent(mat4 inv_projection_matrix, mat4 inv_view_matrix, mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
mat3 local_to_tangent_matrix = mat3(tangent, binormal, normal);
vec3 vector_local = vector_transform_screen_to_local(inv_projection_matrix, inv_view_matrix, model_matrix, vector);
return local_to_tangent_matrix * vector_local;
}
vec3 vector_transform_tangent_to_local(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
vec3 vector_transform_tangent_to_local(vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
return tangent_to_local_matrix * vector;
}
vec3 vector_transform_tangent_to_world(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
vec3 vector_transform_tangent_to_world(mat4 model_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
vec3 vector_local = tangent_to_local_matrix * vector;
return vector_transform_local_to_world(model_matrix, vector_local);
}
vec3 vector_transform_tangent_to_view(mat4 model_matrix, mat4 view_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
vec3 vector_transform_tangent_to_view(mat4 model_matrix, mat4 view_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
vec3 vector_local = tangent_to_local_matrix * vector;
return vector_transform_local_to_view(model_matrix, view_matrix, vector_local);
}
vec3 vector_transform_tangent_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector){
vec3 vector_transform_tangent_to_screen(mat4 model_matrix, mat4 view_matrix, mat4 projection_matrix, vec3 normal, vec3 binormal, vec3 tangent, vec3 vector) {
mat3 tangent_to_local_matrix = inverse(mat3(tangent, binormal, normal));
vec3 vector_local = tangent_to_local_matrix * vector;
return vector_transform_local_to_screen(model_matrix, view_matrix, projection_matrix, vector_local);
}
vec4 noise_sine_wave(vec4 input, vec2 min_max) {
vec4 _sin_in = sin(input);
vec4 _sin_in_offset = sin(input + 1.0);
vec4 _random_number = fract(sin((_sin_in - _sin_in_offset) * (12.9898 + 78.233))*43758.5453);
float _noise = mix(min_max.x, min_max.y, _random_number.x);
return _sin_in + vec4(_noise);
vec4 sin_in = sin(input);
vec4 sin_in_offset = sin(input + 1.0);
vec4 random_number = fract(sin((sin_in - sin_in_offset) * (12.9898 + 78.233)) * 43758.5453);
float noise = mix(min_max.x, min_max.y, random_number.x);
return sin_in + vec4(noise);
}
vec4 sawtooth_wave(vec4 input) {

View File

@ -1,19 +1,19 @@
#include "res://addons/ShaderLib/Maths/Maths.gdshaderinc"
vec3 checker_board(vec2 uv, vec3 color_a, vec3 color_b, vec2 frequency){
vec3 checker_board(vec2 uv, vec3 color_a, vec3 color_b, vec2 frequency) {
uv = (uv.xy + 0.5) * frequency;
vec4 _derivatives = vec4(dFdx(uv), dFdy(uv));
vec2 _duv_length = sqrt(vec2(dot(_derivatives.xz, _derivatives.xz), dot(_derivatives.yw, _derivatives.yw)));
float _width = 1.0;
vec2 _distance3 = 4.0 * abs(fract(uv + 0.25) - 0.5) - _width;
vec2 _scale = 0.35 / _duv_length.xy;
float _frequency_limiter = sqrt(clamp(1.1f - max(_duv_length.x, _duv_length.y), 0.0, 1.0));
vec2 _vector_alpha = clamp(_distance3 * _scale.xy, -1.0, 1.0);
float _alpha = clamp(0.5f + 0.5f * _vector_alpha.x * _vector_alpha.y * _frequency_limiter, 0.0, 1.0);
return mix(color_b, color_a, _alpha);
vec4 derivatives = vec4(dFdx(uv), dFdy(uv));
vec2 duv_length = sqrt(vec2(dot(derivatives.xz, derivatives.xz), dot(derivatives.yw, derivatives.yw)));
float width = 1.0;
vec2 distance3 = 4.0 * abs(fract(uv + 0.25) - 0.5) - width;
vec2 scale = 0.35 / duv_length.xy;
float frequency_limiter = sqrt(clamp(1.1f - max(duv_length.x, duv_length.y), 0.0, 1.0));
vec2 vector_alpha = clamp(distance3 * scale.xy, -1.0, 1.0);
float alpha = clamp(0.5f + 0.5f * vector_alpha.x * vector_alpha.y * frequency_limiter, 0.0, 1.0);
return mix(color_b, color_a, alpha);
}
vec2 koch_fractal_direction(float angle){
vec2 koch_fractal_direction(float angle) {
return vec2(sin(angle), cos(angle));
}
@ -50,33 +50,33 @@ float koch_fractal(vec2 uv, float outline, int iteration, float shape_width, flo
return 1.0 - dist;
}
vec2 gradient_modulo(vec2 divident, vec2 divisor){
vec2 _positive_divident = mod(divident, divisor) + divisor;
return mod(_positive_divident, divisor);
vec2 gradient_modulo(vec2 divident, vec2 divisor) {
vec2 positive_divident = mod(divident, divisor) + divisor;
return mod(positive_divident, divisor);
}
vec2 gradient_random(vec2 uv){
vec2 gradient_random(vec2 uv) {
uv = vec2(dot(uv, vec2(127.1,311.7)), dot(uv, vec2(269.5,183.3)));
return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123);
}
float gradient_noise(vec2 uv, float scale) {
uv = uv * float(scale);
vec2 _period = vec2(30.0, 60.0);
vec2 _cells_minimum = floor(uv);
vec2 _cells_maximum = ceil(uv);
vec2 _uv_fract = fract(uv);
_cells_minimum = gradient_modulo(_cells_minimum, _period);
_cells_maximum = gradient_modulo(_cells_maximum, _period);
vec2 _blur = smoothstep(0.0, 1.0, _uv_fract);
vec2 _lowerLeftDirection = gradient_random(vec2(_cells_minimum.x, _cells_minimum.y));
vec2 _lowerRightDirection = gradient_random(vec2(_cells_maximum.x, _cells_minimum.y));
vec2 _upperLeftDirection = gradient_random(vec2(_cells_minimum.x, _cells_maximum.y));
vec2 _upperRightDirection = gradient_random(vec2(_cells_maximum.x, _cells_maximum.y));
vec2 _fraction = fract(uv);
float _mix_one = mix(dot(_lowerLeftDirection, _fraction - vec2(0, 0)), dot(_lowerRightDirection, _fraction - vec2(1, 0)), _blur.x);
float _mix_two = mix(dot(_upperLeftDirection, _fraction - vec2(0, 1)), dot(_upperRightDirection, _fraction - vec2(1, 1)), _blur.x);
return mix(_mix_one, _mix_two, _blur.y) * 0.8 + 0.5;
vec2 period = vec2(30.0, 60.0);
vec2 cells_minimum = floor(uv);
vec2 cells_maximum = ceil(uv);
vec2 uv_fract = fract(uv);
cells_minimum = gradient_modulo(cells_minimum, period);
cells_maximum = gradient_modulo(cells_maximum, period);
vec2 blur = smoothstep(0.0, 1.0, uv_fract);
vec2 lowerLeftDirection = gradient_random(vec2(cells_minimum.x, cells_minimum.y));
vec2 lowerRightDirection = gradient_random(vec2(cells_maximum.x, cells_minimum.y));
vec2 upperLeftDirection = gradient_random(vec2(cells_minimum.x, cells_maximum.y));
vec2 upperRightDirection = gradient_random(vec2(cells_maximum.x, cells_maximum.y));
vec2 fraction = fract(uv);
float mix_one = mix(dot(lowerLeftDirection, fraction - vec2(0, 0)), dot(lowerRightDirection, fraction - vec2(1, 0)), blur.x);
float mix_two = mix(dot(upperLeftDirection, fraction - vec2(0, 1)), dot(upperRightDirection, fraction - vec2(1, 1)), blur.x);
return mix(mix_one, mix_two, blur.y) * 0.8 + 0.5;
}
float gyroid_noise(vec2 uv, float scale, vec2 ratio, float height, float thickness) {
@ -166,59 +166,59 @@ void voronoi_noise(vec2 uv, float cell_density, float angle_offset, int distance
cells = cell_id.y;
}
float ellipse_shape(vec2 uv, float width, float height){
float _distance = length((uv * 2.0 - 1.0) / vec2(width, height));
return clamp((1.0 - _distance) / fwidth(_distance), 0.0, 1.0);
float ellipse_shape(vec2 uv, float width, float height) {
float dist = length((uv * 2.0 - 1.0) / vec2(width, height));
return clamp((1.0 - dist) / fwidth(dist), 0.0, 1.0);
}
float polygon_shape(vec2 uv, int sides, float width, float height){
float _a_width = width * cos(PI / float(sides));
float _a_height = height * cos(PI / float(sides));
uv = (uv * 2.0 - 1.0) / vec2(_a_width, _a_height);
float polygon_shape(vec2 uv, int sides, float width, float height) {
float a_width = width * cos(PI / float(sides));
float a_height = height * cos(PI / float(sides));
uv = (uv * 2.0 - 1.0) / vec2(a_width, a_height);
uv.y *= -1.0;
float _polar_coords = atan(uv.x, uv.y);
float _radius = 2.0 * PI / float(sides);
float _distance = cos(floor(0.5 + _polar_coords / _radius) * _radius - _polar_coords) * length(uv);
return clamp((1.0 - _distance) / fwidth(_distance), 0.0, 1.0);
float polar_coords = atan(uv.x, uv.y);
float radius = 2.0 * PI / float(sides);
float dist = cos(floor(0.5 + polar_coords / radius) * radius - polar_coords) * length(uv);
return clamp((1.0 - dist) / fwidth(dist), 0.0, 1.0);
}
float rectangle_shape(vec2 uv, float width, float height){
vec2 _distance = abs(uv * 2.0 - 1.0) - vec2(width, height);
_distance = 1.0 - _distance / fwidth(_distance);
return clamp(min(_distance.x, _distance.y), 0.0, 1.0);
float rectangle_shape(vec2 uv, float width, float height) {
vec2 dist = abs(uv * 2.0 - 1.0) - vec2(width, height);
dist = 1.0 - dist / fwidth(dist);
return clamp(min(dist.x, dist.y), 0.0, 1.0);
}
float rounded_polygon_shape(vec2 uv, float width, float height, float sides, float roundness){
uv = uv * 2.0 + vec2(-1.0);
roundness /= 10.0;
float _epsilon = 1e-6;
uv.x = uv.x / ( width + ((width>-_epsilon && width<_epsilon) ? 1.0 : 0.0 * _epsilon));
uv.y = uv.y / ( height + ((height>-_epsilon && height<_epsilon) ? 1.0 : 0.0 * _epsilon));
float epsilon = 1e-6;
uv.x = uv.x / ( width + ((width > -epsilon && width < epsilon) ? 1.0 : 0.0 * epsilon));
uv.y = uv.y / ( height + ((height > -epsilon && height < epsilon) ? 1.0 : 0.0 * epsilon));
roundness = clamp(roundness, 1e-6, 1.0);
float _i_sides = floor( abs( sides ) );
float _full_angle = 2.0 * PI / _i_sides;
float _half_angle = _full_angle / 2.;
float _diagonal = 1.0 / cos( _half_angle );
float _chamfer_angle = roundness * _half_angle;
float _remaining_angle = _half_angle - _chamfer_angle;
float _ratio = tan(_remaining_angle) / tan(_half_angle);
vec2 _chamfer_center = vec2(cos(_half_angle) , sin(_half_angle))* _ratio * _diagonal;
float i_sides = floor( abs( sides ) );
float full_angle = 2.0 * PI / i_sides;
float half_angle = full_angle / 2.;
float diagonal = 1.0 / cos( half_angle );
float chamfer_angle = roundness * half_angle;
float remaining_angle = half_angle - chamfer_angle;
float ratio = tan(remaining_angle) / tan(half_angle);
vec2 chamfer_center = vec2(cos(half_angle) , sin(half_angle))* ratio * diagonal;
float _dist_a = length(_chamfer_center);
float _dist_b = 1.0 - _chamfer_center.x;
float _uv_scale = _diagonal;
uv *= _uv_scale;
vec2 _polar_uv = vec2(atan(uv.y, uv.x), length(uv));
float dist_a = length(chamfer_center);
float dist_b = 1.0 - chamfer_center.x;
float uv_scale = diagonal;
uv *= uv_scale;
vec2 polar_uv = vec2(atan(uv.y, uv.x), length(uv));
_polar_uv.x += PI / 2.0 + TAU;
_polar_uv.x = mod(_polar_uv.x + _half_angle, _full_angle );
_polar_uv.x = abs(_polar_uv.x - _half_angle);
uv = vec2(cos(_polar_uv.x), sin(_polar_uv.x)) * _polar_uv.y;
float _angle_ratio = 1.0 - (_polar_uv.x-_remaining_angle) / _chamfer_angle;
float _dist_c = sqrt(_dist_a * _dist_a + _dist_b * _dist_b - 2.0 * _dist_a *_dist_b * cos(PI - _half_angle * _angle_ratio));
polar_uv.x += PI / 2.0 + TAU;
polar_uv.x = mod(polar_uv.x + half_angle, full_angle );
polar_uv.x = abs(polar_uv.x - half_angle);
uv = vec2(cos(polar_uv.x), sin(polar_uv.x)) * polar_uv.y;
float angle_ratio = 1.0 - (polar_uv.x- remaining_angle) / chamfer_angle;
float dist_c = sqrt(dist_a * dist_a + dist_b * dist_b - 2.0 * dist_a * dist_b * cos(PI - half_angle * angle_ratio));
float output = uv.x;
float _chamfer_zone = (_half_angle - _polar_uv.x) < _chamfer_angle ? 1.0 : 0.0;
output = mix(uv.x, _polar_uv.y / _dist_c, _chamfer_zone);
float chamfer_zone = (half_angle - polar_uv.x) < chamfer_angle ? 1.0 : 0.0;
output = mix(uv.x, polar_uv.y / dist_c, chamfer_zone);
output = clamp((1.0 - output) / fwidth(output), 0.0, 1.0);
return output;
}
@ -227,6 +227,6 @@ float rounded_rectangle_shape(vec2 uv, float width, float height, float radius){
radius /= 10.0;
radius = max(min(min(abs(radius * 2.0), abs(width)), abs(height)), 1e-5);
uv = abs(uv * 2.0 - 1.0) - vec2(width, height) + radius;
float _distance = length(max(vec2(0.0), uv)) / radius;
return clamp((1.0 - _distance) / fwidth(_distance), 0.0, 1.0);
float dist = length(max(vec2(0.0), uv)) / radius;
return clamp((1.0 - dist) / fwidth(dist), 0.0, 1.0);
}

View File

@ -1,4 +1,4 @@
vec2 flipbook_uv(vec2 uv, int rows, int columns, float anim_speed){
vec2 flipbook_uv(vec2 uv, int rows, int columns, float anim_speed) {
int start_frame = 1;
int end_frame = rows * columns;
start_frame += int(fract(TIME * anim_speed) * float(end_frame));
@ -8,7 +8,6 @@ vec2 flipbook_uv(vec2 uv, int rows, int columns, float anim_speed){
vec2 current_sprite = vec2(0.0, 1.0 - off_per_frame.y);
current_sprite.x += frame * off_per_frame.x;
float row_index;
float mod = modf(frame / float(columns), row_index);
current_sprite.y -= 1.0 - (row_index * off_per_frame.y);
current_sprite.x -= row_index * float(columns) * off_per_frame.x;
vec2 sprite_uv = (sprite_size + current_sprite);
@ -22,8 +21,7 @@ vec2 parallax_mapping_uv_offset_1_step(float height, float amplitude, vec3 view_
return height * (vector.xz / vector.y);
}
vec2 parallax_mapping_uv(sampler2D height, float amplitude, vec2 uv, vec3 tangent, vec3 normal, vec3 binormal, vec3 view)
{
vec2 parallax_mapping_uv(sampler2D height, float amplitude, vec2 uv, vec3 tangent, vec3 normal, vec3 binormal, vec3 view) {
float depth = amplitude / 10.0;
mat3 tangent_matrix = mat3(tangent, normal, -binormal); // VIEW TO TANGENT SPACE
vec3 view_tangent = transpose(tangent_matrix) * view;
@ -32,28 +30,31 @@ vec2 parallax_mapping_uv(sampler2D height, float amplitude, vec2 uv, vec3 tangen
return parallaxOffset + uv;
}
vec2 radial_shear_uv(vec2 uv, vec2 center, float strength, vec2 offset){
vec2 radial_shear_uv(vec2 uv, vec2 center, float strength, vec2 offset) {
vec2 delta = uv - center;
float delta2 = dot(delta.xy, delta.xy);
vec2 delta_offset = vec2(delta2 * strength);
return uv + vec2(delta.y, -delta.x) * delta_offset + offset;
}
vec2 rotate_uv(vec2 uv, vec2 center, float rotation, bool use_degrees){
mat2 rotation_mat2(float angle) {
return mat2(
vec2(cos(angle), -sin(angle)),
vec2(sin(angle), cos(angle))
);
}
vec2 rotate_uv(vec2 uv, vec2 center, float rotation, bool use_degrees) {
float angle = rotation;
if(use_degrees){
angle = rotation * (3.1415926/180.0);
}
mat2 rot = mat2(
vec2(cos(angle), -sin(angle)),
vec2(sin(angle), cos(angle))
);
vec2 delta = uv - center;
delta = rot * delta;
delta = rotation_mat2(angle) * delta;
return delta + center;
}
vec2 spherize_uv(vec2 uv, vec2 center, float strength, vec2 offset){
vec2 spherize_uv(vec2 uv, vec2 center, float strength, vec2 offset) {
vec2 delta = uv - center;
float delta2 = dot(delta.xy, delta.xy);
float delta4 = delta2 * delta2;
@ -61,24 +62,16 @@ vec2 spherize_uv(vec2 uv, vec2 center, float strength, vec2 offset){
return uv + delta * delta_offset + offset;
}
vec2 swirl_uv(vec2 uv, vec2 center, float strength, vec2 offset){
vec2 swirl_uv(vec2 uv, vec2 center, float strength, vec2 offset) {
vec2 delta = uv - center;
float angle = strength * max(pow(1. - length(delta), 3), 0);
mat2 rotation = mat2(
vec2(cos(angle), -sin(angle)),
vec2(sin(angle), cos(angle))
);
delta = rotation * delta;
delta = rotation_mat2(angle) * delta;
return delta + center + offset;
}
vec2 twirl_uv(vec2 uv, vec2 center, float strength, vec2 offset){
vec2 twirl_uv(vec2 uv, vec2 center, float strength, vec2 offset) {
vec2 delta = uv - center;
float angle = strength * length(delta);
mat2 rotation = mat2(
vec2(cos(angle), -sin(angle)),
vec2(sin(angle), cos(angle))
);
delta = rotation * delta;
delta = rotation_mat2(angle) * delta;
return delta + center + offset;
}