-" // Compute world lighting contribution and apply it according to the\n"
-" // shadow map\n"
-" //\n"
-" vec3 world_light = newlight_compute_world_diffuse( wnormal );\n"
-" world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow();\n"
-"\n"
-" total_light += world_light * world_shadow;\n"
-"\n"
-" // Compute the other lights that exist in the map, not effected by the sun\n"
-" // shadow\n"
-" total_light += newlight_compute_quadratic\n"
-" ( \n"
-" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.x ].xyz,\n"
-" g_point_light_colours[ aLights.x ].rgb \n"
-" );\n"
-" total_light += newlight_compute_quadratic\n"
-" ( \n"
-" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.y ].xyz,\n"
-" g_point_light_colours[ aLights.y ].rgb \n"
-" );\n"
-" total_light += newlight_compute_quadratic\n"
-" ( \n"
-" wnormal, halfview,\n"
-" g_point_light_positions[ aLights.z ].xyz,\n"
-" g_point_light_colours[ aLights.z ].rgb \n"
-" );\n"
-"\n"
-" return apply_fog( diffuse * total_light, fdist );\n"
+" ivec3 coord = ivec3( cube_coord );\n"
+" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
+"\n"
+" total_light += \n"
+" scene_calculate_packed_light_patch( index_sample.x,\n"
+" halfview, co, normal ) \n"
+" * light_mask;\n"
+" total_light += \n"
+" scene_calculate_packed_light_patch( index_sample.y,\n"
+" halfview, co, normal )\n"
+" * light_mask;\n"
+"\n"
+" // Take a section of the sky function to give us a matching fog colour\n"
+"\n"
+" vec3 fog_colour = clearskies_ambient( -halfview );\n"
+" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
+" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
+" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
+" \n"
+" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
+" sun_colour *= sun_shape;\n"
+"\n"
+" fog_colour += sun_colour;\n"
+" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
+"}\n"
+"\n"
+"#line 9 0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+" vec3 pa = p - a;\n"
+" vec3 ba = b - a;\n"
+"\n"
+" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+" return length( pa - ba*h );\n"