Skip to content

Instantly share code, notes, and snippets.

/**
* \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
@belzecue
belzecue / text_decal_sdf.shader
Created January 6, 2024 16:39
Godot 3 SDF shader for clear decal edges at low resolutions, as used by Valve
// Generate high-resolution white on black text decal in GIMP and apply Filters > Generic > Distance Map
// then scale down to e.g. 64 pixel height.
// Import decal image into Godot and set:
// Compression mode to lossless
// Filter ON
// Mipmaps ON
// Fix alpha border ON
// Invert color ON (if required)
@belzecue
belzecue / AnimationToPNG.gd
Last active January 1, 2024 17:20
Capture an animation to a PNG sequence, e.g. to turn into an Animated Sprite.
"""
Attach this script to the parent node of an AnimationPlayer.
"""
extends Node2D
export(NodePath) var anim_player_path: NodePath
export(String) var track_name: String
onready var anim_player: AnimationPlayer = get_node(anim_player_path) as AnimationPlayer
onready var tree: SceneTree = get_tree()
class_name RingBuffer extends Reference
"""
Uses simple arrays as ring buffers, passed to these static methods.
Allocates the first two slots for metadata (pointer, queue length).
USAGE:
var rb: Array = RingBuffer.create(5)
@belzecue
belzecue / GdscriptCallSequence.txt
Created November 30, 2023 09:57 — forked from Gnumaru/GdscriptCallSequence.txt
The sequence in which methods and signals gets called in gdscript
# as of godot 4.1
_static_init
_init
_notification 20 Node.NOTIFICATION_SCENE_INSTANTIATED # only on instantiated scene roots
_notification 18 Node.NOTIFICATION_PARENTED
_enter_tree
tree_entered signal
_notification 27 Node.NOTIFICATION_POST_ENTER_TREE
_ready
ready signal
export var viewportResizeStanddown = 0.5
var viewportResizeCounter = 0.0
signal settingsChanged()
signal particlesSettingsChanged()
signal removeGpuParticles()
func forbidParticles(time):
particlesForbiddenCounter = time
particlesForbidden = true
@belzecue
belzecue / LinkedList.gd
Last active November 11, 2023 19:25 — forked from bojidar-bg/LinkedList.gd
Doubly Linked List for Godot
# Linked List
# from https://gist.github.com/bojidar-bg/a570c614a4dd1cd84949
# Example use
"""
var my_linked_list = LinkedList.new()
func _ready():
var ll = my_linked_list
@belzecue
belzecue / DoomGlow.cs
Created April 25, 2023 02:34 — forked from TiliSleepStealer/DoomGlow.cs
Doom glow - fake volumetric light glow effect in Unity by Tili_us
// This file is in the public domain. Where
// a public domain declaration is not recognized, you are granted
// a license to freely use, modify, and redistribute this file in
// any way you choose.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Unity remake of a fake volumetric light glow effect
@belzecue
belzecue / CharRigidBody.gd
Last active August 14, 2023 18:36
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 / gist:4e4f64a579037e5b9c1088a9b7e82a1a
Created February 9, 2023 04:06 — forked from WolfgangSenff/gist:0a9c1d800db42a9a9441b2d0288ed0fd
GDScript 1.0 to 2.0 Beginner Friendly Conversion Guide
Beginner-friendly GDScript 1 to GDScript 2 Conversion Guide
First and foremost, this should not be considered a replacement for the official migration guide,
found at https://docs.godotengine.org/en/latest/tutorials/migrating/upgrading_to_godot_4.html!
Instead, this document is intended to be a friendly guide to helping you upgrade your projects from
GDScript 1 to 2. To do this, I'm going to list the most common conversions I've run into while upgrading
a few of my games and tools. This document is written as of the first release candidate version of Godot 4.0.
The first thing to do when converting a project (no need if you're starting from new) is to either have your
project in source control, or make a duplicate of your entire project's folder and rename it. This will