- [Surface Extrude] Add back side properties.

This commit is contained in:
Tanasart 2024-06-17 09:47:08 +07:00
parent aacbc437aa
commit 9421160f5f
5 changed files with 328 additions and 152 deletions

View File

@ -238,6 +238,8 @@ function RM_Environment() constructor {
shader_set_surface($"texture0", surface);
shader_set_i("MAX_MARCHING_STEPS", 512);
shader_set_i("ortho", projection);
shader_set_f("fov", fov);
shader_set_f("orthoScale", orthoScale);

View File

@ -108,4 +108,6 @@ function buffer_compress_string(str) { #region
return buffer_compress(buffer, 0, buffer_get_size(buffer));
} #endregion
function buffer_to_start(buff) { INLINE buffer_seek(buff, buffer_seek_start, 0); }
function buffer_to_start(buff) { INLINE buffer_seek(buff, buffer_seek_start, 0); }
function buffer_delete_safe(buff) { INLINE if(buffer_exists(buff)) buffer_delete(buff); }

View File

@ -6,11 +6,9 @@ function __3dSurfaceExtrude(surface = noone, height = noone, smooth = false) : _
self.height = height;
self.smooth = smooth;
surface_w = 1;
surface_h = 1;
height_w = 1;
height_h = 1;
back = false;
bsurface = noone;
bheight = noone;
normal_draw_size = 0.05;
vertex_array = [];
@ -18,118 +16,167 @@ function __3dSurfaceExtrude(surface = noone, height = noone, smooth = false) : _
static initModel = function() {
if(!is_surface(surface)) return;
var _surface = surface;
var _height = height;
var _surface = surface;
var _height = height;
var _bsurface = noone;
var _bheight = noone;
var ww = surface_get_width_safe(_surface);
var hh = surface_get_height_safe(_surface);
var ww = surface_get_width_safe(_surface);
var hh = surface_get_height_safe(_surface);
var hg_ww = surface_get_width_safe(_height);
var hg_hh = surface_get_height_safe(_height);
surface_w = ww;
surface_h = hh;
var useH = is_surface(_height);
var h_buff = 0;
var c_buff = 0;
var hb_buff = 0;
var cb_buff = 0;
var ap = ww / hh;
var tw = ap / ww;
var th = 1 / hh;
var sw = -ap / 2;
var sh = 0.5;
var fw = 1 / ww;
var fh = 1 / hh;
var useH = is_surface(_height);
var hei = 0;
/////////////////////////////////////////////////////////////// Buffer
#region ---- buffer prepare ----
if(smooth) {
var ts = surface_create(ww, hh);
surface_set_shader(ts, sh_3d_extrude_filler);
shader_set_f("dimension", ww, hh);
draw_surface(_surface, 0, 0);
surface_reset_shader();
_surface = ts;
if(useH) {
var hgtW = hg_ww / ww;
var hgtH = hg_hh / hh;
if(useH) {
var ds = surface_create(ww, hh);
surface_set_shader(ds, sh_3d_extrude_filler_depth);
shader_set_f("dimension", ww, hh);
draw_surface(_height, 0, 0);
surface_reset_shader();
_height = ds;
}
var height_buffer = buffer_create(hg_ww * hg_hh * 4, buffer_fixed, 2);
buffer_get_surface(height_buffer, _height, 0);
buffer_seek(height_buffer, buffer_seek_start, 0);
h_buff = buffer_create(hg_hh * hg_ww * 2, buffer_fixed, 2);
buffer_to_start(h_buff);
repeat(hg_hh * hg_ww) {
var cc = buffer_read(height_buffer, buffer_u32);
var _b = round(colorBrightness(cc & ~0b11111111) * 65536);
buffer_write(h_buff, buffer_u16, _b);
}
if(useH) {
height_w = surface_get_width_safe(_height);
height_h = surface_get_height_safe(_height);
buffer_delete(height_buffer);
}
var surface_buffer = buffer_create(ww * hh * 4, buffer_fixed, 2);
buffer_get_surface(surface_buffer, _surface, 0);
buffer_seek(surface_buffer, buffer_seek_start, 0);
c_buff = buffer_create(hh * ww, buffer_fast, 1);
buffer_to_start(c_buff);
repeat(hh * ww) {
var cc = buffer_read(surface_buffer, buffer_u32);
var _a = (cc & (0xFF << 24)) >> 24;
buffer_write(c_buff, buffer_u8, _a);
}
buffer_delete(surface_buffer);
if(back) {
_bsurface = surface_create(ww, hh);
_bheight = surface_create(hg_ww, hg_hh);
BLEND_OVERRIDE
surface_set_target(_bsurface);
DRAW_CLEAR
draw_surface_stretched(is_surface(bsurface)? bsurface : surface, 0, 0, ww, hh);
surface_reset_target();
var hgtW = height_w / ww;
var hgtH = height_h / hh;
var height_buffer = buffer_create(height_w * height_h * 4, buffer_fixed, 2);
buffer_get_surface(height_buffer, _height, 0);
buffer_seek(height_buffer, buffer_seek_start, 0);
surface_set_target(_bheight);
DRAW_CLEAR
draw_surface_stretched(is_surface(bheight)? bheight : _height, 0, 0, hg_ww, hg_hh);
surface_reset_target();
BLEND_NORMAL
var hei = buffer_create(height_h * height_w * 2, buffer_fixed, 2);
buffer_to_start(hei);
/////////////////////////////////////////////////////////////////////////////////////////////////
repeat(height_h * height_w) {
var cc = buffer_read(height_buffer, buffer_u32);
var _b = round(colorBrightness(cc & ~0b11111111) * 65536);
buffer_write(hei, buffer_u16, _b);
}
var height_buffer = buffer_create(hg_ww * hg_hh * 4, buffer_fixed, 2);
buffer_get_surface(height_buffer, _bheight, 0);
buffer_seek(height_buffer, buffer_seek_start, 0);
hb_buff = buffer_create(hg_hh * hg_ww * 2, buffer_fixed, 2);
buffer_to_start(hb_buff);
buffer_delete(height_buffer);
repeat(hg_hh * hg_ww) {
var cc = buffer_read(height_buffer, buffer_u32);
var _b = round(colorBrightness(cc & ~0b11111111) * 65536);
buffer_write(hb_buff, buffer_u16, _b);
}
var surface_buffer = buffer_create(ww * hh * 4, buffer_fixed, 2);
buffer_get_surface(surface_buffer, _surface, 0);
buffer_seek(surface_buffer, buffer_seek_start, 0);
buffer_delete(height_buffer);
var ap = buffer_create(hh * ww, buffer_fast, 1);
buffer_to_start(ap);
/////////////////////////////////////////////////////////////////////////////////////////////////
// var surface_buffer = buffer_create(ww * hh * 4, buffer_fixed, 2);
// buffer_get_surface(surface_buffer, _bsurface, 0);
// buffer_seek(surface_buffer, buffer_seek_start, 0);
repeat(hh * ww) {
var cc = buffer_read(surface_buffer, buffer_u32);
var _a = (cc & (0b11111111 << 24)) >> 24;
buffer_write(ap, buffer_u8, _a);
}
// cb_buff = buffer_create(hh * ww, buffer_fast, 1);
// buffer_to_start(cb_buff);
buffer_delete(surface_buffer);
// repeat(hh * ww) {
// var cc = buffer_read(surface_buffer, buffer_u32);
// var _a = (cc & (0xFF << 24)) >> 24;
// buffer_write(cb_buff, buffer_u8, _a);
// }
if(smooth) {
surface_free(_surface);
if(useH) surface_free(_height);
}
#endregion
// buffer_delete(surface_buffer);
surface_free(_bsurface);
surface_free(_bheight);
}
///////////////////////////////////////////////////////////////
var asp = ww / hh;
var tw = asp / ww;
var th = 1 / hh;
var sw = -asp / 2;
var sh = 0.5;
var fw = 1 / ww;
var fh = 1 / hh;
var _len = array_length(vertex_array);
for(var i = _len; i < ww * hh * 36; i++)
var _amo = back? ww * hh * 60 : ww * hh * 36;
for(var i = _len; i < _amo; i++)
vertex_array[i] = new __vertex();
var v = array_create(ww * hh * 36);
var v = array_create(_amo);
var ind = 0;
var i = 0, j = 0, n = 0;
repeat(hh * ww) {
if(!smooth && buffer_read_at(ap, (j) * ww + (i), buffer_u8) == 0) continue;
i = floor(n / ww);
j = n % ww;
n++;
if(buffer_read_at(c_buff, j * ww + i, buffer_u8) == 0) continue;
var i0 = sw + i * tw;
var j0 = sh - j * th;
var i1 = i0 + tw;
var j1 = j0 - th;
var tx0 = fw * i, tx1 = tx0 + fw;
var ty0 = fh * j, ty1 = ty0 + fh;
var tx0 = i * fw * 0.5;
var tx1 = tx0 + fw * 0.5;
var dep = useH? buffer_read_at(hei, (round(i * hgtW) + round(j * hgtH) * height_w) * 2, buffer_u16) / 65536 * 0.5
var tb0 = tx0 + 0.5;
var tb1 = tb0 + fw * 0.5;
var ty0 = j * fh;
var ty1 = ty0 + fh;
var dep = useH? buffer_read_at(h_buff, (round(i * hgtW) + round(j * hgtH) * hg_ww) * 2, buffer_u16) / 65536 * 0.5
: 0.5;
var depb = back? buffer_read_at(hb_buff, (round(i * hgtW) + round(j * hgtH) * hg_ww) * 2, buffer_u16) / 65536 * 0.5
: dep;
depb = -depb;
v[ind] = vertex_array[ind].set(i1, j0, -dep, 0, 0, -1, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j0, -dep, 0, 0, -1, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, -dep, 0, 0, -1, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j0, depb, 0, 0, -1, tb1, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j0, depb, 0, 0, -1, tb0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, depb, 0, 0, -1, tb1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, -dep, 0, 0, -1, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j0, -dep, 0, 0, -1, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j1, -dep, 0, 0, -1, tx0, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, depb, 0, 0, -1, tb1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j0, depb, 0, 0, -1, tb0, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j1, depb, 0, 0, -1, tb0, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j0, dep, 0, 0, 1, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 0, 0, 1, tx1, ty1); ind++;
@ -138,64 +185,164 @@ function __3dSurfaceExtrude(surface = noone, height = noone, smooth = false) : _
v[ind] = vertex_array[ind].set(i1, j1, dep, 0, 0, 1, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, dep, 0, 0, 1, tx0, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j0, dep, 0, 0, 1, tx0, ty0); ind++;
if((useH && dep * 2 > buffer_read_at(hei, (round(i * hgtW) + max(0, round((j - 1) * hgtH)) * height_w) * 2, buffer_u16) / 65536)
|| (j == 0 || buffer_read_at(ap, (j - 1) * ww + (i), buffer_u8) == 0)) { //y side
v[ind] = vertex_array[ind].set(i0, j0, dep, 0, 1, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j0, -dep, 0, 1, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, dep, 0, 1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j0, -dep, 0, 1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j0, -dep, 0, 1, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, dep, 0, 1, 0, tx0, ty1); ind++;
}
if(back) {
if((useH && dep * 2 > buffer_read_at(hei, (round(i * hgtW) + min(round((j + 1) * hgtH), height_h - 1) * height_w) * 2, buffer_u16) / 65536)
|| (j == hh - 1 || buffer_read_at(ap, (j + 1) * ww + (i), buffer_u8) == 0)) { //y side
if((useH && dep * 2 > buffer_read_at(h_buff, (round(i * hgtW) + max(0, round((j - 1) * hgtH)) * hg_ww) * 2, buffer_u16) / 65536)
|| (j == 0 || buffer_read_at(c_buff, (j - 1) * ww + (i), buffer_u8) == 0)) { //y side
v[ind] = vertex_array[ind].set(i0, j0, dep, 0, 1, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j0, 0, 0, 1, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, dep, 0, 1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j0, 0, 0, 1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j0, 0, 0, 1, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, dep, 0, 1, 0, tx0, ty1); ind++;
}
v[ind] = vertex_array[ind].set(i0, j1, dep, 0, -1, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 0, -1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, -dep, 0, -1, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j1, -dep, 0, -1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 0, -1, 0, tx0, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, -dep, 0, -1, 0, tx0, ty0); ind++;
if((useH && abs(depb) * 2 > buffer_read_at(hb_buff, (round(i * hgtW) + max(0, round((j - 1) * hgtH)) * hg_ww) * 2, buffer_u16) / 65536)
|| (j == 0 || buffer_read_at(c_buff, (j - 1) * ww + (i), buffer_u8) == 0)) { //y side
v[ind] = vertex_array[ind].set(i0, j0, 0, 0, 1, 0, tb1, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j0, depb, 0, 1, 0, tb0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, 0, 0, 1, 0, tb1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j0, depb, 0, 1, 0, tb1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j0, depb, 0, 1, 0, tb0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, 0, 0, 1, 0, tb0, ty1); ind++;
}
if((useH && dep * 2 > buffer_read_at(h_buff, (round(i * hgtW) + min(round((j + 1) * hgtH), hg_hh - 1) * hg_ww) * 2, buffer_u16) / 65536)
|| (j == hh - 1 || buffer_read_at(c_buff, (j + 1) * ww + (i), buffer_u8) == 0)) { //y side
v[ind] = vertex_array[ind].set(i0, j1, dep, 0, -1, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 0, -1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, 0, 0, -1, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j1, 0, 0, -1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 0, -1, 0, tx0, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, 0, 0, -1, 0, tx0, ty0); ind++;
}
if((useH && abs(depb) * 2 > buffer_read_at(hb_buff, (round(i * hgtW) + min(round((j + 1) * hgtH), hg_hh - 1) * hg_ww) * 2, buffer_u16) / 65536)
|| (j == hh - 1 || buffer_read_at(c_buff, (j + 1) * ww + (i), buffer_u8) == 0)) { //y side
v[ind] = vertex_array[ind].set(i0, j1, 0, 0, -1, 0, tb1, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, 0, 0, -1, 0, tb1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, depb, 0, -1, 0, tb0, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j1, depb, 0, -1, 0, tb1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, 0, 0, -1, 0, tb0, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, depb, 0, -1, 0, tb0, ty0); ind++;
}
if((useH && dep * 2 > buffer_read_at(h_buff, (max(0, round((i - 1) * hgtW)) + round(j * hgtH) * hg_ww) * 2, buffer_u16) / 65536)
|| (i == 0 || buffer_read_at(c_buff, (j) * ww + (i - 1), buffer_u8) == 0)) { //x side
v[ind] = vertex_array[ind].set(i0, j0, dep, -1, 0, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j1, dep, -1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j0, 0, -1, 0, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j0, 0, -1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, dep, -1, 0, 0, tx0, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, 0, -1, 0, 0, tx0, ty0); ind++;
}
if((useH && abs(depb) * 2 > buffer_read_at(hb_buff, (max(0, round((i - 1) * hgtW)) + round(j * hgtH) * hg_ww) * 2, buffer_u16) / 65536)
|| (i == 0 || buffer_read_at(c_buff, (j) * ww + (i - 1), buffer_u8) == 0)) { //x side
v[ind] = vertex_array[ind].set(i0, j0, 0, -1, 0, 0, tb1, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j1, 0, -1, 0, 0, tb1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j0, depb, -1, 0, 0, tb0, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j0, depb, -1, 0, 0, tb1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, 0, -1, 0, 0, tb0, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, depb, -1, 0, 0, tb0, ty0); ind++;
}
if((useH && dep * 2 > buffer_read_at(h_buff, (min(round((i + 1) * hgtW), hg_ww - 1 ) + round(j * hgtH) * hg_ww) * 2, buffer_u16) / 65536)
|| (i == ww - 1 || buffer_read_at(c_buff, (j) * ww + (i + 1), buffer_u8) == 0)) { //x side
v[ind] = vertex_array[ind].set(i1, j0, dep, 1, 0, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, 0, 1, 0, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j0, 0, 1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, 0, 1, 0, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 1, 0, 0, tx0, ty1); ind++;
}
if((useH && abs(depb) * 2 > buffer_read_at(hb_buff, (min(round((i + 1) * hgtW), hg_ww - 1 ) + round(j * hgtH) * hg_ww) * 2, buffer_u16) / 65536)
|| (i == ww - 1 || buffer_read_at(c_buff, (j) * ww + (i + 1), buffer_u8) == 0)) { //x side
v[ind] = vertex_array[ind].set(i1, j0, 0, 1, 0, 0, tb1, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, depb, 1, 0, 0, tb0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, 0, 1, 0, 0, tb1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j0, depb, 1, 0, 0, tb1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, depb, 1, 0, 0, tb0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, 0, 1, 0, 0, tb0, ty1); ind++;
}
} else {
if((useH && dep * 2 > buffer_read_at(h_buff, (round(i * hgtW) + max(0, round((j - 1) * hgtH)) * hg_ww) * 2, buffer_u16) / 65536)
|| (j == 0 || buffer_read_at(c_buff, (j - 1) * ww + (i), buffer_u8) == 0)) { //y side
v[ind] = vertex_array[ind].set(i0, j0, dep, 0, 1, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j0, depb, 0, 1, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, dep, 0, 1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j0, depb, 0, 1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j0, depb, 0, 1, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, dep, 0, 1, 0, tx0, ty1); ind++;
}
if((useH && dep * 2 > buffer_read_at(h_buff, (round(i * hgtW) + min(round((j + 1) * hgtH), hg_hh - 1) * hg_ww) * 2, buffer_u16) / 65536)
|| (j == hh - 1 || buffer_read_at(c_buff, (j + 1) * ww + (i), buffer_u8) == 0)) { //y side
v[ind] = vertex_array[ind].set(i0, j1, dep, 0, -1, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 0, -1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, depb, 0, -1, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j1, depb, 0, -1, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 0, -1, 0, tx0, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, depb, 0, -1, 0, tx0, ty0); ind++;
}
if((useH && dep * 2 > buffer_read_at(h_buff, (max(0, round((i - 1) * hgtW)) + round(j * hgtH) * hg_ww) * 2, buffer_u16) / 65536)
|| (i == 0 || buffer_read_at(c_buff, (j) * ww + (i - 1), buffer_u8) == 0)) { //x side
v[ind] = vertex_array[ind].set(i0, j0, dep, -1, 0, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j1, dep, -1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j0, depb, -1, 0, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j0, depb, -1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, dep, -1, 0, 0, tx0, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, depb, -1, 0, 0, tx0, ty0); ind++;
}
if((useH && dep * 2 > buffer_read_at(h_buff, (min(round((i + 1) * hgtW), hg_ww - 1 ) + round(j * hgtH) * hg_ww) * 2, buffer_u16) / 65536)
|| (i == ww - 1 || buffer_read_at(c_buff, (j) * ww + (i + 1), buffer_u8) == 0)) { //x side
v[ind] = vertex_array[ind].set(i1, j0, dep, 1, 0, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, depb, 1, 0, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j0, depb, 1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, depb, 1, 0, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 1, 0, 0, tx0, ty1); ind++;
}
}
if((useH && dep * 2 > buffer_read_at(hei, (max(0, round((i - 1) * hgtW)) + round(j * hgtH) * height_w) * 2, buffer_u16) / 65536)
|| (i == 0 || buffer_read_at(ap, (j) * ww + (i - 1), buffer_u8) == 0)) { //x side
v[ind] = vertex_array[ind].set(i0, j0, dep, -1, 0, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j1, dep, -1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j0, -dep, -1, 0, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i0, j0, -dep, -1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, dep, -1, 0, 0, tx0, ty1); ind++;
v[ind] = vertex_array[ind].set(i0, j1, -dep, -1, 0, 0, tx0, ty0); ind++;
}
if((useH && dep * 2 > buffer_read_at(hei, (min(round((i + 1) * hgtW), height_w - 1 ) + round(j * hgtH) * height_w) * 2, buffer_u16) / 65536)
|| (i == ww - 1 || buffer_read_at(ap, (j) * ww + (i + 1), buffer_u8) == 0)) { //x side
v[ind] = vertex_array[ind].set(i1, j0, dep, 1, 0, 0, tx1, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j0, -dep, 1, 0, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j0, -dep, 1, 0, 0, tx1, ty1); ind++;
v[ind] = vertex_array[ind].set(i1, j1, -dep, 1, 0, 0, tx0, ty0); ind++;
v[ind] = vertex_array[ind].set(i1, j1, dep, 1, 0, 0, tx0, ty1); ind++;
}
n++;
i = floor(n / ww);
j = n % ww;
}
array_resize(v, ind);
if(hei) buffer_delete(hei);
buffer_delete(ap);
buffer_delete_safe(h_buff);
buffer_delete_safe(c_buff);
buffer_delete_safe(hb_buff);
buffer_delete_safe(cb_buff);
vertex = [ v ];
VB = build();

View File

@ -12,36 +12,66 @@ function Node_3D_Mesh_Extrude(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _gr
inputs[| in_mesh + 3] = nodeValue("Always update", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
inputs[| in_mesh + 4] = nodeValue("Double Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
inputs[| in_mesh + 5] = nodeValue("Back Surface", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, new __d3dMaterial())
.setVisible(true, true);
inputs[| in_mesh + 6] = nodeValue("Back Height", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);
input_display_list = [
__d3d_input_list_mesh,
__d3d_input_list_transform,
["Extrude", false], in_mesh + 0, in_mesh + 1, in_mesh + 3,
["Extrude", false], in_mesh + 0, in_mesh + 1, in_mesh + 3,
["Textures", false], in_mesh + 4, in_mesh + 5, in_mesh + 6,
]
temp_surface = [ noone, noone ];
static step = function() {
var _double = getSingleValue(in_mesh + 4);
inputs[| in_mesh + 5].setVisible(true, _double);
inputs[| in_mesh + 6].setVisible(true, _double);
}
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
var _mat = _data[in_mesh + 0];
if(!is_instanceof(_mat, __d3dMaterial)) return noone;
var _hght = _data[in_mesh + 1];
var _smt = _data[in_mesh + 2];
var _updt = _data[in_mesh + 3];
var _surf = _mat.surface;
var _back = _data[in_mesh + 4];
var _bmat = _data[in_mesh + 5];
var _bhgt = _data[in_mesh + 6];
var _surf = is_instanceof(_mat, __d3dMaterial)? _mat.surface : noone;
var _bsurf = is_instanceof(_bmat, __d3dMaterial)? _bmat.surface : noone;
if(!is_surface(_surf)) return noone;
temp_surface[0] = surface_cvt_8unorm(temp_surface[0], _surf);
temp_surface[1] = surface_cvt_8unorm(temp_surface[1], _hght);
var object = getObject(_array_index);
object.checkParameter({ surface: temp_surface[0], height: temp_surface[1], smooth: _smt }, _updt);
var _matN = _mat.clone();
var _nSurf = surface_create(surface_get_width(_surf), surface_get_height(_surf));
var object = getObject(_array_index);
object.checkParameter( {
surface : _surf,
height : _hght,
back : _back,
bsurface : _bsurf,
bheight : _bhgt,
smooth : _smt,
}, _updt);
var _dim = surface_get_dimension(_surf);
var _nSurf = surface_create(_dim[0] * 2, _dim[1]);
surface_set_shader(_nSurf, sh_d3d_extrude_extends);
shader_set_dim("dimension", _surf);
draw_surface_safe(_surf);
draw_surface_safe(_surf, 0);
if(_back) draw_surface_stretched_safe(_bsurf, _dim[0], 0, _dim[0], _dim[1]);
else draw_surface_stretched_safe(_surf, _dim[0], 0, _dim[0], _dim[1]);
surface_reset_shader();
_matN.surface = _nSurf;

View File

@ -9,7 +9,6 @@
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
const int MAX_MARCHING_STEPS = 512;
const float EPSILON = 1e-5;
const float PI = 3.14159265358979323846;
@ -23,6 +22,7 @@ uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform int MAX_MARCHING_STEPS;
uniform int operations[MAX_OP];
uniform float opArgument[MAX_OP];
uniform int opLength;
@ -97,7 +97,7 @@ uniform float gridStep;
uniform float gridScale;
uniform float axisBlend;
float influences[MAX_SHAPES];
float influences[MAX_SHAPES];
#region ////========== Transform ============
mat3 rotateX(float dg) {
@ -709,16 +709,11 @@ vec3 normal(vec3 p) {
vec3 b;
vec2 e = vec2(1.0, -1.0) * 0.0001;
return normalize( e.xyy * operateSceneSDF( p + e.xyy, b ) +
return normalize( e.xyy * operateSceneSDF( p + e.xyy, b ) +
e.yyx * operateSceneSDF( p + e.yyx, b ) +
e.yxy * operateSceneSDF( p + e.yxy, b ) +
e.xxx * operateSceneSDF( p + e.xxx, b ) );
// return normalize(vec3(
// operateSceneSDF(vec3(p.x + EPSILON, p.y, p.z), b) - operateSceneSDF(vec3(p.x - EPSILON, p.y, p.z), b),
// operateSceneSDF(vec3(p.x, p.y + EPSILON, p.z), b) - operateSceneSDF(vec3(p.x, p.y - EPSILON, p.z), b),
// operateSceneSDF(vec3(p.x, p.y, p.z + EPSILON), b) - operateSceneSDF(vec3(p.x, p.y, p.z - EPSILON), b)
// ));
}
float march(vec3 camera, vec3 direction, out vec3 blendIndx) {