Skip to content

Instantly share code, notes, and snippets.

@belzecue
belzecue / height_blend_optimised.shader
Created February 1, 2025 06:27
Optimised Godot 3 version of this Godot 4 shader: https://github.com/Foyezes/Godot-HeightBlend-Node
shader_type spatial;
// alpha for tex1 and tex2 is the heightmap
uniform sampler2D tex1 : hint_black_albedo;
uniform sampler2D tex2 : hint_black_albedo;
uniform vec2 tex1_scale = vec2(1.);
uniform vec2 tex2_scale = vec2(1.);
uniform float height_offset = 0.;
uniform float contrast = 1.;
@belzecue
belzecue / 2d_dropshadow.shader
Created January 25, 2025 08:27
Remove branching from drop-shadow shader
// based on https://godotshaders.com/shader/drop-shadow/
shader_type canvas_item;
uniform vec4 drop_shadow_color : hint_color = vec4(0,0,0,0.5);
uniform vec2 shadow_offset = vec2(0.1);
varying float max_offset;
void vertex() {
@belzecue
belzecue / RingBufferDic.gd
Created February 24, 2022 15:54
Godot ring buffer using Dictionary. Can pop FIFO or LIFO.
class_name RingBufferDic extends Node
enum PopMode {LIFO, FIFO}
export(int) var maxHistoryEntries := 32
var history := {}
var hwm := 0 # high water mark
var LIFO := -1 # -1 means buffer empty
var FIFO := -1 # -1 means buffer empty
var pop_counter := 0
@belzecue
belzecue / CharRigidBody.gd
Last active December 7, 2024 13:44
The ONLY guaranteed solution to physics body jitter in Godot - separate your physics body from its visual representation. Works with 3D too, but smoothing is now built into Godot for 3D (not yet built in for 2D).
class_name CharRigidBody extends RigidBody2D
# Your visual representation node, e.g. Sprite
export(NodePath) var visual_body_path: NodePath
# For RigidBody tweening
var physics_body_trans_last: Transform
var physics_body_trans_current: Transform
var debug: bool = true
@belzecue
belzecue / 1-pico8-godot-shader.shader
Created November 28, 2024 15:29 — forked from stephanbogner/1-pico8-godot-shader.shader
PICO-8 color palette (or any other) shader for Godot (with the .html file below you can easily adjust the shader to any color palette)
// Adapted from "How to Limit Color Output with Shaders in Godot"
// By TheBuffED
// On https://www.youtube.com/watch?v=Scrdv4oSeNw
// Type of shader https://docs.godotengine.org/en/3.0/tutorials/shading/shading_language.html#shader-types
shader_type canvas_item;
// The shader strength which between 0 (not applied) and 1 (fully applied) because I want to fade the shader in and out
// Can be changed from node via `get_material().set_shader_param("shaderStrength", newValue)`
uniform float shaderStrength = 1.0;
@belzecue
belzecue / bake_morph_textures.py
Created November 21, 2024 14:38 — forked from alexmalyutindev/bake_morph_textures.py
Vertex animation baker for Blender.
# Source
# Vertex animation textures, beanbags and boneless animations
# by Martin Donald
# https://www.youtube.com/watch?v=NQ5Dllbxbz4
import bpy
import bmesh
import mathutils
"""
Based on Calinou's Godot3 movie render script:
https://github.com/Calinou/godot-video-rendering-demo/blob/master/camera.gd
# Copyright © 2019 Hugo Locurcio and contributors - MIT License
# See `LICENSE.md` included in the source distribution for details.
This script asynchronously renders gameplay or camera animation
to PNG files which can then be combined into a video via ffmpeg.
IMPORTANT!
@belzecue
belzecue / catmull-rom.gd
Created June 22, 2024 11:55 — forked from JoelBesada/catmull-rom.gd
Catmull-Rom Spline in GDScript
func catmull_rom_spline(
_points: Array, resolution: int = 10, extrapolate_end_points = true
) -> PackedVector2Array:
var points = _points.duplicate()
if extrapolate_end_points:
points.insert(0, points[0] - (points[1] - points[0]))
points.append(points[-1] + (points[-1] - points[-2]))
var smooth_points := PackedVector2Array()
if points.size() < 4:
@belzecue
belzecue / create_export_pack.sh
Created April 20, 2024 11:41 — forked from pavanpodila/create_export_pack.sh
Export each Git branch as a separate folder
previous_pwd=$PWD
cd $(dirname $0)
PROJECT="$HOME/Desktop/project"
EXPORT_DIR="$HOME/Desktop/export"
rm -rf $EXPORT_DIR
mkdir -p $EXPORT_DIR
/**
* \brief Returns positional offset for a given point as a result of summing 4 gerstner waves
* \param positionWS point in world space
* \param wavelengths wavelength of each of the 4 waves
* \param amplitudes amplitudes of each of the 4 waves
* \param directions direction of each of the 4 waves (each row = one direction). MUST BE NORMALIZED!
* \param speed global speed multiplier. Individual wave speed depends on Wavelength
* \param steepness Gerstner wave 'Steepness' parameter. Modulates the horizontal offset of points
* \param normal returns the normal of given point.
* \return positional offset of the given point