3d wireframe

This commit is contained in:
Tanasart 2024-12-18 12:18:41 +07:00
parent cba206ba16
commit aaa74eed52
16 changed files with 467 additions and 288 deletions

View file

@ -190,9 +190,8 @@
{"name":"sprites","order":7,"path":"folders/panels/preview/sprites.yy",},
{"name":"shader","order":331,"path":"folders/shader.yy",},
{"name":"3d","order":1,"path":"folders/shader/3d.yy",},
{"name":"2d effect","order":12,"path":"folders/shader/3d/2d effect.yy",},
{"name":"legacy","order":13,"path":"folders/shader/3d/legacy.yy",},
{"name":"ssao","order":14,"path":"folders/shader/3d/ssao.yy",},
{"name":"legacy","order":1,"path":"folders/shader/3d/legacy.yy",},
{"name":"ssao","order":2,"path":"folders/shader/3d/ssao.yy",},
{"name":"blend","order":2,"path":"folders/shader/blend.yy",},
{"name":"canvas","order":3,"path":"folders/shader/canvas.yy",},
{"name":"color_picker","order":4,"path":"folders/shader/color_picker.yy",},
@ -1525,19 +1524,20 @@
{"name":"sh_cross_section","order":25,"path":"shaders/sh_cross_section/sh_cross_section.yy",},
{"name":"sh_curve_hsv","order":53,"path":"shaders/sh_curve_hsv/sh_curve_hsv.yy",},
{"name":"sh_curve","order":19,"path":"shaders/sh_curve/sh_curve.yy",},
{"name":"sh_d3d_3d_transform","order":15,"path":"shaders/sh_d3d_3d_transform/sh_d3d_3d_transform.yy",},
{"name":"sh_d3d_background","order":8,"path":"shaders/sh_d3d_background/sh_d3d_background.yy",},
{"name":"sh_d3d_extrude_extends","order":11,"path":"shaders/sh_d3d_extrude_extends/sh_d3d_extrude_extends.yy",},
{"name":"sh_d3d_geometry","order":9,"path":"shaders/sh_d3d_geometry/sh_d3d_geometry.yy",},
{"name":"sh_d3d_grid_view","order":1,"path":"shaders/sh_d3d_grid_view/sh_d3d_grid_view.yy",},
{"name":"sh_d3d_normal_blur","order":10,"path":"shaders/sh_d3d_normal_blur/sh_d3d_normal_blur.yy",},
{"name":"sh_d3d_normal","order":5,"path":"shaders/sh_d3d_normal/sh_d3d_normal.yy",},
{"name":"sh_d3d_outline","order":3,"path":"shaders/sh_d3d_outline/sh_d3d_outline.yy",},
{"name":"sh_d3d_shadow_cube_depth","order":7,"path":"shaders/sh_d3d_shadow_cube_depth/sh_d3d_shadow_cube_depth.yy",},
{"name":"sh_d3d_shadow_depth","order":6,"path":"shaders/sh_d3d_shadow_depth/sh_d3d_shadow_depth.yy",},
{"name":"sh_d3d_silhouette","order":2,"path":"shaders/sh_d3d_silhouette/sh_d3d_silhouette.yy",},
{"name":"sh_d3d_3d_transform","order":16,"path":"shaders/sh_d3d_3d_transform/sh_d3d_3d_transform.yy",},
{"name":"sh_d3d_background","order":12,"path":"shaders/sh_d3d_background/sh_d3d_background.yy",},
{"name":"sh_d3d_default","order":3,"path":"shaders/sh_d3d_default/sh_d3d_default.yy",},
{"name":"sh_d3d_extrude_extends","order":15,"path":"shaders/sh_d3d_extrude_extends/sh_d3d_extrude_extends.yy",},
{"name":"sh_d3d_geometry","order":13,"path":"shaders/sh_d3d_geometry/sh_d3d_geometry.yy",},
{"name":"sh_d3d_grid_view","order":5,"path":"shaders/sh_d3d_grid_view/sh_d3d_grid_view.yy",},
{"name":"sh_d3d_normal_blur","order":14,"path":"shaders/sh_d3d_normal_blur/sh_d3d_normal_blur.yy",},
{"name":"sh_d3d_normal","order":9,"path":"shaders/sh_d3d_normal/sh_d3d_normal.yy",},
{"name":"sh_d3d_outline","order":7,"path":"shaders/sh_d3d_outline/sh_d3d_outline.yy",},
{"name":"sh_d3d_shadow_cube_depth","order":11,"path":"shaders/sh_d3d_shadow_cube_depth/sh_d3d_shadow_cube_depth.yy",},
{"name":"sh_d3d_shadow_depth","order":10,"path":"shaders/sh_d3d_shadow_depth/sh_d3d_shadow_depth.yy",},
{"name":"sh_d3d_silhouette","order":6,"path":"shaders/sh_d3d_silhouette/sh_d3d_silhouette.yy",},
{"name":"sh_d3d_ssao_blur","order":1,"path":"shaders/sh_d3d_ssao_blur/sh_d3d_ssao_blur.yy",},
{"name":"sh_d3d_wireframe","order":4,"path":"shaders/sh_d3d_wireframe/sh_d3d_wireframe.yy",},
{"name":"sh_d3d_wireframe","order":8,"path":"shaders/sh_d3d_wireframe/sh_d3d_wireframe.yy",},
{"name":"sh_de_corner","order":21,"path":"shaders/sh_de_corner/sh_de_corner.yy",},
{"name":"sh_de_stray","order":22,"path":"shaders/sh_de_stray/sh_de_stray.yy",},
{"name":"sh_default","order":6,"path":"shaders/sh_default/sh_default.yy",},

View file

@ -1,6 +1,9 @@
/// @description
if !ready exit;
if(!is_undefined(content) && content != noone)
content.preDraw();
DIALOG_PREDRAW
DIALOG_WINCLEAR

View file

@ -1,5 +1,4 @@
/// @description
if(!is_undefined(content) && content != noone)
content.drawGUI();
event_inherited();

View file

@ -42,11 +42,26 @@ function Panel_Linear_Setting() : PanelContent() constructor {
selecting_menu = noone;
properties = [];
static setHeight = function() { h = ui(12 + 36 * array_length(properties)); }
prop_height = ui(32);
curr_height = 0;
static drawSettings = function(panel) {
var yy = ui(24);
var th = ui(36);
static setHeight = function() { h = prop_height * array_length(properties) + ui(16); }
static resetHeight = function(_h) {
if(h == _h) return;
if(in_dialog) {
panel.dialog_y -= _h - h;
panel.dialog_h = _h
h = _h;
panel.contentResize();
}
h = _h;
}
static drawSettings = function() {
var yy = ui(4);
var th = prop_height;
var ww = max(wdgw, w * 0.5);
var wh = TEXTBOX_HEIGHT;
@ -56,17 +71,53 @@ function Panel_Linear_Setting() : PanelContent() constructor {
for( var i = 0, n = array_length(properties); i < n; i++ ) {
var _prop = properties[i];
if(is_array(_prop)) {
yy += bool(i) * ui(4);
var txt = __txt(_prop[0]);
var coll = _prop[1];
var lbx = ui(4);
var lby = ui(0);
var lbh = th - ui(4);
var lbw = w - ui(8);
if(pHOVER && point_in_rectangle(mx, my, lbx, yy, lbx + lbw, yy + lbh)) {
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, lbx, yy, lbw, lbh, COLORS.panel_inspector_group_hover, 1);
if(mouse_press(mb_left, pFOCUS)) _prop[@ 1] = !coll;
} else
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, lbx, yy, lbw, lbh, CDEF.main_ltgrey, 1);
draw_sprite_ui(THEME.arrow, coll * 3, lbx + ui(16), yy + lbh / 2, 1, 1, 0, COLORS.panel_inspector_group_bg, 1);
draw_set_text(f_p2, fa_left, fa_center, COLORS.panel_inspector_group_bg, 1);
draw_text_add(lbx + ui(32), yy + lbh / 2, txt);
draw_set_alpha(1);
if(coll) { // skip
var j = i + 1;
while(j < n) {
if(is_array(properties[j])) break;
j++;
}
i = j - 1;
}
yy += lbh + (!coll) * ui(4);
continue;
}
if(is_instanceof(_prop, __Panel_Linear_Setting_Label)) {
var _text = _prop.name;
var _spr = _prop.sprite;
var _ind = _prop.index;
var _colr = _prop.color;
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, ui(4), yy - th / 2 + ui(2), w - ui(8), th - ui(4), _colr, 1);
draw_sprite_ui(_spr, _ind, ui(4) + th / 2, yy);
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, ui(4), yy + ui(2), w - ui(8), th - ui(4), _colr, 1);
draw_sprite_ui(_spr, _ind, ui(4) + th / 2, yy + th / 2);
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text);
draw_text_add(ui(4) + th, yy, _text);
draw_set_text(f_p2, fa_left, fa_center, COLORS._main_text);
draw_text_add(ui(4) + th, yy + th / 2, _text);
yy += th;
continue;
@ -82,14 +133,14 @@ function Panel_Linear_Setting() : PanelContent() constructor {
_widg.register();
var _whover = false;
if(pHOVER && point_in_rectangle(mx, my, 0, yy - th / 2, w, yy + th / 2)) {
bg_y_to = yy - th / 2;
if(pHOVER && point_in_rectangle(mx, my, 0, yy, w, yy + th)) {
bg_y_to = yy;
_hov = true;
_whover = true;
}
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text);
draw_text_add(ui(16), yy, _text);
draw_set_text(f_p2, fa_left, fa_center, COLORS._main_text);
draw_text_add(ui(16), yy + th / 2, _text);
var _x1 = w - ui(8);
var _wdw = ww;
@ -97,7 +148,9 @@ function Panel_Linear_Setting() : PanelContent() constructor {
if(_prop.getDefault != noone)
_wdw -= ui(32 + 8);
var params = new widgetParam(_x1 - ww, yy - wh / 2, _wdw, wh, _data, {}, [ mx, my ], x, y);
var params = new widgetParam(_x1 - ww, yy + th / 2 - wh / 2, _wdw, wh, _data, {}, [ mx, my ], x, y)
.setFont(f_p2);
if(is_instanceof(_widg, checkBox)) {
params.halign = fa_center;
params.valign = fa_center;
@ -128,7 +181,7 @@ function Panel_Linear_Setting() : PanelContent() constructor {
var _th = line_get_height();
var _hx = _x1 - ww - ui(16);
var _hy = yy + ui(2);
var _hy = yy + th / 2 + ui(2);
var _bx = _hx - _tw - ui(4);
var _by = _hy - _th / 2 - ui(3);
@ -153,7 +206,7 @@ function Panel_Linear_Setting() : PanelContent() constructor {
var _defVal = is_method(_prop.getDefault)? _prop.getDefault() : _prop.getDefault;
var _bs = ui(32);
var _bx = _x1 - _bs;
var _by = yy - _bs / 2;
var _by = yy + th / 2 - _bs / 2;
if(isEqual(_data, _defVal))
draw_sprite_ext(THEME.refresh_16, 0, _bx + _bs / 2, _by + _bs / 2, 1, 1, 0, COLORS._main_icon_dark);
@ -169,9 +222,7 @@ function Panel_Linear_Setting() : PanelContent() constructor {
}
bg_a = lerp_float(bg_a, _hov, 2);
if(bg_y == -1) bg_y = bg_y_to;
else bg_y = lerp_float(bg_y, bg_y_to, 2);
bg_y = bg_y == -1? bg_y_to : lerp_float(bg_y, bg_y_to, 2);
if(hk_editing != noone) {
if(keyboard_check_pressed(vk_enter)) hk_editing = noone;
@ -179,7 +230,13 @@ function Panel_Linear_Setting() : PanelContent() constructor {
if(keyboard_check_pressed(vk_escape)) hk_editing = noone;
}
curr_height = yy + ui(4);
}
function drawContent(panel) { drawSettings(panel); }
function drawContent() { drawSettings(); }
function preDraw() {
resetHeight(curr_height);
}
}

View file

@ -1,4 +1,8 @@
#region vertex format
vertex_format_begin();
vertex_format_add_position_3d();
global.VF_POS = vertex_format_end();
vertex_format_begin();
vertex_format_add_position_3d();
vertex_format_add_color();
@ -9,30 +13,31 @@
vertex_format_add_normal(); // x y z // 12
vertex_format_add_texcoord(); // u v // 8
vertex_format_add_color(); // r g b a // 4
vertex_format_add_custom(vertex_type_float3, vertex_usage_texcoord); // x y z // 12 // barycentric
global.VF_POS_NORM_TEX_COL = vertex_format_end();
global.VF_POS_NORM_TEX_COL_size = 36;
global.VF_POS_NORM_TEX_COL_size = 48;
#endregion
function __3dObject() constructor {
object_counts = 1;
vertex = [];
VB = [];
normal_vertex = [];
object_counts = 1;
NVB = noone;
normal_draw_size = 0.2;
VF = global.VF_POS_COL;
render_type = pr_trianglelist;
custom_shader = noone;
NVB = noone;
WVB = noone;
transform = new __transform();
size = new __vec3(1);
normal_draw_size = 0.2;
render_type = pr_trianglelist;
custom_shader = noone;
texture_flip = false;
materials = [];
material_index = [];
texture_flip = false;
////- Object
static checkParameter = function(params = {}, forceUpdate = false) {
var _keys = struct_get_names(params);
@ -56,31 +61,37 @@ function __3dObject() constructor {
static onParameterUpdate = function() {}
////- Verticies
static generateNormal = function(_s = normal_draw_size) {
if(render_type != pr_trianglelist) return;
NVB = array_create(object_counts);
if(is_array(NVB)) array_foreach(NVB, function(v) /*=>*/ {return vertex_delete_buffer(v)});
NVB = array_verify(NVB, object_counts);
for( var i = 0; i < object_counts; i++ ) {
NVB[i] = vertex_create_buffer();
var _obj = vertex[i];
var _nvb = vertex_create_buffer();
vertex_begin(NVB[i], global.VF_POS_COL);
for( var j = 0, n = array_length(vertex[i]); j < n; j++ ) {
var _v = vertex[i][j];
vertex_begin(_nvb, global.VF_POS_COL);
for( var j = 0, n = array_length(_obj); j < n; j++ ) {
var _v = _obj[j];
vertex_position_3d(NVB[i], _v.x, _v.y, _v.z);
vertex_color(NVB[i], c_red, 1);
vertex_position_3d(_nvb, _v.x, _v.y, _v.z);
vertex_color(_nvb, c_red, 1);
vertex_position_3d(NVB[i], _v.x + _v.nx * _s, _v.y + _v.ny * _s, _v.z + _v.nz * _s);
vertex_color(NVB[i], c_red, 1);
vertex_position_3d(_nvb, _v.x + _v.nx * _s, _v.y + _v.ny * _s, _v.z + _v.nz * _s);
vertex_color(_nvb, c_red, 1);
}
vertex_end(NVB[i]);
vertex_end(_nvb);
NVB[i] = _nvb;
}
}
static buildVertex = function(_vertex) {
var _buffer = vertex_create_buffer();
vertex_begin(_buffer, VF);
switch(VF) {
case global.VF_POS_COL :
for( var i = 0, n = array_length(_vertex); i < n; i++ ) {
@ -91,25 +102,40 @@ function __3dObject() constructor {
break;
case global.VF_POS_NORM_TEX_COL :
for( var i = 0, n = array_length(_vertex); i < n; i++ ) {
var v = _vertex[i];
vertex_position_3d(_buffer, v.x, v.y, v.z);
vertex_normal(_buffer, v.nx, v.ny, v.nz);
vertex_texcoord(_buffer, v.u, v.v);
vertex_color(_buffer, v.color, v.alpha);
for( var i = 0, n = array_length(_vertex); i < n; i += 3 ) {
var v0 = _vertex[i + 0];
var v1 = _vertex[i + 1];
var v2 = _vertex[i + 2];
vertex_position_3d( _buffer, v0.x, v0.y, v0.z);
vertex_normal( _buffer, v0.nx, v0.ny, v0.nz);
vertex_texcoord( _buffer, v0.u, v0.v);
vertex_color( _buffer, v0.color, v0.alpha);
vertex_float3( _buffer, 255, 0, 0);
vertex_position_3d( _buffer, v1.x, v1.y, v1.z);
vertex_normal( _buffer, v1.nx, v1.ny, v1.nz);
vertex_texcoord( _buffer, v1.u, v1.v);
vertex_color( _buffer, v1.color, v1.alpha);
vertex_float3( _buffer, 0, 255, 0);
vertex_position_3d( _buffer, v2.x, v2.y, v2.z);
vertex_normal( _buffer, v2.nx, v2.ny, v2.nz);
vertex_texcoord( _buffer, v2.u, v2.v);
vertex_color( _buffer, v2.color, v2.alpha);
vertex_float3( _buffer, 0, 0, 255);
}
break;
}
vertex_end(_buffer);
return _buffer;
}
static build = function(_buffer = VB, _vertex = vertex, counts = object_counts) {
if(is_array(_buffer)) {
for( var i = 0, n = array_length(_buffer); i < n; i++ )
if(_buffer[i] != noone) vertex_delete_buffer(_buffer[i])
} else if(_buffer != noone) vertex_delete_buffer(_buffer);
if(is_array(_buffer)) array_foreach(_buffer, function(b) /*=>*/ { if(b != noone) vertex_delete_buffer(b); });
else if(_buffer != noone) vertex_delete_buffer(_buffer);
if(array_empty(_vertex)) return noone;
@ -120,17 +146,14 @@ function __3dObject() constructor {
return _res;
}
////- Submit
static preSubmitVertex = function(scene = {}) {}
static postSubmitVertex = function(scene = {}) {}
static getCenter = function() { return new __vec3(transform.position.x, transform.position.y, transform.position.z); }
static getBBOX = function() { return new __bbox3D(size.multiplyVec(transform.scale).multiply(-0.5), size.multiplyVec(transform.scale).multiply(0.5)); }
#region params
defDrawParam = { wireframe: false };
defDrawParamW = { wireframe: true };
#endregion
static submit = function(scene = {}, shader = noone) { submitVertex(scene, shader); }
static submitUI = function(scene = {}, shader = noone) { submitVertex(scene, shader); }
static submitSel = function(scene = {}, shader = noone) {
@ -142,17 +165,17 @@ function __3dObject() constructor {
static submitShader = function(scene = {}, shader = noone) {}
static submitShadow = function(scene = {}, object = noone) {}
static submitVertex = function(scene = {}, shader = noone, param = defDrawParam) {
var _shader = sh_d3d_default;
static submitVertex = function(scene = {}, shader = noone) {
var _shader;
switch(VF) {
case global.VF_POS_NORM_TEX_COL: _shader = sh_d3d_default; break;
case global.VF_POS_COL: _shader = sh_d3d_wireframe; break;
case global.VF_POS_NORM_TEX_COL:
default : _shader = sh_d3d_default; break;
}
if(custom_shader != noone) _shader = custom_shader;
if(shader != noone) _shader = shader;
if(!is_undefined(shader)) shader_set(_shader);
preSubmitVertex(scene);
@ -160,7 +183,6 @@ function __3dObject() constructor {
matrix_set(matrix_world, matrix_stack_top());
gpu_set_tex_repeat(true);
for( var i = 0, n = array_length(VB); i < n; i++ ) {
var _ind = array_safe_get_fast(material_index, i, i);
var _mat = array_safe_get_fast(materials, _ind, noone);
@ -189,7 +211,6 @@ function __3dObject() constructor {
vertex_submit(VB[i], render_type, _tex);
}
gpu_set_tex_repeat(false);
if(!is_undefined(shader)) shader_reset();
@ -199,9 +220,7 @@ function __3dObject() constructor {
if(NVB != noone) {
shader_set(sh_d3d_wireframe);
shader_set_color("blend", c_white);
for( var i = 0, n = array_length(NVB); i < n; i++ )
vertex_submit(NVB[i], pr_linelist, -1);
array_foreach(NVB, function(n) /*=>*/ {return vertex_submit(n, pr_linelist, -1)});
shader_reset();
}
}
@ -212,6 +231,8 @@ function __3dObject() constructor {
}
////- Actions
static clone = function(_vertex = true, cloneBuffer = false) {
var _obj = new __3dObject();

View file

@ -38,7 +38,7 @@ function __3dScene(camera, name = "New scene") constructor {
apply_transform = false;
custom_transform = new __transform();
lightAmbient = c_black;
lightAmbient = cola(c_black, 1);
lightDir_max = 16;
lightDir_shadow_max = 4;
lightPnt_max = 16;
@ -48,12 +48,17 @@ function __3dScene(camera, name = "New scene") constructor {
enviroment_map = noone;
gammaCorrection = true;
draw_background = false;
defer_normal = true;
defer_normal_radius = 0;
draw_background = false;
show_normal = false;
show_wireframe = false;
wireframe_width = 1;
wireframe_color = cola(c_black, 1);
wireframe_aa = true;
wireframe_shade = false;
wireframe_only = false;
ssao_enabled = false;
ssao_sample = 32;
@ -88,11 +93,15 @@ function __3dScene(camera, name = "New scene") constructor {
lightPnt_shadowBias = [];
} reset();
////- Submit
static submit = function(object, shader = noone) { D3DSCENE_PRESUBMIT object.submit (self, shader); D3DSCENE_POSTSUBMIT }
static submitUI = function(object, shader = noone) { D3DSCENE_PRESUBMIT object.submitUI (self, shader); D3DSCENE_POSTSUBMIT }
static submitSel = function(object, shader = noone) { D3DSCENE_PRESUBMIT object.submitSel (self, shader); D3DSCENE_POSTSUBMIT }
static submitShader = function(object, shader = noone) { D3DSCENE_PRESUBMIT object.submitShader (self, shader); D3DSCENE_POSTSUBMIT }
////- Rendering
static deferPass = function(object, w, h, deferData = noone) {
if(deferData == noone) deferData = {
geometry_data: [ noone, noone, noone ],
@ -228,6 +237,7 @@ function __3dScene(camera, name = "New scene") constructor {
shader_set_f("light_dir_color", lightDir_color);
shader_set_f("light_dir_intensity", lightDir_intensity);
shader_set_i("light_dir_shadow_active", lightDir_shadow);
for( var i = 0, n = array_length(lightDir_shadowMap); i < n; i++ )
var _sid = shader_set_surface($"light_dir_shadowmap_{i}", lightDir_shadowMap[i], true);
@ -268,10 +278,21 @@ function __3dScene(camera, name = "New scene") constructor {
shader_set_f("viewProjMat", camera.getCombinedMatrix() );
#endregion
#region ---- wireframe ----
shader_set_i("show_wireframe", show_wireframe);
shader_set_i("wireframe_aa", wireframe_aa);
shader_set_i("wireframe_shade", wireframe_shade);
shader_set_i("wireframe_only", wireframe_only);
shader_set_f("wireframe_width", max(0, wireframe_width));
shader_set_color("wireframe_color", wireframe_color);
#endregion
//print($"Submitting scene with {lightDir_count} dir, {lightPnt_count} pnt lights.");
shader_reset();
}
////- Data
static addLightDirectional = function(light) {
if(lightDir_count >= lightDir_max) {
noti_warning("Direction light limit exceeded");

View file

@ -15,7 +15,6 @@ function __vertex(_x = 0, _y = _x, _z = _x, color = c_white, alpha = 1) construc
static set = function(_x, _y, _z, _nx, _ny, _nz, _u, _v) {
INLINE
x = _x;
y = _y;
z = _z;
@ -26,26 +25,21 @@ function __vertex(_x = 0, _y = _x, _z = _x, color = c_white, alpha = 1) construc
u = _u;
v = _v;
return self;
}
static setNormal = function(_nx = 0, _ny = _nx, _nz = _nx) {
INLINE
nx = _nx;
ny = _ny;
nz = _nz;
return self;
}
static setUV = function(_u = 0, _v = _u) {
INLINE
u = _u;
v = _v;
return self;
}

View file

@ -44,7 +44,7 @@
LATEST_VERSION = 1_18_00_0;
VERSION = 1_18_05_1;
SAVE_VERSION = 1_18_05_0;
VERSION_STRING = MAC? "1.18.003m" : "1.18.6.005";
VERSION_STRING = MAC? "1.18.003m" : "1.18.6.006";
BUILD_NUMBER = 1_18_05_1;
var _vsp = string_split(VERSION_STRING, ".");
@ -167,6 +167,10 @@
#macro returnNull_mf2 ; if(is_undefined(
#macro returnNull_mf3 ) ||
#macro returnNull_mf4 == noone) return;
//!#mfunc case2 {"args":["a"," b"],"order":[0,1],"token":"keyword"}
#macro case2_mf0 case
#macro case2_mf1 : case
#macro case2_mf2 //
#endregion

View file

@ -17,58 +17,71 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
deferData = noone;
global.SKY_SPHERE = new __3dUVSphere(0.5, 16, 8, true);
var i = in_d3d;
newInput(in_d3d + 0, nodeValue_Int("FOV", self, 60 ))
newInput(i+0, nodeValue_Int("FOV", self, 60 ))
.setDisplay(VALUE_DISPLAY.slider, { range: [ 10, 90, 0.1 ] });
newInput(in_d3d + 1, nodeValue_Vec2("Clipping Distance", self, [ 1, 10 ] ));
newInput(i+1, nodeValue_Vec2("Clipping Distance", self, [ 1, 10 ] ));
newInput(in_d3d + 2, nodeValue_Dimension(self));
newInput(i+2, nodeValue_Dimension(self));
newInput(in_d3d + 3, nodeValue_Enum_Button("Projection", self, 1 , [ "Perspective", "Orthographic" ]));
newInput(i+3, nodeValue_Enum_Button("Projection", self, 1 , [ "Perspective", "Orthographic" ]));
newInput(in_d3d + 4, nodeValue_D3Scene("Scene", self, noone ))
newInput(i+4, nodeValue_D3Scene("Scene", self, noone ))
.setVisible(true, true);
newInput(in_d3d + 5, nodeValue_Color("Ambient Light", self, c_dkgrey ));
newInput(i+5, nodeValue_Color("Ambient Light", self, c_dkgrey ));
newInput(in_d3d + 6, nodeValue_Bool("Show Background", self, false ));
newInput(i+6, nodeValue_Bool("Show Background", self, false ));
newInput(in_d3d + 7, nodeValue_Enum_Button("Backface Culling", self, 2 , [ "None", "CW", "CCW" ]));
newInput(i+7, nodeValue_Enum_Button("Backface Culling", self, 2 , [ "None", "CW", "CCW" ]));
newInput(in_d3d + 8, nodeValue_Float("Orthographic Scale", self, 0.5 ))
newInput(i+8, nodeValue_Float("Orthographic Scale", self, 0.5 ))
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0.01, 4, 0.01 ] });
newInput(in_d3d + 9, nodeValue_Enum_Scroll("Postioning Mode", self, 2, [ "Position + Rotation", "Position + Lookat", "Lookat + Rotation" ] ));
newInput(i+9, nodeValue_Enum_Scroll("Postioning Mode", self, 2, [ "Position + Rotation", "Position + Lookat", "Lookat + Rotation" ] ));
newInput(in_d3d + 10, nodeValue_Vec3("Lookat Position", self, [ 0, 0, 0 ] ));
newInput(i+10, nodeValue_Vec3("Lookat Position", self, [ 0, 0, 0 ] ));
newInput(in_d3d + 11, nodeValue_Rotation("Roll", self, 0));
newInput(i+11, nodeValue_Rotation("Roll", self, 0));
newInput(in_d3d + 12, nodeValue_Rotation("Horizontal Angle", self, 45 ));
newInput(i+12, nodeValue_Rotation("Horizontal Angle", self, 45 ));
newInput(in_d3d + 13, nodeValue_Float("Vertical Angle", self, 30 ))
newInput(i+13, nodeValue_Float("Vertical Angle", self, 30 ))
.setDisplay(VALUE_DISPLAY.slider, { range: [0, 90, 0.1] });
newInput(in_d3d + 14, nodeValue_Float("Distance", self, 4 ));
newInput(i+14, nodeValue_Float("Distance", self, 4 ));
newInput(in_d3d + 15, nodeValue_Bool("Gamma Adjust", self, false ));
newInput(i+15, nodeValue_Bool("Gamma Adjust", self, false ));
newInput(in_d3d + 16, nodeValue_Surface("Environment Texture", self));
newInput(i+16, nodeValue_Surface("Environment Texture", self));
newInput(in_d3d + 17, nodeValue_Bool("Ambient Occlusion", self, false ));
newInput(i+17, nodeValue_Bool("Ambient Occlusion", self, false ));
newInput(in_d3d + 18, nodeValue_Float("AO Radius", self, 0.25 ));
newInput(i+18, nodeValue_Float("AO Radius", self, 0.25 ));
newInput(in_d3d + 19, nodeValue_Float("AO Bias", self, 0.05 ));
newInput(i+19, nodeValue_Float("AO Bias", self, 0.05 ));
newInput(in_d3d + 20, nodeValue_Float("AO Strength", self, 1. ))
newInput(i+20, nodeValue_Float("AO Strength", self, 1. ))
.setDisplay(VALUE_DISPLAY.slider, { range: [ 0.01, 4, 0.01 ] });
newInput(in_d3d + 21, nodeValue_Int("Round Normal", self, 0 ))
newInput(i+21, nodeValue_Int("Round Normal", self, 0 ))
.setWindows();
newInput(in_d3d + 22, nodeValue_Enum_Button("Blend mode", self, 0 , [ "Normal", "Additive" ]));
newInput(i+22, nodeValue_Enum_Button("Blend mode", self, 0 , [ "Normal", "Additive" ]));
newInput(i+23, nodeValue_Bool("Wireframe", self, false));
newInput(i+24, nodeValue_Float("Wireframe Thickness", self, 1));
newInput(i+25, nodeValue_Color("Wireframe Color", self, cola(c_black)));
newInput(i+26, nodeValue_Bool("Wireframe antialias", self, false));
newInput(i+27, nodeValue_Bool("Wireframe shading", self, false));
newInput(i+28, nodeValue_Bool("Wireframe only", self, false));
in_cam = array_length(inputs);
@ -80,25 +93,23 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
newOutput(2, nodeValue_Output("Depth", self, VALUE_TYPE.surface, noone ))
.setVisible(false);
input_display_list = [ in_d3d + 4,
["Output", false], in_d3d + 2,
["Transform", false], in_d3d + 9, 0, 1, in_d3d + 10, in_d3d + 11, in_d3d + 12, in_d3d + 13, in_d3d + 14,
["Camera", true], in_d3d + 3, in_d3d + 0, in_d3d + 1, in_d3d + 8,
["Render", true], in_d3d + 5, in_d3d + 16, in_d3d + 6, in_d3d + 7, in_d3d + 15, in_d3d + 22,
["Ambient Occlusion", true], in_d3d + 17, in_d3d + 20, in_d3d + 18, in_d3d + 19,
["Effects", true], in_d3d + 21,
input_display_list = [ i+4,
["Output", false], i+ 2,
["Transform", false], i+ 9, 0, 1, i+10, i+11, i+12, i+13, i+14,
["Camera", true], i+ 3, i+ 0, i+ 1, i+ 8,
["Render", true], i+ 5, i+16, i+ 6, i+ 7, i+15, i+22,
["Wireframe", true, i+23], i+24, i+25, i+26, i+27, i+28,
["Ambient Occlusion", true], i+17, i+20, i+18, i+19,
["Effects", true], i+21,
];
tool_lookat = new NodeTool( "Move Target", THEME.tools_3d_transform_object );
////- Preview
static getToolSettings = function() {
var _posm = getInputData(in_d3d + 9);
switch(_posm) {
case 0 : return tool_settings;
case 1 :
case 2 : return [];
}
if(_posm == 0) return tool_settings;
return [];
}
@ -148,6 +159,8 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
#endregion
}
////- Update
static onValueUpdate = function(index) {
if(index == in_d3d + 9) PANEL_PREVIEW.tool_current = noone;
}
@ -176,10 +189,12 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
case 0 :
tools = [ tool_pos, tool_rot ];
break;
case 1 :
tools = [ tool_pos, tool_lookat ];
tool_attribute.context = 1;
break;
case 2 :
tools = [ tool_lookat ];
tool_attribute.context = 1;
@ -224,6 +239,13 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
var _nrmSmt = _data[in_d3d + 21];
var _blend = _data[in_d3d + 22];
var _wire = _data[in_d3d + 23];
var _wiret = _data[in_d3d + 24];
var _wirec = _data[in_d3d + 25];
var _wirea = _data[in_d3d + 26];
var _wires = _data[in_d3d + 27];
var _wireo = _data[in_d3d + 28];
var _qi1 = new BBMOD_Quaternion().FromAxisAngle(new BBMOD_Vec3(0, 1, 0), 90);
var _qi2 = new BBMOD_Quaternion().FromAxisAngle(new BBMOD_Vec3(1, 0, 0), -90);
var _qi3 = new BBMOD_Quaternion().FromAxisAngle(new BBMOD_Vec3(1, 0, 0), 90);
@ -279,8 +301,10 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
#region camera view project
camera.projection = _proj;
camera.setViewFov(_fov, _clip[0], _clip[1]);
if(_proj == 0) camera.setViewSize(_dim[0], _dim[1]);
else if(_proj == 1) camera.setViewSize(1 / _orts, _dim[0] / _dim[1] / _orts);
camera.setMatrix();
#endregion
@ -296,6 +320,13 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
scene.ssao_strength = _aoSr;
scene.defer_normal_radius = _nrmSmt;
scene.draw_background = _dbg;
scene.show_wireframe = _wire;
scene.wireframe_width = _wiret;
scene.wireframe_color = _wirec;
scene.wireframe_aa = _wirea;
scene.wireframe_shade = _wires;
scene.wireframe_only = _wireo;
#endregion
#region submit
@ -371,11 +402,11 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
return [ _finalRender, _normal, _depth ];
}
////- Draw
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {}
static getPreviewObject = function() {
return getSingleValue(in_d3d + 4);
}
static getPreviewObject = function() { return getSingleValue(in_d3d + 4); }
static getPreviewObjects = function() {
var _posm = getInputData(in_d3d + 9);
@ -392,6 +423,8 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
static getPreviewObjectOutline = function() { return isUsingTool("Move Target")? [ lookat ] : [ object ]; }
////- Serialize
static doSerialize = function(_map) {
_map.camera_base_length = in_cam;
}

View file

@ -1,6 +1,7 @@
function Node_GMRoom(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "GMRoom";
color = COLORS.node_blend_input;
icon = s_gamemaker;
gmRoom = noone;
layers = [];

View file

@ -968,6 +968,7 @@ function PanelContent() constructor {
function drawContent(panel) {}
function preDraw() {}
function drawGUI() {}
static onFullScreen = function() {}

View file

@ -497,7 +497,7 @@ function Panel_Preview() : PanelContent() constructor {
[
THEME.icon_visibility,
new tooltipHotkey(__txtx("graph_visibility_title", "Visibility settings") + "...", "Preview", "View Settings"),
function(param) /*=>*/ { dialogPanelCall(new Panel_Preview_View_Setting(self), param.x, param.y, { anchor: ANCHOR}); },
function(param) /*=>*/ { dialogPanelCall(new Panel_Preview_View_Setting(self), param.x, param.y, { anchor: ANCHOR.bottom | ANCHOR.left }); },
function() /*=>*/ {return 0},
],
[
@ -1259,7 +1259,8 @@ function Panel_Preview() : PanelContent() constructor {
#region draw
d3_scene_preview.reset();
gpu_set_cullmode(cull_counterclockwise);
gpu_set_cullmode(d3_scene_preview.cull_mode);
// gpu_set_cullmode(cull_counterclockwise);
var _prev_obj = _node.getPreviewObjects();

View file

@ -1,68 +1,87 @@
function Panel_Preview_3D_Setting(panel) : Panel_Linear_Setting() constructor {
function Panel_Preview_3D_Setting(_panel) : Panel_Linear_Setting() constructor {
title = __txtx("preview_3d_settings", "3D Preview Settings");
preview_panel = panel;
preview = _panel;
scene = _panel.d3_scene;
properties_default = [
new __Panel_Linear_Setting_Item(
__txt("Preview Pass"),
new scrollBox([ "Rendered", "Normal", "Depth" ], function(index) { preview_panel.d3_preview_channel = index; }),
function() { return preview_panel.d3_preview_channel },
function(val) { preview_panel.d3_preview_channel = val; },
0,
),
new __Panel_Linear_Setting_Item(
__txt("Preview Light"),
new checkBox(function() { preview_panel.d3_scene_light_enabled = !preview_panel.d3_scene_light_enabled; }),
function() { return preview_panel.d3_scene_light_enabled },
function(val) { preview_panel.d3_scene_light_enabled = val; },
true,
),
new __Panel_Linear_Setting_Item(
__txt("Ambient Color"),
new buttonColor(function(col) { preview_panel.d3_scene.lightAmbient = col; }),
function() { return preview_panel.d3_scene.lightAmbient },
function(val) { preview_panel.d3_scene.lightAmbient = val; },
$404040,
),
new __Panel_Linear_Setting_Item(
__txt("Light Intensity"),
slider(0, 1, 0.01, function(val) {
preview_panel.d3_scene_light0.intensity = val;
preview_panel.d3_scene_light1.intensity = val;
}),
function() { return preview_panel.d3_scene_light0.intensity },
function(val) { preview_panel.d3_scene_light0.intensity = val; },
1,
),
new __Panel_Linear_Setting_Item(
__txt("Shadow"),
new checkBox(function() { preview_panel.d3_scene_light0.shadow_active = !preview_panel.d3_scene_light0.shadow_active; }),
function() { return preview_panel.d3_scene_light0.shadow_active },
function(val) { preview_panel.d3_scene_light0.shadow_active = val; },
["Wireframe", false],
new __Panel_Linear_Setting_Item( __txt("Wireframe"),
new checkBox(function() /*=>*/ { scene.show_wireframe = !scene.show_wireframe; }),
function( ) /*=>*/ {return scene.show_wireframe},
function(val) /*=>*/ { scene.show_wireframe = val; },
false,
),
new __Panel_Linear_Setting_Item(
__txt("View Plane"),
new vectorBox(2, function(value, index) {
if(index == 0) preview_panel.d3_view_camera.view_near = value;
else if(index == 1) preview_panel.d3_view_camera.view_far = value;
}),
function() { return [ preview_panel.d3_view_camera.view_near, preview_panel.d3_view_camera.view_far ] },
function(val) { preview_panel.d3_view_camera.view_near = val[0]; preview_panel.d3_view_camera.view_far = val[1] },
[ 0.01, 50 ],
new __Panel_Linear_Setting_Item( __txt("Wireframe Thickness"),
new textBox(TEXTBOX_INPUT.number, function(v) /*=>*/ { scene.wireframe_width = v; }),
function( ) /*=>*/ {return scene.wireframe_width},
function(val) /*=>*/ { scene.wireframe_width = val; },
1,
),
new __Panel_Linear_Setting_Item(
__txt("Gamma Correct"),
new checkBox(function() { preview_panel.d3_scene.gammaCorrection = !preview_panel.d3_scene.gammaCorrection; }),
function() { return preview_panel.d3_scene.gammaCorrection },
function(val) { preview_panel.d3_scene.gammaCorrection = val; },
new __Panel_Linear_Setting_Item( __txt("Wireframe Color"),
new buttonColor(function(c) /*=>*/ { scene.wireframe_color = c; }),
function( ) /*=>*/ {return scene.wireframe_color},
function(val) /*=>*/ { scene.wireframe_color = val; },
cola(c_black, 1),
),
["Passes", false],
new __Panel_Linear_Setting_Item( __txt("Preview Pass"),
new scrollBox([ "Rendered", "Normal", "Depth" ], function(index) /*=>*/ { preview.d3_preview_channel = index; }),
function( ) /*=>*/ {return preview.d3_preview_channel},
function(val) /*=>*/ { preview.d3_preview_channel = val; },
0,
),
["Lighting", false],
new __Panel_Linear_Setting_Item( __txt("Preview Light"),
new checkBox(function() /*=>*/ { preview.d3_scene_light_enabled = !preview.d3_scene_light_enabled; }),
function( ) /*=>*/ {return preview.d3_scene_light_enabled},
function(val) /*=>*/ { preview.d3_scene_light_enabled = val; },
true,
),
new __Panel_Linear_Setting_Item(
__txt("Normal"),
new checkBox(function() { preview_panel.d3_scene.show_normal = !preview_panel.d3_scene.show_normal; }),
function() { return preview_panel.d3_scene.show_normal },
function(val) { preview_panel.d3_scene.show_normal = val; },
new __Panel_Linear_Setting_Item( __txt("Ambient Color"),
new buttonColor(function(col) /*=>*/ { scene.lightAmbient = col; }),
function( ) /*=>*/ {return scene.lightAmbient},
function(val) /*=>*/ { scene.lightAmbient = val; },
$404040,
),
new __Panel_Linear_Setting_Item( __txt("Light Intensity"),
slider(0, 1, 0.01, function(val) /*=>*/ {
preview.d3_scene_light0.intensity = val;
preview.d3_scene_light1.intensity = val;
}),
function( ) /*=>*/ {return preview.d3_scene_light0.intensity},
function(val) /*=>*/ { preview.d3_scene_light0.intensity = val; },
1,
),
["Render", false],
new __Panel_Linear_Setting_Item( __txt("Shadow"),
new checkBox(function() /*=>*/ { preview.d3_scene_light0.shadow_active = !preview.d3_scene_light0.shadow_active; }),
function( ) /*=>*/ {return preview.d3_scene_light0.shadow_active},
function(val) /*=>*/ { preview.d3_scene_light0.shadow_active = val; },
false,
),
new __Panel_Linear_Setting_Item( __txt("View Plane"),
new vectorBox(2, function(value, index) /*=>*/ {
if(index == 0) preview.d3_view_camera.view_near = value;
else if(index == 1) preview.d3_view_camera.view_far = value;
}),
function( ) /*=>*/ {return [ preview.d3_view_camera.view_near, preview.d3_view_camera.view_far ]},
function(val) /*=>*/ { preview.d3_view_camera.view_near = val[0]; preview.d3_view_camera.view_far = val[1] },
[ 0.01, 50 ],
),
new __Panel_Linear_Setting_Item( __txt("Gamma Correct"),
new checkBox(function() /*=>*/ { scene.gammaCorrection = !scene.gammaCorrection; }),
function( ) /*=>*/ {return scene.gammaCorrection},
function(val) /*=>*/ { scene.gammaCorrection = val; },
true,
),
new __Panel_Linear_Setting_Item( __txt("Normal"),
new checkBox(function() /*=>*/ { scene.show_normal = !scene.show_normal; }),
function( ) /*=>*/ {return scene.show_normal},
function(val) /*=>*/ { scene.show_normal = val; },
false,
),
]
@ -72,7 +91,7 @@ function Panel_Preview_3D_Setting(panel) : Panel_Linear_Setting() constructor {
];
properties_camera = array_append(scene_camera, properties_default);
properties = preview_panel.d3_scene_preview == preview_panel.d3_scene? properties_default : properties_camera;
properties = preview.d3_scene_preview == scene? properties_default : properties_camera;
setHeight();
}

View file

@ -1,8 +1,9 @@
// PC3D rendering shader
#extension GL_OES_standard_derivatives : enable
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec3 v_vNormal;
varying vec3 v_barycentric;
varying vec4 v_worldPosition;
varying vec3 v_viewPosition;
@ -84,6 +85,13 @@ uniform int use_8bit;
uniform vec2 env_map_dimension;
uniform mat4 viewProjMat;
uniform int show_wireframe;
uniform int wireframe_aa;
uniform int wireframe_shade;
uniform int wireframe_only;
uniform float wireframe_width;
uniform vec4 wireframe_color;
#endregion
#region ++++ mapping ++++
@ -174,6 +182,18 @@ uniform int use_8bit;
}
#endregion
vec4 wireframeCalc(in vec4 baseColr) {
vec3 bc_width = fwidth(v_barycentric);
vec3 aa_width = wireframe_aa == 1? smoothstep(bc_width * wireframe_width * .9, bc_width * wireframe_width, v_barycentric) :
step(bc_width * wireframe_width, v_barycentric);
float edge_factor = 1. - min(aa_width.r, min(aa_width.g, aa_width.b));
vec4 baseColor = wireframe_only == 1? vec4(0.) : baseColr;
vec4 mixed_color = mix(baseColor, wireframe_color, edge_factor * wireframe_color.a);
return mixed_color;
}
void main() {
vec2 uv_coord = v_vTexcoord;
if(mat_flip == 1) uv_coord.y = -uv_coord.y;
@ -183,25 +203,21 @@ void main() {
mat_baseColor *= v_vColour;
vec4 final_color = mat_baseColor;
if(show_wireframe == 1 && wireframe_shade == 1) final_color = wireframeCalc(final_color);
vec3 viewDirection = normalize(cameraPosition - v_worldPosition.xyz);
vec4 viewProjPos = viewProjMat * vec4(v_worldPosition.xyz, 1.);
viewProjPos /= viewProjPos.w;
viewProjPos = viewProjPos * 0.5 + 0.5;
#region ++++ normal ++++
vec3 _norm = v_vNormal;
if(mat_defer_normal == 1)
_norm = texture2D(mat_normal_map, viewProjPos.xy).rgb;
vec3 normal = normalize(_norm);
#endregion
vec3 normal = mat_defer_normal == 1? texture2D(mat_normal_map, viewProjPos.xy).rgb : v_vNormal;
normal = normalize(normal);
#region ++++ environment ++++
if(env_use_mapping == 1 && mat_reflective > 0.) {
vec3 reflectDir = reflect(viewDirection, normal);
vec3 reflectDir = reflect(viewDirection, normal);
float refRad = mix(16., 0., mat_reflective);
vec2 tx = 1. / env_map_dimension;
vec2 reflect_sample_pos = equirectangularUv(reflectDir);
@ -211,6 +227,7 @@ void main() {
for(float i = -refRad; i <= refRad; i++)
for(float j = -refRad; j <= refRad; j++) {
vec2 _map_pos = reflect_sample_pos + vec2(i, j) * tx;
if(_map_pos.y < 0.) _map_pos.y = -_map_pos.y;
else if(_map_pos.y > 1.) _map_pos.y = 1. - (_map_pos.y - 1.);
@ -218,6 +235,7 @@ void main() {
env_sampled += _samp;
weight += _samp.a;
}
env_sampled /= weight;
env_sampled.a = 1.;
@ -333,6 +351,7 @@ void main() {
final_color.rgb *= light_effect;
#endregion
if(show_wireframe == 1 && wireframe_shade == 0) final_color = wireframeCalc(final_color);
if(final_color.a < 0.1) discard;
gl_FragData[0] = final_color;

View file

@ -1,11 +1,14 @@
attribute vec3 in_Position;
attribute vec3 in_Normal;
attribute vec4 in_Colour;
attribute vec2 in_TextureCoord;
attribute vec4 in_Colour;
attribute vec3 in_Barycentric;
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec3 v_vNormal;
varying vec3 v_barycentric;
varying vec4 v_worldPosition;
varying vec3 v_viewPosition;
varying float v_cameraDistance;
@ -29,4 +32,6 @@ void main() {
float depthRange = abs(planeFar - planeNear);
float ndcDepth = (gl_Position.z - planeNear) / depthRange;
v_cameraDistance = ndcDepth * 0.5 + 0.5;
v_barycentric = in_Barycentric;
}

View file

@ -1,7 +1,8 @@
attribute vec3 in_Position;
attribute vec3 in_Normal;
attribute vec4 in_Colour;
attribute vec2 in_TextureCoord;
attribute vec4 in_Colour;
attribute vec3 in_Barycentric;
varying vec2 v_vTexcoord;
varying vec4 v_worldPosition;