This commit is contained in:
Tanasart 2024-06-16 13:04:40 +07:00
parent a7d756d565
commit aacbc437aa
4 changed files with 86 additions and 29 deletions

View file

@ -112,9 +112,9 @@ function RM_Object() constructor {
shader_set_i("tileActive", tileActive);
shader_set_f("tileAmount", tileAmount);
shader_set_f("tileSize", tileSpace);
shader_set_f("tileShiftPos", tilePos);
shader_set_f("tileShiftRot", tileRot);
shader_set_f("tileShiftSca", tileSca);
// shader_set_f("tileShiftPos", tilePos);
// shader_set_f("tileShiftRot", tileRot);
// shader_set_f("tileShiftSca", tileSca);
shader_set_f("diffuseColor", diffuseColor);
shader_set_f("reflective", reflective);
@ -250,6 +250,7 @@ function RM_Environment() constructor {
shader_set_f("lightPosition", light);
shader_set_i("useEnv", is_surface(bgEnv));
shader_set_i("drawGrid", false);
}
}

View file

@ -79,7 +79,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con
inputs[| 19] = nodeValue("Twist Amount", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0, 8, 0.1 ] });
inputs[| 20] = nodeValue("Tile Distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ])
inputs[| 20] = nodeValue("Tile Distance", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1, 1 ])
.setDisplay(VALUE_DISPLAY.vector);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -110,7 +110,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inputs[| 29] = nodeValue("Tile Amount", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 0, 0 ])
inputs[| 29] = nodeValue("Tile Amount", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 1, 1, 1 ])
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 30] = nodeValue("Background", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_black);
@ -177,7 +177,7 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con
["Modify", false], 12, 11,
["Deform", true], 15, 16, 17, 18, 19,
["Transform", false], 2, 3, 4,
["Tile", false, 45], 20, 29, 46, 47, 48,
["Tile", false, 45], 20, 29, /*46, 47, 48,*/
["Material", false], 9, 36, 35, 37, 38,
["Camera", false], 42, 43, 13, 14, 5, 6,
@ -583,12 +583,12 @@ function Node_RM_Primitive(_x, _y, _group = noone) : Node_RM(_x, _y, _group) con
var _csa = _data[43];
var _ren = _data[44];
var _tileActive = _data[46];
var _tileActive = _data[45];
var _tileAmount = _data[29];
var _tileSpace = _data[20];
var _tilePos = _data[47];
var _tileRot = _data[48];
var _tileSca = _data[49];
var _tilePos = _data[46];
var _tileRot = _data[47];
var _tileSca = _data[48];
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1]);

View file

@ -1038,7 +1038,7 @@ function Panel_Preview() : PanelContent() constructor {
var _scale = _dist * 2;
while(_scale > 32) _scale /= 2;
shader_set_f("axisBlend", _blend);
shader_set_f("scale", _scale);
shader_set_f("shift", _tx / _dist / 2, _ty / _dist / 2);
@ -1195,6 +1195,18 @@ function Panel_Preview() : PanelContent() constructor {
shader_set_f("viewRange", [ d3_view_camera.view_near, d3_view_camera.view_far ]);
shader_set_f("depthInt", 0);
var _scale = zm / 2;
var _step = 1;
while(_scale > 32) {
_scale /= 2;
_step /= 2;
}
shader_set_i("drawGrid", true);
shader_set_f("gridStep", _step);
shader_set_f("gridScale", zm / 2);
shader_set_f("axisBlend", 1.);
draw_sprite_stretched(s_fx_pixel, 0, 0, 0, w, h);
shader_reset();
gpu_set_texfilter(false);

View file

@ -1,3 +1,5 @@
#extension GL_OES_standard_derivatives : enable
//Inigo Quilez
//Oh where would I be without you.
@ -90,6 +92,10 @@ uniform float ambientIntns;
uniform vec3 lightPosition;
uniform int useEnv;
uniform int drawGrid;
uniform float gridStep;
uniform float gridScale;
uniform float axisBlend;
float influences[MAX_SHAPES];
@ -179,6 +185,16 @@ float influences[MAX_SHAPES];
return vec2((atan(n.x, n.z) / (PI * 2.)) + 0.5, 1. - acos(n.y) / PI);
}
vec4 blend(in vec4 bg, in vec4 fg) {
float al = fg.a + bg.a * (1. - fg.a);
if(al == 0.) return bg;
vec4 res = ((fg * fg.a) + (bg * bg.a * (1. - fg.a))) / al;
res.a = al;
return res;
}
#endregion
#region ////======== 2D Primitives ==========
@ -486,7 +502,27 @@ float influences[MAX_SHAPES];
// blend and return
return (x * w.x + y * w.y + z * w.z) / (w.x + w.y + w.z);
}
vec4 viewGrid(vec2 pos, float scale) {
vec2 coord = pos * scale; // use the scale variable to set the distance between the lines
vec2 derivative = fwidth(coord);
vec2 grid = abs(fract(coord - 0.5) - 0.5) / derivative;
float line = min(grid.x, grid.y);
float minimumy = min(derivative.y, 1.);
float minimumx = min(derivative.x, 1.);
vec4 color = vec4(.3, .3, .3, 1. - min(line, 1.));
// y axis
if(pos.x > -1. * minimumx / scale && pos.x < 1. * minimumx / scale)
color.y = 0.3 + axisBlend * 0.7;
// x axis
if(pos.y > -1. * minimumy / scale && pos.y < 1. * minimumy / scale)
color.x = 0.3 + axisBlend * 0.7;
return color;
}
#endregion
////========= Ray Marching ==========
@ -508,22 +544,23 @@ float sceneSDF(int index, vec3 p) {
p = wave(waveAmp[index], waveShift[index], waveInt[index], p);
if(tileActive[index] == 1) {
p = tilePosition(tileAmount[index], tileSize[index], p);
vec3 tindex = tileIndex(tileAmount[index], tileSize[index], p);
vec3 tpos = tileShiftPos[index] * random(tindex + vec3(1., 0., 0.));
vec3 trot = tileShiftRot[index] * random(tindex + vec3(0., 1., 0.));
vec3 tpos = tileShiftPos[index] * (random(tindex + vec3(1., 0., 0.)) * 2. - 1.);
vec3 trot = tileShiftRot[index] * (random(tindex + vec3(0., 1., 0.)) * 2. - 1.);
float tsca = 1. + tileShiftSca[index] * (random(tindex + vec3(0., 0., 1.)) * 2. - 1.);
tindex += tpos;
p = p - tindex;
mat3 trx = rotateX(trot.x);
mat3 try = rotateY(trot.y);
mat3 trz = rotateZ(trot.z);
mat3 trotMatrix = rx * ry * rz;
mat3 tirotMatrix = inverse(rotMatrix);
mat3 tirotMatrix = inverse(trotMatrix);
sca *= tsca;
p /= tsca;
p -= tpos;
p = tirotMatrix * p;
}
@ -642,6 +679,7 @@ float operateSceneSDF(vec3 p, out vec3 blendIndx) {
blendIndx.x = float(o2);
influences[o1] = 0.;
influences[o2] = 1.;
depth[top] = m;
index[top] = o2;
@ -735,6 +773,8 @@ float marchDensity(vec3 camera, vec3 direction) {
return dens;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
vec4 scene() {
mat3 rx = rotateX(camRotation.x);
mat3 ry = rotateY(camRotation.y);
@ -767,9 +807,16 @@ vec4 scene() {
vec3 coll = eye + dir * depth;
vec3 norm = normal(coll);
vec4 grid = vec4(0.);
if(drawGrid == 1 && sign(eye.y) != sign(coll.y)) {
vec3 gp = eye + dir * depth * (abs(eye.y) / (abs(coll.y) + abs(eye.y)));
grid = viewGrid( gp.xz, gridStep );
grid.a *= clamp(1. - length(gp.xz) * gridScale, 0., 1.) * 0.75;
}
if(depth > viewRange.y - EPSILON) // Not hitting anything.
return vec4(0.);
return drawGrid == 1? grid : vec4(0.);
///////////////////////////////////////////////////////////
@ -818,17 +865,14 @@ vec4 scene() {
float lamo = min(1., max(0., dot(norm, light)) + ambientIntns);
c = mix(c * background.rgb, c, lamo);
return vec4(c, 1.);
}
vec4 blend(in vec4 bg, in vec4 fg) {
float al = fg.a + bg.a * (1. - fg.a);
if(al == 0.) return bg;
vec4 res = ((fg * fg.a) + (bg * bg.a * (1. - fg.a))) / al;
res.a = al;
return res;
///////////////////////////////////////////////////////////
vec4 res = vec4(c, 1.);
if(drawGrid == 1 && sign(eye.y) != sign(coll.y))
res = blend(res, grid);
return res;
}
void main() {