Pixel-Composer/scripts/d3d_light_point/d3d_light_point.gml

129 lines
4.5 KiB
Text
Raw Normal View History

2023-08-16 20:16:31 +02:00
function __3dLightPoint() : __3dLight() constructor {
color = c_white;
intensity = 1;
radius = 10;
2023-08-24 19:44:12 +02:00
shadow_mapper = sh_d3d_shadow_depth;
shadow_map_size = 512;
shadow_map_views = array_create(6);
shadow_maps = array_create(6);
2023-08-16 20:16:31 +02:00
static submitSel = function(params = {}) {
shader_set(sh_d3d_wireframe);
2023-11-15 02:35:30 +01:00
shader_set_color("blend", color);
2023-08-16 20:16:31 +02:00
preSubmitVertex(params);
shader_reset();
}
static submitShader = function(params = {}) { params.addLightPoint(self); }
static preSubmitVertex = function(params = {}) { #region
2023-08-30 16:40:45 +02:00
var _rot = new __rot3(0, 0, 0).lookAt(transform.position, params.camera.position);
2023-08-16 20:16:31 +02:00
var rot = matrix_build(0, 0, 0,
_rot.x, _rot.y, _rot.z,
1, 1, 1);
var sca = matrix_build(0, 0, 0,
0, 0, 0,
0.6, 0.6, 0.6);
var ran = matrix_build(0, 0, 0,
0, 0, 0,
radius * 2, radius * 2, radius * 2);
2023-08-30 16:40:45 +02:00
var pos = matrix_build(transform.position.x, transform.position.y, transform.position.z,
2023-08-16 20:16:31 +02:00
0, 0, 0,
1, 1, 1);
matrix_stack_push(pos);
matrix_stack_push(rot);
matrix_set(matrix_world, matrix_stack_top());
vertex_submit(VB_UI[0], pr_linestrip, -1);
2023-08-16 20:16:31 +02:00
matrix_stack_push(sca);
matrix_set(matrix_world, matrix_stack_top());
vertex_submit(VB_UI[0], pr_linestrip, -1);
2023-08-16 20:16:31 +02:00
matrix_stack_pop();
matrix_stack_push(ran);
matrix_set(matrix_world, matrix_stack_top());
vertex_submit(VB_UI[0], pr_linestrip, -1);
2023-08-16 20:16:31 +02:00
matrix_stack_pop();
2023-08-30 16:40:45 +02:00
matrix_stack_pop();
matrix_stack_pop();
2023-08-16 20:16:31 +02:00
matrix_set(matrix_world, matrix_build_identity());
} #endregion
static shadowProjectBegin = function(index = 0) { #region
//print($"Projecting cube face {index} to {shadow_maps[index]} with view {shadow_map_views[index]}")
surface_set_target(shadow_maps[index]);
draw_clear(c_black);
shader_set(shadow_mapper);
2023-12-06 13:51:22 +01:00
shader_set_i("use_8bit", OS == os_macosx);
gpu_set_ztestenable(true);
camera_set_view_mat(shadow_map_camera, shadow_map_views[index]);
camera_set_proj_mat(shadow_map_camera, shadow_map_proj);
camera_apply(shadow_map_camera);
} #endregion
static shadowProjectEnd = function() { #region
shader_reset();
surface_reset_target();
camera_apply(0);
2024-01-25 08:24:02 +01:00
gpu_set_ztestenable(false);
} #endregion
2023-09-11 16:08:58 +02:00
static submitShadow = function(scene, objects) { #region
if(!shadow_active) return;
for( var i = 0; i < 6; i++ )
2023-12-06 13:51:22 +01:00
shadow_maps[i] = surface_verify(shadow_maps[i], shadow_map_size, shadow_map_size, OS == os_macosx? surface_rgba8unorm : surface_r32float);
2023-08-30 16:40:45 +02:00
var position = transform.position;
shadow_map_views = array_create(6);
shadow_map_views[0] = matrix_build_lookat(position.x, position.y, position.z, position.x + 1, position.y, position.z, 0, 0, -1);
shadow_map_views[1] = matrix_build_lookat(position.x, position.y, position.z, position.x - 1, position.y, position.z, 0, 0, -1);
shadow_map_views[2] = matrix_build_lookat(position.x, position.y, position.z, position.x, position.y + 1, position.z, 0, 0, -1);
shadow_map_views[3] = matrix_build_lookat(position.x, position.y, position.z, position.x, position.y - 1, position.z, 0, 0, -1);
shadow_map_views[4] = matrix_build_lookat(position.x, position.y, position.z, position.x, position.y, position.z + 1, 0, -1, 0);
shadow_map_views[5] = matrix_build_lookat(position.x, position.y, position.z, position.x, position.y, position.z - 1, 0, 1, 0);
shadow_map_view = array_merge( shadow_map_views[0], shadow_map_views[1], shadow_map_views[2], shadow_map_views[3], shadow_map_views[4], shadow_map_views[5] );
shadow_map_proj = matrix_build_projection_perspective_fov(90, 1, .01, radius);
for( var j = 0; j < 6; j++ ) { ///FUCK There's gotta be a better way to do this in GameMaker
shadowProjectBegin(j);
2023-10-08 09:22:01 +02:00
objects.submit(scene, shadow_mapper);
shadowProjectEnd();
}
2023-12-06 13:51:22 +01:00
shadow_map = surface_verify(shadow_map, shadow_map_size * 2, shadow_map_size, OS == os_macosx? surface_rgba8unorm : surface_rgba32float);
surface_set_target(shadow_map);
draw_clear(c_black);
gpu_set_blendmode_ext(bm_one, bm_one);
draw_surface(shadow_maps[0], 0, 0);
draw_surface(shadow_maps[3], shadow_map_size, 0);
shader_set(sh_channel_R2G);
draw_surface(shadow_maps[1], 0, 0);
draw_surface(shadow_maps[4], shadow_map_size, 0);
shader_reset();
shader_set(sh_channel_R2B);
draw_surface(shadow_maps[2], 0, 0);
draw_surface(shadow_maps[5], shadow_map_size, 0);
shader_reset();
gpu_set_blendmode(bm_normal);
surface_reset_target();
} #endregion
2023-08-16 20:16:31 +02:00
}