Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------Draw--------
- var view_mat = camera_get_view_mat(cam),
- x_scale = camera_get_view_width/surface_get_width(application_surface),
- y_scale = camera_get_view_height/surface_get_height(application_surface),
- view_x = c_x + camera_get_view_width(cam)*.5 - camera_get_view_width(cam)*.5 * view_mat[0] - camera_get_view_height(cam)*.5 * view_mat[1],
- view_y = c_y + camera_get_view_height(cam)*.5 + camera_get_view_width(cam)*.5 * view_mat[1] - camera_get_view_height(cam)*.5 * view_mat[0];
- //Create and populate array of lights
- var l_count = instance_number(o_Light),
- l_arr = array_create(l_count * 7 + 1),
- l_i = 1;
- l_arr[0] = l_count;
- with (o_Light) {
- l_arr[l_i++] = x;
- l_arr[l_i++] = y;
- l_arr[l_i++] = image_blend;
- l_arr[l_i++] = in_rad;
- l_arr[l_i++] = out_rad;
- l_arr[l_i++] = dir;
- l_arr[l_i++] = fov;
- }
- //Create the light surface and set it as target
- if (!surface_exists(light_surf))
- light_surf = surface_create(surface_get_width(application_surface), surface_get_height(application_surface));
- gpu_set_blendmode_ext(bm_one, bm_zero);
- surface_set_target(light_surf); {
- camera_apply(cam);
- shader_set(sh_LightArray);
- shader_set_uniform_f_array(l_array, l_arr);
- draw_surface_ext(application_surface, view_x, view_y, x_scale, y_scale, 0, c_white, 1);
- shader_reset();
- } surface_reset_target();
- //Draw light_surf back to app_surf
- draw_surface_ext(light_surf, view_x, view_y, x_scale, y_scale, 0, c_white, 1);
- gpu_set_blendmode(bm_normal);
- -------Shader--------
- vec3 get_radiance(float c)
- {
- // UNPACK COLOR BITS
- vec3 col;
- col.b = floor(c * 0.0000152587890625);
- float blue_bits = c - col.b * 65536.0;
- col.g = floor(blue_bits * 0.00390625);
- col.r = floor(blue_bits - col.g * 256.0);
- // NORMALIZE 0-255
- return col * 0.00390625;
- }
- varying vec2 pos; //Pixel position
- varying vec2 tex;
- uniform float l_array[512];
- #define PI 3.1415926538
- void main() {
- vec3 albedo = texture2D(gm_BaseTexture, tex).rgb;
- vec3 color = vec3(0.0);
- //Iterate over the lights array
- int num_lights = int(l_array[0]);
- int l_i = 1;
- for (int i=0; i<num_lights; ++i) {
- vec2 l_pos = vec2(l_array[l_i++], l_array[l_i++]);
- vec3 radiance = get_radiance(l_array[l_i++]);
- float l_in_rad = l_array[l_i++];
- float l_out_rad = l_array[l_i++];
- float l_dir = l_array[l_i++];
- float l_fov = l_array[l_i++];
- //Test attenuation
- float dist = length(l_pos.xy - pos.xy) / l_out_rad;
- float new_alpha = 5./(dist*dist*.1 + 1.);
- color += albedo * new_alpha * radiance;
- }
- gl_FragColor = vec4(color, 1.);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement