Merge pull request #20787 from Calinou/tweak-default-material-properties

Tweak the default SpatialMaterial properties
This commit is contained in:
Juan Linietsky 2018-08-08 09:44:31 -03:00 committed by GitHub
commit 913a7dbd8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 52 deletions

View file

@ -181,7 +181,7 @@ void main() {
#else #else
// look up transform from the "pose texture" // look up transform from the "pose texture"
{ {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
ivec2 tex_ofs = ivec2(int(bone_ids[i]) * 3, 0); ivec2 tex_ofs = ivec2(int(bone_ids[i]) * 3, 0);
@ -252,7 +252,7 @@ VERTEX_SHADER_CODE
float z_ofs = light_bias; float z_ofs = light_bias;
z_ofs += (1.0 - abs(normal_interp.z)) * light_normal_bias; z_ofs += (1.0 - abs(normal_interp.z)) * light_normal_bias;
vertex_interp.z -= z_ofs; vertex_interp.z -= z_ofs;
#endif #endif
@ -460,7 +460,7 @@ float sample_shadow(highp sampler2D shadow,
vec4 clamp_rect) vec4 clamp_rect)
{ {
// vec4 depth_value = texture2D(shadow, pos); // vec4 depth_value = texture2D(shadow, pos);
// return depth_value.z; // return depth_value.z;
return texture2DProj(shadow, vec4(pos, depth, 1.0)).r; return texture2DProj(shadow, vec4(pos, depth, 1.0)).r;
// return (depth_value.x + depth_value.y + depth_value.z + depth_value.w) / 4.0; // return (depth_value.x + depth_value.y + depth_value.z + depth_value.w) / 4.0;
@ -469,22 +469,22 @@ float sample_shadow(highp sampler2D shadow,
#endif #endif
void main() void main()
{ {
highp vec3 vertex = vertex_interp; highp vec3 vertex = vertex_interp;
vec3 albedo = vec3(0.8, 0.8, 0.8); vec3 albedo = vec3(1.0);
vec3 transmission = vec3(0.0); vec3 transmission = vec3(0.0);
float metallic = 0.0; float metallic = 0.0;
float specular = 0.5; float specular = 0.5;
vec3 emission = vec3(0.0, 0.0, 0.0); vec3 emission = vec3(0.0);
float roughness = 1.0; float roughness = 1.0;
float rim = 0.0; float rim = 0.0;
float rim_tint = 0.0; float rim_tint = 0.0;
float clearcoat = 0.0; float clearcoat = 0.0;
float clearcoat_gloss = 0.0; float clearcoat_gloss = 0.0;
float anisotropy = 1.0; float anisotropy = 0.0;
vec2 anisotropy_flow = vec2(1.0,0.0); vec2 anisotropy_flow = vec2(1.0, 0.0);
float alpha = 1.0; float alpha = 1.0;
float side = 1.0; float side = 1.0;
@ -536,7 +536,7 @@ FRAGMENT_SHADER_CODE
normal = normalize(normal); normal = normalize(normal);
vec3 N = normal; vec3 N = normal;
vec3 specular_light = vec3(0.0, 0.0, 0.0); vec3 specular_light = vec3(0.0, 0.0, 0.0);
vec3 diffuse_light = vec3(0.0, 0.0, 0.0); vec3 diffuse_light = vec3(0.0, 0.0, 0.0);
@ -551,7 +551,7 @@ FRAGMENT_SHADER_CODE
discard; discard;
} }
#endif #endif
// //
// Lighting // Lighting
// //
@ -621,11 +621,11 @@ FRAGMENT_SHADER_CODE
vec3 light_vec = -light_direction; vec3 light_vec = -light_direction;
vec3 attenuation = vec3(1.0, 1.0, 1.0); vec3 attenuation = vec3(1.0, 1.0, 1.0);
float depth_z = -vertex.z; float depth_z = -vertex.z;
if (light_has_shadow > 0.5) { if (light_has_shadow > 0.5) {
#ifdef LIGHT_USE_PSSM4 #ifdef LIGHT_USE_PSSM4
if (depth_z < light_split_offsets.w) { if (depth_z < light_split_offsets.w) {
#elif defined(LIGHT_USE_PSSM2) #elif defined(LIGHT_USE_PSSM2)
@ -633,36 +633,36 @@ FRAGMENT_SHADER_CODE
#else #else
if (depth_z < light_split_offsets.x) { if (depth_z < light_split_offsets.x) {
#endif #endif
vec3 pssm_coord; vec3 pssm_coord;
float pssm_fade = 0.0; float pssm_fade = 0.0;
#ifdef LIGHT_USE_PSSM_BLEND #ifdef LIGHT_USE_PSSM_BLEND
float pssm_blend; float pssm_blend;
vec3 pssm_coord2; vec3 pssm_coord2;
bool use_blend = true; bool use_blend = true;
#endif #endif
#ifdef LIGHT_USE_PSSM4 #ifdef LIGHT_USE_PSSM4
if (depth_z < light_split_offsets.y) { if (depth_z < light_split_offsets.y) {
if (depth_z < light_split_offsets.x) { if (depth_z < light_split_offsets.x) {
highp vec4 splane = (light_shadow_matrix1 * vec4(vertex, 1.0)); highp vec4 splane = (light_shadow_matrix1 * vec4(vertex, 1.0));
pssm_coord = splane.xyz / splane.w; pssm_coord = splane.xyz / splane.w;
#ifdef LIGHT_USE_PSSM_BLEND #ifdef LIGHT_USE_PSSM_BLEND
splane = (light_shadow_matrix2 * vec4(vertex, 1.0)); splane = (light_shadow_matrix2 * vec4(vertex, 1.0));
pssm_coord2 = splane.xyz / splane.w; pssm_coord2 = splane.xyz / splane.w;
pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z); pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
#endif #endif
} else { } else {
highp vec4 splane = (light_shadow_matrix2 * vec4(vertex, 1.0)); highp vec4 splane = (light_shadow_matrix2 * vec4(vertex, 1.0));
pssm_coord = splane.xyz / splane.w; pssm_coord = splane.xyz / splane.w;
#ifdef LIGHT_USE_PSSM_BLEND #ifdef LIGHT_USE_PSSM_BLEND
splane = (light_shadow_matrix3 * vec4(vertex, 1.0)); splane = (light_shadow_matrix3 * vec4(vertex, 1.0));
pssm_coord2 = splane.xyz / splane.w; pssm_coord2 = splane.xyz / splane.w;
pssm_blend = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z); pssm_blend = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
#endif #endif
} }
@ -689,15 +689,15 @@ FRAGMENT_SHADER_CODE
#endif #endif
} }
} }
#endif // LIGHT_USE_PSSM4 #endif // LIGHT_USE_PSSM4
#ifdef LIGHT_USE_PSSM2 #ifdef LIGHT_USE_PSSM2
if (depth_z < light_split_offsets.x) { if (depth_z < light_split_offsets.x) {
highp vec4 splane = (light_shadow_matrix1 * vec4(vertex, 1.0)); highp vec4 splane = (light_shadow_matrix1 * vec4(vertex, 1.0));
pssm_coord = splane.xyz / splane.w; pssm_coord = splane.xyz / splane.w;
#ifdef LIGHT_USE_PSSM_BLEND #ifdef LIGHT_USE_PSSM_BLEND
splane = (light_shadow_matrix2 * vec4(vertex, 1.0)); splane = (light_shadow_matrix2 * vec4(vertex, 1.0));
pssm_coord2 = splane.xyz / splane.w; pssm_coord2 = splane.xyz / splane.w;
@ -711,29 +711,29 @@ FRAGMENT_SHADER_CODE
use_blend = false; use_blend = false;
#endif #endif
} }
#endif // LIGHT_USE_PSSM2 #endif // LIGHT_USE_PSSM2
#if !defined(LIGHT_USE_PSSM4) && !defined(LIGHT_USE_PSSM2) #if !defined(LIGHT_USE_PSSM4) && !defined(LIGHT_USE_PSSM2)
{ {
highp vec4 splane = (light_shadow_matrix1 * vec4(vertex, 1.0)); highp vec4 splane = (light_shadow_matrix1 * vec4(vertex, 1.0));
pssm_coord = splane.xyz / splane.w; pssm_coord = splane.xyz / splane.w;
} }
#endif #endif
float shadow = sample_shadow(light_shadow_atlas, vec2(0.0), pssm_coord.xy, pssm_coord.z, light_clamp); float shadow = sample_shadow(light_shadow_atlas, vec2(0.0), pssm_coord.xy, pssm_coord.z, light_clamp);
#ifdef LIGHT_USE_PSSM_BLEND #ifdef LIGHT_USE_PSSM_BLEND
if (use_blend) { if (use_blend) {
shadow = mix(shadow, sample_shadow(light_shadow_atlas, vec2(0.0), pssm_coord2.xy, pssm_coord2.z, light_clamp), pssm_blend); shadow = mix(shadow, sample_shadow(light_shadow_atlas, vec2(0.0), pssm_coord2.xy, pssm_coord2.z, light_clamp), pssm_blend);
} }
#endif #endif
attenuation *= shadow; attenuation *= shadow;
} }
} }
light_compute(normal, light_compute(normal,
@ -758,19 +758,19 @@ FRAGMENT_SHADER_CODE
} else if (light_type == LIGHT_TYPE_SPOT) { } else if (light_type == LIGHT_TYPE_SPOT) {
vec3 light_att = vec3(1.0); vec3 light_att = vec3(1.0);
if (light_has_shadow > 0.5) { if (light_has_shadow > 0.5) {
highp vec4 splane = (light_shadow_matrix * vec4(vertex, 1.0)); highp vec4 splane = (light_shadow_matrix * vec4(vertex, 1.0));
splane.xyz /= splane.w; splane.xyz /= splane.w;
float shadow = sample_shadow(light_shadow_atlas, vec2(0.0), splane.xy, splane.z, light_clamp); float shadow = sample_shadow(light_shadow_atlas, vec2(0.0), splane.xy, splane.z, light_clamp);
if (shadow > splane.z) { if (shadow > splane.z) {
} else { } else {
light_att = vec3(0.0); light_att = vec3(0.0);
} }
} }
vec3 light_rel_vec = light_position - vertex; vec3 light_rel_vec = light_position - vertex;
@ -788,7 +788,7 @@ FRAGMENT_SHADER_CODE
spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation); spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
light_att *= vec3(spot_attenuation); light_att *= vec3(spot_attenuation);
light_compute(normal, light_compute(normal,
normalize(light_rel_vec), normalize(light_rel_vec),
eye_position, eye_position,
@ -837,9 +837,9 @@ FRAGMENT_SHADER_CODE
} }
ambient_light *= ambient_energy; ambient_light *= ambient_energy;
specular_light += env_reflection_light; specular_light += env_reflection_light;
ambient_light *= albedo; ambient_light *= albedo;
#if defined(ENABLE_AO) #if defined(ENABLE_AO)
@ -848,12 +848,12 @@ FRAGMENT_SHADER_CODE
specular_light *= ao_light_affect; specular_light *= ao_light_affect;
diffuse_light *= ao_light_affect; diffuse_light *= ao_light_affect;
#endif #endif
diffuse_light *= 1.0 - metallic; diffuse_light *= 1.0 - metallic;
ambient_light *= 1.0 - metallic; ambient_light *= 1.0 - metallic;
// environment BRDF approximation // environment BRDF approximation
// TODO shadeless // TODO shadeless
{ {
const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022); const vec4 c0 = vec4(-1.0, -0.0275, -0.572, 0.022);

View file

@ -339,7 +339,7 @@ void main() {
#endif #endif
#endif #endif
float roughness=0.0; float roughness = 1.0;
//defines that make writing custom shaders easier //defines that make writing custom shaders easier
#define projection_matrix local_projection #define projection_matrix local_projection
@ -1608,18 +1608,18 @@ void main() {
//lay out everything, whathever is unused is optimized away anyway //lay out everything, whathever is unused is optimized away anyway
highp vec3 vertex = vertex_interp; highp vec3 vertex = vertex_interp;
vec3 albedo = vec3(0.8,0.8,0.8); vec3 albedo = vec3(1.0);
vec3 transmission = vec3(0.0); vec3 transmission = vec3(0.0);
float metallic = 0.0; float metallic = 0.0;
float specular = 0.5; float specular = 0.5;
vec3 emission = vec3(0.0,0.0,0.0); vec3 emission = vec3(0.0);
float roughness = 1.0; float roughness = 1.0;
float rim = 0.0; float rim = 0.0;
float rim_tint = 0.0; float rim_tint = 0.0;
float clearcoat=0.0; float clearcoat = 0.0;
float clearcoat_gloss=0.0; float clearcoat_gloss = 0.0;
float anisotropy = 1.0; float anisotropy = 0.0;
vec2 anisotropy_flow = vec2(1.0,0.0); vec2 anisotropy_flow = vec2(1.0, 0.0);
#if defined(ENABLE_AO) #if defined(ENABLE_AO)
float ao=1.0; float ao=1.0;

View file

@ -2106,10 +2106,10 @@ void SpatialMaterial::_bind_methods() {
SpatialMaterial::SpatialMaterial() : SpatialMaterial::SpatialMaterial() :
element(this) { element(this) {
//initialize to right values // Initialize to the same values as the shader
set_albedo(Color(1.0, 1.0, 1.0, 1.0)); set_albedo(Color(1.0, 1.0, 1.0, 1.0));
set_specular(0.5); set_specular(0.5);
set_roughness(0.0); set_roughness(1.0);
set_metallic(0.0); set_metallic(0.0);
set_emission(Color(0, 0, 0)); set_emission(Color(0, 0, 0));
set_emission_energy(1.0); set_emission_energy(1.0);