Skip to content

Instantly share code, notes, and snippets.

@lucasvanmol
lucasvanmol / bend3D_quat.shader
Created November 13, 2020 16:40
bend3D shader but using quaternions instead of matrices
shader_type spatial;
uniform vec3 strength = vec3(0.0);
uniform vec3 center = vec3(0.0, 0.0, 1.0);
vec4 quat_mult(vec4 q1, vec4 q2) {
vec4 qr;
qr.x = (q1.w * q2.x) + (q1.x * q2.w) + (q1.y * q2.z) - (q1.z * q2.y);
qr.y = (q1.w * q2.y) - (q1.x * q2.z) + (q1.y * q2.w) + (q1.z * q2.x);
qr.z = (q1.w * q2.z) + (q1.x * q2.y) - (q1.y * q2.x) + (q1.z * q2.w);
shader_type canvas_item;
uniform float STRENGTH = 0.0;
uniform vec2 CENTER = vec2(0.5);
void fragment() {
vec2 uv = UV - CENTER;
float angle = STRENGTH * uv.y;
mat2 rot = mat2(
vec2( cos(angle), -sin(angle) ),
shader_type spatial;
uniform float strength_x = 0.0;
uniform float strength_y = 0.0;
uniform float strength_z = 0.0;
uniform vec3 center = vec3(0.0, 0.0, 1.0);
void vertex() {
vec3 v = VERTEX - center;
@lucasvanmol
lucasvanmol / oscillator.gd
Last active November 10, 2020 13:36
Godot script describing the motion of a damped oscillator
extends Sprite
var displacement := 0.0
var velocity := 0.0
export (float) var spring_constant := 150.0
export (float) var damp_constant := 5.0
func _process(delta):
var force = -spring_constant * displacement + damp_constant * velocity
@lucasvanmol
lucasvanmol / uv_rotation.shader
Last active November 7, 2020 17:13
Simple shader to rotate UV space
shader_type canvas_item;
uniform float ANGLE = 0.0;
uniform vec2 CENTER = vec2(0.5);
uniform float TILING = 3.0;
void fragment() {
vec2 uv = (UV - CENTER)*TILING;
mat2 rot = mat2(