Skip to content

Instantly share code, notes, and snippets.

@partybusiness
partybusiness / screen_space_gradient.gdshader
Created July 27, 2024 19:44
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 / depth_cube.gdshader
Last active July 19, 2024 15:58
Godot Depth Cube
shader_type spatial;
render_mode unshaded, blend_mix, shadows_disabled;
uniform vec4 main_colour:source_color;
//calculates depth to the back of a cube behind each 0 to 1 UV face.bool
//If you have a cube where each face is 0 to 1 UV then it calculates the distance to each side and the back
//based on my earlier depth cube in Unity: https://gist.github.com/partybusiness/b7ec339d16d3f3b7e2b202ac4e5d8686
@partybusiness
partybusiness / figure_eight_render.gdshader
Last active June 17, 2024 15:07
generates a mesh in a figure-eight shape and saves it as a resource
shader_type spatial;
render_mode cull_disabled, unshaded, depth_draw_opaque;
//just something I used to diaply the figure eight
uniform sampler2D tex:source_color;
uniform float spin_speed = 1.0;
void vertex() {
UV.y = UV.y + TIME * spin_speed;
}
@partybusiness
partybusiness / GameOfLife.gd
Last active May 17, 2024 19:46
Conway's Game of Life implemented as a compute shader in Godot
extends Node
@export var display_material:Material
@export var game_state:PackedByteArray
const width:int = 64
const height:int = 64
var rd := RenderingServer.create_local_rendering_device()
@partybusiness
partybusiness / ComputerScreen.gdshader
Last active May 18, 2024 15:34
Displays tile sheet of characters as tiles stored in a byte array.
shader_type spatial;
//render_mode unshaded;
uniform uint tilemap[1024]; // up to 128 8-byte 8x8 tiles
uniform uint screen[1000];// 40 x 25 screen map, 7 bits index one of the 128 tiles, highest bit inverts
uniform uint screenWidth = 40;
uniform uint screenHeight = 25;
@partybusiness
partybusiness / BitmapToArray.gd
Last active May 5, 2024 17:11
Godot shader that treats an array of integers as a tilemap and Godot editor scripts to work with those arrays
@tool
extends EditorScript
class_name BitmapToArray
# this is using a tile map available here:
# https://hexany-ives.itch.io/hexanys-roguelike-tiles
const sourceImage:String = "res://arraydemo/monochrome_16x16.png" #image we get tiles from
const width:int = 32 # how many tiles wide is the source image
const height:int = 32 # how many tiles tall is the source image
shader_type particles;
void start() {
if (RESTART_POSITION) {
TRANSFORM[3].xyz = EMISSION_TRANSFORM[3].xyz; //sets to emitter position
float _time = TIME * 200.0;
VELOCITY = vec3(1.*cos(_time),0.,1.*sin(_time)); //sets angle based on time
}
}
@partybusiness
partybusiness / random_wang_tiles.gdshader
Created April 2, 2024 21:46
Godot Wang Tile Shaders
shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;
uniform sampler2D Tile_Texture:source_color;
//used for random values on tile
vec2 random(float x, float y) {
vec2 co = round(vec2(x,y));
return vec2(
Shader "Unlit/ScreenSpaceGradient"
{
Properties
{
_TopColour("Top Colour", Color) = (0.5,0.5,0.5,1)
_BottomColour("Bottom Colour", Color) = (0.5,0.5,0.5,1)
_Height("Height", float) = 0.0
}
SubShader
{
@partybusiness
partybusiness / TwoPassStencilShader.shader
Last active April 23, 2023 03:20
Testing stencil to prove the order that passes are rendered
Shader "Unlit/TwoPassStencilShader"
{
Properties
{
_Color1("Colour1", Color) = (1,0,0,1)
_Color2("Colour2", Color) = (0,0,1,1)
}
SubShader
{
Tags{