Skip to content

Instantly share code, notes, and snippets.

@partybusiness
partybusiness / stat.gd
Created May 5, 2025 17:33
Pattern for numerical stats that can have buffs or debuffs applied.
extends Resource
class_name Stat
# keeps track a a numerical stat and connected buffs / debuffs
# name of stat, also used as a matching ID for buffs
@export var name:String = ""
# whether value needs to be recalculated
var dirty:bool = false
@partybusiness
partybusiness / iris_texture_transition.gdshader
Last active April 30, 2025 17:36
Iris shader in godot that can open and close for transitions
shader_type canvas_item;
render_mode unshaded;
// iris shader, apply to a ColorRect that overlays the screen and set iris_size to iris in and out
// this one allows you to use a texture to shape the iris
// 0.0 = fully close, 1.0 = fully open
uniform float iris_size:hint_range(0.0, 1.0, 0.01) = 0.5;
// multiply the size of the texture beyond centre
uniform float max_size_mult:hint_range(1.0, 10.0, 0.1) = 2.5;
@partybusiness
partybusiness / tictactoe.txt
Last active April 27, 2025 00:19
R commands for analyzing tic tac toe match where each player plays randomly
# create 3x3 tic tac toe board
board = matrix(0, nrow=3, ncol=3, byrow=TRUE)
# each square can be 0 = empty, 1 = X, 2 = O
# returns index of board state
board_index <- function(board) {
index = 1
x = 1
@partybusiness
partybusiness / chrome_with_viewshadow.gdshader
Last active April 24, 2025 01:40
fake chrome using cubemap for reflection, with a black blob shadow superimposed over the viewer's position
shader_type spatial;
uniform samplerCube sky_cube:source_color;
uniform sampler2D shadow_texture:source_color, repeat_disable, hint_default_white;
uniform vec2 shadow_scale = vec2(2.0, 1.0);
uniform vec2 shadow_offset = vec2(0.5,0.2);
@partybusiness
partybusiness / pixel_size.gdshader
Created March 27, 2025 02:48
Gets the size of a texel on-screen in pixels
shader_type spatial;
// quick test for how large a texel in on-screen in pixels
uniform sampler2D test_texture:filter_nearest;
void fragment() {
vec2 uv_per_texel = vec2(1.0, 1.0) / vec2(textureSize(test_texture, 0));
vec2 dfx = dFdx(UV);
vec2 dfy = dFdy(UV);
vec2 uv_per_pixel = vec2(length(vec2(dfx.x, dfy.x)), length(vec2(dfx.y, dfy.y)));
@partybusiness
partybusiness / moon_sky.gdshader
Created March 26, 2025 22:35
Godot sky shader that displays the moon based on light direction
shader_type sky;
uniform sampler2D moon_texture:source_color, repeat_disable;
// updirection of moon texture will try to align with this
uniform vec3 north = vec3(0, 0, -1);
void sky() {
vec3 light_dir = normalize(-LIGHT0_DIRECTION);
vec3 side_dir = normalize(cross(light_dir, north));
@partybusiness
partybusiness / snakes_and_ladder_board.csv
Last active May 5, 2025 01:07
Snakes and ladders analysis using a transition matrix in R
start end
73 1
46 5
55 7
8 26
48 9
52 11
59 17
83 19
21 82
shader_type canvas_item;
// draws black dots at corners
uniform float dot_size = 30; // size of dots at vertices
varying vec2 vertex_uv; // used to pass fake UV since real UV wasn't behaving as expected
void vertex() {
vertex_uv = COLOR.rg; // using vertex colour because UV array from Polygon2D wasn't working for me?
//vertex_uv = UV;
#Based on Procedural Toolkit by Syomus (https://github.com/Syomus/ProceduralToolkit)
@tool
extends PrimitiveMesh
class_name SuperSphere
# generates a supersphere
## size of the supersphere
@export var radius : float = 1.0:
get:
@partybusiness
partybusiness / fake_ground_plane.gdshader
Last active January 9, 2025 18:53
Displays a fake ground plane that doesn't need to correspond to geometry. Useful for creating a ground plane that extends to the horizon without requiring infinite geometry.
shader_type spatial;
uniform sampler2D ground_texture:source_color, repeat_enable, filter_linear_mipmap;
uniform float ground_height = -1.0;
uniform float scale = 2.0;
varying vec3 world_position;
varying vec3 cam_pos;