diff --git a/scripts/globals/globals.gml b/scripts/globals/globals.gml index f41ffd93e..c4d0de3fc 100644 --- a/scripts/globals/globals.gml +++ b/scripts/globals/globals.gml @@ -36,10 +36,10 @@ globalvar VERSION, SAVE_VERSION, VERSION_STRING, BUILD_NUMBER, LATEST_VERSION; LATEST_VERSION = 11700; - VERSION = 11712; + VERSION = 11720; SAVE_VERSION = 11690; - VERSION_STRING = "1.17.1.2"; - BUILD_NUMBER = 11712; + VERSION_STRING = "1.17.2.0"; + BUILD_NUMBER = 11720; globalvar HOTKEYS, HOTKEY_CONTEXT; HOTKEYS = ds_map_create(); diff --git a/scripts/node_normalize/node_normalize.gml b/scripts/node_normalize/node_normalize.gml index 4cc4bd0fa..5af136e0a 100644 --- a/scripts/node_normalize/node_normalize.gml +++ b/scripts/node_normalize/node_normalize.gml @@ -3,7 +3,10 @@ function Node_Normalize(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) inputs[| 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone); - input_display_list = [ 0 ]; + inputs[| 1] = nodeValue("Mode", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0) + .setDisplay(VALUE_DISPLAY.enum_button, [ "BW", "RGB" ]); + + input_display_list = [ 0, 1 ]; outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); @@ -17,6 +20,7 @@ function Node_Normalize(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) static processData = function(_outSurf, _data, _output_index, _array_index) { #region var _surf = _data[0]; + var _mode = _data[1]; var _sw = surface_get_width(_surf); var _sh = surface_get_height(_surf); @@ -88,6 +92,14 @@ function Node_Normalize(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) buffer_delete(_bMin); #endregion + if(_mode == 0) { + var _bmax = (_max[0] + _max[1] + _max[2]) / 2; + var _bmin = (_min[0] + _min[1] + _min[2]) / 2; + + _max = [ _bmax, _bmax, _bmax ]; + _min = [ _bmin, _bmin, _bmin ]; + } + surface_set_shader(_outSurf, sh_normalize); shader_set_f("cMax", _max); shader_set_f("cMin", _min); diff --git a/scripts/node_rm_primitive/node_rm_primitive.gml b/scripts/node_rm_primitive/node_rm_primitive.gml index 9e8806ab3..42bf65eae 100644 --- a/scripts/node_rm_primitive/node_rm_primitive.gml +++ b/scripts/node_rm_primitive/node_rm_primitive.gml @@ -29,7 +29,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro inputs[| 2] = nodeValue("Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ]) .setDisplay(VALUE_DISPLAY.vector); - inputs[| 3] = nodeValue("Rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ]) + inputs[| 3] = nodeValue("Rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 30, 45, 0 ]) .setDisplay(VALUE_DISPLAY.vector); inputs[| 4] = nodeValue("Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1) @@ -47,9 +47,9 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro inputs[| 8] = nodeValue("Light Position", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ -.5, -.5, 1 ]) .setDisplay(VALUE_DISPLAY.vector); - inputs[| 9] = nodeValue("Ambient", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white); + inputs[| 9] = nodeValue("Base Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white); - inputs[| 10] = nodeValue("Ambient Intensity", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.2) + inputs[| 10] = nodeValue("Ambient Level", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.2) .setDisplay(VALUE_DISPLAY.slider); inputs[| 11] = nodeValue("Elongate", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ]) @@ -117,16 +117,30 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro inputs[| 31] = nodeValue("Draw BG", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, true); + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + inputs[| 32] = nodeValue("Volumetric", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false); + + inputs[| 33] = nodeValue("Density", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.1) + .setDisplay(VALUE_DISPLAY.slider); + + inputs[| 34] = nodeValue("Environment", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, false); + + inputs[| 35] = nodeValue("Reflective", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.) + .setDisplay(VALUE_DISPLAY.slider); + outputs[| 0] = nodeValue("Surface Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone); input_display_list = [ 0, - ["Primitive", false], 1, 21, 22, 23, 24, 25, 26, 27, 28, - ["Modify", false], 12, 11, - ["Deform", true], 15, 16, 17, 18, 19, - ["Transform", false], 2, 3, 4, - ["Camera", false], 13, 14, 5, 6, - ["Render", false], 31, 30, 7, 9, 10, 8, - ["Tile", false], 20, 29, + ["Primitive", false], 1, 21, 22, 23, 24, 25, 26, 27, 28, + ["Modify", false], 12, 11, + ["Deform", true], 15, 16, 17, 18, 19, + ["Transform", false], 2, 3, 4, + ["Material", false], 9, 35, + ["Camera", false], 13, 14, 5, 6, + ["Render", false], 31, 30, 34, 10, 7, 8, + ["Tile", false], 20, 29, + ["Volumetric", true, 32], 33, ]; temp_surface = [ 0, 0, 0, 0 ]; @@ -264,6 +278,11 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro var _bgc = _data[30]; var _bgd = _data[31]; + var _vol = _data[32]; + var _vden = _data[33]; + var bgEnv = _data[34]; + var _refl = _data[35]; + _outSurf = surface_verify(_outSurf, _dim[0], _dim[1]); for (var i = 0, n = array_length(temp_surface); i < n; i++) @@ -271,7 +290,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro var tx = 1024; surface_set_shader(temp_surface[0]); - + draw_surface_stretched_safe(bgEnv, tx * 0, tx * 0, tx, tx); surface_reset_shader(); gpu_set_texfilter(true); @@ -282,26 +301,26 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro var _shpI = 0; switch(_shape) { - case "Plane" : _shpI = 100; break; - case "Box" : _shpI = 101; break; - case "Box Frame" : _shpI = 102; break; + case "Plane" : _shpI = 100; break; + case "Box" : _shpI = 101; break; + case "Box Frame" : _shpI = 102; break; + + case "Sphere" : _shpI = 200; break; + case "Ellipse" : _shpI = 201; break; + case "Cut Sphere" : _shpI = 202; break; + case "Cut Hollow Sphere" : _shpI = 203; _crop = _crop / pi * 2.15; break; + case "Torus" : _shpI = 204; break; + case "Capped Torus" : _shpI = 205; break; - case "Sphere" : _shpI = 200; break; - case "Ellipse" : _shpI = 201; break; - case "Cut Sphere" : _shpI = 202; break; - case "Cut Hollow Sphere" : _shpI = 203; break; - case "Torus" : _shpI = 204; break; - case "Capped Torus" : _shpI = 205; break; + case "Cylinder" : _shpI = 300; break; + case "Capsule" : _shpI = 301; break; + case "Cone" : _shpI = 302; break; + case "Capped Cone" : _shpI = 303; break; + case "Round Cone" : _shpI = 304; break; + case "3D Arc" : _shpI = 305; break; - case "Cylinder" : _shpI = 300; break; - case "Capsule" : _shpI = 301; break; - case "Cone" : _shpI = 302; break; - case "Capped Cone" : _shpI = 303; break; - case "Round Cone" : _shpI = 304; break; - case "3D Arc" : _shpI = 305; break; - - case "Octahedron" : _shpI = 400; break; - case "Pyramid" : _shpI = 401; break; + case "Octahedron" : _shpI = 400; break; + case "Pyramid" : _shpI = 401; break; } for (var i = 0, n = array_length(temp_surface); i < n; i++) @@ -342,10 +361,17 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro shader_set_i("drawBg", _bgd); shader_set_color("background", _bgc); - shader_set_color("ambient", _amb); shader_set_f("ambientIntns", _ambI); shader_set_f("lightPosition", _lPos); + shader_set_color("ambient", _amb); + shader_set_f("reflective", _refl); + + shader_set_i("volumetric", _vol); + shader_set_f("volumeDensity", _vden); + + shader_set_i("useEnv", is_surface(bgEnv)); + draw_sprite_stretched(s_fx_pixel, 0, 0, 0, _dim[0], _dim[1]); surface_reset_shader(); diff --git a/shaders/sh_rm_primitive/sh_rm_primitive.fsh b/shaders/sh_rm_primitive/sh_rm_primitive.fsh index ca500c3c3..c861eba4e 100644 --- a/shaders/sh_rm_primitive/sh_rm_primitive.fsh +++ b/shaders/sh_rm_primitive/sh_rm_primitive.fsh @@ -51,11 +51,18 @@ uniform float depthInt; uniform vec3 tileSize; uniform vec3 tileAmount; -uniform int drawBg; -uniform vec4 background; -uniform vec4 ambient; +uniform int drawBg; +uniform vec4 background; uniform float ambientIntns; -uniform vec3 lightPosition; +uniform vec3 lightPosition; + +uniform vec4 ambient; +uniform float reflective; + +uniform int useEnv; + +uniform int volumetric; +uniform float volumeDensity; mat3 rotMatrix, irotMatrix; @@ -134,6 +141,12 @@ mat3 rotMatrix, irotMatrix; return texture2D(texture0, sm); } + + vec2 equirectangularUv(vec3 dir) { + vec3 n = normalize(dir); + return vec2((atan(n.x, n.z) / (PI * 2.)) + 0.5, 1. - acos(n.y) / PI); + } + #endregion #region ////========== Primitives =========== @@ -368,10 +381,6 @@ mat3 rotMatrix, irotMatrix; float sceneSDF(vec3 p) { float d; - p = irotMatrix * p; - p /= objectScale; - p -= position; - p = wave(p); if(tileSize != vec3(0.)) @@ -426,7 +435,7 @@ vec3 normal(vec3 p) { } float march(vec3 camera, vec3 direction) { - float depth = viewRange.x; + float depth = viewRange.x; for (int i = 0; i < MAX_MARCHING_STEPS; i++) { float dist = sceneSDF(camera + depth * direction); @@ -437,12 +446,29 @@ float march(vec3 camera, vec3 direction) { if (depth >= viewRange.y) return viewRange.y; } + + return viewRange.y; +} + +float marchDensity(vec3 camera, vec3 direction) { + float st = 1. / float(MAX_MARCHING_STEPS); + float dens = 0.; + float stp = volumeDensity == 0. ? 0. : pow(2., 10. * volumeDensity * 0.5 - 10.); + + for (int i = 0; i <= MAX_MARCHING_STEPS; i++) { + float depth = mix(viewRange.x, viewRange.y, float(i) * st); + vec3 pos = camera + depth * direction; + float hit = sceneSDF(pos); + float inst = (pos.y + objectScale) / (objectScale * 2.); + inst = inst <= 0.? 0. : pow(2., 10. * inst - 10.) * 10.; + + if (hit <= 0.) dens += stp * inst; + } - return viewRange.y; + return dens; } void main() { - gl_FragColor = drawBg == 1? background : vec4(0.); mat3 rx = rotateX(rotation.x); mat3 ry = rotateY(rotation.y); @@ -450,16 +476,32 @@ void main() { rotMatrix = rx * ry * rz; irotMatrix = inverse(rotMatrix); - vec3 eye, dir; + float dz = 1. / tan(radians(fov) / 2.); + vec3 dir = normalize(vec3((v_vTexcoord - .5) * 2., -dz)); + vec3 eye = vec3(0., 0., 5.); - if(ortho == 1) { - dir = vec3(0., 0., 1.); - eye = vec3((v_vTexcoord - .5) * 2. * orthoScale, viewRange.x); + dir = normalize(irotMatrix * dir) / objectScale; + eye = irotMatrix * eye; + eye /= objectScale; + eye -= position; + + vec4 bg = background; + if(useEnv == 1) { + float edz = 1. / tan(radians(fov * 2.) / 2.); + vec3 edir = normalize(vec3((v_vTexcoord - .5) * 2., -edz)); + edir = normalize(irotMatrix * edir) / objectScale; - } else { - float z = 1. / tan(radians(fov) / 2.); - dir = normalize(vec3((v_vTexcoord - .5) * 2., -z)); - eye = vec3(0., 0., 5.); + vec2 envUV = equirectangularUv(edir); + vec4 endC = sampleTexture(0, envUV); + bg = endC; + } + + gl_FragColor = drawBg == 1? bg : vec4(0.); + + if(volumetric == 1) { + float _dens = clamp(marchDensity(eye, dir), 0., 1.); + gl_FragColor = mix(background, ambient, _dens); + return; } float dist = march(eye, dir); @@ -472,17 +514,35 @@ void main() { vec3 c = ambient.rgb; /////////////////////////////////////////////////////////// + + float distNorm = (dist - viewRange.x) / (viewRange.y - viewRange.x); distNorm = 1. - distNorm; distNorm = smoothstep(.0, .3, distNorm); c = mix(background.rgb, c, mix(1., distNorm, depthInt)); + /////////////////////////////////////////////////////////// + vec3 norm = normal(coll); + vec3 ref = reflect(dir, norm); + + if(useEnv == 1) { + vec4 refC = sampleTexture(0, equirectangularUv(ref)) + + sampleTexture(0, equirectangularUv(ref + vec3( 0.01, 0., 0.))) * 0.5 + + sampleTexture(0, equirectangularUv(ref + vec3(-0.01, 0., 0.))) * 0.5 + + sampleTexture(0, equirectangularUv(ref + vec3(0., 0.01, 0.))) * 0.5 + + sampleTexture(0, equirectangularUv(ref + vec3(0., -0.01, 0.))) * 0.5 + + sampleTexture(0, equirectangularUv(ref + vec3(0., 0., 0.01))) * 0.5 + + sampleTexture(0, equirectangularUv(ref + vec3(0., 0., -0.01))) * 0.5; + refC /= 4.; + + c = mix(c, c * refC.rgb, reflective); + } + + /////////////////////////////////////////////////////////// + vec3 light = normalize(lightPosition); - float lamo = dot(norm, light) + ambientIntns; - + float lamo = min(1., max(0., dot(norm, light)) + ambientIntns); c = mix(background.rgb, c, lamo); - // c *= lamo; - gl_FragColor = vec4(c, 1.); } \ No newline at end of file