Skip to content

Instantly share code, notes, and snippets.

@partybusiness
partybusiness / clipped_shader.gdshader
Last active May 23, 2025 17:01
cuts off part of the mesh above a y threshold
shader_type spatial;
render_mode cull_disabled;
uniform float threshold = 0.0;
uniform vec3 direction = vec3(0.0, 1.0, 0.0);
// normal of dividing plane in model space
varying vec3 local_plane_normal;
@partybusiness
partybusiness / hcl_blend.gdshader
Last active May 21, 2025 00:27
Trying out different ways of blending colours in different colour spaces.
shader_type canvas_item;
uniform sampler2D textureA:source_color;
uniform sampler2D textureB:source_color;
uniform float blend:hint_range(0.0, 1.0, 0.01) = 0.5;
// lowers saturation for colours that pass through the centre of hue space
uniform float pow_comp:hint_range(0.0, 10.0, 0.01) = 1.0;
shader_type spatial;
render_mode unshaded;
// example shader that uses the light pattern to flicker brightness on and off
// other possible ways to use this is give it render_mode additive have lights_on and lights_off versions of a texture and mix between them
uniform sampler2D light_texture:source_color;
uniform float fps:hint_range(1.0, 60.0, 1.0) = 10.0;
// temporal light pattern
@partybusiness
partybusiness / stat.gd
Last active May 10, 2025 16:28
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