Shader: Difusión Simple

uniform sampler2D initTex;
uniform sampler2D prevFrame;
uniform vec2 resolution;
uniform float K0; 
uniform float K1;
uniform float K2;
uniform float bbmix;
uniform float time;

IN vec2 texCoord; 


{{MODULES_HEAD}}

void main()
{
    vec2 pixel = texCoord;
    vec4 init = texture2D(initTex,texCoord);
    vec4 prev = texture2D(prevFrame,texCoord);
    
    vec2 dy = vec2(1.,-1.)*1./resolution.y;
    vec2 dx = vec2(1.,-1.)*1./resolution.x;
    
    vec4 N = texture2D(prevFrame, vec2(pixel.x, pixel.y + dy.y));
    vec4 S = texture2D(prevFrame, vec2(pixel.x, pixel.y + dy.x));
    vec4 E = texture2D(prevFrame, vec2(pixel.x + dx.x, pixel.y));
    vec4 W = texture2D(prevFrame, vec2(pixel.x + dx.y, pixel.y));
    
    vec4 NE = texture2D(prevFrame, vec2(pixel.x + dx.x, pixel.y + dy.x));
    vec4 NW = texture2D(prevFrame, vec2(pixel.x + dx.y, pixel.y + dy.x));
    vec4 SE = texture2D(prevFrame, vec2(pixel.x + dx.x, pixel.y + dy.y));
    vec4 SW = texture2D(prevFrame, vec2(pixel.x + dx.y, pixel.y + dy.y));
    
    
    // Lapalace 
    float lap = 0.0;
    lap += prev.r * K0;
    lap += N.r * K1;
    lap += S.r * K1;
    lap += E.r * K1;
    lap += W.r * K1;
    lap += NE.r * K2;
    lap += NW.r * K2;
    lap += SE.r * K2;
    lap += SW.r * K2;
  
    
    vec4 newColor ;
    newColor.r = prev.r+lap*0.045*texCoord.y;
    newColor.g = prev.g+lap*0.02;
    newColor.b = prev.b+lap*0.05;
    newColor.a = 1.0;
    
   
    outColor = mix( init , newColor, bbmix);
}

Last updated