diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-11-09 23:55:06 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-11-09 23:55:06 -0300 |
commit | cacf9ebb7fd8df8845daca9da2fe55456cc179aa (patch) | |
tree | 5881cb42ace5001916e9d1843f5a7acbc35332a6 /scene | |
parent | 6b2a27bbe5fa112365fc88b9b4678a61293bcb53 (diff) |
all light types and shadows are working, pending a lot of clean-up
Diffstat (limited to 'scene')
-rw-r--r-- | scene/3d/light.cpp | 91 | ||||
-rw-r--r-- | scene/3d/light.h | 71 | ||||
-rw-r--r-- | scene/3d/navigation_mesh.cpp | 2 | ||||
-rw-r--r-- | scene/main/scene_main_loop.cpp | 2 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 61 | ||||
-rw-r--r-- | scene/main/viewport.h | 24 | ||||
-rw-r--r-- | scene/resources/material.cpp | 2 | ||||
-rw-r--r-- | scene/resources/mesh.cpp | 102 | ||||
-rw-r--r-- | scene/resources/mesh.h | 4 | ||||
-rw-r--r-- | scene/resources/mesh_data_tool.cpp | 2 | ||||
-rw-r--r-- | scene/resources/shape.cpp | 2 | ||||
-rw-r--r-- | scene/resources/surface_tool.cpp | 2 |
12 files changed, 318 insertions, 47 deletions
diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index 88ba7b3731..cfc829078d 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -202,7 +202,7 @@ void Light::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::BOOL, "light/negative"), _SCS("set_negative"), _SCS("is_negative")); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "light/specular"), _SCS("set_param"), _SCS("get_param"), PARAM_SPECULAR); ADD_PROPERTY( PropertyInfo( Variant::INT, "light/cull_mask"), _SCS("set_cull_mask"), _SCS("get_cull_mask")); - ADD_PROPERTY( PropertyInfo( Variant::INT, "shadow/enabled"), _SCS("set_shadow"), _SCS("has_shadow")); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "shadow/enabled"), _SCS("set_shadow"), _SCS("has_shadow")); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow/darkness"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_DARKNESS); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow/normal_bias"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_NORMAL_BIAS); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow/bias"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_BIAS); @@ -222,7 +222,6 @@ void Light::_bind_methods() { BIND_CONSTANT( PARAM_SHADOW_SPLIT_1_OFFSET ); BIND_CONSTANT( PARAM_SHADOW_SPLIT_2_OFFSET ); BIND_CONSTANT( PARAM_SHADOW_SPLIT_3_OFFSET ); - BIND_CONSTANT( PARAM_SHADOW_SPLIT_4_OFFSET ); BIND_CONSTANT( PARAM_SHADOW_NORMAL_BIAS ); BIND_CONSTANT( PARAM_SHADOW_BIAS ); BIND_CONSTANT( PARAM_SHADOW_BIAS_SPLIT_SCALE ); @@ -255,7 +254,6 @@ Light::Light(VisualServer::LightType p_type) { set_param(PARAM_SHADOW_SPLIT_1_OFFSET,0.1); set_param(PARAM_SHADOW_SPLIT_2_OFFSET,0.2); set_param(PARAM_SHADOW_SPLIT_3_OFFSET,0.5); - set_param(PARAM_SHADOW_SPLIT_4_OFFSET,1.0); set_param(PARAM_SHADOW_NORMAL_BIAS,0.1); set_param(PARAM_SHADOW_BIAS,0.1); set_param(PARAM_SHADOW_BIAS_SPLIT_SCALE,0.1); @@ -279,36 +277,107 @@ Light::~Light() { } ///////////////////////////////////////// +void DirectionalLight::set_shadow_mode(ShadowMode p_mode) { + + shadow_mode=p_mode; + VS::get_singleton()->light_directional_set_shadow_mode(light,VS::LightDirectionalShadowMode(p_mode)); +} + +DirectionalLight::ShadowMode DirectionalLight::get_shadow_mode() const { + + return shadow_mode; +} + +void DirectionalLight::set_blend_splits(bool p_enable) { + + blend_splits=p_enable; +} + +bool DirectionalLight::is_blend_splits_enabled() const { + + return blend_splits; +} + void DirectionalLight::_bind_methods() { + ObjectTypeDB::bind_method( _MD("set_shadow_mode","mode"),&DirectionalLight::set_shadow_mode); + ObjectTypeDB::bind_method( _MD("get_shadow_mode"),&DirectionalLight::get_shadow_mode); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "pssm/split_1"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_SPLIT_1_OFFSET); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "pssm/split_2"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_SPLIT_2_OFFSET); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "pssm/split_3"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_SPLIT_3_OFFSET); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "pssm/split_4"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_SPLIT_4_OFFSET); + ObjectTypeDB::bind_method( _MD("set_blend_splits","enabled"),&DirectionalLight::set_blend_splits); + ObjectTypeDB::bind_method( _MD("is_blend_splits_enabled"),&DirectionalLight::is_blend_splits_enabled); + + ADD_PROPERTY( PropertyInfo( Variant::INT, "directional/shadow_mode",PROPERTY_HINT_ENUM,"Orthogonal,PSSM 2 Splits,PSSM 4 Splits"), _SCS("set_shadow_mode"), _SCS("get_shadow_mode")); + ADD_PROPERTYI( PropertyInfo( Variant::REAL, "directional/split_1"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_SPLIT_1_OFFSET); + ADD_PROPERTYI( PropertyInfo( Variant::REAL, "directional/split_2"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_SPLIT_2_OFFSET); + ADD_PROPERTYI( PropertyInfo( Variant::REAL, "directional/split_3"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_SPLIT_3_OFFSET); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "directional/blend_splits"), _SCS("set_blend_splits"), _SCS("is_blend_splits_enabled")); + + BIND_CONSTANT( SHADOW_ORTHOGONAL ); + BIND_CONSTANT( SHADOW_PARALLEL_2_SPLITS ); + BIND_CONSTANT( SHADOW_PARALLEL_4_SPLITS ); } DirectionalLight::DirectionalLight() : Light( VisualServer::LIGHT_DIRECTIONAL ) { + set_shadow_mode(SHADOW_PARALLEL_4_SPLITS); + blend_splits=false; +} +void OmniLight::set_shadow_mode(ShadowMode p_mode) { + shadow_mode=p_mode; + VS::get_singleton()->light_omni_set_shadow_mode(light,VS::LightOmniShadowMode(p_mode)); } +OmniLight::ShadowMode OmniLight::get_shadow_mode() const{ + + return shadow_mode; +} + +void OmniLight::set_shadow_detail(ShadowDetail p_detail){ + + shadow_detail=p_detail; + VS::get_singleton()->light_omni_set_shadow_detail(light,VS::LightOmniShadowDetail(p_detail)); +} +OmniLight::ShadowDetail OmniLight::get_shadow_detail() const{ + + return shadow_detail; +} + + + void OmniLight::_bind_methods() { - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "light/range"), _SCS("set_param"), _SCS("get_param"), PARAM_RANGE); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "light/attenuation"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION); + ObjectTypeDB::bind_method( _MD("set_shadow_mode","mode"),&OmniLight::set_shadow_mode); + ObjectTypeDB::bind_method( _MD("get_shadow_mode"),&OmniLight::get_shadow_mode); + + ObjectTypeDB::bind_method( _MD("set_shadow_detail","detail"),&OmniLight::set_shadow_detail); + ObjectTypeDB::bind_method( _MD("get_shadow_detail"),&OmniLight::get_shadow_detail); + + ADD_PROPERTYI( PropertyInfo( Variant::REAL, "omni/range"), _SCS("set_param"), _SCS("get_param"), PARAM_RANGE); + ADD_PROPERTYI( PropertyInfo( Variant::REAL, "omni/attenuation"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION); + ADD_PROPERTY( PropertyInfo( Variant::INT, "omni/shadow_mode",PROPERTY_HINT_ENUM,"Dual Paraboloid,Cube"), _SCS("set_shadow_mode"), _SCS("get_shadow_mode")); + ADD_PROPERTY( PropertyInfo( Variant::INT, "omni/shadow_detail",PROPERTY_HINT_ENUM,"Vertical,Horizontal"), _SCS("set_shadow_detail"), _SCS("get_shadow_detail")); + +} + +OmniLight::OmniLight() : Light( VisualServer::LIGHT_OMNI ) { + + set_shadow_mode(SHADOW_DUAL_PARABOLOID); + set_shadow_detail(SHADOW_DETAIL_HORIZONTAL); } void SpotLight::_bind_methods() { - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "light/spot_angle"), _SCS("set_param"), _SCS("get_param"), PARAM_SPOT_ANGLE); - ADD_PROPERTYI( PropertyInfo( Variant::REAL, "light/spot_attenuation"), _SCS("set_param"), _SCS("get_param"), PARAM_SPOT_ATTENUATION); + ADD_PROPERTYI( PropertyInfo( Variant::REAL, "spot/range"), _SCS("set_param"), _SCS("get_param"), PARAM_RANGE); + ADD_PROPERTYI( PropertyInfo( Variant::REAL, "spot/attenuation"), _SCS("set_param"), _SCS("get_param"), PARAM_ATTENUATION); + ADD_PROPERTYI( PropertyInfo( Variant::REAL, "spot/spot_angle"), _SCS("set_param"), _SCS("get_param"), PARAM_SPOT_ANGLE); + ADD_PROPERTYI( PropertyInfo( Variant::REAL, "spot/spot_attenuation"), _SCS("set_param"), _SCS("get_param"), PARAM_SPOT_ATTENUATION); } diff --git a/scene/3d/light.h b/scene/3d/light.h index 7da2d8e7ca..da28542817 100644 --- a/scene/3d/light.h +++ b/scene/3d/light.h @@ -45,22 +45,21 @@ class Light : public VisualInstance { public: enum Param { - PARAM_ENERGY, - PARAM_SPECULAR, - PARAM_RANGE, - PARAM_ATTENUATION, - PARAM_SPOT_ANGLE, - PARAM_SPOT_ATTENUATION, - PARAM_SHADOW_MAX_DISTANCE, - PARAM_SHADOW_DARKNESS, - PARAM_SHADOW_SPLIT_1_OFFSET, - PARAM_SHADOW_SPLIT_2_OFFSET, - PARAM_SHADOW_SPLIT_3_OFFSET, - PARAM_SHADOW_SPLIT_4_OFFSET, - PARAM_SHADOW_NORMAL_BIAS, - PARAM_SHADOW_BIAS, - PARAM_SHADOW_BIAS_SPLIT_SCALE, - PARAM_MAX + PARAM_ENERGY = VS::LIGHT_PARAM_ENERGY, + PARAM_SPECULAR = VS::LIGHT_PARAM_SPECULAR, + PARAM_RANGE = VS::LIGHT_PARAM_RANGE, + PARAM_ATTENUATION = VS::LIGHT_PARAM_ATTENUATION, + PARAM_SPOT_ANGLE = VS::LIGHT_PARAM_SPOT_ANGLE, + PARAM_SPOT_ATTENUATION = VS::LIGHT_PARAM_SPOT_ATTENUATION, + PARAM_SHADOW_MAX_DISTANCE = VS::LIGHT_PARAM_SHADOW_MAX_DISTANCE, + PARAM_SHADOW_DARKNESS = VS::LIGHT_PARAM_SHADOW_DARKNESS, + PARAM_SHADOW_SPLIT_1_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET, + PARAM_SHADOW_SPLIT_2_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET, + PARAM_SHADOW_SPLIT_3_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET, + PARAM_SHADOW_NORMAL_BIAS = VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS, + PARAM_SHADOW_BIAS = VS::LIGHT_PARAM_SHADOW_BIAS, + PARAM_SHADOW_BIAS_SPLIT_SCALE = VS::LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE, + PARAM_MAX = VS::LIGHT_PARAM_MAX }; private: @@ -126,31 +125,69 @@ class DirectionalLight : public Light { public: + enum ShadowMode { + SHADOW_ORTHOGONAL, + SHADOW_PARALLEL_2_SPLITS, + SHADOW_PARALLEL_4_SPLITS + }; private: + bool blend_splits; + ShadowMode shadow_mode; protected: static void _bind_methods(); public: + void set_shadow_mode(ShadowMode p_mode); + ShadowMode get_shadow_mode() const; + + void set_blend_splits(bool p_enable); + bool is_blend_splits_enabled() const; DirectionalLight(); }; +VARIANT_ENUM_CAST(DirectionalLight::ShadowMode) class OmniLight : public Light { OBJ_TYPE( OmniLight, Light ); +public: + // omni light + enum ShadowMode { + SHADOW_DUAL_PARABOLOID, + SHADOW_CUBE, + }; + + // omni light + enum ShadowDetail { + SHADOW_DETAIL_VERTICAL, + SHADOW_DETAIL_HORIZONTAL + }; + +private: + + ShadowMode shadow_mode; + ShadowDetail shadow_detail; protected: static void _bind_methods(); public: + void set_shadow_mode(ShadowMode p_mode); + ShadowMode get_shadow_mode() const; - OmniLight() : Light( VisualServer::LIGHT_OMNI ) { } + void set_shadow_detail(ShadowDetail p_detail); + ShadowDetail get_shadow_detail() const; + + OmniLight(); }; +VARIANT_ENUM_CAST(OmniLight::ShadowMode) +VARIANT_ENUM_CAST(OmniLight::ShadowDetail) + class SpotLight : public Light { OBJ_TYPE( SpotLight, Light ); diff --git a/scene/3d/navigation_mesh.cpp b/scene/3d/navigation_mesh.cpp index 386a0fab57..5e1bda3436 100644 --- a/scene/3d/navigation_mesh.cpp +++ b/scene/3d/navigation_mesh.cpp @@ -201,7 +201,7 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() { arr.resize(Mesh::ARRAY_MAX); arr[Mesh::ARRAY_VERTEX]=varr; - debug_mesh->add_surface(Mesh::PRIMITIVE_LINES,arr); + debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES,arr); return debug_mesh; } diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index cfc6753378..ef619244d0 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -845,7 +845,7 @@ Ref<Mesh> SceneTree::get_debug_contact_mesh() { arr[Mesh::ARRAY_INDEX]=indices; - debug_contact_mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES,arr); + debug_contact_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES,arr); debug_contact_mesh->surface_set_material(0,mat); return debug_contact_mesh; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 35f72c5ce7..0ca72eaa2a 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1297,6 +1297,39 @@ bool Viewport::get_clear_on_new_frame() const{ return clear_on_new_frame; } +void Viewport::set_shadow_atlas_size(int p_size) { + + shadow_atlas_size=p_size; + VS::get_singleton()->viewport_set_shadow_atlas_size(viewport,p_size); +} + +int Viewport::get_shadow_atlas_size() const{ + + return shadow_atlas_size; +} + +void Viewport::set_shadow_atlas_quadrant_subdiv(int p_quadrant,ShadowAtlasQuadrantSubdiv p_subdiv){ + + + ERR_FAIL_INDEX(p_quadrant,4); + ERR_FAIL_INDEX(p_subdiv,SHADOW_ATLAS_QUADRANT_SUBDIV_MAX); + + if (shadow_atlas_quadrant_subdiv[p_quadrant]==p_subdiv) + return; + + shadow_atlas_quadrant_subdiv[p_quadrant]=p_subdiv; + static const int subdiv[SHADOW_ATLAS_QUADRANT_SUBDIV_MAX]={0,1,4,16,64,256,1024}; + + VS::get_singleton()->viewport_set_shadow_atlas_quadrant_subdivision(viewport,p_quadrant,subdiv[p_subdiv]); + +} +Viewport::ShadowAtlasQuadrantSubdiv Viewport::get_shadow_atlas_quadrant_subdiv(int p_quadrant) const{ + + ERR_FAIL_INDEX_V(p_quadrant,4,SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED); + return shadow_atlas_quadrant_subdiv[p_quadrant]; +} + + void Viewport::clear() { //clear=true; @@ -2661,6 +2694,12 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip); ObjectTypeDB::bind_method(_MD("_gui_remove_focus"), &Viewport::_gui_remove_focus); + ObjectTypeDB::bind_method(_MD("set_shadow_atlas_size","size"), &Viewport::set_shadow_atlas_size); + ObjectTypeDB::bind_method(_MD("get_shadow_atlas_size"), &Viewport::get_shadow_atlas_size); + + ObjectTypeDB::bind_method(_MD("set_shadow_atlas_quadrant_subdiv","quadrant","subdiv"), &Viewport::set_shadow_atlas_quadrant_subdiv); + ObjectTypeDB::bind_method(_MD("get_shadow_atlas_quadrant_subdiv","quadrant"), &Viewport::get_shadow_atlas_quadrant_subdiv); + ADD_PROPERTY( PropertyInfo(Variant::RECT2,"size"), _SCS("set_size"), _SCS("get_size") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"own_world"), _SCS("set_use_own_world"), _SCS("is_using_own_world") ); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world",PROPERTY_HINT_RESOURCE_TYPE,"World"), _SCS("set_world"), _SCS("get_world") ); @@ -2674,6 +2713,11 @@ void Viewport::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"physics/object_picking"), _SCS("set_physics_object_picking"), _SCS("get_physics_object_picking") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gui/disable_input"), _SCS("set_disable_input"), _SCS("is_input_disabled") ); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"3d/disable_3d"), _SCS("set_disable_3d"), _SCS("is_3d_disabled") ); + ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow_atlas/size"), _SCS("set_shadow_atlas_size"), _SCS("get_shadow_atlas_size") ); + ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas/quad_0",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), _SCS("set_shadow_atlas_quadrant_subdiv"), _SCS("get_shadow_atlas_quadrant_subdiv"),0 ); + ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas/quad_1",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), _SCS("set_shadow_atlas_quadrant_subdiv"), _SCS("get_shadow_atlas_quadrant_subdiv"),1 ); + ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas/quad_2",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), _SCS("set_shadow_atlas_quadrant_subdiv"), _SCS("get_shadow_atlas_quadrant_subdiv"),2 ); + ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas/quad_3",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), _SCS("set_shadow_atlas_quadrant_subdiv"), _SCS("get_shadow_atlas_quadrant_subdiv"),3 ); ADD_SIGNAL(MethodInfo("size_changed")); @@ -2682,6 +2726,14 @@ void Viewport::_bind_methods() { BIND_CONSTANT( UPDATE_WHEN_VISIBLE ); BIND_CONSTANT( UPDATE_ALWAYS ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_1 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_4 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_16 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_64 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_256 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_1024 ); + BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_MAX ); } @@ -2719,6 +2771,15 @@ Viewport::Viewport() { physics_object_over=0; physics_last_mousepos=Vector2(1e20,1e20); + shadow_atlas_size=0; + for(int i=0;i<4;i++) { + shadow_atlas_quadrant_subdiv[0]=SHADOW_ATLAS_QUADRANT_SUBDIV_MAX; + } + set_shadow_atlas_quadrant_subdiv(0,SHADOW_ATLAS_QUADRANT_SUBDIV_4); + set_shadow_atlas_quadrant_subdiv(1,SHADOW_ATLAS_QUADRANT_SUBDIV_4); + set_shadow_atlas_quadrant_subdiv(2,SHADOW_ATLAS_QUADRANT_SUBDIV_16); + set_shadow_atlas_quadrant_subdiv(3,SHADOW_ATLAS_QUADRANT_SUBDIV_64); + String id=itos(get_instance_ID()); input_group = "_vp_input"+id; diff --git a/scene/main/viewport.h b/scene/main/viewport.h index c5d61469dd..462ecff93e 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -86,6 +86,18 @@ public: UPDATE_ALWAYS }; + enum ShadowAtlasQuadrantSubdiv { + SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED, + SHADOW_ATLAS_QUADRANT_SUBDIV_1, + SHADOW_ATLAS_QUADRANT_SUBDIV_4, + SHADOW_ATLAS_QUADRANT_SUBDIV_16, + SHADOW_ATLAS_QUADRANT_SUBDIV_64, + SHADOW_ATLAS_QUADRANT_SUBDIV_256, + SHADOW_ATLAS_QUADRANT_SUBDIV_1024, + SHADOW_ATLAS_QUADRANT_SUBDIV_MAX, + + }; + private: friend class ViewportTexture; @@ -120,8 +132,6 @@ friend class ViewportTexture; RID contact_3d_debug_multimesh; RID contact_3d_debug_instance; - - bool size_override; bool size_override_stretch; Size2 size_override_size; @@ -175,6 +185,9 @@ friend class ViewportTexture; RID texture_rid; Ref<ViewportTexture> texture; + int shadow_atlas_size; + ShadowAtlasQuadrantSubdiv shadow_atlas_quadrant_subdiv[4]; + struct GUI { // info used when this is a window @@ -347,6 +360,11 @@ public: UpdateMode get_update_mode() const; Ref<ViewportTexture> get_texture() const; + void set_shadow_atlas_size(int p_size); + int get_shadow_atlas_size() const; + + void set_shadow_atlas_quadrant_subdiv(int p_quadrant,ShadowAtlasQuadrantSubdiv p_subdiv); + ShadowAtlasQuadrantSubdiv get_shadow_atlas_quadrant_subdiv(int p_quadrant) const; Vector2 get_camera_coords(const Vector2& p_viewport_coords) const; Vector2 get_camera_rect_size() const; @@ -393,4 +411,6 @@ public: }; VARIANT_ENUM_CAST(Viewport::UpdateMode); +VARIANT_ENUM_CAST(Viewport::ShadowAtlasQuadrantSubdiv); + #endif diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 3c7b0fbe6c..cb55f4f030 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -152,7 +152,7 @@ void FixedSpatialMaterial::_update_shader() { switch(cull_mode) { case CULL_BACK: code+=",cull_back"; break; case CULL_FRONT: code+=",cull_front"; break; - case CULL_DISABLED: code+=",cull_disable"; break; + case CULL_DISABLED: code+=",cull_disabled"; break; } diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 132ec54e48..e737c5c37e 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -125,11 +125,61 @@ bool Mesh::_set(const StringName& p_name, const Variant& p_value) { //create Dictionary d=p_value; ERR_FAIL_COND_V(!d.has("primitive"),false); - ERR_FAIL_COND_V(!d.has("arrays"),false); - ERR_FAIL_COND_V(!d.has("morph_arrays"),false); + + if (d.has("arrays")) { + //old format + ERR_FAIL_COND_V(!d.has("morph_arrays"),false); + add_surface_from_arrays(PrimitiveType(int(d["primitive"])),d["arrays"],d["morph_arrays"]); + + } else if (d.has("array_data")) { + + DVector<uint8_t> array_data = d["array_data"]; + DVector<uint8_t> array_index_data; + if (d.has("array_index_data")) + array_index_data=d["array_index_data"]; + + ERR_FAIL_COND_V(!d.has("format"),false); + uint32_t format = d["format"]; + + ERR_FAIL_COND_V(!d.has("primitive"),false); + uint32_t primitive = d["primitive"]; + + ERR_FAIL_COND_V(!d.has("vertex_count"),false); + int vertex_count = d["vertex_count"]; + + int index_count=0; + if (d.has("index_count")) + index_count=d["index_count"]; + + Vector< DVector<uint8_t> > morphs; + + if (d.has("morph_data")) { + Array morph_data=d["morph_data"]; + for(int i=0;i<morph_data.size();i++) { + DVector<uint8_t> morph = morph_data[i]; + morphs.push_back(morph_data[i]); + } + } + + ERR_FAIL_COND_V(!d.has("aabb"),false); + AABB aabb = d["aabb"]; + + Vector<AABB> bone_aabb; + if (d.has("bone_aabb")) { + Array baabb = d["bone_aabb"]; + bone_aabb.resize(baabb.size()); + + for(int i=0;i<baabb.size();i++) { + bone_aabb[i]=baabb[i]; + } + } + + add_surface(format,PrimitiveType(primitive),array_data,vertex_count,array_index_data,index_count,aabb,morphs,bone_aabb); + } else { + ERR_FAIL_V(false); + } - add_surface(PrimitiveType(int(d["primitive"])),d["arrays"],d["morph_arrays"]); if (d.has("material")) { surface_set_material(idx,d["material"]); @@ -185,9 +235,31 @@ bool Mesh::_get(const StringName& p_name,Variant &r_ret) const { ERR_FAIL_INDEX_V(idx,surfaces.size(),false); Dictionary d; - d["primitive"]=surface_get_primitive_type(idx); - d["arrays"]=surface_get_arrays(idx); - d["morph_arrays"]=surface_get_morph_arrays(idx); + + d["array_data"]=VS::get_singleton()->mesh_surface_get_array(mesh,idx); + d["vertex_count"]=VS::get_singleton()->mesh_surface_get_array_len(mesh,idx); + d["array_index_data"]=VS::get_singleton()->mesh_surface_get_index_array(mesh,idx); + d["index_count"]=VS::get_singleton()->mesh_surface_get_array_index_len(mesh,idx); + d["primitive"]=VS::get_singleton()->mesh_surface_get_primitive_type(mesh,idx); + d["format"]=VS::get_singleton()->mesh_surface_get_format(mesh,idx); + d["aabb"]=VS::get_singleton()->mesh_surface_get_aabb(mesh,idx); + + Vector<AABB> skel_aabb = VS::get_singleton()->mesh_surface_get_skeleton_aabb(mesh,idx); + Array arr; + for(int i=0;i<skel_aabb.size();i++) { + arr[i]=skel_aabb[i]; + } + d["skeleton_aabb"]=arr; + + Vector< DVector<uint8_t> > morph_data = VS::get_singleton()->mesh_surface_get_blend_shapes(mesh,idx); + + Array md; + for(int i=0;i<morph_data.size();i++) { + md.push_back(morph_data[i]); + } + + d["morph_data"]=md; + Ref<Material> m = surface_get_material(idx); if (m.is_valid()) d["material"]=m; @@ -234,7 +306,17 @@ void Mesh::_recompute_aabb() { } -void Mesh::add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes) { +void Mesh::add_surface(uint32_t p_format,PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const AABB& p_aabb,const Vector<DVector<uint8_t> >& p_blend_shapes,const Vector<AABB>& p_bone_aabbs) { + + Surface s; + s.aabb=p_aabb; + surfaces.push_back(s); + + VisualServer::get_singleton()->mesh_add_surface(mesh,p_format,(VS::PrimitiveType)p_primitive,p_array,p_vertex_count,p_index_array,p_index_count,p_aabb,p_blend_shapes,p_bone_aabbs); + +} + +void Mesh::add_surface_from_arrays(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes) { ERR_FAIL_COND(p_arrays.size()!=ARRAY_MAX); @@ -279,8 +361,7 @@ void Mesh::add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Arr Array Mesh::surface_get_arrays(int p_surface) const { ERR_FAIL_INDEX_V(p_surface,surfaces.size(),Array()); - //return VisualServer::get_singleton()->mesh_get_surface_arrays(mesh,p_surface); - return Array(); + return VisualServer::get_singleton()->mesh_surface_get_arrays(mesh,p_surface); } Array Mesh::surface_get_morph_arrays(int p_surface) const { @@ -929,7 +1010,7 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { Ref<Mesh> newmesh = memnew( Mesh ); - newmesh->add_surface(PRIMITIVE_TRIANGLES,arrays); + newmesh->add_surface_from_arrays(PRIMITIVE_TRIANGLES,arrays); return newmesh; } @@ -943,6 +1024,7 @@ void Mesh::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_morph_target_mode","mode"),&Mesh::set_morph_target_mode); ObjectTypeDB::bind_method(_MD("get_morph_target_mode"),&Mesh::get_morph_target_mode); + ObjectTypeDB::bind_method(_MD("add_surface_from_arrays","primitive","arrays","blend_shapes"),&Mesh::add_surface_from_arrays,DEFVAL(Array())); ObjectTypeDB::bind_method(_MD("get_surface_count"),&Mesh::get_surface_count); ObjectTypeDB::bind_method(_MD("surface_remove","surf_idx"),&Mesh::surface_remove); ObjectTypeDB::bind_method(_MD("surface_get_array_len","surf_idx"),&Mesh::surface_get_array_len); diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index e329c353a0..2b28f1187e 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -122,7 +122,9 @@ protected: public: - void add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array()); + void add_surface_from_arrays(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array()); + void add_surface(uint32_t p_format,PrimitiveType p_primitive,const DVector<uint8_t>& p_array,int p_vertex_count,const DVector<uint8_t>& p_index_array,int p_index_count,const AABB& p_aabb,const Vector<DVector<uint8_t> >& p_blend_shapes=Vector<DVector<uint8_t> >(),const Vector<AABB>& p_bone_aabbs=Vector<AABB>()); + Array surface_get_arrays(int p_surface) const; virtual Array surface_get_morph_arrays(int p_surface) const; diff --git a/scene/resources/mesh_data_tool.cpp b/scene/resources/mesh_data_tool.cpp index fb0fc2a247..758d78e513 100644 --- a/scene/resources/mesh_data_tool.cpp +++ b/scene/resources/mesh_data_tool.cpp @@ -328,7 +328,7 @@ Error MeshDataTool::commit_to_surface(const Ref<Mesh>& p_mesh) { Ref<Mesh> ncmesh=p_mesh; int sc = ncmesh->get_surface_count(); - ncmesh->add_surface(Mesh::PRIMITIVE_TRIANGLES,arr); + ncmesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES,arr); ncmesh->surface_set_material(sc,material); return OK; diff --git a/scene/resources/shape.cpp b/scene/resources/shape.cpp index a71e414f61..778764a832 100644 --- a/scene/resources/shape.cpp +++ b/scene/resources/shape.cpp @@ -77,7 +77,7 @@ Ref<Mesh> Shape::get_debug_mesh() { SceneTree *st=OS::get_singleton()->get_main_loop()->cast_to<SceneTree>(); - debug_mesh_cache->add_surface(Mesh::PRIMITIVE_LINES,arr); + debug_mesh_cache->add_surface_from_arrays(Mesh::PRIMITIVE_LINES,arr); if (st) { debug_mesh_cache->surface_set_material(0,st->get_debug_collision_material()); diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index e1769d099b..6f08d69221 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -410,7 +410,7 @@ Ref<Mesh> SurfaceTool::commit(const Ref<Mesh>& p_existing) { } - mesh->add_surface(primitive,a); + mesh->add_surface_from_arrays(primitive,a); if (material.is_valid()) mesh->surface_set_material(surface,material); |