Posted July 08, 2024 by Not Jam
Star layers spawn a user-specified number of stars at random locations onscreen. They have a simple set of parameters to give the user some control over this generation:
A subtle twinkling effect is applied to star layers when displayed within Space Generator - this is a very simple shader applied to the whole layer:
shader_type canvas_item; uniform sampler2D noise_texture; uniform float rate; uniform float depth; float get_lum(vec4 color) { return (color.r * 0.299) + (color.g * 0.587) + (color.b * 0.114); } void fragment() { float offset = get_lum(texture(noise_texture, UV)) * 2.0; float color_mod = 0.5 * (1.0 + sin(2.0 * PI * rate * (TIME + offset))); COLOR *= (1.0 - (color_mod * depth)); }
Note: the language used here is .gdshader, but this is very similar in use to GLSL ES 3.0 - if you're familiar it shouldn't be too challenging to port this over. A useful reference for migrating between GLSL ES 3.0 and .gdshader can be found here
This shader allows the user to specify a handful of variables:
With these parameters set, the shader will then adjust the brightness of each pixel at the same rate, but offset according to the brightness of the noise texture at that pixel's coordinates. These variables are exposed via the layer settings for the user to experiment with.
This shader is under CC0 terms - feel free to copy this over to your own projects and adjust the variables to your taste, or rewrite it to better suit your needs!