diff --git a/sdf.fs b/sdf.fs index 6d707df..8829c94 100644 --- a/sdf.fs +++ b/sdf.fs @@ -100,17 +100,33 @@ void main() vec3 normal = calcNormal(ray); vec3 lighDir = normalize(vec3(.5,-1.0,0.5)); - float light = (- min(dot(normal,lighDir),0.0))*0.85+0.3; + float light = (- min(dot(normal,lighDir),0.0))*0.85; - Ray shRay = Ray(lighDir * (-1.0), ray.pos + 0.5*normal , .0,.0, vec3(.0)); - shRay = march(shRay); + float shLeve = 1.0; - if( (dot(lighDir,normal) < 0.0) && (shRay.len <20)){ - light *= min(shRay.len*0.1,1.0); + vec2 offsets[8] = vec2[]( + vec2( -0.94201624, -0.39906216 ), + vec2( 0.94558609, -0.76890725 ), + vec2( -0.094184101, -0.92938870 ), + vec2( 0.34495938, 0.29387760 ), + vec2( 0.94201624, 0.39906216 ), + vec2( -0.94558609, 0.76890725 ), + vec2( 0.094184101, 0.92938870 ), + vec2( -0.34495938, -0.29387760 ) + ); + + for(int i = 0; i < 8; i++){ + Ray shRay = Ray(lighDir * (-1.0) + vec3(offsets[i].x,.0,offsets[i].y)*0.05, ray.pos + 0.5*normal, .0,.0, vec3(.0)); + shRay = march(shRay); + if( (dot(lighDir,normal) < 0.0) && (shRay.len <20)){ + shLeve -= 0.125*max(1.0-shRay.len*0.07 , 0.0); + } } + light *= shLeve * .8; + if(ray.min <= 0.2){ - FragColor = vec4(ray.color * light, 1.0); + FragColor = vec4(ray.color * (light+0.3), 1.0); } else { FragColor = vec4(.0,0.0,0.0,1.0); }