axmol/tests/cpp-tests/Source/shaders/shadertoy_FireBall.fsh

72 lines
1.9 KiB
Plaintext
Raw Normal View History

2023-09-01 14:49:03 +08:00
#version 310 es
precision highp float;
precision highp int;
//vec2 iCenter = center;
//uniform float iChannelTime[4]; // channel playback time (in seconds)
//uniform vec3 iChannelResolution[4]; // channel resolution (in pixels)
//vec4 iMouse = vec4(0,0,0,0); // mouse pixel coords. xy: current (if MLB down),
layout(std140) uniform fs_ub {
vec2 center;
vec2 resolution;
vec2 u_screenSize;
vec4 u_Time;
};
float snoise(vec3 uv, float res)
{
const vec3 s = vec3(1e0, 1e2, 1e4);
uv *= res;
vec3 uv0 = floor(mod(uv, res))*s;
vec3 uv1 = floor(mod(uv+vec3(1.), res))*s;
vec3 f = fract(uv); f = f*f*(3.0-2.0*f);
vec4 v = vec4(uv0.x+uv0.y+uv0.z, uv1.x+uv0.y+uv0.z,
uv0.x+uv1.y+uv0.z, uv1.x+uv1.y+uv0.z);
vec4 r = fract(sin(v*1e-3)*1e5);
float r0 = mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y);
r = fract(sin((v + uv1.z - uv0.z)*1e-3)*1e5);
float r1 = mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y);
return mix(r0, r1, f.z)*2.-1.;
}
layout(location = SV_Target0) out vec4 FragColor;
void main(void)
{
#ifdef METAL
vec2 fragCoord = vec2(gl_FragCoord.x, u_screenSize.y - gl_FragCoord.y);
#else
vec2 fragCoord = gl_FragCoord.xy;
#endif
vec2 iResolution = resolution; // viewport resolution (in pixels)
float iGlobalTime = u_Time[1]; // shader playback time (in seconds)
//vec2 p = -.5 + fragCoord.xy / iResolution.xy;
vec2 p = (fragCoord.xy - center.xy) / iResolution.xy;
p.x *= iResolution.x/iResolution.y;
float color = 3.0 - (3.*length(2.*p));
vec3 coord = vec3(atan(p.x,p.y)/6.2832+.5, length(p)*.4, .5);
for(int i = 1; i <= 3; i++)
{
float power = pow(2.0, float(i));
color += (1.5 / power) * snoise(coord + vec3(0.,-iGlobalTime*.05, iGlobalTime*.01), power*16.);
}
FragColor = vec4( color, pow(max(color,0.),2.)*0.4, pow(max(color,0.),3.)*0.15 , 1.0);
}