Skip to content

Instantly share code, notes, and snippets.

@partybusiness
partybusiness / screen_space_gradient.gdshader
Last active January 16, 2026 16:06
Some screen-space gradients and texture shaders that account for position of mesh
shader_type spatial;
render_mode unshaded;
//renders vertical gradient that centres on node's position
uniform vec4 _TopColour:source_color = vec4(1.0,1.0,1.0,1.0);
uniform vec4 _BottomColour:source_color = vec4(0.0,0.0,0.0,1.0);
uniform float _Height = 1.0;
uniform float _exp = 1.0;
void fragment() {
@partybusiness
partybusiness / moon_sky.gdshader
Last active January 12, 2026 03:39
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 / fake_perspective.gdshader
Last active January 9, 2026 03:51
fake perspective shader in Godot
shader_type canvas_item;
// displays a texture but distorts it based on the size of the top and bottom
uniform sampler2D main_texture:source_color, repeat_disable;
// scale the bottom of the image
uniform float scale_x_bottom = 1.0;
// scale the top of the image
uniform float scale_x_top = 1.0;
@partybusiness
partybusiness / OnePointPerspective.cs
Last active December 29, 2025 17:22
Some camera tricks with the camera projectionMatrix in Unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class OnePointPerspective : MonoBehaviour {
[SerializeField]
private Camera camcam;
#Based on Procedural Toolkit by Syomus (https://github.com/Syomus/ProceduralToolkit)
@tool
extends PrimitiveMesh
class_name DiamondMesh
enum CutType {
Point,
Table,
OldMine,
OldEuropean,
@partybusiness
partybusiness / palette_swap.gdshader
Last active July 7, 2025 13:52
Godot shader that will let you replace colours (usually full-saturation RGB, Yellow, Cyan, Magenta) with new colours based on a texture.
shader_type canvas_item;
// expects this as 4x2
// black, red, blue, magenta
// green, yellow, cyan, white
// set alpha to 0 for sections you don't want replaced
// usually black pixel is alpha 0 because most colours are below threshold
uniform sampler2D colours:source_color;
// threshold for what counts as full saturation
@partybusiness
partybusiness / canvas_wrapper.gd
Created June 9, 2025 01:13
An attempt to make a wrapper that could accept custom Canvas textures as a parameter and turn it into something a material can accept as a uniform
@tool
extends PortableCompressedTexture2D
class_name CanvasWrapper
@export var source_texture:Texture2D:
get:
return source_texture
set(new_value):
if source_texture != new_value:
@partybusiness
partybusiness / pixel_line.gdshader
Created May 31, 2025 15:36
pixel line shader test
shader_type canvas_item;
// pixelated shader for use with Line2D
// will still have incorrect behaviour at tips and corners where there can be diagonal cut-offs that don't align with pixel_size
uniform int pixel_size = 4;
void fragment() {
vec2 rounded_pixel = floor(FRAGCOORD.xy / float(pixel_size)) * float(pixel_size); //
vec2 pixel_diff = FRAGCOORD.xy - rounded_pixel;
@partybusiness
partybusiness / face_oriented.gdshader
Created May 25, 2025 16:53
Godot shader that samples texture from world pos oriented with surface normal
shader_type spatial;
// if you have a mesh with big flat surfaces this might work better than a triplanar shader
// applied to a curved surfact this will look distorted
uniform sampler2D main_texture:source_color, repeat_enable;
uniform float scale = 1.0;
varying vec3 world_pos;
varying vec3 world_tangent;
@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;