diff --git a/README.md b/README.md index f8c2798..1d39d6f 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # Shaders -Shader projects for [SHADERed](https://github.com/dfranx/SHADERed). +GLSL shaders and projects for [SHADERed](https://github.com/dfranx/SHADERed). ## Gallery ![neon_pulse](/render/neon_pulse.gif) ![flame](/render/flame.gif) ![sun](/render/sun.gif) +![galaxy](/render/galaxy.gif) diff --git a/galaxy.sprj b/galaxy.sprj new file mode 100644 index 0000000..89f0ec5 --- /dev/null +++ b/galaxy.sprj @@ -0,0 +1,44 @@ + + + + + + + + + + + + + ScreenQuadNDC + 1 + 1 + 1 + TriangleList + + + + + + + + + + + + + + + + + + 4 + 25 + 319 + 360 + + + + + + diff --git a/render/galaxy.gif b/render/galaxy.gif new file mode 100644 index 0000000..1a6cdaa Binary files /dev/null and b/render/galaxy.gif differ diff --git a/shaders/galaxy_GalaxyPS.glsl b/shaders/galaxy_GalaxyPS.glsl new file mode 100644 index 0000000..dc39f87 --- /dev/null +++ b/shaders/galaxy_GalaxyPS.glsl @@ -0,0 +1,65 @@ +#version 330 + +uniform vec2 uResolution; +uniform float uTime; + +out vec4 outColor; + +const float PI = 3.14159; +const int CIRCLES = 2000; +const float OUTER_RAD = 1.0; +const float TILT_X = 0.05; +const float TILT_Y = 0.1; +const float CENTER_SPIN_SPEED = 1.0; + +float circle(vec2 uv, vec2 center, float r0, float r1) +{ + float d = length(center - uv); + return 1.0 - smoothstep(r0, r1, d); +} + +float rand(vec2 co) +{ + return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453); +} + +// https://iquilezles.org/articles/palettes/ +// http://dev.thi.ng/gradients/ +vec3 palette(float t) +{ + vec3 a = vec3(0.838, 0.838, 0.788); + vec3 b = vec3(0.445, 0.390, 0.641); + vec3 c = vec3(0.380, 0.584, 0.380); + vec3 d = vec3(-0.272, -0.239, 0.075); + + return a + b*cos(6.28318*(c*t+d)); +} + +void main() +{ + vec2 uv = (gl_FragCoord.xy * 2.0 - uResolution.xy) / uResolution.y; + vec3 finalColor = vec3(0.0); + + for (int i = 0; i < CIRCLES; i++) + { + float centerDist = rand(vec2(i)); + float offset = i * PI * 2 / CIRCLES; + float distSpeed = 1.0 + (1.0 - centerDist) * CENTER_SPIN_SPEED; + float posX = sin(uTime * (TILT_X + distSpeed) + offset); + float posY = cos(uTime * (TILT_Y + distSpeed) + offset); + + vec3 col = palette(centerDist + sin(uTime) * 0.5); + + finalColor += circle( + uv, + vec2( + posX * OUTER_RAD * centerDist, + posY * OUTER_RAD * centerDist + ), + 0.0, + 0.04 * (1.0 - centerDist * 0.5) + ) * col; + } + + outColor = vec4(finalColor,1.0); +} \ No newline at end of file diff --git a/shaders/galaxy_GalaxyVS.glsl b/shaders/galaxy_GalaxyVS.glsl new file mode 100644 index 0000000..1ea7fd7 --- /dev/null +++ b/shaders/galaxy_GalaxyVS.glsl @@ -0,0 +1,7 @@ +#version 330 + +layout (location = 0) in vec2 pos; + +void main() { + gl_Position = vec4(pos, 0.0f, 1); +}