// Physically based lightness calculation // for a rod light perpendicular to a // matte (Lambertian) ground plane, expanding up and down. // details: https://hyperknot.com/blog/area_lights_in_shaders/ float rod_light_antideriv(vec2 uv, float i, float h) { return i * uv.x / (dot(uv,uv) + h*h); } float rod_light(vec2 uv, float i, float h_top, float h_bottom) { // h_top and h_bottom - the light's top and bottom above the ground // i - light's intensity return rod_light_antideriv(uv, i, h_top) - rod_light_antideriv(uv, i, h_bottom); } float lin_to_srgb ( float val ) { if( val < 0.0031308 ) return val * 12.92; else return 1.055 * pow(val,1.0/2.4) - 0.055; } void mainImage( out vec4 fragColor, in vec2 fragCoord ){ vec2 uv = ( fragCoord - .5*iResolution.xy ) / iResolution.y; float h = pow(sin(iTime/3.), 2.) * 0.1 + 0.002; float v = rod_light(uv, 0.1, h, 0.001); v = lin_to_srgb(v); fragColor=vec4(v); }