Parcourir la source

support 'transmission' in BSDF node

Jason0214 il y a 6 ans
Parent
commit
ef4184b5e7

+ 7 - 1
io_scene_godot/converters/material_node_tree/node_vistors.py

@@ -135,9 +135,15 @@ def visit_bsdf_node(shader, node):
         new_var = shader.define_variable(
             var_type, 'out_' + attr_name
         )
+        out_arguments.append(new_var)
 
+        if attr_name == "transmission" and "Transmission" in node.inputs:
+            # due to different implementation of transmission between
+            # godot and blender, only export it when it is set.
+            socket = node.inputs["Transmission"]
+            if not socket.is_linked and socket.default_value == 0.0:
+                continue
         output.set_attribute(attr_name, new_var)
-        out_arguments.append(new_var)
 
     shader.add_function_call(function, in_arguments, out_arguments)
 

+ 1 - 2
io_scene_godot/converters/material_node_tree/shader_functions.py

@@ -79,7 +79,6 @@ void node_bsdf_principled(vec4 color, float subsurface, vec4 subsurface_color,
     transmission = clamp(transmission, 0.0, 1.0);
 
     subsurface = subsurface * (1.0 - metallic);
-    transmission = transmission * (1.0 - metallic);
 
     albedo = mix(color.rgb, subsurface_color.rgb, subsurface);
     sss_strength_out = subsurface;
@@ -89,7 +88,7 @@ void node_bsdf_principled(vec4 color, float subsurface, vec4 subsurface_color,
     clearcoat_out = clearcoat * (1.0 - transmission);
     clearcoat_gloss_out = 1.0 - clearcoat_roughness;
     anisotropy_out = clamp(anisotropy, 0.0, 1.0);
-    transmission_out = transmission;
+    transmission_out = (1.0 - transmission) * (1.0 - metallic);
     ior = IOR;
 }
 """,

+ 2 - 3
io_scene_godot/converters/material_node_tree/shaders.py

@@ -390,12 +390,11 @@ class FragmentShader(BaseShader):
                 self.code_array.append(
                     '{} = {};'.format(name.upper(), str(var))
                 )
-        # XXX: transmission for thick object is not supported in godot
+
         transmission_var = bsdf_output.get_attribute('transmission')
         if transmission_var is not None:
-            self.append_comment_line("transmission usually does not work..")
             self.append_code_line(
-                '// TRANSMISSION = vec3(1.0, 1.0, 1.0) * {};',
+                'TRANSMISSION = vec3(1.0, 1.0, 1.0) * {};',
                 (transmission_var,)
             )
 

+ 1 - 1
tests/godot_project/default_env.tres

@@ -52,7 +52,7 @@ auto_exposure_scale = 0.4
 auto_exposure_min_luma = 0.05
 auto_exposure_max_luma = 8.0
 auto_exposure_speed = 0.5
-ss_reflections_enabled = false 
+ss_reflections_enabled = false
 ss_reflections_max_steps = 64
 ss_reflections_fade_in = 0.15
 ss_reflections_fade_out = 2.0

+ 2 - 8
tests/reference_exports/material_cycle/material_anistropy.escn

@@ -20,7 +20,6 @@ void node_bsdf_principled(vec4 color, float subsurface, vec4 subsurface_color,
     transmission = clamp(transmission, 0.0, 1.0);
 
     subsurface = subsurface * (1.0 - metallic);
-    transmission = transmission * (1.0 - metallic);
 
     albedo = mix(color.rgb, subsurface_color.rgb, subsurface);
     sss_strength_out = subsurface;
@@ -30,7 +29,7 @@ void node_bsdf_principled(vec4 color, float subsurface, vec4 subsurface_color,
     clearcoat_out = clearcoat * (1.0 - transmission);
     clearcoat_gloss_out = 1.0 - clearcoat_roughness;
     anisotropy_out = clamp(anisotropy, 0.0, 1.0);
-    transmission_out = transmission;
+    transmission_out = (1.0 - transmission) * (1.0 - metallic);
     ior = IOR;
 }
 
@@ -92,8 +91,6 @@ void fragment() {
 	ROUGHNESS = var16_out_roughness;
 	CLEARCOAT = var17_out_clearcoat;
 	CLEARCOAT_GLOSS = var18_out_clearcoat_gloss;
-	// transmission usually does not work..
-	// TRANSMISSION = vec3(1.0, 1.0, 1.0) * var20_out_transmission;
 	// uncomment it only when you set diffuse mode to oren nayar
 	// ROUGHNESS = oren_nayar_rougness
 	ANISOTROPY = var19_out_anisotropy;
@@ -147,7 +144,6 @@ void node_bsdf_principled(vec4 color, float subsurface, vec4 subsurface_color,
     transmission = clamp(transmission, 0.0, 1.0);
 
     subsurface = subsurface * (1.0 - metallic);
-    transmission = transmission * (1.0 - metallic);
 
     albedo = mix(color.rgb, subsurface_color.rgb, subsurface);
     sss_strength_out = subsurface;
@@ -157,7 +153,7 @@ void node_bsdf_principled(vec4 color, float subsurface, vec4 subsurface_color,
     clearcoat_out = clearcoat * (1.0 - transmission);
     clearcoat_gloss_out = 1.0 - clearcoat_roughness;
     anisotropy_out = clamp(anisotropy, 0.0, 1.0);
-    transmission_out = transmission;
+    transmission_out = (1.0 - transmission) * (1.0 - metallic);
     ior = IOR;
 }
 
@@ -229,8 +225,6 @@ void fragment() {
 	ROUGHNESS = var17_out_roughness;
 	CLEARCOAT = var18_out_clearcoat;
 	CLEARCOAT_GLOSS = var19_out_clearcoat_gloss;
-	// transmission usually does not work..
-	// TRANSMISSION = vec3(1.0, 1.0, 1.0) * var21_out_transmission;
 	// uncomment it only when you set diffuse mode to oren nayar
 	// ROUGHNESS = oren_nayar_rougness
 	ANISOTROPY = var20_out_anisotropy;

+ 3 - 10
tests/reference_exports/material_cycle/material_cycle.escn

@@ -364,8 +364,7 @@ void fragment() {
 	ALBEDO = var4_out_albedo;
 	SPECULAR = var6_out_specular;
 	ROUGHNESS = var7_out_roughness;
-	// transmission usually does not work..
-	// TRANSMISSION = vec3(1.0, 1.0, 1.0) * var8_out_transmission;
+	TRANSMISSION = vec3(1.0, 1.0, 1.0) * var8_out_transmission;
 	// uncomment it only when you set diffuse mode to oren nayar
 	// ROUGHNESS = oren_nayar_rougness
 	refraction_fresnel(VERTEX, NORMAL, var9_out_ior, var5_out_alpha);
@@ -472,7 +471,6 @@ void node_bsdf_principled(vec4 color, float subsurface, vec4 subsurface_color,
     transmission = clamp(transmission, 0.0, 1.0);
 
     subsurface = subsurface * (1.0 - metallic);
-    transmission = transmission * (1.0 - metallic);
 
     albedo = mix(color.rgb, subsurface_color.rgb, subsurface);
     sss_strength_out = subsurface;
@@ -482,7 +480,7 @@ void node_bsdf_principled(vec4 color, float subsurface, vec4 subsurface_color,
     clearcoat_out = clearcoat * (1.0 - transmission);
     clearcoat_gloss_out = 1.0 - clearcoat_roughness;
     anisotropy_out = clamp(anisotropy, 0.0, 1.0);
-    transmission_out = transmission;
+    transmission_out = (1.0 - transmission) * (1.0 - metallic);
     ior = IOR;
 }
 
@@ -550,8 +548,6 @@ void fragment() {
 	ROUGHNESS = var17_out_roughness;
 	CLEARCOAT = var18_out_clearcoat;
 	CLEARCOAT_GLOSS = var19_out_clearcoat_gloss;
-	// transmission usually does not work..
-	// TRANSMISSION = vec3(1.0, 1.0, 1.0) * var21_out_transmission;
 	// uncomment it only when you set diffuse mode to oren nayar
 	// ROUGHNESS = oren_nayar_rougness
 }
@@ -1124,7 +1120,6 @@ void node_bsdf_principled(vec4 color, float subsurface, vec4 subsurface_color,
     transmission = clamp(transmission, 0.0, 1.0);
 
     subsurface = subsurface * (1.0 - metallic);
-    transmission = transmission * (1.0 - metallic);
 
     albedo = mix(color.rgb, subsurface_color.rgb, subsurface);
     sss_strength_out = subsurface;
@@ -1134,7 +1129,7 @@ void node_bsdf_principled(vec4 color, float subsurface, vec4 subsurface_color,
     clearcoat_out = clearcoat * (1.0 - transmission);
     clearcoat_gloss_out = 1.0 - clearcoat_roughness;
     anisotropy_out = clamp(anisotropy, 0.0, 1.0);
-    transmission_out = transmission;
+    transmission_out = (1.0 - transmission) * (1.0 - metallic);
     ior = IOR;
 }
 
@@ -1212,8 +1207,6 @@ void fragment() {
 	ROUGHNESS = var19_out_roughness;
 	CLEARCOAT = var20_out_clearcoat;
 	CLEARCOAT_GLOSS = var21_out_clearcoat_gloss;
-	// transmission usually does not work..
-	// TRANSMISSION = vec3(1.0, 1.0, 1.0) * var23_out_transmission;
 	// uncomment it only when you set diffuse mode to oren nayar
 	// ROUGHNESS = oren_nayar_rougness
 }