This commit is contained in:
Lauri Räsänen 2023-07-15 20:31:20 +03:00
parent 059afdc5e7
commit 1c57e77c68
5 changed files with 146 additions and 0 deletions

View file

@ -6,3 +6,4 @@ Shader projects for [SHADERed](https://github.com/dfranx/SHADERed).
![neon_pulse](/render/neon_pulse.gif) ![neon_pulse](/render/neon_pulse.gif)
![flame](/render/flame.gif) ![flame](/render/flame.gif)
![sun](/render/sun.gif)

BIN
render/sun.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

94
shaders/sun_SunPS.glsl Normal file
View file

@ -0,0 +1,94 @@
#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));
}
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;
uv *= 0.6; // final scale
vec2 uv0 = uv;
vec3 finalColor = vec3(0.0);
// sun + sky base
float dist = length(uv);
float flareMask = 1.0 - smoothstep(0.4, 0.49, dist);
float hotspotMask = 1.0 - smoothstep(0.4, 0.43, dist);
float noiseMask = 1.0 - smoothstep(0, 0.43, dist);
vec3 col = palette(dist);
dist = 0.6 / dist;
dist = pow(dist, 1.4);
finalColor += col * dist;
// flares
vec3 flareColor = vec3(0.0);
for (float i = 0.0; i < 3.0; i++)
{
uv = fract(uv * 1.6) - 0.5;
float d = length(uv);
vec3 col = palette(d + sin(uTime * 0.1));
d = sin(d * 12.0 + uTime * 0.5) / 12.0;
d = abs(d);
d = 0.04 / d;
d = pow(d, 1.4);
flareColor += col * d * flareMask;
}
finalColor += flareColor;
// hotspots
/*
vec3 hotspotColor = vec3(1.0);
float hotspotMask2 = 1.0;
vec2 hotspotUv = uv0 + 0.01 * vec2(uTime, -uTime * 0.2);
for (float i = 0.0; i < 2.0; i++)
{
hotspotUv = fract(hotspotUv * 1.5) - 0.5;
float d = length(hotspotUv);
d = sin(d * 4.0) / 8.0;
d = abs(d);
d = 0.1 / d;
hotspotMask2 *= d;
}
finalColor -= 0.03 * hotspotColor * hotspotMask * hotspotMask2;
*/
// surface noise + brighter in the middle
float noise = rand(uv * sin(uTime));
finalColor += 1.5 * noise * noiseMask;
// 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.1);
finalColor *= vig;
outColor = vec4(finalColor, 1.0);
//outColor = vec4(hotspotColor * hotspotMask * hotspotMask2, 1.0);
}

7
shaders/sun_SunVS.glsl Normal file
View file

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

44
sun.sprj Normal file
View file

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