diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index 20a8bf00e..4f37c913c 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -985,6 +985,7 @@ {"name":"node_random_tile","order":8,"path":"scripts/node_random_tile/node_random_tile.yy",}, {"name":"node_random","order":5,"path":"scripts/node_random/node_random.yy",}, {"name":"node_rate_remap","order":3,"path":"scripts/node_rate_remap/node_rate_remap.yy",}, + {"name":"node_raymarching","order":5,"path":"scripts/node_raymarching/node_raymarching.yy",}, {"name":"node_rd","order":4,"path":"scripts/node_rd/node_rd.yy",}, {"name":"node_region_fill","order":1,"path":"scripts/node_region_fill/node_region_fill.yy",}, {"name":"node_registry","order":11,"path":"scripts/node_registry/node_registry.yy",}, diff --git a/PixelComposer.yyp b/PixelComposer.yyp index a358fe678..8f4bb9d86 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -1412,6 +1412,7 @@ {"id":{"name":"node_random_tile","path":"scripts/node_random_tile/node_random_tile.yy",},}, {"id":{"name":"node_random","path":"scripts/node_random/node_random.yy",},}, {"id":{"name":"node_rate_remap","path":"scripts/node_rate_remap/node_rate_remap.yy",},}, + {"id":{"name":"node_raymarching","path":"scripts/node_raymarching/node_raymarching.yy",},}, {"id":{"name":"node_rd","path":"scripts/node_rd/node_rd.yy",},}, {"id":{"name":"node_region_fill","path":"scripts/node_region_fill/node_region_fill.yy",},}, {"id":{"name":"node_registry","path":"scripts/node_registry/node_registry.yy",},}, diff --git a/datafiles/data/Theme.zip b/datafiles/data/Theme.zip index 97b47fc26..aa28fdf25 100644 Binary files a/datafiles/data/Theme.zip and b/datafiles/data/Theme.zip differ diff --git a/scripts/__node_3d/__node_3d.gml b/scripts/__node_3d/__node_3d.gml index 4da0a0862..2864048cd 100644 --- a/scripts/__node_3d/__node_3d.gml +++ b/scripts/__node_3d/__node_3d.gml @@ -1,6 +1,6 @@ function Node_3D(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { name = "3D"; - is_3D = true; + is_3D = NODE_3D.polygon; surface_depth_disable(false); mesh_prev_surface = surface_create(64, 64); diff --git a/scripts/__node_3d_object/__node_3d_object.gml b/scripts/__node_3d_object/__node_3d_object.gml index dc58b0c69..1916260d3 100644 --- a/scripts/__node_3d_object/__node_3d_object.gml +++ b/scripts/__node_3d_object/__node_3d_object.gml @@ -60,10 +60,7 @@ function Node_3D_Object(_x, _y, _group = noone) : Node_3D(_x, _y, _group) constr tools = tool_quate; tool_axis_edit = new scrollBox([ "local", "global" ], function(val) { tool_attribute.context = val; }); - // tool_axis_edit.font = f_p2; - // tool_axis_edit.arrow_spr = THEME.arrow; - // tool_axis_edit.arrow_ind = 3; - tool_attribute.context = 0; + tool_attribute.context = 0; tool_settings = [ [ "Axis", tool_axis_edit, "context", tool_attribute ], ]; diff --git a/scripts/__raymarching/__raymarching.gml b/scripts/__raymarching/__raymarching.gml index b18bb9461..7a1f605c3 100644 --- a/scripts/__raymarching/__raymarching.gml +++ b/scripts/__raymarching/__raymarching.gml @@ -43,7 +43,7 @@ function RM_Object() constructor { triplanar = []; opmap = -1; - oparg = []; + oparg = -1; uniformKeys = [ "shape", "size", "radius", "thickness", "crop", "angle", "height", "radRange", "sizeUni", "elongate", "rounded", "corner", "size2D", "sides", "waveAmp", "waveInt", "waveShift", @@ -74,7 +74,7 @@ function RM_Object() constructor { if(shapeAmount <= 0) return; shader_set_i("operations", opmap); - shader_set_i("opArgument", oparg); + shader_set_f("opArgument", oparg); shader_set_i("opLength", array_safe_length(opmap)); shader_set_i("shape", shape); @@ -119,6 +119,9 @@ function RM_Object() constructor { shader_set_f("textureScale", textureScale); shader_set_f("triplanar", triplanar); } + + static serialize = function() { return ""}; + static deserialize = function() { }; } function RM_Operation(type, left, right) : RM_Object() constructor { @@ -170,8 +173,10 @@ function RM_Operation(type, left, right) : RM_Object() constructor { _a.flatten_index = array_length(_nodes); array_push(_nodes, _a); } - + opmap = []; + oparg = []; + for (var i = 0, n = array_length(_arr); i < n; i++) { var _a = _arr[i]; @@ -202,4 +207,39 @@ function RM_Operation(type, left, right) : RM_Object() constructor { function RM_Shape() : RM_Object() constructor { +} + +function RM_Environment() constructor { + surface = noone; + bgEnv = noone; + + projection = 0; + fov = 0; + orthoScale = 1; + viewRange = [ 0, 1 ]; + depthInt = 0; + + bgColor = c_black; + bgDraw = false; + ambInten = 0; + light = [ 1, 0.5, 0 ]; + + static apply = function() { + + shader_set_surface($"texture0", surface); + + shader_set_i("ortho", projection); + shader_set_f("fov", fov); + shader_set_f("orthoScale", orthoScale); + shader_set_f("viewRange", viewRange); + shader_set_f("depthInt", depthInt); + + shader_set_i("drawBg", bgColor); + shader_set_color("background", bgDraw); + shader_set_f("ambientIntns", ambInten); + shader_set_f("lightPosition", light); + + shader_set_i("useEnv", is_surface(bgEnv)); + + } } \ No newline at end of file diff --git a/scripts/node_data/node_data.gml b/scripts/node_data/node_data.gml index 8c5947ce3..af941fe47 100644 --- a/scripts/node_data/node_data.gml +++ b/scripts/node_data/node_data.gml @@ -15,6 +15,12 @@ enum DYNA_INPUT_COND { zero = 1 << 1, } +enum NODE_3D { + none, + polygon, + sdf, +} + function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor { #region ---- main & active ---- @@ -286,7 +292,7 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor { #endregion #region ---- 3d ---- - is_3D = false; + is_3D = NODE_3D.none; #endregion #region ---- cache ---- @@ -512,7 +518,7 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor { will_setHeight = false; } - if(is_3D) USE_DEPTH = true; + if(is_3D == NODE_3D.polygon) USE_DEPTH = true; if(is_simulation) PROJECT.animator.is_simulating = true; } #endregion diff --git a/scripts/node_keyframe/node_keyframe.gml b/scripts/node_keyframe/node_keyframe.gml index f6e6bbdd4..e0a416bce 100644 --- a/scripts/node_keyframe/node_keyframe.gml +++ b/scripts/node_keyframe/node_keyframe.gml @@ -601,7 +601,7 @@ function valueAnimator(_val, _prop, _sep_axis = false) constructor { if(prop.type == VALUE_TYPE.struct) { val = json_stringify(val); - } else if(is_struct(val)) { + } else if(is_struct(val) && struct_has(val, "serialize")) { val = val.serialize(); } else if(!sep_axis && typeArray(prop.display_type) && is_array(val)) { diff --git a/scripts/node_raymarching/node_raymarching.gml b/scripts/node_raymarching/node_raymarching.gml new file mode 100644 index 000000000..52adcb540 --- /dev/null +++ b/scripts/node_raymarching/node_raymarching.gml @@ -0,0 +1,6 @@ +function Node_RM(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { + name = "RM"; + is_3D = NODE_3D.sdf; + batch_output = true; + +} \ No newline at end of file diff --git a/scripts/node_raymarching/node_raymarching.yy b/scripts/node_raymarching/node_raymarching.yy new file mode 100644 index 000000000..31fa62f7a --- /dev/null +++ b/scripts/node_raymarching/node_raymarching.yy @@ -0,0 +1,13 @@ +{ + "$GMScript":"", + "%Name":"node_raymarching", + "isCompatibility":false, + "isDnD":false, + "name":"node_raymarching", + "parent":{ + "name":"raymarching", + "path":"folders/nodes/data/3D/raymarching.yy", + }, + "resourceType":"GMScript", + "resourceVersion":"2.0", +} \ No newline at end of file diff --git a/scripts/node_rm_combine/node_rm_combine.gml b/scripts/node_rm_combine/node_rm_combine.gml index b1f0df0a5..0896388af 100644 --- a/scripts/node_rm_combine/node_rm_combine.gml +++ b/scripts/node_rm_combine/node_rm_combine.gml @@ -1,6 +1,5 @@ -function Node_RM_Combine(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { - name = "RM Combine"; - batch_output = true; +function Node_RM_Combine(_x, _y, _group = noone) : Node_RM(_x, _y, _group) constructor { + name = "RM Combine"; inputs[| 0] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF) .setDisplay(VALUE_DISPLAY.vector); @@ -42,10 +41,10 @@ function Node_RM_Combine(_x, _y, _group = noone) : Node_Processor(_x, _y, _group //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - inputs[| 13] = nodeValue("Shape 1", self, JUNCTION_CONNECT.input, VALUE_TYPE.struct, {}) + inputs[| 13] = nodeValue("Shape 1", self, JUNCTION_CONNECT.input, VALUE_TYPE.sdf, {}) .setVisible(true, true); - inputs[| 14] = nodeValue("Shape 2", self, JUNCTION_CONNECT.input, VALUE_TYPE.struct, {}) + inputs[| 14] = nodeValue("Shape 2", self, JUNCTION_CONNECT.input, VALUE_TYPE.sdf, {}) .setVisible(true, true); //////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -58,23 +57,25 @@ function Node_RM_Combine(_x, _y, _group = noone) : Node_Processor(_x, _y, _group outputs[| 0] = nodeValue("Surface Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); - outputs[| 1] = nodeValue("Shape Data", self, JUNCTION_CONNECT.output, VALUE_TYPE.struct, noone); + outputs[| 1] = nodeValue("Shape Data", self, JUNCTION_CONNECT.output, VALUE_TYPE.sdf, noone); input_display_list = [ 0, - ["Combine", false], 15, 13, 14, + ["Combine", false], 15, 16, 13, 14, ["Camera", false], 11, 12, 1, 2, 3, 4, 5, ["Render", false], 6, 7, 8, 10, 9, ] - object = noone; temp_surface = [ 0, 0 ]; + environ = new RM_Environment(); + object = noone; + + static drawOverlay3D = function(active, params, _mx, _my, _snx, _sny, _panel) {} static step = function() { var _type = getSingleValue(15); inputs[| 16].setVisible(_type > 0); } - static processData = function(_outSurf, _data, _output_index, _array_index = 0) { var _dim = _data[0]; @@ -85,7 +86,7 @@ function Node_RM_Combine(_x, _y, _group = noone) : Node_Processor(_x, _y, _group var _dep = _data[5]; var _bgd = _data[6]; - var _bgc = _data[7]; + var _enc = _data[7]; var _amb = _data[8]; var _lig = _data[9]; var _env = _data[10]; @@ -121,27 +122,28 @@ function Node_RM_Combine(_x, _y, _group = noone) : Node_Processor(_x, _y, _group object.flatten(); object.setTexture(temp_surface[1]); + environ.surface = temp_surface[0]; + environ.bgEnv = _env; + + environ.projection = _ort; + environ.fov = _fov; + environ.orthoScale = _ort; + environ.viewRange = _vrn; + environ.depthInt = _dep; + + environ.bgColor = _enc; + environ.bgDraw = _bgd; + environ.ambInten = _amb; + environ.light = _lig; + gpu_set_texfilter(true); surface_set_shader(_outSurf, sh_rm_primitive); - shader_set_surface($"texture0", temp_surface[0]); - shader_set_f("camRotation", _crt); shader_set_f("camScale", _csa); + shader_set_f("camRatio", _dim[0] / _dim[1]); - shader_set_i("ortho", _pro); - shader_set_f("fov", _fov); - shader_set_f("orthoScale", _ort); - shader_set_f("viewRange", _vrn); - shader_set_f("depthInt", _dep); - - shader_set_i("drawBg", _bgd); - shader_set_color("background", _bgc); - shader_set_f("ambientIntns", _amb); - shader_set_f("lightPosition", _lig); - - shader_set_i("useEnv", is_surface(_env)); - + environ.apply(); object.apply(); draw_sprite_stretched(s_fx_pixel, 0, 0, 0, _dim[0], _dim[1]); diff --git a/scripts/node_rm_primitive/node_rm_primitive.gml b/scripts/node_rm_primitive/node_rm_primitive.gml index e0c25a9b4..cb004d494 100644 --- a/scripts/node_rm_primitive/node_rm_primitive.gml +++ b/scripts/node_rm_primitive/node_rm_primitive.gml @@ -1,6 +1,5 @@ -function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { - name = "RM Primitive"; - batch_output = true; +function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) constructor { + name = "RM Primitive"; inputs[| 0] = nodeValue("Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, DEF_SURF) .setDisplay(VALUE_DISPLAY.vector); @@ -155,7 +154,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro outputs[| 0] = nodeValue("Surface Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); - outputs[| 1] = nodeValue("Shape Data", self, JUNCTION_CONNECT.output, VALUE_TYPE.struct, noone); + outputs[| 1] = nodeValue("Shape Data", self, JUNCTION_CONNECT.output, VALUE_TYPE.sdf, noone); input_display_list = [ 0, ["Primitive", false], 1, 21, 22, 23, 24, 25, 26, 27, 28, 39, 40, 41, @@ -170,9 +169,12 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro ]; temp_surface = [ 0, 0 ]; - object = new RM_Shape(); + environ = new RM_Environment(); + object = new RM_Shape(); - static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {} + static drawOverlay3D = function(active, params, _mx, _my, _snx, _sny, _panel) { + + } static step = function() { var _shp = getSingleValue( 1); @@ -426,27 +428,28 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro object.setTexture(temp_surface[1]); + environ.surface = temp_surface[0]; + environ.bgEnv = bgEnv; + + environ.projection = _ort; + environ.fov = _fov; + environ.orthoScale = _ortS; + environ.viewRange = _rng; + environ.depthInt = _dpi; + + environ.bgColor = _bgd; + environ.bgDraw = _bgc; + environ.ambInten = _ambI; + environ.light = _lPos; + gpu_set_texfilter(true); surface_set_shader(_outSurf, sh_rm_primitive); - shader_set_surface($"texture0", temp_surface[0]); - shader_set_f("camRotation", _crt); shader_set_f("camScale", _csa); + shader_set_f("camRatio", _dim[0] / _dim[1]); - shader_set_i("ortho", _ort); - shader_set_f("fov", _fov); - shader_set_f("orthoScale", _ortS); - shader_set_f("viewRange", _rng); - shader_set_f("depthInt", _dpi); - - shader_set_i("drawBg", _bgd); - shader_set_color("background", _bgc); - shader_set_f("ambientIntns", _ambI); - shader_set_f("lightPosition", _lPos); - - shader_set_i("useEnv", is_surface(bgEnv)); - + environ.apply(); object.apply(); draw_sprite_stretched(s_fx_pixel, 0, 0, 0, _dim[0], _dim[1]); diff --git a/scripts/node_value_types/node_value_types.gml b/scripts/node_value_types/node_value_types.gml index 891a9c9b3..1e08b2c26 100644 --- a/scripts/node_value_types/node_value_types.gml +++ b/scripts/node_value_types/node_value_types.gml @@ -54,10 +54,9 @@ enum VALUE_TYPE { dynaSurface = 31, PCXnode = 32, - - audioBit = 33, - - fdomain = 34, + audioBit = 33, + fdomain = 34, + sdf = 35, action = 99, } @@ -186,6 +185,7 @@ function value_color(i) { #region #c2c2d1, //PCX #8fde5d, //audiobit #4da6ff, //flipfluid + #c1007c, //3D SDF ]; static JUNCTION_COLORS_LENGTH = array_length(JUNCTION_COLORS); @@ -234,6 +234,7 @@ function value_color_bg_array(i) { #region #bd4882, //dynaSurf #83839b, //PCX #3ca370, //audiobit + #c1007c, //3D SDF ]; if(i == 99) return $5dde8f; @@ -282,6 +283,7 @@ function value_bit(i) { #region case VALUE_TYPE.PCXnode : return 1 << 34; case VALUE_TYPE.audioBit : return 1 << 35; case VALUE_TYPE.fdomain : return 1 << 36; + case VALUE_TYPE.sdf : return 1 << 37; case VALUE_TYPE.any : return ~0 & ~(1 << 32); } @@ -355,10 +357,9 @@ function value_type_from_string(str) { #region case "dynaSurface" : return VALUE_TYPE.dynaSurface; case "PCXnode" : return VALUE_TYPE.PCXnode; - - case "audioBit" : return VALUE_TYPE.audioBit; - - case "fDomain" : return VALUE_TYPE.fdomain; + case "audioBit" : return VALUE_TYPE.audioBit; + case "fDomain" : return VALUE_TYPE.fdomain; + case "sdf" : return VALUE_TYPE.sdf; case "action" : return VALUE_TYPE.action; } diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index 7ec89f8f2..6027e8051 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -943,14 +943,10 @@ function Panel_Preview() : PanelContent() constructor { } #endregion } #endregion - function draw3D() { #region - var _prev_node = getNodePreview(); - if(_prev_node == noone) return; - if(!_prev_node.is_3D) return; + function draw3DPolygon(_node) { #region + _node.previewing = 1; - _prev_node.previewing = 1; - - d3_scene_preview = struct_has(_prev_node, "scene")? _prev_node.scene : d3_scene; + d3_scene_preview = struct_has(_node, "scene")? _node.scene : d3_scene; d3_scene_preview.camera = d3_view_camera; #region view @@ -1002,7 +998,7 @@ function Panel_Preview() : PanelContent() constructor { if(d3_scene_preview == d3_scene) { d3_scene_light0.shadow_map_scale = d3_view_camera.focus_dist * 2; - var _prev_obj = _prev_node.getPreviewObject(); + var _prev_obj = _node.getPreviewObject(); if(_prev_obj != noone) { d3_scene_light0.submitShadow(d3_scene_preview, _prev_obj); _prev_obj.submitShadow(d3_scene_preview, _prev_obj); @@ -1016,7 +1012,7 @@ function Panel_Preview() : PanelContent() constructor { d3_surface_outline = surface_verify(d3_surface_outline, w, h); #region defer - var _prev_obj = _prev_node.getPreviewObject(); + var _prev_obj = _node.getPreviewObject(); if(_prev_obj) d3_deferData = d3_scene_preview.deferPass(_prev_obj, w, h, d3_deferData); #endregion @@ -1057,7 +1053,7 @@ function Panel_Preview() : PanelContent() constructor { d3_scene_preview.reset(); gpu_set_cullmode(cull_counterclockwise); - var _prev_obj = _prev_node.getPreviewObjects(); + var _prev_obj = _node.getPreviewObjects(); if(d3_scene_preview == d3_scene) { if(d3_scene_light_enabled) { @@ -1108,7 +1104,7 @@ function Panel_Preview() : PanelContent() constructor { #region outline var inspect_node = PANEL_INSPECTOR.getInspecting(); - if(inspect_node && inspect_node.is_3D) { + if(inspect_node && inspect_node.is_3D == NODE_3D.polygon) { var _inspect_obj = inspect_node.getPreviewObjectOutline(); surface_set_target(d3_surface_outline); @@ -1134,6 +1130,45 @@ function Panel_Preview() : PanelContent() constructor { d3_scene_preview.camera.resetCamera(); } #endregion + function draw3DSdf(_node) { #region + _node.previewing = 1; + + var _env = _node.environ; + var _obj = _node.object; + + draw_clear(bg_color); + + gpu_set_texfilter(true); + shader_set(sh_rm_primitive); + var zm = 4 / d3_view_camera.focus_dist; + + shader_set_f("camRotation", [ d3_view_camera.focus_angle_y, -d3_view_camera.focus_angle_x, 0 ]); + shader_set_f("camScale", zm); + shader_set_f("camRatio", w / h); + + _env.apply(); + _obj.apply(); + + shader_set_i("drawBg", 0); + shader_set_f("viewRange", [ d3_view_camera.view_near, d3_view_camera.view_far ]); + shader_set_f("depthInt", 0); + + draw_sprite_stretched(s_fx_pixel, 0, 0, 0, w, h); + shader_reset(); + gpu_set_texfilter(false); + + } #endregion + + function draw3D() { #region + var _node = getNodePreview(); + if(_node == noone) return; + + switch(_node.is_3D) { + case NODE_3D.polygon : draw3DPolygon(_node); break; + case NODE_3D.sdf : draw3DSdf(_node); break; + } + } #endregion + function drawPreviewOverlay() { #region right_menu_y = toolbar_height - ui(4); if(show_view_control == 2) { @@ -1436,14 +1471,7 @@ function Panel_Preview() : PanelContent() constructor { var params = { w, h, toolbar_height }; var mouse_free = false; - if(_node.is_3D) { - if(key_mod_press(CTRL) || d3_tool_snap) { - _snx = d3_tool_snap_position; - _sny = d3_tool_snap_rotation; - } - - mouse_free = _node.drawOverlay3D(overActive, d3_scene, _mx, _my, _snx, _sny, params); - } else { + if(_node.is_3D == NODE_3D.none) { if(key_mod_press(CTRL)) { _snx = PROJECT.previewGrid.show? PROJECT.previewGrid.size[0] : 1; _sny = PROJECT.previewGrid.show? PROJECT.previewGrid.size[1] : 1; @@ -1453,6 +1481,13 @@ function Panel_Preview() : PanelContent() constructor { } mouse_free = _node.drawOverlay(overHover, overActive, cx, cy, canvas_s, _mx, _my, _snx, _sny, params); + } else { + if(key_mod_press(CTRL) || d3_tool_snap) { + _snx = d3_tool_snap_position; + _sny = d3_tool_snap_rotation; + } + + mouse_free = _node.drawOverlay3D(overActive, d3_scene, _mx, _my, _snx, _sny, params); } #region node overlay @@ -1901,9 +1936,8 @@ function Panel_Preview() : PanelContent() constructor { if(do_fullView) run_in(1, fullView); do_fullView = false; - var _prev_node = getNodePreview(); - - d3_active = _prev_node != noone && _prev_node.is_3D; + var _prev_node = getNodePreview(); + d3_active = _prev_node != noone && _prev_node.is_3D != NODE_3D.none; draw_clear(bg_color); if(canvas_bg == -1 && canvas_s >= 0.1) diff --git a/shaders/sh_rm_primitive/sh_rm_primitive.fsh b/shaders/sh_rm_primitive/sh_rm_primitive.fsh index b749cc4a5..0ff9cfbc5 100644 --- a/shaders/sh_rm_primitive/sh_rm_primitive.fsh +++ b/shaders/sh_rm_primitive/sh_rm_primitive.fsh @@ -72,6 +72,7 @@ uniform float triplanar[MAX_SHAPES] ; uniform vec3 camRotation; uniform float camScale; +uniform float camRatio; uniform int ortho; uniform float fov; @@ -86,8 +87,6 @@ uniform vec3 lightPosition; uniform int useEnv; -mat3 rotMatrix, irotMatrix; - #region ////========== Transform ============ mat3 rotateX(float dg) { float c = cos(radians(dg)); @@ -475,8 +474,8 @@ float sceneSDF(int index, vec3 p) { mat3 rx = rotateX(rotation[index].x); mat3 ry = rotateY(rotation[index].y); mat3 rz = rotateZ(rotation[index].z); - rotMatrix = rx * ry * rz; - irotMatrix = inverse(rotMatrix); + mat3 rotMatrix = rx * ry * rz; + mat3 irotMatrix = inverse(rotMatrix); p /= objectScale[index]; p -= position[index]; @@ -541,20 +540,20 @@ float operateSceneSDF(vec3 p, out vec3 blendIndx) { float index[MAX_OP]; float d1, d2, o1, o2; - float merge; + float mrg; int top = 0; int opr = 0; for(int i = 0; i < opLength; i++) { opr = operations[i]; - merge = opArgument[i]; + mrg = opArgument[i]; if(opr < 100) { depth[top] = sceneSDF(opr, p); index[top] = float(opr); top++; - } else { + } else if(top >= 2) { top--; d1 = depth[top]; o1 = index[top]; @@ -567,21 +566,19 @@ float operateSceneSDF(vec3 p, out vec3 blendIndx) { if(d1 < d2) { depth[top] = d1; index[top] = o1; - blendIndx.x = o1; - blendIndx.z = 0.; + blendIndx.x = o1; + blendIndx.z = 0.; } else { depth[top] = d2; index[top] = o2; - blendIndx.x = o2; - blendIndx.z = 0.; - + blendIndx.x = o2; + blendIndx.z = 0.; + } - top++; - } else if(opr == 101) { - vec2 m = smin(d1, d2, merge); + vec2 m = smin(d1, d2, mrg); blendIndx.x = o1; blendIndx.y = o2; blendIndx.z = m.y; @@ -590,15 +587,15 @@ float operateSceneSDF(vec3 p, out vec3 blendIndx) { index[top] = d1 < d2? o1 : o2; } else if(opr == 102) { - float m = opSmoothSubtraction(d1, d2, merge); - blendIndx.x = o1; + float m = opSmoothSubtraction(d1, d2, mrg); + blendIndx.x = o2; blendIndx.z = 0.; depth[top] = m; - index[top] = o1; + index[top] = o2; } else if(opr == 103) { - float m = opSmoothIntersection(d1, d2, merge); + float m = opSmoothIntersection(d1, d2, mrg); blendIndx.x = o1; blendIndx.z = 0.; @@ -606,7 +603,11 @@ float operateSceneSDF(vec3 p, out vec3 blendIndx) { index[top] = o1; } - } + + top++; + + } else //error, not enough values + break; } return depth[0]; @@ -667,10 +668,13 @@ vec4 scene() { mat3 camIrotMatrix = inverse(camRotMatrix); float dz = 1. / tan(radians(fov) / 2.); - vec3 dir = normalize(vec3((v_vTexcoord - .5) * 2., -dz)); + vec2 cps = (v_vTexcoord - .5) * 2.; + cps.x *= camRatio; + + vec3 dir = normalize(vec3(cps, -dz)); vec3 eye = vec3(0., 0., 5.); - dir = normalize(camIrotMatrix * dir) / camScale; + dir = normalize(camIrotMatrix * dir); eye = camIrotMatrix * eye; eye /= camScale; @@ -692,6 +696,12 @@ vec4 scene() { if(depth > viewRange.y - EPSILON) // Not hitting anything. return vec4(0.); + rx = rotateX(mix(rotation[idx0].x, rotation[idx1].x, rat)); + ry = rotateY(mix(rotation[idx0].y, rotation[idx1].y, rat)); + rz = rotateZ(mix(rotation[idx0].z, rotation[idx1].z, rat)); + mat3 rotMatrix = rx * ry * rz; + mat3 irotMatrix = inverse(rotMatrix); + vec3 c0 = useTexture[idx0] == 1? boxmap(int(TEXTURE_S) + idx0, irotMatrix * coll * textureScale[idx0], irotMatrix * norm, triplanar[idx0]).rgb * diffuseColor[idx0].rgb : diffuseColor[idx0].rgb;