This commit is contained in:
Lauri Räsänen 2023-07-15 16:43:42 +03:00
commit 751e21f981
7 changed files with 155 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/render/*.png

7
README.md Normal file
View file

@ -0,0 +1,7 @@
# Shaders
Shader projects for [SHADERed](https://github.com/dfranx/SHADERed).
## Gallery
![neon_pulse](/render/neon_pulse.gif)

4
create_gif.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
gifski -r 24 -o render/"$1".gif render/"$1"*.png

44
neon_pulse.sprj Normal file
View file

@ -0,0 +1,44 @@
<?xml version="1.0"?>
<project version="2">
<pipeline>
<pass name="Pulse" type="shader" active="true" patchverts="1">
<shader type="vs" path="shaders/neon_pulseVS.glsl" entry="main" />
<shader type="ps" path="shaders/neon_pulsePS.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="Pulse" item="pipe" />
<entry type="file" name="Pulse" shader="vs" />
<entry type="file" name="Pulse" 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/neon_pulse.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 MiB

92
shaders/neon_pulsePS.glsl Normal file
View file

@ -0,0 +1,92 @@
#version 330
uniform vec2 uResolution;
uniform float uTime;
out vec4 outColor;
// https://iquilezles.org/articles/palettes/
// http://dev.thi.ng/gradients/
vec3 palette(float t) {
vec3 a = vec3(0.500, 0.500, 0.000);
vec3 b = vec3(0.500, 0.500, 0.000);
vec3 c = vec3(0.100, 0.500, 0.000);
vec3 d = vec3(0.000, 0.000, 0.000);
return a + b*cos(6.28318*(c*t+d));
}
vec3 palette2(float t) {
vec3 a = vec3(0.500, 0.500, 0.000);
vec3 b = vec3(0.500, 0.500, 0.000);
vec3 c = vec3(1.000, 1.000, 1.000);
vec3 d = vec3(0.000, 0.333, 0.667);
return a + b*cos(6.28318*(c*t+d));
}
float rand(vec2 co){
return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453);
}
void main()
{
vec2 uv = (gl_FragCoord.xy * 2.0 - uResolution.xy) / uResolution.y;
// wobble
uv.x *= mix(1.0, sin(uTime * 0.5), 0.05);
uv.y *= mix(1.0, sin(uTime * 0.4), 0.05);
vec2 uv0 = uv;
float dist = length(uv0);
vec3 finalColor = vec3(0.0);
// foreground flash
for (float i = 0.0; i < 2.0; i++)
{
uv = fract(uv * 0.4) - 0.5;
uv *= cos(uTime * 0.5);
vec3 col = palette(dist + sin(uTime * 0.1));
float d = length(uv);
d = sin(d * 12.0 + uTime * 0.5) / 12.0;
d = abs(d);
d = 0.02 / d;
d = pow(d, 1.4);
finalColor += col * d;
}
// noise
float noise = rand(uv0 * uTime);
float strength = 0.2;
finalColor.x = pow(finalColor.x, mix(1.0, noise, strength));
finalColor.y = pow(finalColor.y, mix(1.0, noise, strength));
finalColor.z = pow(finalColor.z, mix(1.0, noise, strength));
// background circles
uv = fract(uv0 * 30.5) - 0.5;
uv *= sin(uTime * 0.5);
vec3 col = palette2(dist + sin(uTime * 0.4));
float d = length(uv);
d = sin(d * 5.0 + uTime * 0.5) / 5.0;
d = abs(d);
d = 0.01 / d;
d = pow(d, 0.5);
finalColor += col * d;
// vignette
vec2 edge = gl_FragCoord.xy / uResolution.xy;
edge *= 1.0 - edge.yx;
float vig = edge.x * edge.y * 20.0;
vig = pow(vig, 0.4);
finalColor *= vig;
outColor = vec4(finalColor, 1.0);
}

View file

@ -0,0 +1,7 @@
#version 330
layout (location = 0) in vec2 pos;
void main() {
gl_Position = vec4(pos, 0.0f, 1);
}