Skip to content

Instantly share code, notes, and snippets.

@CharStiles
Created July 17, 2019 23:40
Show Gist options
  • Save CharStiles/b3df69a4e4a31a943a2153db550a606f to your computer and use it in GitHub Desktop.
Save CharStiles/b3df69a4e4a31a943a2153db550a606f to your computer and use it in GitHub Desktop.
#version 150
// All of the uniform variables are declared in the side control panel
uniform float time;
uniform vec2 resolution;
uniform sampler2D texture0;
uniform sampler2D prevFrame;
// this is part of the pipeline, it doenst really concern us.
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 nodeStatus; // this is what the output of the node will be
void main(void)
{
vec2 nodeID = inData.v_texcoord;
// this ^^^^ is all the information we have about our fog node.
//JUST the ID which correleates to a pixel position on screen
// so the node given the ID (0,0) is in the bottom left screen and
// the node with the ID (1,1) is represetnted by the pixel in the top right
vec4 prevNodeStatus = texture(prevFrame, nodeID); // if this line isnt working, you have
//a different version of kodelife change the function texture to be texture2D
float frequency = 0.2;
vec2 i = nodeID*8.0- vec2(20.0); // these are magic numbers that scale it to fit the screen
float intensity = .2;
float t = time;
//these next two lines are where the magic happens! feel free to noodle around with the numbers
i += vec2(cos(t - i.x) + sin(t + i.y), sin(t - i.y) + cos(t + i.x));
float fog = 2.0+ (8/length(vec2(i.x / (sin(i.x+t)/intensity),i.y / (cos(i.y+t)/intensity))));
//normalizes the (intensity)colors so theyre between 0 and 1
fog = 1.0-sqrt(fog);
fog = fog*fog*fog*fog;
// if the fog is too bright, copy what it was the previous moment(frame)
if (fog > 0.3){
fog = prevNodeStatus.x * 0.99;
}
vec4 final = vec4(vec3(fog), 1.0); // casting to a vec4
//ignore the last number it doesnt matter in this context
nodeStatus = final;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment