From 7d401a25d42d1dbf5c7be8502877a6e9c194c9d2 Mon Sep 17 00:00:00 2001 From: MakhamDev Date: Mon, 23 Oct 2023 19:33:55 +0700 Subject: [PATCH] - New 3D terrain node. --- PixelComposer.resource_order | 48 +++--- PixelComposer.yyp | 3 +- scripts/color_function/color_function.gml | 6 + scripts/d3d_terrain/d3d_terrain.gml | 90 +++++++++++ scripts/d3d_terrain/d3d_terrain.yy | 11 ++ scripts/globals/globals.gml | 6 +- .../node_3d_mesh_terrain.gml | 71 +++++++++ .../node_3d_mesh_terrain.yy | 11 ++ scripts/node_3d_mesh_terrain/node_counter.yy | 12 ++ scripts/node_registry/node_registry.gml | 1 + scripts/panel_preview/panel_preview.gml | 6 +- .../sh_shape_normalize/sh_shape_normalize.fsh | 147 ------------------ .../sh_shape_normalize/sh_shape_normalize.vsh | 19 --- .../sh_shape_normalize/sh_shape_normalize.yy | 10 -- 14 files changed, 235 insertions(+), 206 deletions(-) create mode 100644 scripts/d3d_terrain/d3d_terrain.gml create mode 100644 scripts/d3d_terrain/d3d_terrain.yy create mode 100644 scripts/node_3d_mesh_terrain/node_3d_mesh_terrain.gml create mode 100644 scripts/node_3d_mesh_terrain/node_3d_mesh_terrain.yy create mode 100644 scripts/node_3d_mesh_terrain/node_counter.yy delete mode 100644 shaders/sh_shape_normalize/sh_shape_normalize.fsh delete mode 100644 shaders/sh_shape_normalize/sh_shape_normalize.vsh delete mode 100644 shaders/sh_shape_normalize/sh_shape_normalize.yy diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index 76f443bf2..70412e491 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -20,11 +20,11 @@ {"name":"widget","order":9,"path":"folders/dialog/widget.yy",}, {"name":"font","order":7,"path":"folders/font.yy",}, {"name":"functions","order":6,"path":"folders/functions.yy",}, - {"name":"camera","order":7,"path":"folders/functions/3d/camera.yy",}, - {"name":"gizmo","order":11,"path":"folders/functions/3d/gizmo.yy",}, - {"name":"light","order":6,"path":"folders/functions/3d/light.yy",}, - {"name":"mesh","order":8,"path":"folders/functions/3d/mesh.yy",}, - {"name":"util","order":5,"path":"folders/functions/3d/util.yy",}, + {"name":"camera","order":5,"path":"folders/functions/3d/camera.yy",}, + {"name":"gizmo","order":8,"path":"folders/functions/3d/gizmo.yy",}, + {"name":"light","order":4,"path":"folders/functions/3d/light.yy",}, + {"name":"mesh","order":6,"path":"folders/functions/3d/mesh.yy",}, + {"name":"util","order":3,"path":"folders/functions/3d/util.yy",}, {"name":"action","order":38,"path":"folders/functions/action.yy",}, {"name":"animation","order":19,"path":"folders/functions/animation.yy",}, {"name":"async","order":34,"path":"folders/functions/async.yy",}, @@ -79,7 +79,7 @@ {"name":"components","order":2,"path":"folders/main/components.yy",}, {"name":"nodes","order":3,"path":"folders/nodes.yy",}, {"name":"data","order":1,"path":"folders/nodes/data.yy",}, - {"name":"3D","order":8,"path":"folders/nodes/data/3D.yy",}, + {"name":"3D","order":20,"path":"folders/nodes/data/3D.yy",}, {"name":"__legacy","order":5,"path":"folders/nodes/data/3D/__legacy.yy",}, {"name":"primitive","order":9,"path":"folders/nodes/data/3D/__legacy/primitive.yy",}, {"name":"2d effects","order":7,"path":"folders/nodes/data/3D/2d effects.yy",}, @@ -87,9 +87,9 @@ {"name":"d3d light","order":14,"path":"folders/nodes/data/3D/d3d light.yy",}, {"name":"d3d mesh","order":12,"path":"folders/nodes/data/3D/d3d mesh.yy",}, {"name":"animation","order":6,"path":"folders/nodes/data/animation.yy",}, - {"name":"compose","order":12,"path":"folders/nodes/data/compose.yy",}, + {"name":"compose","order":11,"path":"folders/nodes/data/compose.yy",}, {"name":"armature","order":5,"path":"folders/nodes/data/compose/armature.yy",}, - {"name":"dynasurf","order":15,"path":"folders/nodes/data/dynasurf.yy",}, + {"name":"dynasurf","order":14,"path":"folders/nodes/data/dynasurf.yy",}, {"name":"filter","order":2,"path":"folders/nodes/data/filter.yy",}, {"name":"colors","order":4,"path":"folders/nodes/data/filter/colors.yy",}, {"name":"combine","order":1,"path":"folders/nodes/data/filter/combine.yy",}, @@ -104,30 +104,30 @@ {"name":"group","order":7,"path":"folders/nodes/data/group.yy",}, {"name":"IO","order":1,"path":"folders/nodes/data/IO.yy",}, {"name":"network","order":16,"path":"folders/nodes/data/IO/network.yy",}, - {"name":"iterate","order":10,"path":"folders/nodes/data/iterate.yy",}, + {"name":"iterate","order":9,"path":"folders/nodes/data/iterate.yy",}, {"name":"feedback","order":7,"path":"folders/nodes/data/iterate/feedback.yy",}, {"name":"for each","order":1,"path":"folders/nodes/data/iterate/for each.yy",}, {"name":"for filter","order":3,"path":"folders/nodes/data/iterate/for filter.yy",}, {"name":"for sort","order":5,"path":"folders/nodes/data/iterate/for sort.yy",}, - {"name":"lua","order":13,"path":"folders/nodes/data/lua.yy",}, - {"name":"misc","order":11,"path":"folders/nodes/data/misc.yy",}, - {"name":"PCX","order":16,"path":"folders/nodes/data/PCX.yy",}, + {"name":"lua","order":12,"path":"folders/nodes/data/lua.yy",}, + {"name":"misc","order":10,"path":"folders/nodes/data/misc.yy",}, + {"name":"PCX","order":15,"path":"folders/nodes/data/PCX.yy",}, {"name":"array","order":6,"path":"folders/nodes/data/PCX/array.yy",}, {"name":"flow control","order":7,"path":"folders/nodes/data/PCX/flow control.yy",}, {"name":"fn","order":2,"path":"folders/nodes/data/PCX/fn.yy",}, {"name":"surface","order":3,"path":"folders/nodes/data/PCX/surface.yy",}, {"name":"value","order":4,"path":"folders/nodes/data/PCX/value.yy",}, - {"name":"pixel builder","order":14,"path":"folders/nodes/data/pixel builder.yy",}, + {"name":"pixel builder","order":13,"path":"folders/nodes/data/pixel builder.yy",}, {"name":"box","order":2,"path":"folders/nodes/data/pixel builder/box.yy",}, {"name":"draw","order":3,"path":"folders/nodes/data/pixel builder/draw.yy",}, {"name":"effect","order":4,"path":"folders/nodes/data/pixel builder/effect.yy",}, {"name":"render","order":3,"path":"folders/nodes/data/render.yy",}, - {"name":"simulation","order":17,"path":"folders/nodes/data/simulation.yy",}, + {"name":"simulation","order":16,"path":"folders/nodes/data/simulation.yy",}, {"name":"fluidSim","order":2,"path":"folders/nodes/data/simulation/fluidSim.yy",}, {"name":"strandSim","order":1,"path":"folders/nodes/data/simulation/strandSim.yy",}, {"name":"VFX","order":3,"path":"folders/nodes/data/simulation/VFX.yy",}, {"name":"effector","order":18,"path":"folders/nodes/data/simulation/VFX/effector.yy",}, - {"name":"transform","order":9,"path":"folders/nodes/data/transform.yy",}, + {"name":"transform","order":8,"path":"folders/nodes/data/transform.yy",}, {"name":"value","order":4,"path":"folders/nodes/data/value.yy",}, {"name":"array","order":1,"path":"folders/nodes/data/value/array.yy",}, {"name":"atlas","order":10,"path":"folders/nodes/data/value/atlas.yy",}, @@ -224,7 +224,6 @@ {"name":"s_node_corner","order":16,"path":"sprites/s_node_corner/s_node_corner.yy",}, {"name":"sh_cell_noise_crystal","order":1,"path":"shaders/sh_cell_noise_crystal/sh_cell_noise_crystal.yy",}, {"name":"panel_function","order":2,"path":"scripts/panel_function/panel_function.yy",}, - {"name":"sh_shape_normalize","order":36,"path":"shaders/sh_shape_normalize/sh_shape_normalize.yy",}, {"name":"node_time_remap","order":3,"path":"scripts/node_time_remap/node_time_remap.yy",}, {"name":"sh_perlin","order":4,"path":"shaders/sh_perlin/sh_perlin.yy",}, {"name":"sh_normal_light","order":1,"path":"shaders/sh_normal_light/sh_normal_light.yy",}, @@ -251,7 +250,7 @@ {"name":"s_node_text_trim","order":7,"path":"sprites/s_node_text_trim/s_node_text_trim.yy",}, {"name":"s_node_pb_fx_shading","order":3,"path":"sprites/s_node_pb_fx_shading/s_node_pb_fx_shading.yy",}, {"name":"sh_noise_grid_hex","order":2,"path":"shaders/sh_noise_grid_hex/sh_noise_grid_hex.yy",}, - {"name":"__node_process_template","order":19,"path":"scripts/__node_process_template/__node_process_template.yy",}, + {"name":"__node_process_template","order":18,"path":"scripts/__node_process_template/__node_process_template.yy",}, {"name":"__node_3d_obj","order":4,"path":"scripts/__node_3d_obj/__node_3d_obj.yy",}, {"name":"__path","order":1,"path":"scripts/__path/__path.yy",}, {"name":"draw_text_path","order":25,"path":"scripts/draw_text_path/draw_text_path.yy",}, @@ -313,6 +312,7 @@ {"name":"sh_blur_final","order":2,"path":"shaders/sh_blur_final/sh_blur_final.yy",}, {"name":"s_window_frame","order":6,"path":"sprites/s_window_frame/s_window_frame.yy",}, {"name":"sh_fd_visualize_velocity_glsl","order":19,"path":"shaders/sh_fd_visualize_velocity_glsl/sh_fd_visualize_velocity_glsl.yy",}, + {"name":"node_3d_mesh_terrain","order":9,"path":"scripts/node_3d_mesh_terrain/node_3d_mesh_terrain.yy",}, {"name":"fd_rectangle_set_material_time_step","order":8,"path":"scripts/fd_rectangle_set_material_time_step/fd_rectangle_set_material_time_step.yy",}, {"name":"credit_badge_popular","order":2,"path":"sprites/credit_badge_popular/credit_badge_popular.yy",}, {"name":"s_node_path_sample","order":3,"path":"sprites/s_node_path_sample/s_node_path_sample.yy",}, @@ -327,7 +327,7 @@ {"name":"s_node_noise_simplex","order":20,"path":"sprites/s_node_noise_simplex/s_node_noise_simplex.yy",}, {"name":"s_node_armature_sample","order":18,"path":"sprites/s_node_armature_sample/s_node_armature_sample.yy",}, {"name":"sh_draw_color","order":8,"path":"shaders/sh_draw_color/sh_draw_color.yy",}, - {"name":"d3d_scene","order":4,"path":"scripts/d3d_scene/d3d_scene.yy",}, + {"name":"d3d_scene","order":2,"path":"scripts/d3d_scene/d3d_scene.yy",}, {"name":"sh_channel_R2A","order":13,"path":"shaders/sh_channel_R2A/sh_channel_R2A.yy",}, {"name":"__node_module","order":14,"path":"scripts/__node_module/__node_module.yy",}, {"name":"s_node_array_find","order":2,"path":"sprites/s_node_array_find/s_node_array_find.yy",}, @@ -377,7 +377,7 @@ {"name":"_f_code","order":9,"path":"fonts/_f_code/_f_code.yy",}, {"name":"sh_combine_rgb","order":11,"path":"shaders/sh_combine_rgb/sh_combine_rgb.yy",}, {"name":"node_armature_to_path","order":4,"path":"scripts/node_armature_to_path/node_armature_to_path.yy",}, - {"name":"d3d_object","order":2,"path":"scripts/d3d_object/d3d_object.yy",}, + {"name":"d3d_object","order":1,"path":"scripts/d3d_object/d3d_object.yy",}, {"name":"s_node_strandSim","order":3,"path":"sprites/s_node_strandSim/s_node_strandSim.yy",}, {"name":"o_dialog_panel","order":13,"path":"objects/o_dialog_panel/o_dialog_panel.yy",}, {"name":"s_node_vfx","order":9,"path":"sprites/s_node_vfx/s_node_vfx.yy",}, @@ -553,6 +553,7 @@ {"name":"o_dialog_add_node","order":1,"path":"objects/o_dialog_add_node/o_dialog_add_node.yy",}, {"name":"s_node_path_reverse","order":8,"path":"sprites/s_node_path_reverse/s_node_path_reverse.yy",}, {"name":"sh_draw_texture","order":6,"path":"shaders/sh_draw_texture/sh_draw_texture.yy",}, + {"name":"d3d_terrain","order":8,"path":"scripts/d3d_terrain/d3d_terrain.yy",}, {"name":"fd_rectangle_get_pressure_width","order":18,"path":"scripts/fd_rectangle_get_pressure_width/fd_rectangle_get_pressure_width.yy",}, {"name":"sh_blend_normal","order":1,"path":"shaders/sh_blend_normal/sh_blend_normal.yy",}, {"name":"node_feedback_output","order":2,"path":"scripts/node_feedback_output/node_feedback_output.yy",}, @@ -561,7 +562,7 @@ {"name":"panel_tunnels","order":1,"path":"scripts/panel_tunnels/panel_tunnels.yy",}, {"name":"node_processor","order":7,"path":"scripts/node_processor/node_processor.yy",}, {"name":"animation_controller","order":1,"path":"scripts/animation_controller/animation_controller.yy",}, - {"name":"node_module_test","order":20,"path":"scripts/node_module_test/node_module_test.yy",}, + {"name":"node_module_test","order":19,"path":"scripts/node_module_test/node_module_test.yy",}, {"name":"s_node_shadow","order":36,"path":"sprites/s_node_shadow/s_node_shadow.yy",}, {"name":"s_node_grid_hex_noise","order":21,"path":"sprites/s_node_grid_hex_noise/s_node_grid_hex_noise.yy",}, {"name":"s_node_logic_opr","order":2,"path":"sprites/s_node_logic_opr/s_node_logic_opr.yy",}, @@ -651,7 +652,6 @@ {"name":"node_mirror","order":3,"path":"scripts/node_mirror/node_mirror.yy",}, {"name":"node_corner","order":6,"path":"scripts/node_corner/node_corner.yy",}, {"name":"node_3d_mesh_cylinder","order":3,"path":"scripts/node_3d_mesh_cylinder/node_3d_mesh_cylinder.yy",}, - {"name":"__vertex_function","order":1,"path":"scripts/__vertex_function/__vertex_function.yy",}, {"name":"node_path_anchor","order":13,"path":"scripts/node_path_anchor/node_path_anchor.yy",}, {"name":"s_node_path_wave","order":7,"path":"sprites/s_node_path_wave/s_node_path_wave.yy",}, {"name":"string_functions","order":6,"path":"scripts/string_functions/string_functions.yy",}, @@ -893,7 +893,7 @@ {"name":"fd_README","order":6,"path":"scripts/fd_README/fd_README.yy",}, {"name":"ase_object","order":7,"path":"scripts/ase_object/ase_object.yy",}, {"name":"node_rigid_object","order":1,"path":"scripts/node_rigid_object/node_rigid_object.yy",}, - {"name":"__node_template","order":18,"path":"scripts/__node_template/__node_template.yy",}, + {"name":"__node_template","order":17,"path":"scripts/__node_template/__node_template.yy",}, {"name":"node_pb_box_transform","order":9,"path":"scripts/node_pb_box_transform/node_pb_box_transform.yy",}, {"name":"areaBox","order":1,"path":"scripts/areaBox/areaBox.yy",}, {"name":"__global_object_depths","order":7,"path":"scripts/__global_object_depths/__global_object_depths.yy",}, @@ -1123,7 +1123,7 @@ {"name":"node_text","order":5,"path":"scripts/node_text/node_text.yy",}, {"name":"panel_collection","order":3,"path":"scripts/panel_collection/panel_collection.yy",}, {"name":"node_string_trim","order":4,"path":"scripts/node_string_trim/node_string_trim.yy",}, - {"name":"d3d_material","order":12,"path":"scripts/d3d_material/d3d_material.yy",}, + {"name":"d3d_material","order":9,"path":"scripts/d3d_material/d3d_material.yy",}, {"name":"lerp_float","order":1,"path":"scripts/lerp_float/lerp_float.yy",}, {"name":"vectorRangeBox","order":19,"path":"scripts/vectorRangeBox/vectorRangeBox.yy",}, {"name":"sh_draw_r8","order":9,"path":"shaders/sh_draw_r8/sh_draw_r8.yy",}, @@ -1228,7 +1228,7 @@ {"name":"__panel_linear_setting","order":8,"path":"scripts/__panel_linear_setting/__panel_linear_setting.yy",}, {"name":"BBMOD_Quaternion","order":3,"path":"scripts/BBMOD_Quaternion/BBMOD_Quaternion.yy",}, {"name":"d3d_cube","order":1,"path":"scripts/d3d_cube/d3d_cube.yy",}, - {"name":"d3d_group","order":9,"path":"scripts/d3d_group/d3d_group.yy",}, + {"name":"d3d_group","order":7,"path":"scripts/d3d_group/d3d_group.yy",}, {"name":"o_dialog_output_visibility","order":2,"path":"objects/o_dialog_output_visibility/o_dialog_output_visibility.yy",}, {"name":"node_normal","order":1,"path":"scripts/node_normal/node_normal.yy",}, {"name":"s_node_glow","order":24,"path":"sprites/s_node_glow/s_node_glow.yy",}, diff --git a/PixelComposer.yyp b/PixelComposer.yyp index 77316d035..672885203 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -774,7 +774,6 @@ {"id":{"name":"s_node_corner","path":"sprites/s_node_corner/s_node_corner.yy",},}, {"id":{"name":"sh_cell_noise_crystal","path":"shaders/sh_cell_noise_crystal/sh_cell_noise_crystal.yy",},}, {"id":{"name":"panel_function","path":"scripts/panel_function/panel_function.yy",},}, - {"id":{"name":"sh_shape_normalize","path":"shaders/sh_shape_normalize/sh_shape_normalize.yy",},}, {"id":{"name":"node_time_remap","path":"scripts/node_time_remap/node_time_remap.yy",},}, {"id":{"name":"sh_perlin","path":"shaders/sh_perlin/sh_perlin.yy",},}, {"id":{"name":"sh_normal_light","path":"shaders/sh_normal_light/sh_normal_light.yy",},}, @@ -870,6 +869,7 @@ {"id":{"name":"sh_blur_final","path":"shaders/sh_blur_final/sh_blur_final.yy",},}, {"id":{"name":"s_window_frame","path":"sprites/s_window_frame/s_window_frame.yy",},}, {"id":{"name":"sh_fd_visualize_velocity_glsl","path":"shaders/sh_fd_visualize_velocity_glsl/sh_fd_visualize_velocity_glsl.yy",},}, + {"id":{"name":"node_3d_mesh_terrain","path":"scripts/node_3d_mesh_terrain/node_3d_mesh_terrain.yy",},}, {"id":{"name":"fd_rectangle_set_material_time_step","path":"scripts/fd_rectangle_set_material_time_step/fd_rectangle_set_material_time_step.yy",},}, {"id":{"name":"credit_badge_popular","path":"sprites/credit_badge_popular/credit_badge_popular.yy",},}, {"id":{"name":"s_node_path_sample","path":"sprites/s_node_path_sample/s_node_path_sample.yy",},}, @@ -1146,6 +1146,7 @@ {"id":{"name":"s_node_curve_eval","path":"sprites/s_node_curve_eval/s_node_curve_eval.yy",},}, {"id":{"name":"s_node_path_reverse","path":"sprites/s_node_path_reverse/s_node_path_reverse.yy",},}, {"id":{"name":"sh_draw_texture","path":"shaders/sh_draw_texture/sh_draw_texture.yy",},}, + {"id":{"name":"d3d_terrain","path":"scripts/d3d_terrain/d3d_terrain.yy",},}, {"id":{"name":"fd_rectangle_get_pressure_width","path":"scripts/fd_rectangle_get_pressure_width/fd_rectangle_get_pressure_width.yy",},}, {"id":{"name":"s_node_strandSim_render","path":"sprites/s_node_strandSim_render/s_node_strandSim_render.yy",},}, {"id":{"name":"sh_blend_normal","path":"shaders/sh_blend_normal/sh_blend_normal.yy",},}, diff --git a/scripts/color_function/color_function.gml b/scripts/color_function/color_function.gml index 08f14712c..879ad57a8 100644 --- a/scripts/color_function/color_function.gml +++ b/scripts/color_function/color_function.gml @@ -76,6 +76,12 @@ function color_diff(c1, c2, fast = false, alpha = false) { return sqrt(sqr(_c1_r - _c2_r) + sqr(_c1_g - _c2_g) + sqr(_c1_b - _c2_b) + sqr(_c1_a - _c2_a)); } +function color_get_brightness(col) { + gml_pragma("forceinline"); + + return (0.299 * color_get_red(col) + 0.587 * color_get_green(col) + 0.114 * color_get_blue(col)) / 255; +} + #region sorting functions function __valHSV(c, h, s, v) { return color_get_hue(c) * h + color_get_saturation(c) * s + color_get_value(c) * v; } function __valRGB(c, r, g, b) { return color_get_red(c) * r + color_get_green(c) * g + color_get_blue(c) * b; } diff --git a/scripts/d3d_terrain/d3d_terrain.gml b/scripts/d3d_terrain/d3d_terrain.gml new file mode 100644 index 000000000..594cbea5d --- /dev/null +++ b/scripts/d3d_terrain/d3d_terrain.gml @@ -0,0 +1,90 @@ +function __3dTerrain() : __3dObject() constructor { + VF = global.VF_POS_NORM_TEX_COL; + render_type = pr_trianglelist; + + self.subdivision = 4; + + heights = array_create((subdivision + 1) * (subdivision + 1)); + + static initModel = function() { + var _hs = 1 / 2; + var _vt = array_create(3 * 2 * subdivision * subdivision); + var _in = 0; + + var amo_ch = (subdivision + 1) * (subdivision + 1); + var hs = array_length(heights) == amo_ch; + + for( var i = 0; i < subdivision; i++ ) + for( var j = 0; j < subdivision; j++ ) { + var u0 = (i + 0) / subdivision; + var u1 = (i + 1) / subdivision; + var v0 = (j + 0) / subdivision; + var v1 = (j + 1) / subdivision; + + var x0 = -0.5 + u0; + var x1 = -0.5 + u1; + var y0 = -0.5 + v0; + var y1 = -0.5 + v1; + + var _i0 = j * (subdivision + 1) + i; + var _i1 = j * (subdivision + 1) + i + 1; + var _i2 = (j + 1) * (subdivision + 1) + i; + var _i3 = (j + 1) * (subdivision + 1) + i + 1; + + var _h0 = hs? heights[_i0] : 0; + var _h1 = hs? heights[_i1] : 0; + var _h2 = hs? heights[_i2] : 0; + var _h3 = hs? heights[_i3] : 0; + + var _n = new __vec3(x1 - x0, y0 - y0, _h1 - _h0) + .cross(new __vec3(x0 - x0, y1 - y0, _h2 - _h0)) + .normalize(); + + _vt[_in + 0] = new __vertex(x0, y0, _h0).setNormal(_n.x, _n.y, _n.z).setUV(u0, v0); + _vt[_in + 1] = new __vertex(x1, y1, _h3).setNormal(_n.x, _n.y, _n.z).setUV(u1, v1); + _vt[_in + 2] = new __vertex(x1, y0, _h1).setNormal(_n.x, _n.y, _n.z).setUV(u1, v0); + + _vt[_in + 3] = new __vertex(x0, y0, _h0).setNormal(_n.x, _n.y, _n.z).setUV(u0, v0); + _vt[_in + 4] = new __vertex(x0, y1, _h2).setNormal(_n.x, _n.y, _n.z).setUV(u0, v1); + _vt[_in + 5] = new __vertex(x1, y1, _h3).setNormal(_n.x, _n.y, _n.z).setUV(u1, v1); + + _in += 6; + } + + vertex = [ _vt ]; + VB = build(); + } initModel(); + + static updateHeight = function(_h) { + heights = _h; + var _in = 0; + var _vt = vertex[0]; + + for( var i = 0; i < subdivision; i++ ) + for( var j = 0; j < subdivision; j++ ) { + var _i0 = j * (subdivision + 1) + i; + var _i1 = j * (subdivision + 1) + i + 1; + var _i2 = (j + 1) * (subdivision + 1) + i; + var _i3 = (j + 1) * (subdivision + 1) + i + 1; + + var _h0 = heights[_i0]; + var _h1 = heights[_i1]; + var _h2 = heights[_i2]; + var _h3 = heights[_i3]; + + _vt[_in + 0].z = _h0; + _vt[_in + 1].z = _h3; + _vt[_in + 2].z = _h1; + + _vt[_in + 3].z = _h0; + _vt[_in + 4].z = _h2; + _vt[_in + 5].z = _h3; + + _in += 6; + } + + VB = build(); + } + + onParameterUpdate = initModel; +} \ No newline at end of file diff --git a/scripts/d3d_terrain/d3d_terrain.yy b/scripts/d3d_terrain/d3d_terrain.yy new file mode 100644 index 000000000..ca8fb15b4 --- /dev/null +++ b/scripts/d3d_terrain/d3d_terrain.yy @@ -0,0 +1,11 @@ +{ + "resourceType": "GMScript", + "resourceVersion": "1.0", + "name": "d3d_terrain", + "isCompatibility": false, + "isDnD": false, + "parent": { + "name": "mesh", + "path": "folders/functions/3d/mesh.yy", + }, +} \ No newline at end of file diff --git a/scripts/globals/globals.gml b/scripts/globals/globals.gml index fd5a570fa..69894f9ba 100644 --- a/scripts/globals/globals.gml +++ b/scripts/globals/globals.gml @@ -26,10 +26,10 @@ globalvar VERSION, SAVE_VERSION, VERSION_STRING, BUILD_NUMBER; - VERSION = 11552; + VERSION = 11560; SAVE_VERSION = 11550; - VERSION_STRING = "1.15.5.2"; - BUILD_NUMBER = 11552; + VERSION_STRING = "1.15.6"; + BUILD_NUMBER = 11560; globalvar APPEND_MAP; APPEND_MAP = ds_map_create(); diff --git a/scripts/node_3d_mesh_terrain/node_3d_mesh_terrain.gml b/scripts/node_3d_mesh_terrain/node_3d_mesh_terrain.gml new file mode 100644 index 000000000..d22f1da17 --- /dev/null +++ b/scripts/node_3d_mesh_terrain/node_3d_mesh_terrain.gml @@ -0,0 +1,71 @@ +function Node_3D_Mesh_Terrain(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group) constructor { + name = "3D Terrain"; + + object_class = __3dTerrain; + + inputs[| in_mesh + 0] = nodeValue("Material", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ) + .setVisible(true, true); + + inputs[| in_mesh + 1] = nodeValue("Input type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 ) + .setDisplay(VALUE_DISPLAY.enum_button, [ "Surface", "Array" ]); + + inputs[| in_mesh + 2] = nodeValue("Height map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone ); + + inputs[| in_mesh + 3] = nodeValue("Subdivision", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4 ); + + inputs[| in_mesh + 4] = nodeValue("Height array", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [] ) + .setArrayDepth(2); + + input_display_list = [ + __d3d_input_list_mesh, + __d3d_input_list_transform, + ["Terrain", false], in_mesh + 3, in_mesh + 1, in_mesh + 2, in_mesh + 4, + ["Material", false], in_mesh + 0, + ] + + static step = function() { #region + var _inT = getInputData(in_mesh + 1); + + inputs[| in_mesh + 2].setVisible(_inT == 0, _inT == 0); + inputs[| in_mesh + 4].setVisible(_inT == 1, _inT == 1); + } #endregion + + static processData = function(_output, _data, _output_index, _array_index = 0) { #region + var _mat = _data[in_mesh + 0]; + var _inT = _data[in_mesh + 1]; + var _sub = _data[in_mesh + 3]; + var _his = _data[in_mesh + 2]; + var _hia = _data[in_mesh + 4]; + + var _h = array_create((_sub + 1) * (_sub + 1)); + var object = getObject(_array_index); + + if(_inT == 0 && is_surface(_his)) { + var _ind = 0; + var _pxw = surface_get_width(_his) / (_sub + 1); + var _pxh = surface_get_height(_his) / (_sub + 1); + + for( var i = 0; i < _sub + 1; i++ ) + for( var j = 0; j < _sub + 1; j++ ) { + var cc = surface_getpixel(_his, i * _pxw, j * _pxh); + _h[_ind] = color_get_brightness(cc); + _ind++; + } + } else if(_inT == 1 && !array_empty(_hia)) { + if(is_array(_hia[0])) _hia = array_spread(_hia); + + array_copy(_h, 0, _hia, 0, min(array_length(_h), array_length(_hia))); + } + + object.checkParameter({ subdivision: _sub }); + object.updateHeight(_h); + object.materials = [ _mat ]; + + object.initModel(); + setTransform(object, _data); + + return object; + } #endregion + + static getPreviewValues = function() { return array_safe_get(all_inputs, in_mesh + 0, noone); } +} \ No newline at end of file diff --git a/scripts/node_3d_mesh_terrain/node_3d_mesh_terrain.yy b/scripts/node_3d_mesh_terrain/node_3d_mesh_terrain.yy new file mode 100644 index 000000000..a44158b3b --- /dev/null +++ b/scripts/node_3d_mesh_terrain/node_3d_mesh_terrain.yy @@ -0,0 +1,11 @@ +{ + "resourceType": "GMScript", + "resourceVersion": "1.0", + "name": "node_3d_mesh_terrain", + "isCompatibility": false, + "isDnD": false, + "parent": { + "name": "d3d mesh", + "path": "folders/nodes/data/3D/d3d mesh.yy", + }, +} \ No newline at end of file diff --git a/scripts/node_3d_mesh_terrain/node_counter.yy b/scripts/node_3d_mesh_terrain/node_counter.yy new file mode 100644 index 000000000..10832a0b0 --- /dev/null +++ b/scripts/node_3d_mesh_terrain/node_counter.yy @@ -0,0 +1,12 @@ +{ + "isDnD": false, + "isCompatibility": false, + "parent": { + "name": "variable", + "path": "folders/nodes/data/variable.yy", + }, + "resourceVersion": "1.0", + "name": "node_counter", + "tags": [], + "resourceType": "GMScript", +} \ No newline at end of file diff --git a/scripts/node_registry/node_registry.gml b/scripts/node_registry/node_registry.gml index ab85bde30..69833d69d 100644 --- a/scripts/node_registry/node_registry.gml +++ b/scripts/node_registry/node_registry.gml @@ -408,6 +408,7 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor { #regio addNodeObject(d3d, "3D UV Sphere", s_node_3d_sphere_uv, "Node_3D_Mesh_Sphere_UV", [1, Node_3D_Mesh_Sphere_UV]).setVersion(11510); addNodeObject(d3d, "3D Icosphere", s_node_3d_sphere_ico, "Node_3D_Mesh_Sphere_Ico", [1, Node_3D_Mesh_Sphere_Ico]).setVersion(11510); addNodeObject(d3d, "3D Cone", s_node_3d_cone, "Node_3D_Mesh_Cone", [1, Node_3D_Mesh_Cone]).setVersion(11510); + addNodeObject(d3d, "3D Terrain", s_node_3d_displace, "Node_3D_Mesh_Terrain", [1, Node_3D_Mesh_Terrain]).setVersion(11552); addNodeObject(d3d, "Surface Extrude", s_node_3d_extrude, "Node_3D_Mesh_Extrude", [1, Node_3D_Mesh_Extrude],, "Extrude 2D image into 3D object.").setVersion(11510); ds_list_add(d3d, "Light"); diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index 43ba77860..fe60fd0d8 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -825,8 +825,10 @@ function Panel_Preview() : PanelContent() constructor { d3_scene_light0.shadow_map_scale = d3_view_camera.focus_dist * 2; var _prev_obj = _prev_node.getPreviewObject(); - d3_scene_light0.submitShadow(d3_scene_preview, _prev_obj); - _prev_obj.submitShadow(d3_scene_preview, _prev_obj); + if(_prev_obj != noone) { + d3_scene_light0.submitShadow(d3_scene_preview, _prev_obj); + _prev_obj.submitShadow(d3_scene_preview, _prev_obj); + } } #endregion diff --git a/shaders/sh_shape_normalize/sh_shape_normalize.fsh b/shaders/sh_shape_normalize/sh_shape_normalize.fsh deleted file mode 100644 index 354c9653a..000000000 --- a/shaders/sh_shape_normalize/sh_shape_normalize.fsh +++ /dev/null @@ -1,147 +0,0 @@ -#extension GL_OES_standard_derivatives : require - -varying vec2 v_vTexcoord; -varying vec4 v_vColour; - -uniform int shape; -uniform int bg; -uniform int aa; -uniform int sides; -uniform int drawDF; - -uniform float angle; -uniform float inner; -uniform float outer; -uniform float corner; - -uniform float stRad; -uniform float edRad; - -uniform vec2 angle_range; - -uniform vec2 dimension; -uniform vec2 center; -uniform vec2 scale; - -uniform vec4 bgColor; - -#define PI 3.14159265359 -#define TAU 6.283185307179586 - -float sdRegularPolygon(in vec2 p, in float r, in int n, in float ang ) { - // these 4 lines can be precomputed for a given shape - float an = PI / float(n); - vec2 acs = vec2(cos(an), sin(an)); - - // reduce to first sector - float bn = mod(atan(p.x, p.y) + PI - ang, 2.0 * an) - an; - p = length(p) * vec2(cos(bn), abs(sin(bn))); - - // line sdf - p -= r * acs; - p.y += clamp( -p.y, 0.0, r * acs.y); - return length(p) * sign(p.x); -} - -// signed distance to a n-star polygon with external angle en -float sdStar(in vec2 p, in float r, in int n, in float m, in float ang) { // m=[2,n] - // these 4 lines can be precomputed for a given shape - float an = PI / float(n); - float en = PI / m; - vec2 acs = vec2(cos(an), sin(an)); - vec2 ecs = vec2(cos(en), sin(en)); // ecs=vec2(0,1) and simplify, for regular polygon, - - // reduce to first sector - float bn = mod( atan(p.x, p.y) + PI - ang, 2.0 * an) - an; - p = length(p) * vec2(cos(bn), abs(sin(bn))); - - // line sdf - p -= r * acs; - p += ecs * clamp( -dot(p, ecs), 0.0, r * acs.y / ecs.y); - return length(p)*sign(p.x); -} - -// sca is the sin/cos of the orientation -// scb is the sin/cos of the aperture -float sdArc( in vec2 p, in vec2 sca, in vec2 scb, in float ra, in float rb ) { - p *= mat2(sca.x, sca.y, -sca.y, sca.x); - p.x = abs(p.x); - float k = (scb.y * p.x > scb.x * p.y) ? dot(p.xy,scb) : length(p); - return sqrt( dot(p, p) + ra * ra - 2.0 * ra * k ) - rb; -} - -float sdRoundBox( in vec2 p, in vec2 b, in vec4 r ) { - r.xy = (p.x > 0.0)? r.xy : r.zw; - r.x = (p.y > 0.0)? r.x : r.y; - vec2 q = abs(p) - b + r.x; - return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r.x; -} - -float sdBox( in vec2 p, in vec2 b ) { - vec2 d = abs(p) - b; - return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0); -} - -float sdTearDrop( vec2 p, float r1, float r2, float h ) { - p.x = abs(p.x); - float b = (r1-r2)/h; - float a = sqrt(1.0-b*b); - float k = dot(p,vec2(-b,a)); - if( k < 0.0 ) return length(p) - r1; - if( k > a*h ) return length(p-vec2(0.0,h)) - r2; - return dot(p, vec2(a,b) ) - r1; -} - -float sdCross( in vec2 p, in vec2 b, float r ) { - p = abs(p); p = (p.y>p.x) ? p.yx : p.xy; - vec2 q = p - b; - float k = max(q.y,q.x); - vec2 w = (k>0.0) ? q : vec2(b.y-p.x,-k); - return sign(k)*length(max(w,0.0)) + r; -} - -float sdVesica(vec2 p, float r, float d) { - p = abs(p); - - float b = sqrt(r*r-d*d); // can delay this sqrt by rewriting the comparison - return ((p.y-b)*d > p.x*b) ? length(p-vec2(0.0,b))*sign(d) - : length(p-vec2(-d,0.0))-r; -} - -void main() { - float color = 0.; - vec2 cen = (v_vTexcoord - center) / scale; - vec2 ratio = dimension / dimension.y; - float d; - - if(shape == 0) { - d = sdBox( (v_vTexcoord - center) * ratio, (scale * ratio - corner)); - d -= corner; - } else if(shape == 1) { - d = length(cen) - 1.; - } else if(shape == 2) { - d = sdRegularPolygon( cen, 0.9 - corner, sides, angle ); - d -= corner; - } else if(shape == 3) { - d = sdStar( cen, 0.9 - corner, sides, 2. + inner * (float(sides) - 2.), angle ); - d -= corner; - } else if(shape == 4) { - d = sdArc( cen, vec2(sin(angle), cos(angle)), angle_range, 0.9 - inner, inner ); - } else if(shape == 5) { - d = sdTearDrop( cen + vec2(0., 0.5), stRad, edRad, 1. ); - } else if(shape == 6) { - d = sdCross( cen, vec2(1. + corner, outer), corner ); - } else if(shape == 7) { - d = sdVesica( cen, inner, outer ); - } - - //d = d; - if(drawDF == 1) - color = -d; - else if(aa == 0) - color = step(d, 0.0); - else - color = smoothstep(0.02, -0.02, d); - - gl_FragColor = mix(bgColor, v_vColour, color); -} diff --git a/shaders/sh_shape_normalize/sh_shape_normalize.vsh b/shaders/sh_shape_normalize/sh_shape_normalize.vsh deleted file mode 100644 index 3900c20f4..000000000 --- a/shaders/sh_shape_normalize/sh_shape_normalize.vsh +++ /dev/null @@ -1,19 +0,0 @@ -// -// Simple passthrough vertex shader -// -attribute vec3 in_Position; // (x,y,z) -//attribute vec3 in_Normal; // (x,y,z) unused in this shader. -attribute vec4 in_Colour; // (r,g,b,a) -attribute vec2 in_TextureCoord; // (u,v) - -varying vec2 v_vTexcoord; -varying vec4 v_vColour; - -void main() -{ - vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0); - gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos; - - v_vColour = in_Colour; - v_vTexcoord = in_TextureCoord; -} diff --git a/shaders/sh_shape_normalize/sh_shape_normalize.yy b/shaders/sh_shape_normalize/sh_shape_normalize.yy deleted file mode 100644 index 58f1dd8fc..000000000 --- a/shaders/sh_shape_normalize/sh_shape_normalize.yy +++ /dev/null @@ -1,10 +0,0 @@ -{ - "resourceType": "GMShader", - "resourceVersion": "1.0", - "name": "sh_shape_normalize", - "parent": { - "name": "generator", - "path": "folders/shader/generator.yy", - }, - "type": 1, -} \ No newline at end of file