summaryrefslogtreecommitdiff
path: root/scene/resources
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/baked_light.cpp16
-rw-r--r--scene/resources/baked_light.h11
-rw-r--r--scene/resources/environment.cpp26
-rw-r--r--scene/resources/environment.h13
-rw-r--r--scene/resources/material.cpp124
-rw-r--r--scene/resources/material.h62
-rw-r--r--scene/resources/polygon_path_finder.cpp228
-rw-r--r--scene/resources/polygon_path_finder.h15
-rw-r--r--scene/resources/shader.cpp23
-rw-r--r--scene/resources/shader.h3
10 files changed, 367 insertions, 154 deletions
diff --git a/scene/resources/baked_light.cpp b/scene/resources/baked_light.cpp
index b3de7143ee..725ac1c946 100644
--- a/scene/resources/baked_light.cpp
+++ b/scene/resources/baked_light.cpp
@@ -201,6 +201,16 @@ bool BakedLight::get_bake_flag(BakeFlags p_flags) const{
return flags[p_flags];
}
+void BakedLight::set_format(Format p_format) {
+
+ format=p_format;
+
+}
+
+BakedLight::Format BakedLight::get_format() const{
+
+ return format;
+}
void BakedLight::_bind_methods(){
@@ -240,6 +250,10 @@ void BakedLight::_bind_methods(){
ObjectTypeDB::bind_method(_MD("set_normal_damp","normal_damp"),&BakedLight::set_normal_damp);
ObjectTypeDB::bind_method(_MD("get_normal_damp"),&BakedLight::get_normal_damp);
+ ObjectTypeDB::bind_method(_MD("set_format","format"),&BakedLight::set_format);
+ ObjectTypeDB::bind_method(_MD("get_format"),&BakedLight::get_format);
+
+
ObjectTypeDB::bind_method(_MD("set_energy_multiplier","energy_multiplier"),&BakedLight::set_energy_multiplier);
ObjectTypeDB::bind_method(_MD("get_energy_multiplier"),&BakedLight::get_energy_multiplier);
@@ -251,6 +265,7 @@ void BakedLight::_bind_methods(){
ADD_PROPERTY( PropertyInfo(Variant::INT,"mode/mode",PROPERTY_HINT_ENUM,"Octree,Lightmaps"),_SCS("set_mode"),_SCS("get_mode"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/format",PROPERTY_HINT_ENUM,"RGB,HDR8,HDR16"),_SCS("set_format"),_SCS("get_format"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/cell_subdiv",PROPERTY_HINT_RANGE,"4,14,1"),_SCS("set_cell_subdivision"),_SCS("get_cell_subdivision"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/lattice_subdiv",PROPERTY_HINT_RANGE,"1,5,1"),_SCS("set_initial_lattice_subdiv"),_SCS("get_initial_lattice_subdiv"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/light_bounces",PROPERTY_HINT_RANGE,"0,3,1"),_SCS("set_bounces"),_SCS("get_bounces"));
@@ -292,6 +307,7 @@ BakedLight::BakedLight() {
cell_extra_margin=0.05;
edge_damp=0.0;
normal_damp=0.0;
+ format=FORMAT_RGB;
flags[BAKE_DIFFUSE]=true;
flags[BAKE_SPECULAR]=false;
diff --git a/scene/resources/baked_light.h b/scene/resources/baked_light.h
index 8b50f6e0d3..df86f98c08 100644
--- a/scene/resources/baked_light.h
+++ b/scene/resources/baked_light.h
@@ -14,6 +14,13 @@ public:
MODE_LIGHTMAPS
};
+ enum Format {
+
+ FORMAT_RGB,
+ FORMAT_HDR8,
+ FORMAT_HDR16
+ };
+
enum BakeFlags {
BAKE_DIFFUSE,
BAKE_SPECULAR,
@@ -38,6 +45,7 @@ private:
float edge_damp;
float normal_damp;
int bounces;
+ Format format;
bool flags[BAKE_MAX];
@@ -80,6 +88,8 @@ public:
void set_bake_flag(BakeFlags p_flags,bool p_enable);
bool get_bake_flag(BakeFlags p_flags) const;
+ void set_format(Format p_margin);
+ Format get_format() const;
void set_mode(Mode p_mode);
Mode get_mode() const;
@@ -100,6 +110,7 @@ public:
};
+VARIANT_ENUM_CAST(BakedLight::Format);
VARIANT_ENUM_CAST(BakedLight::Mode);
VARIANT_ENUM_CAST(BakedLight::BakeFlags);
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index 5c1d190b2e..df18e4f0f5 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -101,6 +101,11 @@ void Environment::_bind_methods() {
ObjectTypeDB::bind_method(_MD("fx_set_param","param","value"),&Environment::fx_set_param);
ObjectTypeDB::bind_method(_MD("fx_get_param","param"),&Environment::fx_get_param);
+ ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"ambient_light/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_AMBIENT_LIGHT);
+ ADD_PROPERTYI( PropertyInfo(Variant::COLOR,"ambient_light/color",PROPERTY_HINT_COLOR_NO_ALPHA),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_AMBIENT_LIGHT_COLOR);
+ ADD_PROPERTYI( PropertyInfo(Variant::REAL,"ambient_light/energy",PROPERTY_HINT_RANGE,"0,64,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_AMBIENT_LIGHT_ENERGY);
+
+
ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"fxaa/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_FXAA);
ADD_PROPERTY( PropertyInfo(Variant::INT,"background/mode",PROPERTY_HINT_ENUM,"Keep,Default Color,Color,Texture,Cubemap,Texture RGBE,Cubemap RGBE"),_SCS("set_background"),_SCS("get_background"));
@@ -123,8 +128,9 @@ void Environment::_bind_methods() {
ADD_PROPERTYI( PropertyInfo(Variant::REAL,"dof_blur/begin",PROPERTY_HINT_RANGE,"0,4096,0.1"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_DOF_BLUR_BEGIN);
ADD_PROPERTYI( PropertyInfo(Variant::REAL,"dof_blur/range",PROPERTY_HINT_RANGE,"0,4096,0.1"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_DOF_BLUR_RANGE);
ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"hdr/enabled"),_SCS("set_enable_fx"),_SCS("is_fx_enabled"), FX_HDR);
+ ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/tonemapper",PROPERTY_HINT_ENUM,"Linear,Log,Reinhardt,ReinhardtAutoWhite"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_TONEMAPPER);
ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/exposure",PROPERTY_HINT_RANGE,"0.01,16,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_EXPOSURE);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/scalar",PROPERTY_HINT_RANGE,"0.01,16,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_SCALAR);
+ ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/white",PROPERTY_HINT_RANGE,"0.01,16,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_WHITE);
ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/glow_treshold",PROPERTY_HINT_RANGE,"0.00,8,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_GLOW_TRESHOLD);
ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/glow_scale",PROPERTY_HINT_RANGE,"0.00,16,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_GLOW_SCALE);
ADD_PROPERTYI( PropertyInfo(Variant::REAL,"hdr/min_luminance",PROPERTY_HINT_RANGE,"0.01,64,0.01"),_SCS("fx_set_param"),_SCS("fx_get_param"), FX_PARAM_HDR_MIN_LUMINANCE);
@@ -153,7 +159,7 @@ void Environment::_bind_methods() {
FX_PARAM_DOF_BLUR_BEGIN=VS::ENV_FX_PARAM_DOF_BLUR_BEGIN,
FX_PARAM_DOF_BLUR_END=VS::ENV_FX_PARAM_DOF_BLUR_END,
FX_PARAM_HDR_EXPOSURE=VS::ENV_FX_PARAM_HDR_EXPOSURE,
- FX_PARAM_HDR_SCALAR=VS::ENV_FX_PARAM_HDR_SCALAR,
+ FX_PARAM_HDR_WHITE=VS::ENV_FX_PARAM_HDR_WHITE,
FX_PARAM_HDR_GLOW_TRESHOLD=VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD,
FX_PARAM_HDR_GLOW_SCALE=VS::ENV_FX_PARAM_HDR_GLOW_SCALE,
FX_PARAM_HDR_MIN_LUMINANCE=VS::ENV_FX_PARAM_HDR_MIN_LUMINANCE,
@@ -188,6 +194,7 @@ void Environment::_bind_methods() {
BIND_CONSTANT( BG_PARAM_MAX );
+ BIND_CONSTANT( FX_AMBIENT_LIGHT );
BIND_CONSTANT( FX_FXAA );
BIND_CONSTANT( FX_GLOW );
BIND_CONSTANT( FX_DOF_BLUR );
@@ -202,6 +209,13 @@ void Environment::_bind_methods() {
BIND_CONSTANT( FX_BLUR_BLEND_MODE_SCREEN );
BIND_CONSTANT( FX_BLUR_BLEND_MODE_SOFTLIGHT );
+ BIND_CONSTANT( FX_HDR_TONE_MAPPER_LINEAR );
+ BIND_CONSTANT( FX_HDR_TONE_MAPPER_LOG );
+ BIND_CONSTANT( FX_HDR_TONE_MAPPER_REINHARDT );
+ BIND_CONSTANT( FX_HDR_TONE_MAPPER_REINHARDT_AUTOWHITE );
+
+ BIND_CONSTANT( FX_PARAM_AMBIENT_LIGHT_COLOR );
+ BIND_CONSTANT( FX_PARAM_AMBIENT_LIGHT_ENERGY );
BIND_CONSTANT( FX_PARAM_GLOW_BLUR_PASSES );
BIND_CONSTANT( FX_PARAM_GLOW_BLUR_SCALE );
BIND_CONSTANT( FX_PARAM_GLOW_BLUR_STRENGTH );
@@ -211,8 +225,9 @@ void Environment::_bind_methods() {
BIND_CONSTANT( FX_PARAM_DOF_BLUR_PASSES );
BIND_CONSTANT( FX_PARAM_DOF_BLUR_BEGIN );
BIND_CONSTANT( FX_PARAM_DOF_BLUR_RANGE );
+ BIND_CONSTANT( FX_PARAM_HDR_TONEMAPPER);
BIND_CONSTANT( FX_PARAM_HDR_EXPOSURE );
- BIND_CONSTANT( FX_PARAM_HDR_SCALAR );
+ BIND_CONSTANT( FX_PARAM_HDR_WHITE );
BIND_CONSTANT( FX_PARAM_HDR_GLOW_TRESHOLD );
BIND_CONSTANT( FX_PARAM_HDR_GLOW_SCALE );
BIND_CONSTANT( FX_PARAM_HDR_MIN_LUMINANCE );
@@ -245,6 +260,8 @@ Environment::Environment() {
for(int i=0;i<FX_MAX;i++)
set_enable_fx(Fx(i),false);
+ fx_set_param(FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0,0,0));
+ fx_set_param(FX_PARAM_AMBIENT_LIGHT_ENERGY,1.0);
fx_set_param(FX_PARAM_GLOW_BLUR_PASSES,1);
fx_set_param(FX_PARAM_GLOW_BLUR_SCALE,1);
fx_set_param(FX_PARAM_GLOW_BLUR_STRENGTH,1);
@@ -253,8 +270,9 @@ Environment::Environment() {
fx_set_param(FX_PARAM_DOF_BLUR_PASSES,1);
fx_set_param(FX_PARAM_DOF_BLUR_BEGIN,100.0);
fx_set_param(FX_PARAM_DOF_BLUR_RANGE,10.0);
+ fx_set_param(FX_PARAM_HDR_TONEMAPPER,FX_HDR_TONE_MAPPER_LINEAR);
fx_set_param(FX_PARAM_HDR_EXPOSURE,0.4);
- fx_set_param(FX_PARAM_HDR_SCALAR,1.0);
+ fx_set_param(FX_PARAM_HDR_WHITE,1.0);
fx_set_param(FX_PARAM_HDR_GLOW_TRESHOLD,0.95);
fx_set_param(FX_PARAM_HDR_GLOW_SCALE,0.2);
fx_set_param(FX_PARAM_HDR_MIN_LUMINANCE,0.4);
diff --git a/scene/resources/environment.h b/scene/resources/environment.h
index b72d6d74be..a9e2f422b9 100644
--- a/scene/resources/environment.h
+++ b/scene/resources/environment.h
@@ -61,6 +61,7 @@ public:
};
enum Fx {
+ FX_AMBIENT_LIGHT=VS::ENV_FX_AMBIENT_LIGHT,
FX_FXAA=VS::ENV_FX_FXAA,
FX_GLOW=VS::ENV_FX_GLOW,
FX_DOF_BLUR=VS::ENV_FX_DOF_BLUR,
@@ -77,7 +78,16 @@ public:
FX_BLUR_BLEND_MODE_SOFTLIGHT,
};
+ enum FxHDRToneMapper {
+ FX_HDR_TONE_MAPPER_LINEAR,
+ FX_HDR_TONE_MAPPER_LOG,
+ FX_HDR_TONE_MAPPER_REINHARDT,
+ FX_HDR_TONE_MAPPER_REINHARDT_AUTOWHITE,
+ };
+
enum FxParam {
+ FX_PARAM_AMBIENT_LIGHT_COLOR=VS::ENV_FX_PARAM_AMBIENT_LIGHT_COLOR,
+ FX_PARAM_AMBIENT_LIGHT_ENERGY=VS::ENV_FX_PARAM_AMBIENT_LIGHT_ENERGY,
FX_PARAM_GLOW_BLUR_PASSES=VS::ENV_FX_PARAM_GLOW_BLUR_PASSES,
FX_PARAM_GLOW_BLUR_SCALE=VS::ENV_FX_PARAM_GLOW_BLUR_SCALE,
FX_PARAM_GLOW_BLUR_STRENGTH=VS::ENV_FX_PARAM_GLOW_BLUR_STRENGTH,
@@ -88,7 +98,8 @@ public:
FX_PARAM_DOF_BLUR_BEGIN=VS::ENV_FX_PARAM_DOF_BLUR_BEGIN,
FX_PARAM_DOF_BLUR_RANGE=VS::ENV_FX_PARAM_DOF_BLUR_RANGE,
FX_PARAM_HDR_EXPOSURE=VS::ENV_FX_PARAM_HDR_EXPOSURE,
- FX_PARAM_HDR_SCALAR=VS::ENV_FX_PARAM_HDR_SCALAR,
+ FX_PARAM_HDR_TONEMAPPER=VS::ENV_FX_PARAM_HDR_TONEMAPPER,
+ FX_PARAM_HDR_WHITE=VS::ENV_FX_PARAM_HDR_WHITE,
FX_PARAM_HDR_GLOW_TRESHOLD=VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD,
FX_PARAM_HDR_GLOW_SCALE=VS::ENV_FX_PARAM_HDR_GLOW_SCALE,
FX_PARAM_HDR_MIN_LUMINANCE=VS::ENV_FX_PARAM_HDR_MIN_LUMINANCE,
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 091a46d4ab..2314926b2b 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -36,17 +36,9 @@ static const char*_flag_names[Material::FLAG_MAX]={
"invert_faces",
"unshaded",
"on_top",
- "wireframe",
- "billboard_sw",
+ "lightmap_on_uv2"
};
-static const char*_hint_names[Material::HINT_MAX]={
- "decal",
- "opaque_pre_zpass",
- "no_shadow",
- "no_depth_draw",
- "no_alpha_depth_draw",
-};
static const Material::Flag _flag_indices[Material::FLAG_MAX]={
Material::FLAG_VISIBLE,
@@ -54,15 +46,7 @@ static const Material::Flag _flag_indices[Material::FLAG_MAX]={
Material::FLAG_INVERT_FACES,
Material::FLAG_UNSHADED,
Material::FLAG_ONTOP,
- Material::FLAG_WIREFRAME,
- Material::FLAG_BILLBOARD_TOGGLE
-};
-
-static const Material::Hint _hint_indices[Material::HINT_MAX]={
- Material::HINT_DECAL,
- Material::HINT_OPAQUE_PRE_PASS,
- Material::HINT_NO_SHADOW,
- Material::HINT_NO_DEPTH_DRAW,
+ Material::FLAG_LIGHTMAP_ON_UV2
};
@@ -80,20 +64,6 @@ void Material::set_flag(Flag p_flag,bool p_enabled) {
}
-void Material::set_hint(Hint p_hint,bool p_enabled) {
-
- ERR_FAIL_INDEX(p_hint,HINT_MAX);
- hints[p_hint]=p_enabled;
- VisualServer::get_singleton()->material_set_hint(material,(VS::MaterialHint)p_hint,p_enabled);
- _change_notify();
-}
-
-bool Material::get_hint(Hint p_hint) const {
-
- ERR_FAIL_INDEX_V(p_hint,HINT_MAX,false);
- return hints[p_hint];
-}
-
void Material::set_blend_mode(BlendMode p_blend_mode) {
ERR_FAIL_INDEX(p_blend_mode,3);
@@ -108,17 +78,15 @@ Material::BlendMode Material::get_blend_mode() const {
}
-void Material::set_shade_model(ShadeModel p_model) {
-
- ERR_FAIL_INDEX(p_model,8);
- shade_model=p_model;
- VisualServer::get_singleton()->material_set_shade_model(material,(VS::MaterialShadeModel)p_model);
+void Material::set_depth_draw_mode(DepthDrawMode p_depth_draw_mode) {
+ depth_draw_mode=p_depth_draw_mode;
+ VisualServer::get_singleton()->material_set_depth_draw_mode(material,(VS::MaterialDepthDrawMode)p_depth_draw_mode);
}
-Material::ShadeModel Material::get_shade_model() const {
+Material::DepthDrawMode Material::get_depth_draw_mode() const {
- return shade_model;
+ return depth_draw_mode;
}
bool Material::get_flag(Flag p_flag) const {
@@ -144,49 +112,32 @@ void Material::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_flag","flag","enable"),&Material::set_flag);
ObjectTypeDB::bind_method(_MD("get_flag","flag"),&Material::get_flag);
- ObjectTypeDB::bind_method(_MD("set_hint","hint","enable"),&Material::set_hint);
- ObjectTypeDB::bind_method(_MD("get_hint","hint"),&Material::get_hint);
ObjectTypeDB::bind_method(_MD("set_blend_mode","mode"),&Material::set_blend_mode);
ObjectTypeDB::bind_method(_MD("get_blend_mode"),&Material::get_blend_mode);
- ObjectTypeDB::bind_method(_MD("set_shade_model","model"),&Material::set_shade_model);
- ObjectTypeDB::bind_method(_MD("get_shade_model"),&Material::get_shade_model);
ObjectTypeDB::bind_method(_MD("set_line_width","width"),&Material::set_line_width);
ObjectTypeDB::bind_method(_MD("get_line_width"),&Material::get_line_width);
+ ObjectTypeDB::bind_method(_MD("set_depth_draw_mode","mode"),&Material::set_depth_draw_mode);
+ ObjectTypeDB::bind_method(_MD("get_depth_draw_mode"),&Material::get_depth_draw_mode);
for(int i=0;i<FLAG_MAX;i++)
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, String()+"flags/"+_flag_names[i] ),_SCS("set_flag"),_SCS("get_flag"),_flag_indices[i]);
- for(int i=0;i<HINT_MAX;i++)
- ADD_PROPERTYI( PropertyInfo( Variant::BOOL, String()+"hints/"+_hint_names[i] ),_SCS("set_hint"),_SCS("get_hint"),_hint_indices[i]);
ADD_PROPERTY( PropertyInfo( Variant::INT, "params/blend_mode",PROPERTY_HINT_ENUM,"Mix,Add,Sub,PMAlpha" ), _SCS("set_blend_mode"),_SCS("get_blend_mode"));
+ ADD_PROPERTY( PropertyInfo( Variant::INT, "params/depth_draw",PROPERTY_HINT_ENUM,"Always,Opaque Only,Pre-Pass Alpha,Never" ), _SCS("set_depth_draw_mode"),_SCS("get_depth_draw_mode"));
ADD_PROPERTY( PropertyInfo( Variant::REAL, "params/line_width",PROPERTY_HINT_RANGE,"0.1,32.0,0.1" ), _SCS("set_line_width"),_SCS("get_line_width"));
-
BIND_CONSTANT( FLAG_VISIBLE );
BIND_CONSTANT( FLAG_DOUBLE_SIDED );
BIND_CONSTANT( FLAG_INVERT_FACES );
BIND_CONSTANT( FLAG_UNSHADED );
BIND_CONSTANT( FLAG_ONTOP );
- BIND_CONSTANT( FLAG_WIREFRAME );
- BIND_CONSTANT( FLAG_BILLBOARD_TOGGLE );
BIND_CONSTANT( FLAG_MAX );
- BIND_CONSTANT( HINT_DECAL );
- BIND_CONSTANT( HINT_OPAQUE_PRE_PASS );
- BIND_CONSTANT( HINT_NO_SHADOW );
- BIND_CONSTANT( HINT_NO_DEPTH_DRAW );
- BIND_CONSTANT( HINT_NO_DEPTH_DRAW_FOR_ALPHA );
- BIND_CONSTANT( HINT_MAX );
-
- BIND_CONSTANT( SHADE_MODEL_LAMBERT );
- BIND_CONSTANT( SHADE_MODEL_LAMBERT_WRAP );
- BIND_CONSTANT( SHADE_MODEL_FRESNEL );
- BIND_CONSTANT( SHADE_MODEL_TOON );
- BIND_CONSTANT( SHADE_MODEL_CUSTOM_0 );
- BIND_CONSTANT( SHADE_MODEL_CUSTOM_1 );
- BIND_CONSTANT( SHADE_MODEL_CUSTOM_2 );
- BIND_CONSTANT( SHADE_MODEL_CUSTOM_3 );
+ BIND_CONSTANT( DEPTH_DRAW_ALWAYS );
+ BIND_CONSTANT( DEPTH_DRAW_OPAQUE_ONLY );
+ BIND_CONSTANT( DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA );
+ BIND_CONSTANT( DEPTH_DRAW_NEVER );
BIND_CONSTANT( BLEND_MODE_MIX );
BIND_CONSTANT( BLEND_MODE_ADD );
@@ -205,15 +156,11 @@ Material::Material(const RID& p_material) {
flags[FLAG_INVERT_FACES]=false;
flags[FLAG_UNSHADED]=false;
flags[FLAG_ONTOP]=false;
- flags[FLAG_WIREFRAME]=false;
- flags[FLAG_BILLBOARD_TOGGLE]=false;
- for(int i=0;i<HINT_MAX;i++)
- hints[i]=false;
- hints[HINT_NO_DEPTH_DRAW_FOR_ALPHA]=true;
+ depth_draw_mode=DEPTH_DRAW_OPAQUE_ONLY;
blend_mode=BLEND_MODE_MIX;
- shade_model = SHADE_MODEL_LAMBERT;
+
}
Material::~Material() {
@@ -340,6 +287,17 @@ FixedMaterial::TexCoordMode FixedMaterial::get_texcoord_mode(Parameter p_paramet
return texture_texcoord[p_parameter];
}
+void FixedMaterial::set_light_shader(LightShader p_shader) {
+
+ light_shader=p_shader;
+ VS::get_singleton()->fixed_material_set_light_shader(material,VS::FixedMaterialLightShader(p_shader));
+}
+
+FixedMaterial::LightShader FixedMaterial::get_light_shader() const {
+
+ return light_shader;
+}
+
void FixedMaterial::set_uv_transform(const Transform& p_transform) {
@@ -356,16 +314,6 @@ Transform FixedMaterial::get_uv_transform() const {
-void FixedMaterial::set_detail_blend_mode(BlendMode p_mode) {
-
- detail_blend_mode=p_mode;
- VS::get_singleton()->fixed_material_set_detail_blend_mode(material,(VS::MaterialBlendMode)p_mode);
-}
-
-Material::BlendMode FixedMaterial::get_detail_blend_mode() const {
-
- return detail_blend_mode;
-}
void FixedMaterial::set_fixed_flag(FixedFlag p_flag, bool p_value) {
ERR_FAIL_INDEX(p_flag,4);
@@ -412,12 +360,12 @@ void FixedMaterial::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_uv_transform","transform"),&FixedMaterial::set_uv_transform);
ObjectTypeDB::bind_method(_MD("get_uv_transform"),&FixedMaterial::get_uv_transform);
+ ObjectTypeDB::bind_method(_MD("set_light_shader","shader"),&FixedMaterial::set_light_shader);
+ ObjectTypeDB::bind_method(_MD("get_light_shader"),&FixedMaterial::get_light_shader);
ObjectTypeDB::bind_method(_MD("set_point_size","size"),&FixedMaterial::set_point_size);
ObjectTypeDB::bind_method(_MD("get_point_size"),&FixedMaterial::get_point_size);
- ObjectTypeDB::bind_method(_MD("set_detail_blend_mode","mode"),&FixedMaterial::set_detail_blend_mode);
- ObjectTypeDB::bind_method(_MD("get_detail_blend_mode"),&FixedMaterial::get_detail_blend_mode);
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "fixed_flags/use_alpha" ), _SCS("set_fixed_flag"), _SCS("get_fixed_flag"), FLAG_USE_ALPHA);
ADD_PROPERTYI( PropertyInfo( Variant::BOOL, "fixed_flags/use_color_array" ), _SCS("set_fixed_flag"), _SCS("get_fixed_flag"), FLAG_USE_COLOR_ARRAY);
@@ -427,11 +375,10 @@ void FixedMaterial::_bind_methods() {
ADD_PROPERTYI( PropertyInfo( Variant::COLOR, "params/specular", PROPERTY_HINT_COLOR_NO_ALPHA ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SPECULAR );
ADD_PROPERTYI( PropertyInfo( Variant::COLOR, "params/emission", PROPERTY_HINT_COLOR_NO_ALPHA ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_EMISSION );
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/specular_exp", PROPERTY_HINT_RANGE,"1,64,0.01" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SPECULAR_EXP );
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "params/detail_blend", PROPERTY_HINT_ENUM,"Mix,Add,Sub,Mul" ), _SCS("set_detail_blend_mode"), _SCS("get_detail_blend_mode") );
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/detail_mix", PROPERTY_HINT_RANGE,"0,1,0.01" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_DETAIL );
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/normal_depth", PROPERTY_HINT_RANGE,"-4,4,0.01" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_NORMAL );
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/shade_param", PROPERTY_HINT_RANGE,"0,1,0.01" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SHADE_PARAM );
-
+ ADD_PROPERTY( PropertyInfo( Variant::INT, "params/shader", PROPERTY_HINT_ENUM,"Lambert,Wrap,Velvet,Toon" ), _SCS("set_light_shader"), _SCS("get_light_shader") );
+ ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/shader_param", PROPERTY_HINT_RANGE,"0,1,0.01" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_SHADE_PARAM );
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "params/glow", PROPERTY_HINT_RANGE,"0,8,0.01" ), _SCS("set_parameter"), _SCS("get_parameter"), PARAM_GLOW );
ADD_PROPERTY( PropertyInfo( Variant::REAL, "params/point_size", PROPERTY_HINT_RANGE,"0,1024,1" ), _SCS("set_point_size"), _SCS("get_point_size"));
ADD_PROPERTY( PropertyInfo( Variant::TRANSFORM, "uv_xform"), _SCS("set_uv_transform"), _SCS("get_uv_transform") );
@@ -479,7 +426,7 @@ FixedMaterial::FixedMaterial() : Material(VS::get_singleton()->fixed_material_cr
param[PARAM_SHADE_PARAM]=0.5;
param[PARAM_DETAIL]=1.0;
- detail_blend_mode=BLEND_MODE_MIX;
+
fixed_flags[FLAG_USE_ALPHA]=false;
fixed_flags[FLAG_USE_COLOR_ARRAY]=false;
@@ -490,6 +437,8 @@ FixedMaterial::FixedMaterial() : Material(VS::get_singleton()->fixed_material_cr
texture_texcoord[i]=TEXCOORD_UV;
}
+ light_shader=LIGHT_SHADER_LAMBERT;
+
point_size=1.0;
}
@@ -633,7 +582,7 @@ ParticleSystemMaterial::ParticleSystemMaterial() :Material(VisualServer::get_sin
set_flag(FLAG_DOUBLE_SIDED,true);
set_flag(FLAG_UNSHADED,true);
- set_hint(HINT_NO_DEPTH_DRAW,true);
+ set_depth_draw_mode(DEPTH_DRAW_NEVER);
VisualServer::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_ALPHA,true);
VisualServer::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true);
}
@@ -680,7 +629,8 @@ void UnshadedMaterial::set_use_alpha(bool p_use_alpha) {
alpha=p_use_alpha;
VS::get_singleton()->fixed_material_set_flag(material,VS::FIXED_MATERIAL_FLAG_USE_ALPHA,p_use_alpha);
- set_hint(HINT_NO_DEPTH_DRAW,p_use_alpha);
+ //set_depth_draw_mode();
+ //set_hint(HINT,p_use_alpha);
}
diff --git a/scene/resources/material.h b/scene/resources/material.h
index 2057b3cac9..23ecb18fac 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -53,23 +53,10 @@ public:
FLAG_INVERT_FACES = VS::MATERIAL_FLAG_INVERT_FACES,
FLAG_UNSHADED = VS::MATERIAL_FLAG_UNSHADED,
FLAG_ONTOP = VS::MATERIAL_FLAG_ONTOP,
- FLAG_WIREFRAME = VS::MATERIAL_FLAG_WIREFRAME,
- FLAG_BILLBOARD_TOGGLE = VS::MATERIAL_FLAG_BILLBOARD,
+ FLAG_LIGHTMAP_ON_UV2 = VS::MATERIAL_FLAG_LIGHTMAP_ON_UV2,
FLAG_MAX = VS::MATERIAL_FLAG_MAX
};
- enum ShadeModel {
- SHADE_MODEL_LAMBERT,
- SHADE_MODEL_LAMBERT_WRAP,
- SHADE_MODEL_FRESNEL,
- SHADE_MODEL_TOON,
- SHADE_MODEL_CUSTOM_0,
- SHADE_MODEL_CUSTOM_1,
- SHADE_MODEL_CUSTOM_2,
- SHADE_MODEL_CUSTOM_3
- };
-
-
enum BlendMode {
BLEND_MODE_MIX = VS::MATERIAL_BLEND_MODE_MIX,
BLEND_MODE_MUL = VS::MATERIAL_BLEND_MODE_MUL,
@@ -79,23 +66,20 @@ public:
};
- enum Hint {
-
- HINT_DECAL=VS::MATERIAL_HINT_DECAL,
- HINT_OPAQUE_PRE_PASS=VS::MATERIAL_HINT_OPAQUE_PRE_PASS,
- HINT_NO_SHADOW=VS::MATERIAL_HINT_NO_SHADOW,
- HINT_NO_DEPTH_DRAW=VS::MATERIAL_HINT_NO_DEPTH_DRAW,
- HINT_NO_DEPTH_DRAW_FOR_ALPHA=VS::MATERIAL_HINT_NO_DEPTH_DRAW_FOR_ALPHA,
- HINT_MAX=VS::MATERIAL_HINT_MAX
+ enum DepthDrawMode {
+ DEPTH_DRAW_ALWAYS = VS::MATERIAL_DEPTH_DRAW_ALWAYS,
+ DEPTH_DRAW_OPAQUE_ONLY = VS::MATERIAL_DEPTH_DRAW_OPAQUE_ONLY,
+ DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA = VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA,
+ DEPTH_DRAW_NEVER = VS::MATERIAL_DEPTH_DRAW_NEVER
};
+
private:
BlendMode blend_mode;
bool flags[VS::MATERIAL_FLAG_MAX];
- bool hints[VS::MATERIAL_HINT_MAX];
- ShadeModel shade_model;
float line_width;
+ DepthDrawMode depth_draw_mode;
protected:
RID material;
@@ -105,18 +89,15 @@ public:
void set_flag(Flag p_flag,bool p_enabled);
bool get_flag(Flag p_flag) const;
- void set_hint(Hint p_hint,bool p_enabled);
- bool get_hint(Hint p_hint) const;
-
void set_blend_mode(BlendMode p_blend_mode);
BlendMode get_blend_mode() const;
+ void set_depth_draw_mode(DepthDrawMode p_depth_draw_mode);
+ DepthDrawMode get_depth_draw_mode() const;
+
void set_line_width(float p_width);
float get_line_width() const;
- void set_shade_model(ShadeModel p_model);
- ShadeModel get_shade_model() const;
-
virtual RID get_rid() const;
Material(const RID& p_rid=RID());
@@ -124,8 +105,8 @@ public:
};
VARIANT_ENUM_CAST( Material::Flag );
-VARIANT_ENUM_CAST( Material::Hint );
-VARIANT_ENUM_CAST( Material::ShadeModel);
+VARIANT_ENUM_CAST( Material::DepthDrawMode );
+
VARIANT_ENUM_CAST( Material::BlendMode );
@@ -163,6 +144,14 @@ public:
FLAG_DISCARD_ALPHA=VS::FIXED_MATERIAL_FLAG_DISCARD_ALPHA
};
+ enum LightShader {
+
+ LIGHT_SHADER_LAMBERT=VS::FIXED_MATERIAL_LIGHT_SHADER_LAMBERT,
+ LIGHT_SHADER_WRAP=VS::FIXED_MATERIAL_LIGHT_SHADER_WRAP,
+ LIGHT_SHADER_VELVET=VS::FIXED_MATERIAL_LIGHT_SHADER_VELVET,
+ LIGHT_SHADER_TOON=VS::FIXED_MATERIAL_LIGHT_SHADER_TOON
+ };
+
private:
@@ -173,10 +162,10 @@ private:
int tex;
};
- BlendMode detail_blend_mode;
Variant param[PARAM_MAX];
Ref<Texture> texture_param[PARAM_MAX];
TexCoordMode texture_texcoord[PARAM_MAX];
+ LightShader light_shader;
bool fixed_flags[3];
float point_size;
@@ -203,15 +192,15 @@ public:
void set_texcoord_mode(Parameter p_parameter, TexCoordMode p_mode);
TexCoordMode get_texcoord_mode(Parameter p_parameter) const;
+ void set_light_shader(LightShader p_shader);
+ LightShader get_light_shader() const;
+
void set_uv_transform(const Transform& p_transform);
Transform get_uv_transform() const;
void set_point_size(float p_transform);
float get_point_size() const;
- void set_detail_blend_mode(BlendMode p_mode);
- BlendMode get_detail_blend_mode() const;
-
FixedMaterial();
~FixedMaterial();
@@ -222,6 +211,7 @@ public:
VARIANT_ENUM_CAST( FixedMaterial::Parameter );
VARIANT_ENUM_CAST( FixedMaterial::TexCoordMode );
VARIANT_ENUM_CAST( FixedMaterial::FixedFlag );
+VARIANT_ENUM_CAST( FixedMaterial::LightShader );
class ShaderMaterial : public Material {
diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp
index 9f7b6d5b9e..afb0ae1815 100644
--- a/scene/resources/polygon_path_finder.cpp
+++ b/scene/resources/polygon_path_finder.cpp
@@ -2,7 +2,7 @@
#include "geometry.h"
-bool PolygonPathFinder::_is_point_inside(const Vector2& p_point) {
+bool PolygonPathFinder::_is_point_inside(const Vector2& p_point) const {
int crosses=0;
@@ -36,13 +36,21 @@ void PolygonPathFinder::setup(const Vector<Vector2>& p_points, const Vector<int>
int point_count=p_points.size();
points.resize(point_count+2);
+ bounds=Rect2();
for(int i=0;i<p_points.size();i++) {
points[i].pos=p_points[i];
+ points[i].penalty=0;
outside_point.x = i==0?p_points[0].x:(MAX( p_points[i].x, outside_point.x ));
outside_point.y = i==0?p_points[0].y:(MAX( p_points[i].y, outside_point.y ));
+
+ if (i==0) {
+ bounds.pos=points[i].pos;
+ } else {
+ bounds.expand_to(points[i].pos);
+ }
}
outside_point.x+=20.451+Math::randf()*10.2039;
@@ -108,10 +116,63 @@ void PolygonPathFinder::setup(const Vector<Vector2>& p_points, const Vector<int>
Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector2& p_to) {
Vector<Vector2> path;
- if (!_is_point_inside(p_from))
- return path;
- if (!_is_point_inside(p_to))
- return path;
+
+ Vector2 from=p_from;
+ Vector2 to=p_to;
+ Edge ignore_from_edge(-1,-1);
+ Edge ignore_to_edge(-1,-1);
+
+ if (!_is_point_inside(from)) {
+
+ float closest_dist=1e20;
+ Vector2 closest_point;
+
+ for (Set<Edge>::Element *E=edges.front();E;E=E->next()) {
+
+ const Edge& e=E->get();
+ Vector2 seg[2]={
+ points[e.points[0]].pos,
+ points[e.points[1]].pos
+ };
+
+
+ Vector2 closest = Geometry::get_closest_point_to_segment_2d(from,seg);
+ float d = from.distance_squared_to(closest);
+
+ if (d<closest_dist) {
+ ignore_from_edge=E->get();
+ closest_dist=d;
+ }
+ }
+
+ from=closest_point;
+ };
+
+
+ if (!_is_point_inside(to)) {
+ float closest_dist=1e20;
+ Vector2 closest_point;
+
+ for (Set<Edge>::Element *E=edges.front();E;E=E->next()) {
+
+ const Edge& e=E->get();
+ Vector2 seg[2]={
+ points[e.points[0]].pos,
+ points[e.points[1]].pos
+ };
+
+
+ Vector2 closest = Geometry::get_closest_point_to_segment_2d(to,seg);
+ float d = to.distance_squared_to(closest);
+
+ if (d<closest_dist) {
+ ignore_to_edge=E->get();
+ closest_dist=d;
+ }
+ }
+
+ to=closest_point;
+ };
//test direct connection
{
@@ -121,11 +182,16 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector
for (Set<Edge>::Element *E=edges.front();E;E=E->next()) {
const Edge& e=E->get();
+ if (e.points[0]==ignore_from_edge.points[0] && e.points[1]==ignore_from_edge.points[1])
+ continue;
+ if (e.points[0]==ignore_to_edge.points[0] && e.points[1]==ignore_to_edge.points[1])
+ continue;
+
Vector2 a = points[e.points[0]].pos;
Vector2 b = points[e.points[1]].pos;
- if (Geometry::segment_intersects_segment_2d(a,b,p_from,p_to,NULL)) {
+ if (Geometry::segment_intersects_segment_2d(a,b,from,to,NULL)) {
can_see_eachother=false;
break;
}
@@ -134,8 +200,8 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector
if (can_see_eachother) {
- path.push_back(p_from);
- path.push_back(p_to);
+ path.push_back(from);
+ path.push_back(to);
return path;
}
}
@@ -144,12 +210,15 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector
int aidx = points.size()-2;
int bidx = points.size()-1;
- points[aidx].pos=p_from;
- points[bidx].pos=p_to;
- points[aidx].distance=0;
- points[bidx].distance=0;
+ points[aidx].pos=from;
+ points[bidx].pos=to;
points[aidx].distance=0;
points[bidx].distance=0;
+ points[aidx].prev=-1;
+ points[bidx].prev=-1;
+ points[aidx].penalty=0;
+ points[bidx].penalty=0;
+
for(int i=0;i<points.size()-2;i++) {
@@ -160,6 +229,18 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector
points[i].prev=-1;
points[i].distance=0;
+ if (!_is_point_inside(from*0.5+points[i].pos*0.5)) {
+ valid_a=false;
+
+ }
+
+
+ if (!_is_point_inside(to*0.5+points[i].pos*0.5)) {
+ valid_b=false;
+
+ }
+
+
for (Set<Edge>::Element *E=edges.front();E;E=E->next()) {
const Edge& e=E->get();
@@ -167,28 +248,45 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector
if (e.points[0]==i || e.points[1]==i)
continue;
+
Vector2 a = points[e.points[0]].pos;
Vector2 b = points[e.points[1]].pos;
if (valid_a) {
- if (Geometry::segment_intersects_segment_2d(a,b,p_from,points[i].pos,NULL)) {
- valid_a=false;
+ if (e.points[0]!=ignore_from_edge.points[1] &&
+ e.points[1]!=ignore_from_edge.points[1] &&
+ e.points[0]!=ignore_from_edge.points[0] &&
+ e.points[1]!=ignore_from_edge.points[0]) {
+
+
+ if (Geometry::segment_intersects_segment_2d(a,b,from,points[i].pos,NULL)) {
+ valid_a=false;
+ }
}
}
if (valid_b) {
- if (Geometry::segment_intersects_segment_2d(a,b,p_to,points[i].pos,NULL)) {
- valid_b=false;
+ if (e.points[0]!=ignore_to_edge.points[1] &&
+ e.points[1]!=ignore_to_edge.points[1] &&
+ e.points[0]!=ignore_to_edge.points[0] &&
+ e.points[1]!=ignore_to_edge.points[0]) {
+
+
+ if (Geometry::segment_intersects_segment_2d(a,b,to,points[i].pos,NULL)) {
+ valid_b=false;
+ }
}
}
if (!valid_a && !valid_b)
- continue;
+ break;
+
}
+
if (valid_a) {
points[i].connections.insert(aidx);
points[aidx].connections.insert(i);
@@ -209,7 +307,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector
for(Set<int>::Element *E=points[aidx].connections.front();E;E=E->next()) {
open_list.insert(E->get());
- points[E->get()].distance=p_from.distance_to(points[E->get()].pos);
+ points[E->get()].distance=from.distance_to(points[E->get()].pos);
points[E->get()].prev=aidx;
}
@@ -220,6 +318,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector
while(true) {
if (open_list.size()==0) {
+ printf("open list empty\n");
break;
}
//check open list
@@ -232,7 +331,9 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector
const Point& p =points[E->get()];
float cost = p.distance;
- cost+=p.pos.distance_to(p_to);
+ cost+=p.pos.distance_to(to);
+ cost+=p.penalty;
+
if (cost<least_cost) {
least_cost_point=E->get();
@@ -315,6 +416,7 @@ void PolygonPathFinder::_set_data(const Dictionary& p_data) {
ERR_FAIL_COND(!p_data.has("points"));
ERR_FAIL_COND(!p_data.has("connections"));
ERR_FAIL_COND(!p_data.has("segments"));
+ ERR_FAIL_COND(!p_data.has("bounds"));
DVector<Vector2> p=p_data["points"];
Array c=p_data["connections"];
@@ -339,6 +441,17 @@ void PolygonPathFinder::_set_data(const Dictionary& p_data) {
}
+ if (p_data.has("penalties")) {
+
+ DVector<float> penalties=p_data["penalties"];
+ if (penalties.size()==pc) {
+ DVector<float>::Read pr = penalties.read();
+ for(int i=0;i<pc;i++) {
+ points[i].penalty=pr[i];
+ }
+ }
+ }
+
DVector<int> segs=p_data["segments"];
int sc=segs.size();
ERR_FAIL_COND(sc&1);
@@ -348,6 +461,7 @@ void PolygonPathFinder::_set_data(const Dictionary& p_data) {
Edge e(sr[i],sr[i+1]);
edges.insert(e);
}
+ bounds=p_data["bounds"];
}
@@ -360,10 +474,15 @@ Dictionary PolygonPathFinder::_get_data() const{
p.resize(points.size()-2);
connections.resize(points.size()-2);
ind.resize(edges.size()*2);
+ DVector<float> penalties;
+ penalties.resize(points.size()-2);
{
DVector<Vector2>::Write wp=p.write();
+ DVector<float>::Write pw=penalties.write();
+
for(int i=0;i<points.size()-2;i++) {
wp[i]=points[i].pos;
+ pw[i]=points[i].penalty;
DVector<int> c;
c.resize(points[i].connections.size());
{
@@ -387,7 +506,9 @@ Dictionary PolygonPathFinder::_get_data() const{
}
+ d["bounds"]=bounds;
d["points"]=p;
+ d["penalties"]=penalties;
d["connections"]=connections;
d["segments"]=ind;
@@ -395,10 +516,79 @@ Dictionary PolygonPathFinder::_get_data() const{
}
+bool PolygonPathFinder::is_point_inside(const Vector2& p_point) const {
+
+ return _is_point_inside(p_point);
+}
+
+Vector2 PolygonPathFinder::get_closest_point(const Vector2& p_point) const {
+
+ int closest_idx=-1;
+ float closest_dist=1e20;
+ for(int i=0;i<points.size()-2;i++) {
+
+ float d = p_point.distance_squared_to(points[i].pos);
+ if (d<closest_dist) {
+ d=closest_dist;
+ closest_idx=i;
+ }
+
+ }
+
+ ERR_FAIL_COND_V(closest_idx==-1,Vector2());
+
+ return points[closest_idx].pos;
+}
+
+
+Vector<Vector2> PolygonPathFinder::get_intersections(const Vector2& p_from, const Vector2& p_to) const {
+
+ Vector<Vector2> inters;
+
+ for (Set<Edge>::Element *E=edges.front();E;E=E->next()) {
+ Vector2 a = points[E->get().points[0]].pos;
+ Vector2 b = points[E->get().points[1]].pos;
+
+ Vector2 res;
+ if (Geometry::segment_intersects_segment_2d(a,b,p_from,p_to,&res)) {
+ inters.push_back(res);
+ }
+ }
+
+ return inters;
+
+}
+
+Rect2 PolygonPathFinder::get_bounds() const {
+
+ return bounds;
+}
+
+void PolygonPathFinder::set_point_penalty(int p_point,float p_penalty) {
+
+ ERR_FAIL_INDEX(p_point,points.size()-2);
+ points[p_point].penalty=p_penalty;
+}
+
+float PolygonPathFinder::get_point_penalty(int p_point) const {
+
+ ERR_FAIL_INDEX_V(p_point,points.size()-2,0);
+ return points[p_point].penalty;
+
+}
+
+
void PolygonPathFinder::_bind_methods() {
ObjectTypeDB::bind_method(_MD("setup","points","connections"),&PolygonPathFinder::setup);
ObjectTypeDB::bind_method(_MD("find_path","from","to"),&PolygonPathFinder::find_path);
+ ObjectTypeDB::bind_method(_MD("get_intersections","from","to"),&PolygonPathFinder::get_intersections);
+ ObjectTypeDB::bind_method(_MD("get_closest_point","point"),&PolygonPathFinder::get_closest_point);
+ ObjectTypeDB::bind_method(_MD("is_point_inside","point"),&PolygonPathFinder::is_point_inside);
+ ObjectTypeDB::bind_method(_MD("set_point_penalty","idx","penalty"),&PolygonPathFinder::set_point_penalty);
+ ObjectTypeDB::bind_method(_MD("get_point_penalty","idx"),&PolygonPathFinder::get_point_penalty);
+
+ ObjectTypeDB::bind_method(_MD("get_bounds"),&PolygonPathFinder::get_bounds);
ObjectTypeDB::bind_method(_MD("_set_data"),&PolygonPathFinder::_set_data);
ObjectTypeDB::bind_method(_MD("_get_data"),&PolygonPathFinder::_get_data);
diff --git a/scene/resources/polygon_path_finder.h b/scene/resources/polygon_path_finder.h
index 31253e3177..2cbe3e949d 100644
--- a/scene/resources/polygon_path_finder.h
+++ b/scene/resources/polygon_path_finder.h
@@ -11,6 +11,7 @@ class PolygonPathFinder : public Resource {
Vector2 pos;
Set<int> connections;
float distance;
+ float penalty;
int prev;
};
@@ -31,15 +32,18 @@ class PolygonPathFinder : public Resource {
if (a>b) {
SWAP(a,b);
}
+ points[0] = a;
+ points[1] = b;
}
};
Vector2 outside_point;
+ Rect2 bounds;
Vector<Point> points;
Set<Edge> edges;
- bool _is_point_inside(const Vector2& p_point);
+ bool _is_point_inside(const Vector2& p_point) const;
void _set_data(const Dictionary& p_data);
Dictionary _get_data() const;
@@ -52,6 +56,15 @@ public:
void setup(const Vector<Vector2>& p_points, const Vector<int>& p_connections);
Vector<Vector2> find_path(const Vector2& p_from, const Vector2& p_to);
+ void set_point_penalty(int p_point,float p_penalty);
+ float get_point_penalty(int p_point) const;
+
+ bool is_point_inside(const Vector2& p_point) const;
+ Vector2 get_closest_point(const Vector2& p_point) const;
+ Vector<Vector2> get_intersections(const Vector2& p_from, const Vector2& p_to) const;
+ Rect2 get_bounds() const;
+
+
PolygonPathFinder();
};
diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp
index ffdd92c2d1..6d65da3782 100644
--- a/scene/resources/shader.cpp
+++ b/scene/resources/shader.cpp
@@ -45,9 +45,9 @@ Shader::Mode Shader::get_mode() const {
return (Mode)VisualServer::get_singleton()->shader_get_mode(shader);
}
-void Shader::set_code( const String& p_vertex, const String& p_fragment, int p_vertex_ofs,int p_fragment_ofs) {
+void Shader::set_code( const String& p_vertex, const String& p_fragment, const String& p_light,int p_fragment_ofs,int p_light_ofs) {
- VisualServer::get_singleton()->shader_set_code(shader,p_vertex,p_fragment,p_vertex_ofs,p_fragment_ofs);
+ VisualServer::get_singleton()->shader_set_code(shader,p_vertex,p_fragment,p_light,0,p_fragment_ofs,p_light_ofs);
params_cache_dirty=true;
emit_signal(SceneStringNames::get_singleton()->changed);
}
@@ -64,6 +64,11 @@ String Shader::get_fragment_code() const {
}
+String Shader::get_light_code() const {
+
+ return VisualServer::get_singleton()->shader_get_light_code(shader);
+
+}
bool Shader::has_param(const StringName& p_param) const {
@@ -106,12 +111,15 @@ Dictionary Shader::_get_code() {
String fs = VisualServer::get_singleton()->shader_get_fragment_code(shader);
String vs = VisualServer::get_singleton()->shader_get_vertex_code(shader);
+ String ls = VisualServer::get_singleton()->shader_get_light_code(shader);
Dictionary c;
c["fragment"]=fs;
c["fragment_ofs"]=0;
c["vertex"]=vs;
c["vertex_ofs"]=0;
+ c["light"]=ls;
+ c["light_ofs"]=0;
return c;
}
@@ -119,8 +127,11 @@ void Shader::_set_code(const Dictionary& p_string) {
ERR_FAIL_COND(!p_string.has("fragment"));
ERR_FAIL_COND(!p_string.has("vertex"));
+ String light;
+ if (p_string.has("light"))
+ light=p_string["light"];
- set_code(p_string["vertex"],p_string["fragment"]);
+ set_code(p_string["vertex"],p_string["fragment"],light);
}
void Shader::_bind_methods() {
@@ -128,9 +139,10 @@ void Shader::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_mode","mode"),&Shader::set_mode);
ObjectTypeDB::bind_method(_MD("get_mode"),&Shader::get_mode);
- ObjectTypeDB::bind_method(_MD("set_code","vcode","fcode","vofs","fofs"),&Shader::set_code,DEFVAL(0),DEFVAL(0));
+ ObjectTypeDB::bind_method(_MD("set_code","vcode","fcode","lcode","fofs","lofs"),&Shader::set_code,DEFVAL(0),DEFVAL(0));
ObjectTypeDB::bind_method(_MD("get_vertex_code"),&Shader::get_vertex_code);
ObjectTypeDB::bind_method(_MD("get_fragment_code"),&Shader::get_fragment_code);
+ ObjectTypeDB::bind_method(_MD("get_light_code"),&Shader::get_light_code);
ObjectTypeDB::bind_method(_MD("has_param","name"),&Shader::has_param);
@@ -169,6 +181,7 @@ RES ResourceFormatLoaderShader::load(const String &p_path,const String& p_origin
String fragment_code;
String vertex_code;
+ String light_code;
int mode=-1;
@@ -377,7 +390,7 @@ RES ResourceFormatLoaderShader::load(const String &p_path,const String& p_origin
}
}
- shader->set_code(vertex_code,fragment_code);
+ shader->set_code(vertex_code,fragment_code,light_code);
f->close();
memdelete(f);
diff --git a/scene/resources/shader.h b/scene/resources/shader.h
index d04774dada..fff6f1d28a 100644
--- a/scene/resources/shader.h
+++ b/scene/resources/shader.h
@@ -64,9 +64,10 @@ public:
void set_mode(Mode p_mode);
Mode get_mode() const;
- void set_code( const String& p_vertex, const String& p_fragment, int p_vertex_ofs=0,int p_fragment_ofs=0);
+ void set_code( const String& p_vertex, const String& p_fragment, const String& p_light,int p_fragment_ofs=0,int p_light_ofs=0);
String get_vertex_code() const;
String get_fragment_code() const;
+ String get_light_code() const;
void get_param_list(List<PropertyInfo> *p_params) const;
bool has_param(const StringName& p_param) const;