Add galaxy
This commit is contained in:
parent
1c57e77c68
commit
2b9a0a9233
5 changed files with 118 additions and 1 deletions
|
@ -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
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
|
44
galaxy.sprj
Normal file
44
galaxy.sprj
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0"?>
|
||||
<project version="2">
|
||||
<pipeline>
|
||||
<pass name="Galaxy" type="shader" active="true" patchverts="1">
|
||||
<shader type="vs" path="shaders/galaxy_GalaxyVS.glsl" entry="main" />
|
||||
<shader type="ps" path="shaders/galaxy_GalaxyPS.glsl" entry="main" />
|
||||
<inputlayout>
|
||||
<item value="Position" semantic="POSITION" />
|
||||
</inputlayout>
|
||||
<rendertexture />
|
||||
<items>
|
||||
<item name="Quad" type="geometry">
|
||||
<type>ScreenQuadNDC</type>
|
||||
<width>1</width>
|
||||
<height>1</height>
|
||||
<depth>1</depth>
|
||||
<topology>TriangleList</topology>
|
||||
</item>
|
||||
</items>
|
||||
<itemvalues />
|
||||
<variables>
|
||||
<variable type="float2" name="uResolution" system="ViewportSize" />
|
||||
<variable type="float" name="uTime" system="Time" />
|
||||
</variables>
|
||||
<macros />
|
||||
</pass>
|
||||
</pipeline>
|
||||
<objects />
|
||||
<cameras />
|
||||
<settings>
|
||||
<entry type="property" name="Galaxy" item="pipe" />
|
||||
<entry type="file" name="Galaxy" shader="vs" />
|
||||
<entry type="file" name="Galaxy" shader="ps" />
|
||||
<entry type="camera" fp="false">
|
||||
<distance>4</distance>
|
||||
<pitch>25</pitch>
|
||||
<yaw>319</yaw>
|
||||
<roll>360</roll>
|
||||
</entry>
|
||||
<entry type="clearcolor" r="0" g="0" b="0" a="0" />
|
||||
<entry type="usealpha" val="false" />
|
||||
</settings>
|
||||
<plugindata />
|
||||
</project>
|
BIN
render/galaxy.gif
Normal file
BIN
render/galaxy.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.7 MiB |
65
shaders/galaxy_GalaxyPS.glsl
Normal file
65
shaders/galaxy_GalaxyPS.glsl
Normal file
|
@ -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);
|
||||
}
|
7
shaders/galaxy_GalaxyVS.glsl
Normal file
7
shaders/galaxy_GalaxyVS.glsl
Normal file
|
@ -0,0 +1,7 @@
|
|||
#version 330
|
||||
|
||||
layout (location = 0) in vec2 pos;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(pos, 0.0f, 1);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue