This commit is contained in:
Tanasart 2023-08-24 19:44:12 +02:00
parent 78b4da0c39
commit a80d684a65
17 changed files with 200 additions and 77 deletions

View file

@ -34,6 +34,8 @@ function __3dGroup() constructor {
_m1 = _m1 == noone? _n1 : _m1.maxVal(_n1); _m1 = _m1 == noone? _n1 : _m1.maxVal(_n1);
} }
if(_m0 == noone) return new __bbox3D(new __vec3(-0.5), new __vec3(0.5));
_m0._subtract(_cc); _m0._subtract(_cc);
_m1._subtract(_cc); _m1._subtract(_cc);

View file

@ -3,8 +3,8 @@ function __3dLightPoint() : __3dLight() constructor {
intensity = 1; intensity = 1;
radius = 10; radius = 10;
shadow_mapper = sh_d3d_shadow_depth; shadow_mapper = sh_d3d_shadow_depth;
shadow_map_size = 512; shadow_map_size = 512;
shadow_map_views = array_create(6); shadow_map_views = array_create(6);
shadow_maps = array_create(6); shadow_maps = array_create(6);

View file

@ -1,12 +1,31 @@
function __d3dMaterial(surface = noone) constructor { function __d3dMaterial(surface = noone) constructor {
self.surface = surface; self.surface = surface;
self.diffuse = 1; self.diffuse = 1;
self.specular = 0; self.specular = 0;
self.metalic = false; self.metalic = false;
self.shine = 1; self.shine = 1;
self.normal = noone;
self.normalStr = 1;
self.reflective = 0;
static getTexture = function() { static getTexture = function() {
if(!is_surface(surface)) return -1; if(!is_surface(surface)) return -1;
return surface_get_texture(surface); return surface_get_texture(surface);
} }
static submitShader = function() {
shader_set_f("mat_diffuse", diffuse );
shader_set_f("mat_specular", specular );
shader_set_f("mat_shine", shine );
shader_set_i("mat_metalic", metalic );
shader_set_i("mat_use_normal", is_surface(normal));
shader_set_surface("mat_normal_map", normal);
shader_set_f("mat_normal_strength", normalStr);
shader_set_f("mat_reflective", reflective);
}
} }

View file

@ -132,7 +132,7 @@ function __3dObject() constructor {
preSubmitVertex(params); preSubmitVertex(params);
if(VB != noone) { if(VB != noone) { #region
matrix_stack_clear(); matrix_stack_clear();
if(params.apply_transform) { if(params.apply_transform) {
@ -164,26 +164,35 @@ function __3dObject() constructor {
matrix_stack_push(sca); matrix_stack_push(sca);
matrix_set(matrix_world, matrix_stack_top()); matrix_set(matrix_world, matrix_stack_top());
} }
} } #endregion
if(VF == global.VF_POS_NORM_TEX_COL) #region ++++ Submit & Material ++++
for( var i = 0, n = array_length(VB); i < n; i++ ) { for( var i = 0, n = array_length(VB); i < n; i++ ) {
var _mat = array_safe_get(materials, i, noone); if(VF == global.VF_POS_NORM_TEX_COL) {
var _tex = _mat == noone? -1 : _mat.getTexture(); var _mat = array_safe_get(materials, i, noone);
if(_mat == noone) {
shader_set_f("mat_diffuse", 1);
shader_set_f("mat_specular", 0);
shader_set_f("mat_shine", 1);
shader_set_i("mat_metalic", 0);
shader_set_i("mat_use_normal", 0);
shader_set_f("mat_reflective", 0);
} else
_mat.submitShader();
shader_set_f("mat_diffuse", _mat == noone? 1 : _mat.diffuse ); var _tex = _mat == noone? -1 : _mat.getTexture();
shader_set_f("mat_specular", _mat == noone? 0 : _mat.specular ); vertex_submit(VB[i], render_type, _tex);
shader_set_f("mat_shine", _mat == noone? 1 : _mat.shine ); } else
shader_set_i("mat_metalic", _mat == noone? 0 : _mat.metalic ); vertex_submit(VB[i], render_type, -1);
vertex_submit(VB[i], render_type, _tex); }
} #endregion
if(params.show_normal && NVB != noone) { if(params.show_normal && NVB != noone) { #region
shader_set(sh_d3d_wireframe); shader_set(sh_d3d_wireframe);
for( var i = 0, n = array_length(NVB); i < n; i++ ) for( var i = 0, n = array_length(NVB); i < n; i++ )
vertex_submit(NVB[i], pr_linelist, -1); vertex_submit(NVB[i], pr_linelist, -1);
shader_reset(); shader_reset();
} } #endregion
matrix_stack_clear(); matrix_stack_clear();
matrix_set(matrix_world, matrix_build_identity()); matrix_set(matrix_world, matrix_build_identity());

View file

@ -72,6 +72,8 @@ function __3dScene(camera) constructor {
lightPnt_viewMat = []; lightPnt_viewMat = [];
lightPnt_projMat = []; lightPnt_projMat = [];
lightPnt_shadowBias = []; lightPnt_shadowBias = [];
enviroment_map = noone;
} reset(); } reset();
static applyCamera = function() { camera.applyCamera(); } static applyCamera = function() { camera.applyCamera(); }
@ -105,17 +107,21 @@ function __3dScene(camera) constructor {
shader_set_surface($"light_pnt_shadowmap_{i}", lightPnt_shadowMap[i], true, true); shader_set_surface($"light_pnt_shadowmap_{i}", lightPnt_shadowMap[i], true, true);
shader_set_f("light_pnt_view", lightPnt_viewMat); shader_set_f("light_pnt_view", lightPnt_viewMat);
shader_set_f("light_pnt_proj", lightPnt_projMat); shader_set_f("light_pnt_proj", lightPnt_projMat);
shader_set_f("light_ont_shadow_bias", lightPnt_shadowBias); shader_set_f("light_pnt_shadow_bias", lightPnt_shadowBias);
} }
shader_set_f("cameraPosition", camera.position.toArray()); shader_set_f("cameraPosition", camera.position.toArray());
shader_set_i("gammaCorrection", gammaCorrection); shader_set_i("gammaCorrection", gammaCorrection);
shader_set_f("planeNear", camera.view_near); shader_set_f("planeNear", camera.view_near);
shader_set_f("planeFar", camera.view_far ); shader_set_f("planeFar", camera.view_far );
shader_set_i("env_use_mapping", is_surface(enviroment_map) );
shader_set_surface("env_map", enviroment_map );
shader_set_dim("env_map_dimension", enviroment_map );
shader_reset(); shader_reset();
} }
static addLightDirectional = function(light) { static addLightDirectional = function(light) { #region
if(lightDir_count >= lightDir_max) { if(lightDir_count >= lightDir_max) {
noti_warning("Direction light limit exceeded"); noti_warning("Direction light limit exceeded");
return self; return self;
@ -136,13 +142,13 @@ function __3dScene(camera) constructor {
} }
array_append(lightDir_viewMat, light.shadow_map_view); array_append(lightDir_viewMat, light.shadow_map_view);
array_append(lightDir_projMat, light.shadow_map_proj); array_append(lightDir_projMat, light.shadow_map_proj);
array_append(lightDir_shadowBias, light.shadow_bias); array_push(lightDir_shadowBias, light.shadow_bias);
lightDir_count++; lightDir_count++;
return self; return self;
} } #endregion
static addLightPoint = function(light) { static addLightPoint = function(light) { #region
if(lightPnt_count >= lightPnt_max) { if(lightPnt_count >= lightPnt_max) {
noti_warning("Point light limit exceeded"); noti_warning("Point light limit exceeded");
return self; return self;
@ -164,9 +170,9 @@ function __3dScene(camera) constructor {
} }
array_append(lightPnt_viewMat, light.shadow_map_view); array_append(lightPnt_viewMat, light.shadow_map_view);
array_append(lightPnt_projMat, light.shadow_map_proj); array_append(lightPnt_projMat, light.shadow_map_proj);
array_append(lightPnt_shadowBias, light.shadow_bias); array_push(lightPnt_shadowBias, light.shadow_bias);
lightPnt_count++; lightPnt_count++;
return self; return self;
} } #endregion
} }

View file

@ -228,9 +228,18 @@ function drawWidget(xx, yy, ww, _m, jun, global_var = true, _hover = false, _foc
break; break;
} }
break; break;
case VALUE_TYPE.boolean : param.halign = lineBreak? fa_left : fa_center;
case VALUE_TYPE.surface : param.h = ui(96); break; case VALUE_TYPE.boolean :
case VALUE_TYPE.curve : param.h = ui(160); param.halign = lineBreak? fa_left : fa_center;
break;
case VALUE_TYPE.d3Material :
case VALUE_TYPE.surface :
param.h = ui(96);
break;
case VALUE_TYPE.curve :
param.h = ui(160);
if(point_in_rectangle(_m[0], _m[1], ui(32), _hsy, ui(32) + ww - ui(16), _hsy + editBoxH)) if(point_in_rectangle(_m[0], _m[1], ui(32), _hsy, ui(32) + ww - ui(16), _hsy + editBoxH))
mbRight = false; mbRight = false;
break; break;

View file

@ -57,6 +57,8 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
inputs[| in_d3d + 15] = nodeValue("Gamma Adjust", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false ); inputs[| in_d3d + 15] = nodeValue("Gamma Adjust", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );
inputs[| in_d3d + 16] = nodeValue("Environment Texture", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone );
outputs[| 0] = nodeValue("Rendered", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone ); outputs[| 0] = nodeValue("Rendered", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone );
outputs[| 1] = nodeValue("Normal", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone ) outputs[| 1] = nodeValue("Normal", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone )
@ -69,7 +71,7 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
["Output", false], in_d3d + 2, ["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, ["Transform", false], in_d3d + 9, 0, 1, in_d3d + 10, in_d3d + 11, in_d3d + 12, in_d3d + 13, in_d3d + 14,
["Camera", false], in_d3d + 3, in_d3d + 0, in_d3d + 1, in_d3d + 8, ["Camera", false], in_d3d + 3, in_d3d + 0, in_d3d + 1, in_d3d + 8,
["Render", false], in_d3d + 5, in_d3d + 6, in_d3d + 7, in_d3d + 15, ["Render", false], in_d3d + 5, in_d3d + 16, in_d3d + 6, in_d3d + 7, in_d3d + 15,
]; ];
tool_lookat = new NodeTool( "Move Target", THEME.tools_3d_transform_object ); tool_lookat = new NodeTool( "Move Target", THEME.tools_3d_transform_object );
@ -164,6 +166,7 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
var _vAng = _data[in_d3d + 13]; var _vAng = _data[in_d3d + 13];
var _dist = _data[in_d3d + 14]; var _dist = _data[in_d3d + 14];
var _gamm = _data[in_d3d + 15]; var _gamm = _data[in_d3d + 15];
var _env = _data[in_d3d + 16];
var _qi1 = new BBMOD_Quaternion().FromAxisAngle(new BBMOD_Vec3(0, 1, 0), 90); 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 _qi2 = new BBMOD_Quaternion().FromAxisAngle(new BBMOD_Vec3(1, 0, 0), -90);
@ -220,9 +223,6 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
if(_proj == 0) camera.setViewSize(_dim[0], _dim[1]); if(_proj == 0) camera.setViewSize(_dim[0], _dim[1]);
else if(_proj == 1) camera.setViewSize(1 / _orts, _dim[0] / _dim[1] / _orts); else if(_proj == 1) camera.setViewSize(1 / _orts, _dim[0] / _dim[1] / _orts);
scene.lightAmbient = _ambt;
_scne.gammaCorrection = _gamm;
var _render = surface_create(_dim[0], _dim[1]); var _render = surface_create(_dim[0], _dim[1]);
var _normal = surface_create(_dim[0], _dim[1]); var _normal = surface_create(_dim[0], _dim[1]);
var _depth = surface_create(_dim[0], _dim[1]); var _depth = surface_create(_dim[0], _dim[1]);
@ -242,6 +242,10 @@ function Node_3D_Camera(_x, _y, _group = noone) : Node_3D_Object(_x, _y, _group)
camera.applyCamera(); camera.applyCamera();
scene.reset(); scene.reset();
scene.lightAmbient = _ambt;
scene.gammaCorrection = _gamm;
scene.enviroment_map = _env;
_scne.submitShader(scene); _scne.submitShader(scene);
scene.apply(); scene.apply();

View file

@ -40,4 +40,9 @@ function Node_3D_Light_Point(_x, _y, _group = noone) : Node_3D_Light(_x, _y, _gr
return object; return object;
} }
//static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
// var object = getObject(0);
// draw_surface_stretched_safe(object.shadow_map, xx, yy, 96, 96);
//}
} }

View file

@ -2,27 +2,43 @@ function Node_3D_Material(_x, _y, _group = noone) : Node_3D(_x, _y, _group) cons
name = "3D Material"; name = "3D Material";
solid_surf = noone; solid_surf = noone;
inputs[| 0] = nodeValue("Texture", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone) inputs[| 0] = nodeValue("Texture", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone )
.setVisible(true, true); .setVisible(true, true);
inputs[| 1] = nodeValue("Diffuse", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1) inputs[| 1] = nodeValue("Diffuse", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 )
.setDisplay(VALUE_DISPLAY.slider, [ 0, 1, 0.01 ]); .setDisplay(VALUE_DISPLAY.slider, [ 0, 1, 0.01 ]);
inputs[| 2] = nodeValue("Specular", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0) inputs[| 2] = nodeValue("Specular", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 )
.setDisplay(VALUE_DISPLAY.slider, [ 0, 1, 0.01 ]); .setDisplay(VALUE_DISPLAY.slider, [ 0, 1, 0.01 ]);
inputs[| 3] = nodeValue("Shininess", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1); inputs[| 3] = nodeValue("Shininess", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 );
inputs[| 4] = nodeValue("Metalic", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false); inputs[| 4] = nodeValue("Metalic", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );
inputs[| 5] = nodeValue("Normal Map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone );
inputs[| 6] = nodeValue("Normal Strength", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 )
.setDisplay(VALUE_DISPLAY.slider, [ 0, 2, 0.01 ]);
inputs[| 7] = nodeValue("Roughness", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 )
.setDisplay(VALUE_DISPLAY.slider, [ 0, 1, 0.01 ]);
outputs[| 0] = nodeValue("Material", self, JUNCTION_CONNECT.output, VALUE_TYPE.d3Material, noone); outputs[| 0] = nodeValue("Material", self, JUNCTION_CONNECT.output, VALUE_TYPE.d3Material, noone);
input_display_list = [ 0,
["Properties", false], 1, 2, 3, 4, 7,
["Normal", false], 5, 6,
];
static processData = function(_output, _data, _output_index, _array_index = 0) { static processData = function(_output, _data, _output_index, _array_index = 0) {
var _surf = _data[0]; var _surf = _data[0];
var _diff = _data[1]; var _diff = _data[1];
var _spec = _data[2]; var _spec = _data[2];
var _shin = _data[3]; var _shin = _data[3];
var _metl = _data[4]; var _metl = _data[4];
var _nor = _data[5];
var _norS = _data[6];
var _roug = _data[7];
if(!is_surface(_surf)) { if(!is_surface(_surf)) {
solid_surf = surface_verify(solid_surf, 1, 1); solid_surf = surface_verify(solid_surf, 1, 1);
@ -35,6 +51,10 @@ function Node_3D_Material(_x, _y, _group = noone) : Node_3D(_x, _y, _group) cons
_mat.shine = _shin; _mat.shine = _shin;
_mat.metalic = _metl; _mat.metalic = _metl;
_mat.normal = _nor;
_mat.normalStr = _norS;
_mat.reflective = clamp(1 - _roug, 0, 1);
return _mat; return _mat;
} }

View file

@ -5,9 +5,11 @@ function Node_3D_Mesh_Cone(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group
inputs[| in_mesh + 0] = nodeValue("Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 8 ); inputs[| in_mesh + 0] = nodeValue("Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 8 );
inputs[| in_mesh + 1] = nodeValue("Material Bottom", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 1] = nodeValue("Material Bottom", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 2] = nodeValue("Material Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 2] = nodeValue("Material Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 3] = nodeValue("Smooth Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false ); inputs[| in_mesh + 3] = nodeValue("Smooth Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );

View file

@ -5,17 +5,23 @@ function Node_3D_Mesh_Cube(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _group
inputs[| in_mesh + 0] = nodeValue("Material per side", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false ); inputs[| in_mesh + 0] = nodeValue("Material per side", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );
inputs[| in_mesh + 1] = nodeValue("Material", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 1] = nodeValue("Material", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 2] = nodeValue("Material Bottom", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 2] = nodeValue("Material Bottom", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 3] = nodeValue("Material Left", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 3] = nodeValue("Material Left", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 4] = nodeValue("Material Right", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 4] = nodeValue("Material Right", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 5] = nodeValue("Material Back", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 5] = nodeValue("Material Back", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 6] = nodeValue("Material Front", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 6] = nodeValue("Material Front", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
input_display_list = [ input_display_list = [
__d3d_input_list_mesh, __d3d_input_list_mesh,

View file

@ -5,11 +5,14 @@ function Node_3D_Mesh_Cylinder(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _g
inputs[| in_mesh + 0] = nodeValue("Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 8 ); inputs[| in_mesh + 0] = nodeValue("Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 8 );
inputs[| in_mesh + 1] = nodeValue("Material Top", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 1] = nodeValue("Material Top", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 2] = nodeValue("Material Bottom", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 2] = nodeValue("Material Bottom", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 3] = nodeValue("Material Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 3] = nodeValue("Material Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 4] = nodeValue("Smooth Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false ); inputs[| in_mesh + 4] = nodeValue("Smooth Side", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );

View file

@ -3,7 +3,8 @@ function Node_3D_Mesh_Extrude(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _gr
object_class = __3dSurfaceExtrude; object_class = __3dSurfaceExtrude;
inputs[| in_mesh + 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone); inputs[| in_mesh + 0] = nodeValue("Surface in", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone)
.setVisible(true, true);
inputs[| in_mesh + 1] = nodeValue("Height map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone); inputs[| in_mesh + 1] = nodeValue("Height map", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone);

View file

@ -5,7 +5,8 @@ function Node_3D_Mesh_Sphere_Ico(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y,
inputs[| in_mesh + 0] = nodeValue("Subdivision", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1 ); inputs[| in_mesh + 0] = nodeValue("Subdivision", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1 );
inputs[| in_mesh + 1] = nodeValue("Material", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 1] = nodeValue("Material", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 2] = nodeValue("Smooth Normal", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false ); inputs[| in_mesh + 2] = nodeValue("Smooth Normal", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );

View file

@ -3,7 +3,8 @@ function Node_3D_Mesh_Plane(_x, _y, _group = noone) : Node_3D_Mesh(_x, _y, _grou
object_class = __3dPlane; object_class = __3dPlane;
inputs[| in_mesh + 0] = nodeValue("Material", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone ); inputs[| in_mesh + 0] = nodeValue("Material", self, JUNCTION_CONNECT.input, VALUE_TYPE.d3Material, noone )
.setVisible(true, true);
inputs[| in_mesh + 1] = nodeValue("Normal", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 2 ) inputs[| in_mesh + 1] = nodeValue("Normal", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 2 )
.setDisplay(VALUE_DISPLAY.enum_button, [ "X", "Y", "Z" ]); .setDisplay(VALUE_DISPLAY.enum_button, [ "X", "Y", "Z" ]);

View file

@ -961,6 +961,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
break; break;
} }
break; #endregion break; #endregion
case VALUE_TYPE.d3Material :
case VALUE_TYPE.surface : #region case VALUE_TYPE.surface : #region
editWidget = new surfaceBox(function(ind) { editWidget = new surfaceBox(function(ind) {
return setValueDirect(ind); return setValueDirect(ind);

View file

@ -1,5 +1,4 @@
// PC3D rendering shader // PC3D rendering shader
// - BRDF By Xpanda and OGLDEV
varying vec2 v_vTexcoord; varying vec2 v_vTexcoord;
varying vec4 v_vColour; varying vec4 v_vColour;
@ -46,10 +45,6 @@ varying float v_cameraDistance;
uniform sampler2D light_pnt_shadowmap_1; uniform sampler2D light_pnt_shadowmap_1;
uniform sampler2D light_pnt_shadowmap_2; uniform sampler2D light_pnt_shadowmap_2;
uniform sampler2D light_pnt_shadowmap_3; uniform sampler2D light_pnt_shadowmap_3;
uniform sampler2D light_pnt_shadowmap_4;
uniform sampler2D light_pnt_shadowmap_5;
uniform sampler2D light_pnt_shadowmap_6;
uniform sampler2D light_pnt_shadowmap_7;
#endregion #endregion
#region ---- material ---- #region ---- material ----
@ -59,11 +54,20 @@ varying float v_cameraDistance;
uniform float mat_specular; uniform float mat_specular;
uniform float mat_shine; uniform float mat_shine;
uniform int mat_metalic; uniform int mat_metalic;
uniform float mat_reflective;
uniform int mat_use_normal;
uniform float mat_normal_strength;
uniform sampler2D mat_normal_map;
#endregion #endregion
#region ---- rendering ---- #region ---- rendering ----
uniform vec3 cameraPosition; uniform vec3 cameraPosition;
uniform int gammaCorrection; uniform int gammaCorrection;
uniform int env_use_mapping;
uniform sampler2D env_map;
uniform vec2 env_map_dimension;
#endregion #endregion
#region ++++ matrix ++++ #region ++++ matrix ++++
@ -132,17 +136,29 @@ varying float v_cameraDistance;
} }
#endregion #endregion
#region ++++ mapping ++++
vec2 equirectangularUv(vec3 dir) {
vec3 n = normalize(dir);
return vec2((atan(n.x, n.y) / TAU) + 0.5, 1. - acos(n.z) / PI);
}
#endregion
void main() { void main() {
mat_baseColor = texture2D( gm_BaseTexture, v_vTexcoord ); mat_baseColor = texture2D( gm_BaseTexture, v_vTexcoord );
mat_baseColor *= v_vColour; mat_baseColor *= v_vColour;
vec4 final_color = mat_baseColor; vec4 final_color = mat_baseColor;
vec3 normal = normalize(v_vNormal);
vec3 viewDirection = normalize(cameraPosition - v_worldPosition.xyz); vec3 viewDirection = normalize(cameraPosition - v_worldPosition.xyz);
gl_FragData[0] = vec4(0.); #region ++++ normal ++++
gl_FragData[1] = vec4(0.); vec3 _norm = v_vNormal;
gl_FragData[2] = vec4(0.); if(mat_use_normal == 1) {
vec3 _sampled_normal = texture2D(mat_normal_map, v_vTexcoord).rgb;
_norm += (_sampled_normal - 0.5) * 2. * mat_normal_strength;
}
vec3 normal = normalize(_norm);
#endregion
#region ++++ light ++++ #region ++++ light ++++
int shadow_map_index = 0; int shadow_map_index = 0;
@ -150,7 +166,6 @@ void main() {
float val = 0.; float val = 0.;
#region ++++ directional ++++ #region ++++ directional ++++
float light_dir_strength;
float light_map_depth; float light_map_depth;
float lightDistance; float lightDistance;
float shadow_culled; float shadow_culled;
@ -158,10 +173,7 @@ void main() {
shadow_map_index = 0; shadow_map_index = 0;
for(int i = 0; i < light_dir_count; i++) { for(int i = 0; i < light_dir_count; i++) {
vec3 lightVector = normalize(light_dir_direction[i]); vec3 lightVector = normalize(light_dir_direction[i]);
//light_dir_strength = dot(normal, lightVector);
//if(light_dir_strength < 0.)
// continue;
if(light_dir_shadow_active[i] == 1) { if(light_dir_shadow_active[i] == 1) {
vec4 cameraSpace = light_dir_view[i] * v_worldPosition; vec4 cameraSpace = light_dir_view[i] * v_worldPosition;
vec4 screenSpace = light_dir_proj[i] * cameraSpace; vec4 screenSpace = light_dir_proj[i] * cameraSpace;
@ -179,7 +191,6 @@ void main() {
continue; continue;
} }
//light_dir_strength = max(light_dir_strength * light_dir_intensity[i], 0.);
vec3 light_phong = phongLight(normal, lightVector, viewDirection, light_dir_color[i].rgb); vec3 light_phong = phongLight(normal, lightVector, viewDirection, light_dir_color[i].rgb);
light_effect += light_phong; light_effect += light_phong;
@ -187,17 +198,13 @@ void main() {
#endregion #endregion
#region ++++ point ++++ #region ++++ point ++++
float light_pnt_strength;
float light_distance; float light_distance;
float light_attenuation; float light_attenuation;
shadow_map_index = 0; shadow_map_index = 0;
for(int i = 0; i < light_pnt_count; i++) { for(int i = 0; i < light_pnt_count; i++) {
vec3 lightVector = normalize(light_pnt_position[i] - v_worldPosition.xyz); vec3 lightVector = normalize(light_pnt_position[i] - v_worldPosition.xyz);
//light_pnt_strength = dot(normal, lightVector);
//if(light_pnt_strength < 0.)
// continue;
light_distance = length(lightVector); light_distance = length(lightVector);
if(light_distance > light_pnt_radius[i]) if(light_distance > light_pnt_radius[i])
continue; continue;
@ -208,14 +215,15 @@ void main() {
(dirAbs.x > dirAbs.z ? 0 : 2) : (dirAbs.x > dirAbs.z ? 0 : 2) :
(dirAbs.y > dirAbs.z ? 1 : 2); (dirAbs.y > dirAbs.z ? 1 : 2);
side *= 2; side *= 2;
if(side == 0 && lightVector.x < 0.) side += 1; if(side == 0 && lightVector.x > 0.) side += 1;
else if(side == 2 && lightVector.y < 0.) side += 1; else if(side == 2 && lightVector.y > 0.) side += 1;
else if(side == 4 && lightVector.z < 0.) side += 1; else if(side == 4 && lightVector.z > 0.) side += 1;
vec4 cameraSpace = light_pnt_view[i * 6 + side] * v_worldPosition; vec4 cameraSpace = light_pnt_view[i * 6 + side] * v_worldPosition;
vec4 screenSpace = light_pnt_proj[i] * cameraSpace; vec4 screenSpace = light_pnt_proj[i] * cameraSpace;
float v_lightDistance = screenSpace.z / screenSpace.w; float v_lightDistance = screenSpace.z / screenSpace.w;
vec2 lightMapPosition = (screenSpace.xy / screenSpace.w * 0.5) + 0.5; vec2 lightMapPosition = (screenSpace.xy / screenSpace.w * 0.5) + 0.5;
float shadowFactor = dot(normal, lightVector); float shadowFactor = dot(normal, lightVector);
float bias = mix(light_pnt_shadow_bias[i], 0., shadowFactor); float bias = mix(light_pnt_shadow_bias[i], 0., shadowFactor);
@ -227,8 +235,7 @@ void main() {
} }
light_attenuation = 1. - pow(light_distance / light_pnt_radius[i], 2.); light_attenuation = 1. - pow(light_distance / light_pnt_radius[i], 2.);
//light_pnt_strength = max(light_pnt_strength * light_pnt_intensity[i] * light_attenuation, 0.);
vec3 light_phong = phongLight(normal, lightVector, viewDirection, light_pnt_color[i].rgb * light_attenuation); vec3 light_phong = phongLight(normal, lightVector, viewDirection, light_pnt_color[i].rgb * light_attenuation);
light_effect += light_phong; light_effect += light_phong;
@ -246,7 +253,34 @@ void main() {
final_color.rgb *= light_effect; final_color.rgb *= light_effect;
#endregion #endregion
#region ++++ environment ++++
if(env_use_mapping == 1) {
vec3 reflectDir = reflect(viewDirection, normal);
float refRad = mix(16., 0., mat_reflective);
vec2 tx = 1. / env_map_dimension;
vec2 reflect_sample_pos = equirectangularUv(reflectDir);
vec4 env_sampled = vec4(0.);
float weight = 0.;
for(float i = -refRad; i <= refRad; i++)
for(float j = -refRad; j <= refRad; j++) {
vec2 _map_pos = reflect_sample_pos + vec2(i, j) * tx;
vec4 _samp = texture2D(env_map, _map_pos);
env_sampled += _samp;
weight += _samp.a;
}
env_sampled /= weight;
env_sampled.a = 1.;
vec4 env_effect = mat_metalic == 1? env_sampled * final_color : env_sampled;
env_effect = 1. - ( mat_reflective * ( 1. - env_effect ));
final_color *= env_effect;
}
#endregion
gl_FragData[0] = final_color; gl_FragData[0] = final_color;
gl_FragData[1] = vec4(0.5 + normal * 0.5, 1.); gl_FragData[1] = vec4(0.5 + normal * 0.5, 1.);
gl_FragData[2] = vec4(vec3(v_cameraDistance), 1.); gl_FragData[2] = vec4(vec3(v_cameraDistance), 1.);
} }