summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-12-02 22:23:16 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-12-02 22:23:16 -0300
commit27a46d78ec43b69a70a1d84c540353e3cb3b04c0 (patch)
treedc4fc077c325b26d6f7a159419fe4ca55bc29783 /scene
parent8c6a586b75692eaa67ddaf4bb73edf325cc60e5d (diff)
Subsurface scattering material param is now working!
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/light.cpp2
-rw-r--r--scene/resources/material.cpp37
-rw-r--r--scene/resources/material.h8
3 files changed, 31 insertions, 16 deletions
diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp
index 49bffd3c21..7177e21e1e 100644
--- a/scene/3d/light.cpp
+++ b/scene/3d/light.cpp
@@ -218,7 +218,7 @@ void Light::_bind_methods() {
ADD_PROPERTY( PropertyInfo( Variant::INT, "light/cull_mask",PROPERTY_HINT_ALL_FLAGS), _SCS("set_cull_mask"), _SCS("get_cull_mask"));
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "shadow/enabled"), _SCS("set_shadow"), _SCS("has_shadow"));
ADD_PROPERTY( PropertyInfo( Variant::COLOR, "shadow/color",PROPERTY_HINT_COLOR_NO_ALPHA), _SCS("set_shadow_color"), _SCS("get_shadow_color"));
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow/bias",PROPERTY_HINT_RANGE,"0,16,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_BIAS);
+ ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow/bias",PROPERTY_HINT_RANGE,"-16,16,0.01"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_BIAS);
ADD_PROPERTYI( PropertyInfo( Variant::REAL, "shadow/max_distance",PROPERTY_HINT_RANGE,"0,65536,0.1"), _SCS("set_param"), _SCS("get_param"), PARAM_SHADOW_MAX_DISTANCE);
ADD_PROPERTY( PropertyInfo( Variant::BOOL, "editor/editor_only"), _SCS("set_editor_only"), _SCS("is_editor_only"));
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 99b7a130f7..70afd68113 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -72,7 +72,7 @@ void FixedSpatialMaterial::init_shaders() {
shader_names->clearcoat_gloss="clearcoat_gloss";
shader_names->anisotropy="anisotropy_ratio";
shader_names->height_scale="height_scale";
- shader_names->subsurface_scattering="subsurface_scattering";
+ shader_names->subsurface_scattering_strength="subsurface_scattering_strength";
shader_names->refraction="refraction";
shader_names->refraction_roughness="refraction_roughness";
shader_names->point_size="point_size";
@@ -217,6 +217,14 @@ void FixedSpatialMaterial::_update_shader() {
code+="uniform sampler2D texture_detail_mask : hint_white;\n";
}
+ if (features[FEATURE_SUBSURACE_SCATTERING]) {
+
+ code+="uniform float subsurface_scattering_strength : hint_range(0,1);\n";
+ code+="uniform sampler2D texture_subsurface_scattering : hint_white;\n";
+
+ }
+
+
code+="\n\n";
code+="void vertex() {\n";
@@ -230,7 +238,7 @@ void FixedSpatialMaterial::_update_shader() {
code+="\tPOINT_SIZE=point_size;\n";
}
code+="\tUV=UV*uv1_scale+uv1_offset;\n";
- if (detail_blend_mode==DETAIL_UV_2) {
+ if (detail_uv==DETAIL_UV_2) {
code+="\tUV2=UV2*uv2_scale+uv2_offset;\n";
}
@@ -284,6 +292,12 @@ void FixedSpatialMaterial::_update_shader() {
code+="\tAO = texture(texture_ambient_occlusion,UV).r;\n";
}
+ if (features[FEATURE_SUBSURACE_SCATTERING]) {
+
+ code+="\tfloat sss_tex = texture(texture_subsurface_scattering,UV).r;\n";
+ code+="\tSSS_STRENGTH=subsurface_scattering_strength*sss_tex;\n";
+ }
+
if (features[FEATURE_DETAIL]) {
String det_uv=detail_uv==DETAIL_UV_1?"UV":"UV2";
code+="\tvec4 detail_tex = texture(texture_detail_albedo,"+det_uv+");\n";
@@ -512,17 +526,18 @@ float FixedSpatialMaterial::get_height_scale() const{
return height_scale;
}
-void FixedSpatialMaterial::set_subsurface_scattering(float p_subsurface_scattering){
- subsurface_scattering=p_subsurface_scattering;
- VS::get_singleton()->material_set_param(_get_material(),shader_names->subsurface_scattering,subsurface_scattering);
+void FixedSpatialMaterial::set_subsurface_scattering_strength(float p_subsurface_scattering_strength){
+
+ subsurface_scattering_strength=p_subsurface_scattering_strength;
+ VS::get_singleton()->material_set_param(_get_material(),shader_names->subsurface_scattering_strength,subsurface_scattering_strength);
}
-float FixedSpatialMaterial::get_subsurface_scattering() const{
+float FixedSpatialMaterial::get_subsurface_scattering_strength() const{
- return subsurface_scattering;
+ return subsurface_scattering_strength;
}
void FixedSpatialMaterial::set_refraction(float p_refraction){
@@ -806,8 +821,8 @@ void FixedSpatialMaterial::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_height_scale","height_scale"),&FixedSpatialMaterial::set_height_scale);
ObjectTypeDB::bind_method(_MD("get_height_scale"),&FixedSpatialMaterial::get_height_scale);
- ObjectTypeDB::bind_method(_MD("set_subsurface_scattering","subsurface_scattering"),&FixedSpatialMaterial::set_subsurface_scattering);
- ObjectTypeDB::bind_method(_MD("get_subsurface_scattering"),&FixedSpatialMaterial::get_subsurface_scattering);
+ ObjectTypeDB::bind_method(_MD("set_subsurface_scattering_strength","strength"),&FixedSpatialMaterial::set_subsurface_scattering_strength);
+ ObjectTypeDB::bind_method(_MD("get_subsurface_scattering_strength"),&FixedSpatialMaterial::get_subsurface_scattering_strength);
ObjectTypeDB::bind_method(_MD("set_refraction","refraction"),&FixedSpatialMaterial::set_refraction);
ObjectTypeDB::bind_method(_MD("get_refraction"),&FixedSpatialMaterial::get_refraction);
@@ -912,7 +927,7 @@ void FixedSpatialMaterial::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT,"height/texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture"),TEXTURE_HEIGHT);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL,"subsurf_scatter/enabled"),_SCS("set_feature"),_SCS("get_feature"),FEATURE_SUBSURACE_SCATTERING);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"subsurf_scatter/amount",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_subsurface_scattering"),_SCS("get_subsurface_scattering"));
+ ADD_PROPERTY(PropertyInfo(Variant::REAL,"subsurf_scatter/strength",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_subsurface_scattering_strength"),_SCS("get_subsurface_scattering_strength"));
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT,"subsurf_scatter/texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture"),TEXTURE_SUBSURFACE_SCATTERING);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL,"refraction/enabled"),_SCS("set_feature"),_SCS("get_feature"),FEATURE_REFRACTION);
@@ -1011,7 +1026,7 @@ FixedSpatialMaterial::FixedSpatialMaterial() : element(this) {
set_clearcoat_gloss(0.5);
set_anisotropy(0);
set_height_scale(1);
- set_subsurface_scattering(0);
+ set_subsurface_scattering_strength(0);
set_refraction(0);
set_refraction_roughness(0);
set_line_width(1);
diff --git a/scene/resources/material.h b/scene/resources/material.h
index 15c5910a9c..9b80b67691 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -213,7 +213,7 @@ private:
StringName clearcoat_gloss;
StringName anisotropy;
StringName height_scale;
- StringName subsurface_scattering;
+ StringName subsurface_scattering_strength;
StringName refraction;
StringName refraction_roughness;
StringName point_size;
@@ -247,7 +247,7 @@ private:
float clearcoat_gloss;
float anisotropy;
float height_scale;
- float subsurface_scattering;
+ float subsurface_scattering_strength;
float refraction;
float refraction_roughness;
float line_width;
@@ -318,8 +318,8 @@ public:
void set_height_scale(float p_height_scale);
float get_height_scale() const;
- void set_subsurface_scattering(float p_subsurface_scattering);
- float get_subsurface_scattering() const;
+ void set_subsurface_scattering_strength(float p_strength);
+ float get_subsurface_scattering_strength() const;
void set_refraction(float p_refraction);
float get_refraction() const;