Last active
December 30, 2022 12:04
-
-
Save andrew-wilkes/de869ab10ab06f18e69bb7c2ce335669 to your computer and use it in GitHub Desktop.
Equirectangular Shader in Godot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This shader creates a 2D image that may be used as a Equirectangular panorama background | |
// It creates fairly evenly spread stars (blobs) on a black background | |
// Todo: randomly modulate the positions via theta and radius | |
shader_type canvas_item; | |
uniform float samples = 1000.0; | |
void fragment() { | |
// Project from plane onto a sphere | |
float phi = PI * UV.y; | |
float th = 2.0 * PI * UV.x; | |
// Get vertex point coordinates | |
float vx = sin(phi) * cos(th); | |
float vz = sin(phi) * sin(th); | |
float vy = cos(phi); | |
// golden angle | |
float ph = PI * (3.0 - sqrt(5.0)); | |
// Step the Y value | |
float ystep = round(vy * samples) / samples; | |
float radius = sqrt(1.0 - ystep * ystep); | |
float theta = ph * samples * (1.0 - ystep); | |
float x = cos(theta) * radius; | |
float z = sin(theta) * radius; | |
// Distance from current point to target | |
float d = length(vec3(vx, vy, vz) - vec3(x, ystep, z)); | |
// Apply this kind of shape to the point: ^ | |
COLOR.rgb = vec3(1.0) * smoothstep(1.0, 0.0, d * 200.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment