 		light_pos = to - light_dir * distance;
 
 		//from -= sign(light_dir)*0.45; //go near the edge towards the light direction to avoid self occlusion
-		float dist = raymarch(distance,distance_adv,light_pos,light_dir);
+
+		/*float dist = raymarch(distance,distance_adv,light_pos,light_dir);
 
 		if (dist > distance_adv) {
 			return false;
 		}
 
+		attenuation *= 1.0 - smoothstep(0.1*distance_adv,distance_adv,dist);
+		*/
+
+		float occlusion = raymarch(distance,distance_adv,light_pos,light_dir);
+
+		if (occlusion==0.0) {
+			return false;
+		}
+
+		attenuation *= occlusion;//1.0 - smoothstep(0.1*distance_adv,distance_adv,dist);
 
 	}
 



		vec3 to = pos;
		to-= sign(light_dir)*0.45; //go near the edge towards the light direction to avoid self occlusion

		//clip
		clip_segment(mix(vec4(-1.0,0.0,0.0,0.0),vec4(1.0,0.0,0.0,float(params.limits.x-1)),bvec4(light_dir.x < 0.0)),to,light_pos);

		distance -= advance;
	}

	return occlusion;//max(0.0,distance);

}

