Skip to content

Instantly share code, notes, and snippets.

shader_type sky;
uniform sampler2D skyTexture:source_color;
void sky() {
COLOR = textureLod(skyTexture, SKY_COORDS, 0.0).rgb;
}
@tool
extends EditorScript
# converts an equirectangular panoramic texture to a skyamid format
var source_panorama:String = "res://skybox_example_pano_left.png"
var target_skyamid:String = "res://skyamid.png"
func _run() -> void:
# load source
@tool
extends EditorScript
class_name GenerateCubemapEditorScript
# collection of helper scripts for generating cubemaps
# file you wish to output the generated cubemap to
var cubemap_filename:String = "color_test_cubemap.tres"
@partybusiness
partybusiness / find_distances.glsl
Last active October 6, 2024 19:21
Godot shader raycast FPS
#[compute]
#version 450
// Invocations in the (x, y, z) dimension
layout(local_size_x = 8, local_size_y = 1, local_size_z = 1) in;
layout(rgba16f, set = 0, binding = 0) uniform restrict image2D distances; //distances to walls along each raycast, as well as data for wall texture
layout(rgba16f, set = 0, binding = 1) uniform restrict image2D map; //map to raycast on
shader_type spatial;
render_mode unshaded, blend_mul, depth_draw_never, depth_test_disabled;
// creates a silhouette that appears when the mesh is behind something else
// you can combine this with another material by assigning this as the Next Pass material
// this might need adjustment to work with 4.3 and later, because of the reversed depth
uniform vec3 shadow_colour:source_color = vec3(0.7,0.7,0.9);
uniform sampler2D depth_texture:hint_depth_texture;
@partybusiness
partybusiness / character_hole.gd
Last active October 15, 2024 15:48
Dithered transparency hole
extends Node3D
# Sets position of hole that makes character visible through walls
func _process(delta):
RenderingServer.global_shader_parameter_set("character_position", global_position)
@partybusiness
partybusiness / in_radius_test.gdshader
Created August 13, 2024 18:50
Godot shader that displays a white circle based on a formula for distance between a line and a point
shader_type spatial;
render_mode unshaded;
uniform float _Radius = 1.;
//https://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
float distance_between_point_and_line(vec3 ls, vec3 le, vec3 point) {
//ls = line start
//le = line end
//point = posiiton of point
@partybusiness
partybusiness / compute_life.glsl
Last active August 7, 2024 23:07
New version of Conway's Game of Life for Godot
#[compute]
#version 450
// Invocations in the (x, y, z) dimension
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout(r32f, set = 0, binding = 0) uniform restrict image2D input_image;
layout(push_constant, std430) uniform Params {
@partybusiness
partybusiness / screen_bulge.gdshader
Created August 5, 2024 00:37
Godot shader that distorts a texture as though it's viewed through a slightly bulbous CRT
shader_type canvas_item;
render_mode blend_mix;
uniform float bulge = 0.1;
uniform float scale = 1.0;
//used to set curvature of screen crop
uniform float n = 5.0;
@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() {