Re: Share a Shader!
Posted: Sun Dec 22, 2019 10:08 pm
Just another simple Shader.
Splits a colored image into separate R,G,B images.
Splits a colored image into separate R,G,B images.
learn match (since there so much ways to create cool effects using only sine, cosine, etc)
I only get the coordinates of the point and change color depending on it. sinus, cosinus and their friend exponential (that is like a combination of both) are the base to create model of so much things on universe ^ ^. I made an easy to understand interactive tutorial https://tic80.com/play?cart=1739 in Lua too with TIC-80 (a fantasy console). I think both LÖVE and TIC-80 are complementary tools, with same language but different goals. cos & sin and e (and so ln) are some of the really convenient math tool, but you can also make nice effect without it, everything depend on reading the doc, let try several things with tool you learn and let your own imagination go as wild as possible.
thank you! that's an amazing piece of software! I think many teachers would find it very useful! thanks for sharing, it's time to relearn some math if I want to make my own shaders, I think it worth the effort.Popolon wrote: ↑Sat Mar 12, 2022 8:57 pmI only get the coordinates of the point and change color depending on it. sinus, cosinus and their friend exponential (that is like a combination of both) are the base to create model of so much things on universe ^ ^. I made an easy to understand interactive tutorial https://tic80.com/play?cart=1739 in Lua too with TIC-80 (a fantasy console). I think both LÖVE and TIC-80 are complementary tools, with same language but different goals. cos & sin and e (and so ln) are some of the really convenient math tool, but you can also make nice effect without it, everything depend on reading the doc, let try several things with tool you learn and let your own imagination go as wild as possible.
Code: Select all
#define fireMovement vec2(0.01, 0.2) // SPEED & DIRECTION
#define normalStrength 10.0 // INTENSITY OF FIRE
extern float time;
float rand(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
vec2 hash( vec2 p ) {
p = vec2( dot(p,vec2(127.1,311.7)),
dot(p,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(p)*43758.5453123);
}
float noise( in vec2 p ) {
const float K1 = 0.366025404; // (sqrt(3)-1)/2;
const float K2 = 0.211324865; // (3-sqrt(3))/6;
vec2 i = floor(p + (p.x+p.y)*K1);
vec2 a = p - i + (i.x+i.y)*K2;
vec2 o = step(a.yx,a.xy);
vec2 b = a - o + K2;
vec2 c = a - 1.0 + 2.0*K2;
vec3 h = max( 0.5-vec3(dot(a,a), dot(b,b), dot(c,c) ), 0.0 );
vec3 n = h*h*h*h*vec3( dot(a,hash(i+0.0)), dot(b,hash(i+o)), dot(c,hash(i+1.0)));
return dot( n, vec3(70.0) );
}
float fbm ( in vec2 p ) {
float f = 0.0;
mat2 m = mat2( 1.6, 1.2, -1.2, 1.6 );
f = 0.5000*noise(p); p = m*p;
f += 0.2500*noise(p); p = m*p;
f += 0.1250*noise(p); p = m*p;
f += 0.0625*noise(p); p = m*p;
f = 0.5 + 0.5 * f;
return f;
}
vec4 effect(vec4 color, Image tex, vec2 texCoords, vec2 screenCoords) {
vec2 uv = texCoords;
vec2 uvT = (uv * vec2(1.0, 0.5)) + time * fireMovement;
float n = pow(fbm(8.0 * uvT), 1.0);
float gradient = pow(1.0 - (1.0 - uv.y), 2.0) * normalStrength;
float finalNoise = n * gradient;
vec3 pixel = finalNoise * vec3(2.*n, 2.*n*n*n, n*n*n*n);
return vec4(pixel, 1.);
}