Skip to content

Instantly share code, notes, and snippets.

@AlainBarrios
Created July 19, 2019 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlainBarrios/50e1e785b455b34b1d8fe79bfffc11fa to your computer and use it in GitHub Desktop.
Save AlainBarrios/50e1e785b455b34b1d8fe79bfffc11fa to your computer and use it in GitHub Desktop.
vec2 uv = vTextureCoord;
vec2 m = uMouse / uReso;
vec3 lightAmbient = vec3(.2, .2, .2 );
vec4 lightColor = vec4(1., 1., 1., 1.3);
vec3 lightPos = vec3(uv - m, .1);
vec3 color = texture2D(texture0, uv).xyz;
vec3 normalMap = texture2D(map, uv).xyz - .5;
vec3 diff = lightColor.rgb * lightColor.a * max(dot(normalize(normalMap), normalize(lightPos)), 0.);
float d = distance(m, uv);
float att = 1. - pow(clamp(d / 10., 0., 1.), .5);
vec3 totalLight = diff * att;
gl_FragColor = vec4(color * totalLight, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment