void CreateFrom3DsSimplifiedPhysicalMaterial(MaterialDescription description, Material material, AnimationClip[] clips) { float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; description.TryGetProperty("basecolor", out vectorProperty); bool hasTransparencyScalar = vectorProperty.w != 1.0f; var hasTransparencyMap = description.TryGetProperty("opacity_map", out textureProperty); bool isTransparent = hasTransparencyMap | hasTransparencyScalar; Shader shader; if (isTransparent) { shader = GraphicsSettings.currentRenderPipeline.autodeskInteractiveTransparentShader; } else { shader = GraphicsSettings.currentRenderPipeline.autodeskInteractiveShader; } if (shader == null) { return; } material.shader = shader; foreach (var clip in clips) { clip.ClearCurves(); } if (hasTransparencyMap) { material.SetFloat("_UseOpacityMap", 1.0f); material.SetTexture("_OpacityMap", textureProperty.texture); } else if (hasTransparencyScalar) { material.SetFloat("_Opacity", vectorProperty.w); } if (description.TryGetProperty("basecolor", out vectorProperty)) { material.SetColor("_Color", vectorProperty); } if (description.TryGetProperty("emit_color", out vectorProperty)) { material.SetColor("_EmissionColor", vectorProperty); } if (description.TryGetProperty("roughness", out floatProperty)) { material.SetFloat("_Glossiness", floatProperty); } if (description.TryGetProperty("metalness", out floatProperty)) { material.SetFloat("_Metallic", floatProperty); } if (description.TryGetProperty("base_color_map", out textureProperty)) { material.SetTexture("_MainTex", textureProperty.texture); material.SetFloat("_UseColorMap", 1.0f); material.SetColor("_UvTiling", new Vector4(textureProperty.scale.x, textureProperty.scale.y, 0.0f, 0.0f)); material.SetColor("_UvOffset", new Vector4(textureProperty.offset.x, textureProperty.offset.y, 0.0f, 0.0f)); } else { material.SetFloat("_UseColorMap", 0.0f); } if (description.TryGetProperty("norm_map", out textureProperty)) { material.SetTexture("_BumpMap", textureProperty.texture); material.SetFloat("_UseNormalMap", 1.0f); } else { material.SetFloat("_UseNormalMap", 0.0f); } if (description.TryGetProperty("roughness_map", out textureProperty)) { material.SetTexture("_SpecGlossMap", textureProperty.texture); material.SetFloat("_UseRoughnessMap", 1.0f); } else { material.SetFloat("_UseRoughnessMap", 0.0f); } if (description.TryGetProperty("metalness_map", out textureProperty)) { material.SetTexture("_MetallicGlossMap", textureProperty.texture); material.SetFloat("_UseMetallicMap", 1.0f); } else { material.SetFloat("_UseMetallicMap", 0.0f); } if (description.TryGetProperty("emit_color_map", out textureProperty)) { material.SetTexture("_EmissionMap", textureProperty.texture); material.SetFloat("_UseEmissiveMap", 1.0f); } else { material.SetFloat("_UseEmissiveMap", 0.0f); } if (description.TryGetProperty("ao_map", out textureProperty)) { var tex = AssetDatabase.LoadAssetAtPath <Texture>(textureProperty.relativePath); material.SetTexture("AoMap", tex); material.SetFloat("UseAoMap", 1.0f); } else { material.SetFloat("UseAoMap", 0.0f); } }
void CreateFrom3DsPhysicalMaterial(MaterialDescription description, Material material, AnimationClip[] clips) { float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; Shader shader; description.TryGetProperty("transparency", out floatProperty); bool hasTransparencyMap = description.TryGetProperty("transparency_map", out textureProperty); if (floatProperty > 0.0f || hasTransparencyMap) { shader = AssetDatabase.LoadAssetAtPath <Shader>(k_ShaderTransparentPath); if (shader == null) { return; } material.shader = shader; if (hasTransparencyMap) { material.SetTexture("_TRANSPARENCY_MAP", textureProperty.texture); material.SetFloat("_TRANSPARENCY", 1.0f); } else { material.SetFloat("_TRANSPARENCY", floatProperty); } } else { shader = AssetDatabase.LoadAssetAtPath <Shader>(k_ShaderPath); if (shader == null) { return; } material.shader = shader; } foreach (var clip in clips) { clip.ClearCurves(); } RemapPropertyFloat(description, material, "base_weight", "_BASE_COLOR_WEIGHT"); if (description.TryGetProperty("base_color_map", out textureProperty)) { SetMaterialTextureProperty("_BASE_COLOR_MAP", material, textureProperty); } else if (description.TryGetProperty("base_color", out vectorProperty)) { if (QualitySettings.activeColorSpace == ColorSpace.Gamma) { vectorProperty.x = Mathf.LinearToGammaSpace(vectorProperty.x); vectorProperty.y = Mathf.LinearToGammaSpace(vectorProperty.y); vectorProperty.z = Mathf.LinearToGammaSpace(vectorProperty.z); vectorProperty.w = Mathf.LinearToGammaSpace(vectorProperty.w); } material.SetColor("_BASE_COLOR", vectorProperty); } RemapPropertyFloat(description, material, "reflectivity", "_REFLECTIONS_WEIGHT"); RemapPropertyTextureOrColor(description, material, "refl_color", "_REFLECTIONS_COLOR"); RemapPropertyTextureOrFloat(description, material, "metalness", "_METALNESS"); RemapPropertyTextureOrFloat(description, material, "roughness", "_REFLECTIONS_ROUGHNESS"); RemapPropertyTextureOrFloat(description, material, "trans_ior", "_REFLECTIONS_IOR"); RemapPropertyFloat(description, material, "emission", "_EMISSION_WEIGHT"); RemapPropertyTextureOrColor(description, material, "emit_color", "_EMISSION_COLOR"); RemapPropertyFloat(description, material, "bump_map_amt", "_BUMP_MAP_STRENGTH"); RemapPropertyTexture(description, material, "bump_map", "_BUMP_MAP"); }
public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] clips) { var pipelineAsset = GraphicsSettings.currentRenderPipeline; if (!pipelineAsset || pipelineAsset.GetType() != typeof(HDRenderPipelineAsset)) { return; } var lowerCasePath = Path.GetExtension(assetPath).ToLower(); if (lowerCasePath != ".skp") { return; } var shader = Shader.Find("HDRP/Lit"); if (shader == null) { return; } material.shader = shader; float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; material.SetShaderPassEnabled("DistortionVectors", false); material.SetShaderPassEnabled("TransparentDepthPrepass", false); material.SetShaderPassEnabled("TransparentDepthPostpass", false); material.SetShaderPassEnabled("TransparentBackface", false); material.SetShaderPassEnabled("MOTIONVECTORS", false); if (description.TryGetProperty("DiffuseMap", out textureProperty) && textureProperty.texture != null) { SetMaterialTextureProperty("_BaseColorMap", material, textureProperty); SetMaterialTextureProperty("_MainTex", material, textureProperty); var color = new Color(1.0f, 1.0f, 1.0f, 1.0f); material.SetColor("_BaseColor", color); material.SetColor("_Color", color); } else if (description.TryGetProperty("DiffuseColor", out vectorProperty)) { Color diffuseColor = vectorProperty; diffuseColor = PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor; material.SetColor("_BaseColor", diffuseColor); material.SetColor("_Color", diffuseColor); } if (description.TryGetProperty("IsTransparent", out floatProperty) && floatProperty == 1.0f) { material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.SetFloat("_BlendMode", (float)BlendMode.Alpha); material.SetFloat("_EnableBlendModePreserveSpecularLighting", 1.0f); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; } else { material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.renderQueue = -1; } }
void CreateFromMayaArnoldStandardSurfaceMaterial(MaterialDescription description, Material material, AnimationClip[] clips) { float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; var shader = AssetDatabase.LoadAssetAtPath <Shader>(k_ShaderPath); if (shader == null) { return; } material.shader = shader; foreach (var clip in clips) { clip.ClearCurves(); } float opacity = 1.0f; Vector4 opacityColor; TexturePropertyDescription opacityMap; description.TryGetProperty("opacity", out opacityColor); bool hasOpacityMap = description.TryGetProperty("opacity", out opacityMap); opacity = Mathf.Min(Mathf.Min(opacityColor.x, opacityColor.y), opacityColor.z); float transmission; description.TryGetProperty("transmission", out transmission); if (opacity == 1.0f && !hasOpacityMap) { opacity = 1.0f - transmission; } if (opacity < 1.0f || hasOpacityMap) { if (hasOpacityMap) { material.SetTexture("_OPACITY_MAP", opacityMap.texture); material.SetFloat("_OPACITY", 1.0f); } else { material.SetFloat("_OPACITY", opacity); } material.SetInt("_SrcBlend", 1); material.SetInt("_DstBlend", 10); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_ALPHA"); material.renderQueue = 3000; } else { material.EnableKeyword("_DOUBLESIDED_ON"); material.SetInt("_CullMode", 0); material.SetInt("_CullModeForward", 0); material.doubleSidedGI = true; } description.TryGetProperty("base", out floatProperty); if (description.TryGetProperty("baseColor", out textureProperty)) { SetMaterialTextureProperty("_BASE_COLOR_MAP", material, textureProperty); material.SetColor("_BASE_COLOR", Color.white * floatProperty); } else if (description.TryGetProperty("baseColor", out vectorProperty)) { if (QualitySettings.activeColorSpace == ColorSpace.Gamma) { vectorProperty.x = Mathf.LinearToGammaSpace(vectorProperty.x); vectorProperty.y = Mathf.LinearToGammaSpace(vectorProperty.y); vectorProperty.z = Mathf.LinearToGammaSpace(vectorProperty.z); } material.SetColor("_BASE_COLOR", vectorProperty * floatProperty); } if (description.TryGetProperty("emission", out floatProperty) && floatProperty > 0.0f) { remapPropertyColorOrTexture(description, material, "emissionColor", "_EMISSION_COLOR", floatProperty); } remapPropertyFloatOrTexture(description, material, "metalness", "_METALNESS"); remapPropertyFloat(description, material, "specular", "_SPECULAR_WEIGHT"); remapPropertyColorOrTexture(description, material, "specularColor", "_SPECULAR_COLOR"); remapPropertyFloatOrTexture(description, material, "specularRoughness", "_SPECULAR_ROUGHNESS"); remapPropertyFloatOrTexture(description, material, "specularIOR", "_SPECULAR_IOR"); remapPropertyFloatOrTexture(description, material, "specularAnisotropy", "_SPECULAR_ANISOTROPY"); remapPropertyFloatOrTexture(description, material, "specularRotation", "_SPECULAR_ROTATION"); remapPropertyTexture(description, material, "normalCamera", "_NORMAL_MAP"); remapPropertyFloat(description, material, "coat", "_COAT_WEIGHT"); remapPropertyColorOrTexture(description, material, "coatColor", "_COAT_COLOR"); remapPropertyFloatOrTexture(description, material, "coatRoughness", "_COAT_ROUGHNESS"); remapPropertyFloatOrTexture(description, material, "coatIOR", "_COAT_IOR"); remapPropertyTexture(description, material, "coatNormal", "_COAT_NORMAL"); }
void CreateFromMayaArnoldStandardSurfaceMaterial(MaterialDescription description, Material material, AnimationClip[] clips) { float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; Shader shader; float opacity = 1.0f; Vector4 opacityColor; TexturePropertyDescription opacityMap; description.TryGetProperty("opacity", out opacityColor); bool hasOpacityMap = description.TryGetProperty("opacity", out opacityMap); opacity = Mathf.Min(Mathf.Min(opacityColor.x, opacityColor.y), opacityColor.z); float transmission; description.TryGetProperty("transmission", out transmission); if (opacity == 1.0f && !hasOpacityMap) { opacity = 1.0f - transmission; } if (opacity < 1.0f || hasOpacityMap) { shader = AssetDatabase.LoadAssetAtPath <Shader>(k_ShaderTransparentPath); if (shader == null) { return; } material.shader = shader; if (hasOpacityMap) { material.SetTexture("_OPACITY_MAP", opacityMap.texture); material.SetFloat("_OPACITY", 1.0f); } else { material.SetFloat("_OPACITY", opacity); } } else { shader = AssetDatabase.LoadAssetAtPath <Shader>(k_ShaderPath); if (shader == null) { return; } material.shader = shader; } foreach (var clip in clips) { clip.ClearCurves(); } description.TryGetProperty("base", out floatProperty); if (description.TryGetProperty("baseColor", out textureProperty)) { SetMaterialTextureProperty("_BASE_COLOR_MAP", material, textureProperty); material.SetColor("_BASE_COLOR", Color.white * floatProperty); } else if (description.TryGetProperty("baseColor", out vectorProperty)) { if (QualitySettings.activeColorSpace == ColorSpace.Gamma) { vectorProperty.x = Mathf.LinearToGammaSpace(vectorProperty.x); vectorProperty.y = Mathf.LinearToGammaSpace(vectorProperty.y); vectorProperty.z = Mathf.LinearToGammaSpace(vectorProperty.z); vectorProperty *= floatProperty; } material.SetColor("_BASE_COLOR", vectorProperty * floatProperty); } if (description.TryGetProperty("emission", out floatProperty) && floatProperty > 0.0f) { remapPropertyColorOrTexture(description, material, "emissionColor", "_EMISSION_COLOR", floatProperty); } remapPropertyFloatOrTexture(description, material, "metalness", "_METALNESS"); description.TryGetProperty("specular", out floatProperty); remapPropertyColorOrTexture(description, material, "specularColor", "_SPECULAR_COLOR", floatProperty); remapPropertyFloatOrTexture(description, material, "specularRoughness", "_SPECULAR_ROUGHNESS"); remapPropertyFloatOrTexture(description, material, "specularIOR", "_SPECULAR_IOR"); remapPropertyTexture(description, material, "normalCamera", "_NORMAL_MAP"); }
public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] clips) { var lowerCaseExtension = Path.GetExtension(assetPath).ToLower(); if (lowerCaseExtension != ".fbx" && lowerCaseExtension != ".obj" && lowerCaseExtension != ".blend" && lowerCaseExtension != ".mb" && lowerCaseExtension != ".ma" && lowerCaseExtension != ".max") { return; } string path = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(ShaderPathID.Lit)); var shader = AssetDatabase.LoadAssetAtPath <Shader>(path); if (shader == null) { return; } material.shader = shader; Vector4 vectorProperty; float floatProperty; TexturePropertyDescription textureProperty; bool isTransparent = false; float opacity; float transparencyFactor; if (!description.TryGetProperty("Opacity", out opacity)) { if (description.TryGetProperty("TransparencyFactor", out transparencyFactor)) { opacity = transparencyFactor == 1.0f ? 1.0f : 1.0f - transparencyFactor; } if (opacity == 1.0f && description.TryGetProperty("TransparentColor", out vectorProperty)) { opacity = vectorProperty.x == 1.0f ? 1.0f : 1.0f - vectorProperty.x; } } if (opacity < 1.0f || (opacity == 1.0f && description.TryGetProperty("TransparentColor", out textureProperty))) { isTransparent = true; } else if (description.HasAnimationCurve("TransparencyFactor") || description.HasAnimationCurve("TransparentColor")) { isTransparent = true; } if (isTransparent) { material.SetInt("_Mode", 3); material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; material.SetInt("_Surface", 1); } else { material.SetInt("_Mode", 0); material.SetOverrideTag("RenderType", ""); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = -1; material.SetInt("_Surface", 0); } if (description.TryGetProperty("DiffuseColor", out textureProperty) && textureProperty.texture != null) { Color diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); if (description.TryGetProperty("DiffuseFactor", out floatProperty)) { diffuseColor *= floatProperty; } diffuseColor.a = opacity; SetMaterialTextureProperty("_BaseMap", material, textureProperty); material.SetColor("_BaseColor", diffuseColor); } else if (description.TryGetProperty("DiffuseColor", out vectorProperty)) { Color diffuseColor = vectorProperty; diffuseColor.a = opacity; material.SetColor("_BaseColor", PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor); } if (description.TryGetProperty("Bump", out textureProperty)) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); material.EnableKeyword("_NORMALMAP"); if (description.TryGetProperty("BumpFactor", out floatProperty)) { material.SetFloat("_BumpScale", floatProperty); } } else if (description.TryGetProperty("NormalMap", out textureProperty)) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); material.EnableKeyword("_NORMALMAP"); if (description.TryGetProperty("BumpFactor", out floatProperty)) { material.SetFloat("_BumpScale", floatProperty); } } if (description.TryGetProperty("EmissiveColor", out textureProperty)) { Color emissiveColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); material.SetColor("_EmissionColor", emissiveColor); SetMaterialTextureProperty("_EmissionMap", material, textureProperty); if (description.TryGetProperty("EmissiveFactor", out floatProperty) && floatProperty > 0.0f) { material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } } else if ( description.TryGetProperty("EmissiveColor", out vectorProperty) && vectorProperty.magnitude > vectorProperty.w || description.HasAnimationCurve("EmissiveColor.x")) { if (description.TryGetProperty("EmissiveFactor", out floatProperty)) { vectorProperty *= floatProperty; } material.SetColor("_EmissionColor", vectorProperty); if (floatProperty > 0.0f) { material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } } material.SetFloat("_Glossiness", 0.0f); if (PlayerSettings.colorSpace == ColorSpace.Linear) { RemapAndTransformColorCurves(description, clips, "DiffuseColor", "_BaseColor", ConvertFloatLinearToGamma); } else { RemapColorCurves(description, clips, "DiffuseColor", "_BaseColor"); } RemapTransparencyCurves(description, clips); RemapColorCurves(description, clips, "EmissiveColor", "_EmissionColor"); }
public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] clips) { var pipelineAsset = GraphicsSettings.currentRenderPipeline; if (!pipelineAsset || pipelineAsset.GetType() != typeof(HDRenderPipelineAsset)) { return; } var lowerCaseExtension = Path.GetExtension(assetPath).ToLower(); if (lowerCaseExtension != ".fbx" && lowerCaseExtension != ".obj" && lowerCaseExtension != ".dae" && lowerCaseExtension != ".obj" && lowerCaseExtension != ".blend" && lowerCaseExtension != ".mb" && lowerCaseExtension != ".ma" && lowerCaseExtension != ".max") { return; } var shader = AssetDatabase.LoadAssetAtPath <Shader>(k_ShaderPath); if (shader == null) { return; } material.shader = shader; material.SetShaderPassEnabled("DistortionVectors", false); material.SetShaderPassEnabled("TransparentDepthPrepass", false); material.SetShaderPassEnabled("TransparentDepthPostpass", false); material.SetShaderPassEnabled("TransparentBackface", false); material.SetShaderPassEnabled("MOTIONVECTORS", false); Vector4 vectorProperty; float floatProperty; TexturePropertyDescription textureProperty; bool isTransparent = false; float opacity; float transparencyFactor; if (!description.TryGetProperty("Opacity", out opacity)) { if (description.TryGetProperty("TransparencyFactor", out transparencyFactor)) { opacity = transparencyFactor == 1.0f ? 1.0f : 1.0f - transparencyFactor; } if (opacity == 1.0f && description.TryGetProperty("TransparentColor", out vectorProperty)) { opacity = vectorProperty.x == 1.0f ? 1.0f : 1.0f - vectorProperty.x; } } if (opacity < 1.0f || (opacity == 1.0f && description.TryGetProperty("TransparentColor", out textureProperty))) { isTransparent = true; } else if (description.HasAnimationCurve("TransparencyFactor") || description.HasAnimationCurve("TransparentColor")) { isTransparent = true; } if (isTransparent) { material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.SetFloat("_BlendMode", (float)BlendMode.Alpha); material.SetFloat("_EnableBlendModePreserveSpecularLighting", 1.0f); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); material.EnableKeyword("_ALPHATEST_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; material.SetFloat("_SurfaceType", 1.0f); material.SetFloat("_Cutoff", .0f); material.SetFloat("_AlphaCutoffEnable", 1.0f); material.SetFloat("_AlphaCutoff", .0f); material.SetFloat("_AlphaCutoffShadow", 1.0f); material.SetFloat("_UseShadowThreshold", 1.0f); } else { material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.renderQueue = -1; } if (description.TryGetProperty("DiffuseColor", out textureProperty) && textureProperty.texture != null) { Color diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); if (description.TryGetProperty("DiffuseFactor", out floatProperty)) { diffuseColor *= floatProperty; } diffuseColor.a = opacity; SetMaterialTextureProperty("_BaseColorMap", material, textureProperty); material.SetColor("_BaseColor", diffuseColor); } else if (description.TryGetProperty("DiffuseColor", out vectorProperty)) { Color diffuseColor = vectorProperty; if (description.TryGetProperty("DiffuseFactor", out floatProperty)) { diffuseColor *= floatProperty; } diffuseColor.a = opacity; material.SetColor("_BaseColor", PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor); } if (description.TryGetProperty("Bump", out textureProperty) && textureProperty.texture != null) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); material.EnableKeyword("_NORMALMAP_TANGENT_SPACE"); if (description.TryGetProperty("BumpFactor", out floatProperty)) { material.SetFloat("_BumpScale", floatProperty); } } else if (description.TryGetProperty("NormalMap", out textureProperty) && textureProperty.texture != null) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); material.EnableKeyword("_NORMALMAP_TANGENT_SPACE"); if (description.TryGetProperty("BumpFactor", out floatProperty)) { material.SetFloat("_BumpScale", floatProperty); } } else { material.DisableKeyword("_NORMALMAP"); } if (description.TryGetProperty("EmissiveColor", out textureProperty)) { Color emissiveColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); material.SetColor("_EmissionColor", emissiveColor); material.SetColor("_EmissiveColor", emissiveColor); SetMaterialTextureProperty("_EmissionMap", material, textureProperty); if (description.TryGetProperty("EmissiveFactor", out floatProperty) && floatProperty > 0.0f) { material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } } else if (description.TryGetProperty("EmissiveColor", out vectorProperty) && vectorProperty.magnitude > vectorProperty.w || description.HasAnimationCurve("EmissiveColor.x")) { if (description.TryGetProperty("EmissiveFactor", out floatProperty)) { vectorProperty *= floatProperty; } material.SetColor("_EmissionColor", vectorProperty); material.SetColor("_EmissiveColor", vectorProperty); if (floatProperty > 0.0f) { material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } } material.SetFloat("_Glossiness", 0.0f); if (PlayerSettings.colorSpace == ColorSpace.Linear) { RemapAndTransformColorCurves(description, clips, "DiffuseColor", "_BaseColor", ConvertFloatLinearToGamma); } else { RemapColorCurves(description, clips, "DiffuseColor", "_BaseColor"); } RemapTransparencyCurves(description, clips); RemapColorCurves(description, clips, "EmissiveColor", "_EmissionColor"); RemapColorCurves(description, clips, "EmissiveColor", "_EmissiveColor"); }
public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] clips) { var lowerCasePath = Path.GetExtension(assetPath).ToLower(); if (lowerCasePath != ".skp") { return; } var shader = Shader.Find("Universal Render Pipeline/Lit"); if (shader == null) { return; } material.shader = shader; float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; if (description.TryGetProperty("DiffuseMap", out textureProperty) && textureProperty.texture != null) { SetMaterialTextureProperty("_BaseMap", material, textureProperty); SetMaterialTextureProperty("_MainTex", material, textureProperty); var color = new Color(1.0f, 1.0f, 1.0f, 1.0f); material.SetColor("_BaseColor", color); material.SetColor("_Color", color); } else if (description.TryGetProperty("DiffuseColor", out vectorProperty)) { Color diffuseColor = vectorProperty; diffuseColor = PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor; material.SetColor("_BaseColor", diffuseColor); material.SetColor("_Color", diffuseColor); } if (description.TryGetProperty("IsTransparent", out floatProperty) && floatProperty == 1.0f) { material.SetFloat("_Mode", (float)3.0); // From C# enum BlendMode material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; material.SetInt("_Surface", 1); } else { material.SetFloat("_Mode", (float)0.0); // From C# enum BlendMode material.SetOverrideTag("RenderType", ""); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = -1; material.SetInt("_Surface", 0); } }
void CreateFromStandardMaterial(MaterialDescription description, Material material, AnimationClip[] clips) { var shader = Shader.Find("Standard"); if (shader == null) { context.LogImportError("ThreeDSMaterialDescriptionPreprocessor cannot find a shader named 'Standard'."); return; } material.shader = shader; Vector4 vectorProperty; float floatProperty; TexturePropertyDescription textureProperty; bool isTransparent = false; float opacity; float transparencyFactor; if (!description.TryGetProperty("Opacity", out opacity)) { if (description.TryGetProperty("TransparencyFactor", out transparencyFactor)) { opacity = transparencyFactor == 1.0f ? 1.0f : 1.0f - transparencyFactor; } if (opacity == 1.0f && description.TryGetProperty("TransparentColor", out vectorProperty)) { opacity = vectorProperty.x == 1.0f ? 1.0f : 1.0f - vectorProperty.x; } } if (opacity < 1.0f || (opacity == 1.0f && description.TryGetProperty("TransparentColor", out textureProperty))) { isTransparent = true; } else if (description.HasAnimationCurve("TransparencyFactor") || description.HasAnimationCurve("TransparentColor")) { isTransparent = true; } if (isTransparent) { material.SetInt("_Mode", (int)StandardShaderGUI.BlendMode.Transparent); material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; } else { material.SetInt("_Mode", (int)StandardShaderGUI.BlendMode.Opaque); material.SetOverrideTag("RenderType", ""); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = -1; } if (description.TryGetProperty("DiffuseColor", out textureProperty)) { Color diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); if (description.TryGetProperty("DiffuseFactor", out floatProperty)) { diffuseColor *= floatProperty; } diffuseColor.a = opacity; SetMaterialTextureProperty("_MainTex", material, textureProperty); material.SetColor("_Color", PlayerSettings.colorSpace == ColorSpace.Gamma ? diffuseColor.gamma : diffuseColor); } else if (description.TryGetProperty("DiffuseColor", out vectorProperty)) { Color diffuseColor = vectorProperty; if (description.TryGetProperty("DiffuseFactor", out floatProperty)) { diffuseColor *= floatProperty; } diffuseColor.a = opacity; material.SetColor("_Color", PlayerSettings.colorSpace == ColorSpace.Gamma ? diffuseColor.gamma : diffuseColor); } if (description.TryGetProperty("Bump", out textureProperty)) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); material.EnableKeyword("_NORMALMAP"); if (description.TryGetProperty("BumpFactor", out floatProperty)) { material.SetFloat("_BumpScale", floatProperty); } } else if (description.TryGetProperty("NormalMap", out textureProperty)) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); material.EnableKeyword("_NORMALMAP"); if (description.TryGetProperty("BumpFactor", out floatProperty)) { material.SetFloat("_BumpScale", floatProperty); } } if (description.TryGetProperty("EmissiveColor", out textureProperty)) { Color emissiveColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); material.SetColor("_EmissionColor", emissiveColor); SetMaterialTextureProperty("_EmissionMap", material, textureProperty); if (description.TryGetProperty("EmissiveFactor", out floatProperty) && floatProperty > 0.0f) { material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } } else if ( description.TryGetProperty("EmissiveColor", out vectorProperty) && vectorProperty.magnitude > vectorProperty.w || description.HasAnimationCurve("EmissiveColor.x")) { if (description.TryGetProperty("EmissiveFactor", out floatProperty)) { vectorProperty *= floatProperty; } material.SetColor("_EmissionColor", vectorProperty); if (floatProperty > 0.0f) { material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } } material.SetFloat("_Glossiness", 0.0f); if (PlayerSettings.colorSpace == ColorSpace.Gamma) { RemapAndTransformColorCurves(description, clips, "DiffuseColor", "_Color", ConvertFloatLinearToGamma); } else { RemapColorCurves(description, clips, "DiffuseColor", "_Color"); } RemapTransparencyCurves(description, clips); RemapColorCurves(description, clips, "EmissiveColor", "_EmissionColor"); }
void CreateFrom3DsMaxArnoldStandardSurfaceMaterial(MaterialDescription description, Material material, AnimationClip[] clips) { // 3DsMax does not export material animations for Arnold materials. var shader = Shader.Find("Autodesk Interactive"); if (shader == null) { context.LogImportError("ThreeDSMaterialDescriptionPreprocessor cannot find a shader named 'Autodesk Interactive'."); return; } material.shader = shader; float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; if (description.TryGetProperty("transmission", out floatProperty) && floatProperty > 0.0f) { material.SetInt("_Mode", (int)StandardShaderGUI.BlendMode.Transparent); material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; } else { material.SetInt("_Mode", (int)StandardShaderGUI.BlendMode.Opaque); material.SetOverrideTag("RenderType", ""); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = -1; } if (description.TryGetProperty("base_color.shader", out textureProperty)) { SetMaterialTextureProperty("_MainTex", material, textureProperty); Color baseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f - floatProperty); material.SetColor("_Color", baseColor); } else if (description.TryGetProperty("base_color", out vectorProperty)) { if (QualitySettings.activeColorSpace == ColorSpace.Gamma) { vectorProperty.x = Mathf.LinearToGammaSpace(vectorProperty.x); vectorProperty.y = Mathf.LinearToGammaSpace(vectorProperty.y); vectorProperty.z = Mathf.LinearToGammaSpace(vectorProperty.z); } vectorProperty.w = 1.0f - floatProperty; material.SetColor("_Color", vectorProperty); } if (description.TryGetProperty("normal.shader", out textureProperty)) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); material.EnableKeyword("_NORMALMAP"); } if (description.TryGetProperty("specular_roughness", out textureProperty)) { SetMaterialTextureProperty("_SpecGlossMap", material, textureProperty); material.EnableKeyword("_SPECGLOSSMAP"); } else if (description.TryGetProperty("specular_roughness", out floatProperty)) { material.SetFloat("_Glossiness", floatProperty); } if (description.TryGetProperty("metalness", out textureProperty)) { SetMaterialTextureProperty("_MetallicGlossMap", material, textureProperty); material.EnableKeyword("_METALLICGLOSSMAP"); } if (description.TryGetProperty("emission", out floatProperty) && floatProperty > 0.0f) { Color emissiveColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); if (description.TryGetProperty("emission_color.shader", out textureProperty)) { emissiveColor *= floatProperty; SetMaterialTextureProperty("_EmissionMap", material, textureProperty); material.SetColor("_EmissionColor", emissiveColor); material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } else if (description.TryGetProperty("emission_color", out vectorProperty)) { emissiveColor = vectorProperty * floatProperty; material.SetColor("_EmissionColor", emissiveColor); material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } } }
void CreateFromAutodeskInteractiveMaterial(MaterialDescription description, Material material, AnimationClip[] clips) { var shader = Shader.Find("Autodesk Interactive"); if (shader == null) { context.LogImportError("ThreeDSMaterialDescriptionPreprocessor cannot find a shader named 'Autodesk Interactive'."); return; } material.shader = shader; float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; AnimationCurve curve; Vector2 uvOffset = new Vector2(0.0f, 0.0f); Vector2 uvScale = new Vector2(1.0f, 1.0f); if (description.TryGetProperty("uv_offset", out vectorProperty)) { uvOffset.x = vectorProperty.x; uvOffset.y = -vectorProperty.y; } if (description.TryGetProperty("uv_scale", out vectorProperty)) { uvScale.x = vectorProperty.x; uvScale.y = vectorProperty.y; } for (int i = 0; i < clips.Length; i++) { if (description.HasAnimationCurveInClip(clips[i].name, "uv_scale.x") || description.HasAnimationCurveInClip(clips[i].name, "uv_scale.y") || description.HasAnimationCurveInClip(clips[i].name, "uv_offset.x") || description.HasAnimationCurveInClip(clips[i].name, "uv_offset.y") ) { if (description.TryGetAnimationCurve(clips[i].name, "uv_scale.x", out curve)) { clips[i].SetCurve("", typeof(Material), "_MainTex_ST.x", curve); } else { clips[i].SetCurve("", typeof(Material), "_MainTex_ST.x", AnimationCurve.Constant(0.0f, 1.0f, 1.0f)); } if (description.TryGetAnimationCurve(clips[i].name, "uv_scale.y", out curve)) { clips[i].SetCurve("", typeof(Material), "_MainTex_ST.y", curve); } else { clips[i].SetCurve("", typeof(Material), "_MainTex_ST.y", AnimationCurve.Constant(0.0f, 1.0f, 1.0f)); } if (description.TryGetAnimationCurve(clips[i].name, "uv_offset.x", out curve)) { clips[i].SetCurve("", typeof(Material), "_MainTex_ST.z", curve); } else { clips[i].SetCurve("", typeof(Material), "_MainTex_ST.z", AnimationCurve.Constant(0.0f, 1.0f, 0.0f)); } if (description.TryGetAnimationCurve(clips[i].name, "uv_offset.y", out curve)) { ConvertKeys(curve, ConvertFloatNegate); clips[i].SetCurve("", typeof(Material), "_MainTex_ST.w", curve); } else { clips[i].SetCurve("", typeof(Material), "_MainTex_ST.w", AnimationCurve.Constant(0.0f, 1.0f, 0.0f)); } } } float opacity = 1.0f; float alphaThreshold = 0.0f; description.TryGetProperty("opacity", out opacity); description.TryGetProperty("mask_threshold", out alphaThreshold); if (alphaThreshold > 0.0f || description.HasAnimationCurve("mask_threshold")) { material.SetInt("_Mode", (int)StandardShaderGUI.BlendMode.Cutout); material.SetOverrideTag("RenderType", "TransparentCutout"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 1); material.EnableKeyword("_ALPHATEST_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; } else if (opacity < 1.0f || description.HasAnimationCurve("opacity") || (description.TryGetProperty("use_opacity_map", out floatProperty) && floatProperty == 1.0f)) { material.SetInt("_Mode", (int)StandardShaderGUI.BlendMode.Transparent); material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; } else { material.SetInt("_Mode", (int)StandardShaderGUI.BlendMode.Opaque); material.SetOverrideTag("RenderType", ""); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = -1; } if (description.TryGetProperty("use_color_map", out floatProperty) && floatProperty == 1.0f || description.TryGetProperty("use_opacity_map", out floatProperty) && floatProperty == 1.0f) { if (description.TryGetProperty("TEX_color_map", out textureProperty)) { material.SetTexture("_MainTex", textureProperty.texture); material.SetTextureOffset("_MainTex", uvOffset); material.SetTextureScale("_MainTex", uvScale); material.SetColor("_Color", new Vector4(1.0f, 1.0f, 1.0f, opacity)); if (alphaThreshold > 0.0f || description.HasAnimationCurve("mask_threshold")) { material.SetFloat("_Cutoff", alphaThreshold); RemapCurve(description, clips, "mask_threshold", "_Cutoff"); } } } else { description.TryGetProperty("base_color", out vectorProperty); vectorProperty.w = opacity; material.SetColor("_Color", vectorProperty); RemapColorCurves(description, clips, "base_color", "_Color"); } if (description.HasAnimationCurve("opacity")) { for (int i = 0; i < clips.Length; i++) { AnimationCurve opacityCurve; description.TryGetAnimationCurve(clips[i].name, "opacity", out opacityCurve); clips[i].SetCurve("", typeof(Material), "_Color.a", opacityCurve); if (!description.HasAnimationCurveInClip(clips[i].name, "base_color.x")) { Vector4 diffuseColor; description.TryGetProperty("base_color", out diffuseColor); clips[i].SetCurve("", typeof(Material), "_Color.r", AnimationCurve.Constant(0.0f, 1.0f, diffuseColor.x)); clips[i].SetCurve("", typeof(Material), "_Color.g", AnimationCurve.Constant(0.0f, 1.0f, diffuseColor.y)); clips[i].SetCurve("", typeof(Material), "_Color.b", AnimationCurve.Constant(0.0f, 1.0f, diffuseColor.z)); } } } if (description.TryGetProperty("use_normal_map", out floatProperty) && floatProperty == 1.0f) { if (description.TryGetProperty("TEX_normal_map", out textureProperty)) { material.SetTexture("_BumpMap", textureProperty.texture); material.SetTextureOffset("_BumpMap", uvOffset); material.SetTextureScale("_BumpMap", uvScale); material.EnableKeyword("_NORMALMAP"); } } if (description.TryGetProperty("use_metallic_map", out floatProperty) && floatProperty == 1.0f) { if (description.TryGetProperty("TEX_metallic_map", out textureProperty)) { material.SetTexture("_MetallicGlossMap", textureProperty.texture); material.SetTextureOffset("_MetallicGlossMap", uvOffset); material.SetTextureScale("_MetallicGlossMap", uvScale); material.EnableKeyword("_METALLICGLOSSMAP"); } } else { if (description.TryGetProperty("metallic", out floatProperty)) { material.SetFloat("_Metallic", floatProperty); RemapCurve(description, clips, "metallic", "_Metallic"); } } if (description.TryGetProperty("use_roughness_map", out floatProperty) && floatProperty == 1.0f) { if (description.TryGetProperty("TEX_roughness_map", out textureProperty)) { material.SetTexture("_SpecGlossMap", textureProperty.texture); material.SetTextureOffset("_SpecGlossMap", uvOffset); material.SetTextureScale("_SpecGlossMap", uvScale); material.EnableKeyword("_SPECGLOSSMAP"); } } else { if (description.TryGetProperty("roughness", out floatProperty)) { material.SetFloat("_Glossiness", floatProperty); RemapCurve(description, clips, "roughness", "_Glossiness"); } } if (description.TryGetProperty("use_emissive_map", out floatProperty) && floatProperty == 1.0f) { if (description.TryGetProperty("TEX_emissive_map", out textureProperty)) { Vector4 emissiveColor = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); if (description.TryGetProperty("emissive_intensity", out floatProperty)) { emissiveColor *= floatProperty; } material.SetColor("_EmissionColor", emissiveColor); material.SetTexture("_EmissionMap", textureProperty.texture); material.SetTextureOffset("_EmissionMap", uvOffset); material.SetTextureScale("_EmissionMap", uvScale); material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } if (description.HasAnimationCurve("emissive_intensity")) { Vector4 emissiveColor; description.TryGetProperty("emissive", out emissiveColor); for (int i = 0; i < clips.Length; i++) { description.TryGetAnimationCurve(clips[i].name, "emissive_intensity", out curve); // remap emissive intensity to emission color clips[i].SetCurve("", typeof(Material), "_EmissionColor.r", curve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.g", curve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.b", curve); } } } else if (description.TryGetProperty("emissive", out vectorProperty)) { if (vectorProperty.x > 0.0f || vectorProperty.y > 0.0f || vectorProperty.z > 0.0f) { material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; material.EnableKeyword("_EMISSION"); } if (description.TryGetProperty("emissive_intensity", out floatProperty)) { vectorProperty *= floatProperty; } material.SetColor("_EmissionColor", vectorProperty); if (description.HasAnimationCurve("emissive.x")) { if (description.HasAnimationCurve("emissive_intensity")) { // combine color and intensity. for (int i = 0; i < clips.Length; i++) { AnimationCurve intensityCurve; description.TryGetAnimationCurve(clips[i].name, "emissive_intensity", out intensityCurve); description.TryGetAnimationCurve(clips[i].name, "emissive.x", out curve); MultiplyCurves(curve, intensityCurve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.r", curve); description.TryGetAnimationCurve(clips[i].name, "emissive.y", out curve); MultiplyCurves(curve, intensityCurve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.g", curve); description.TryGetAnimationCurve(clips[i].name, "emissive.z", out curve); MultiplyCurves(curve, intensityCurve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.b", curve); } } else { RemapColorCurves(description, clips, "emissive", "_EmissionColor"); } } else if (description.HasAnimationCurve("emissive_intensity")) { Vector4 emissiveColor; description.TryGetProperty("emissive", out emissiveColor); for (int i = 0; i < clips.Length; i++) { description.TryGetAnimationCurve(clips[i].name, "emissive_intensity", out curve); // remap emissive intensity to emission color AnimationCurve curveR = new AnimationCurve(); ConvertAndCopyKeys(curveR, curve, value => ConvertFloatMultiply(emissiveColor.x, value)); clips[i].SetCurve("", typeof(Material), "_EmissionColor.r", curveR); AnimationCurve curveG = new AnimationCurve(); ConvertAndCopyKeys(curveG, curve, value => ConvertFloatMultiply(emissiveColor.y, value)); clips[i].SetCurve("", typeof(Material), "_EmissionColor.g", curveG); AnimationCurve curveB = new AnimationCurve(); ConvertAndCopyKeys(curveB, curve, value => ConvertFloatMultiply(emissiveColor.z, value)); clips[i].SetCurve("", typeof(Material), "_EmissionColor.b", curveB); } } } if (description.TryGetProperty("use_ao_map", out floatProperty) && floatProperty == 1.0f) { if (description.TryGetProperty("TEX_ao_map", out textureProperty)) { material.SetTexture("_OcclusionMap", textureProperty.texture); material.SetTextureOffset("_OcclusionMap", uvOffset); material.SetTextureScale("_OcclusionMap", uvScale); } } }
void CreateFrom3DsMaxPhysicalMaterial(MaterialDescription description, Material material, AnimationClip[] clips) { var shader = Shader.Find("Autodesk Interactive"); if (shader == null) { context.LogImportError("ThreeDSMaterialDescriptionPreprocessor cannot find a shader named 'Autodesk Interactive'."); return; } material.shader = shader; float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; float transparency = 0.0f; description.TryGetProperty("transparency", out transparency); if (transparency > 0.0f) { material.SetInt("_Mode", (int)StandardShaderGUI.BlendMode.Transparent); material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; } else { material.SetInt("_Mode", (int)StandardShaderGUI.BlendMode.Opaque); material.SetOverrideTag("RenderType", ""); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = -1; } if (description.TryGetProperty("base_color_map", out textureProperty)) { SetMaterialTextureProperty("_MainTex", material, textureProperty); material.SetColor("_Color", new Color(1.0f, 1.0f, 1.0f, 1.0f - transparency)); } else if (description.TryGetProperty("base_color", out vectorProperty)) { vectorProperty.w = 1.0f - transparency; material.SetColor("_Color", vectorProperty); } if (description.TryGetProperty("bump_map", out textureProperty)) { if (description.TryGetProperty("bump_map_amt", out floatProperty)) { material.SetFloat("_BumpScale", floatProperty); } SetMaterialTextureProperty("_BumpMap", material, textureProperty); material.EnableKeyword("_NORMALMAP"); } if (description.TryGetProperty("roughness_map", out textureProperty)) { SetMaterialTextureProperty("_SpecGlossMap", material, textureProperty); material.EnableKeyword("_SPECGLOSSMAP"); } if (description.TryGetProperty("metalness_map", out textureProperty)) { SetMaterialTextureProperty("_MetallicGlossMap", material, textureProperty); material.EnableKeyword("_METALLICGLOSSMAP"); } if (description.TryGetProperty("emit_color", out vectorProperty)) { if (description.TryGetProperty("emission", out floatProperty)) { vectorProperty *= floatProperty; } material.SetColor("_EmissionColor", vectorProperty); material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } }
void CreateFromMayaArnoldStandardSurfaceMaterial(MaterialDescription description, Material material, AnimationClip[] clips) { var shader = Shader.Find("Autodesk Interactive"); if (shader == null) { context.LogImportError("ThreeDSMaterialDescriptionPreprocessor cannot find a shader named 'Autodesk Interactive'."); return; } material.shader = shader; float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; if (description.TryGetProperty("transmission", out floatProperty) && floatProperty > 0.0f) { material.SetInt("_Mode", (int)StandardShaderGUI.BlendMode.Transparent); material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; } else { material.SetInt("_Mode", (int)StandardShaderGUI.BlendMode.Opaque); material.SetOverrideTag("RenderType", ""); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = -1; } if (description.TryGetProperty("baseColor", out textureProperty)) { SetMaterialTextureProperty("_MainTex", material, textureProperty); Color baseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f - floatProperty); material.SetColor("_Color", baseColor); } else if (description.TryGetProperty("baseColor", out vectorProperty)) { if (QualitySettings.activeColorSpace == ColorSpace.Gamma) { vectorProperty.x = Mathf.LinearToGammaSpace(vectorProperty.x); vectorProperty.y = Mathf.LinearToGammaSpace(vectorProperty.y); vectorProperty.z = Mathf.LinearToGammaSpace(vectorProperty.z); } vectorProperty.w = 1.0f - floatProperty; material.SetColor("_Color", vectorProperty); RemapColorCurves(description, clips, "baseColor", "_Color"); } if (description.HasAnimationCurve("transmission")) { for (int i = 0; i < clips.Length; i++) { AnimationCurve opacityCurve; description.TryGetAnimationCurve(clips[i].name, "transmission", out opacityCurve); clips[i].SetCurve("", typeof(Material), "_Color.a", opacityCurve); if (!description.HasAnimationCurveInClip(clips[i].name, "baseColor.x")) { Vector4 diffuseColor; description.TryGetProperty("baseColor", out diffuseColor); clips[i].SetCurve("", typeof(Material), "_Color.r", AnimationCurve.Constant(0.0f, 1.0f, diffuseColor.x)); clips[i].SetCurve("", typeof(Material), "_Color.g", AnimationCurve.Constant(0.0f, 1.0f, diffuseColor.y)); clips[i].SetCurve("", typeof(Material), "_Color.b", AnimationCurve.Constant(0.0f, 1.0f, diffuseColor.z)); } } } if (description.TryGetProperty("normalCamera", out textureProperty)) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); material.EnableKeyword("_NORMALMAP"); } if (description.TryGetProperty("specularRoughness", out textureProperty)) { SetMaterialTextureProperty("_SpecGlossMap", material, textureProperty); material.EnableKeyword("_SPECGLOSSMAP"); } else if (description.TryGetProperty("specularRoughness", out floatProperty)) { material.SetFloat("_Glossiness", floatProperty); RemapCurve(description, clips, "specularRoughness", "_Glossiness"); } if (description.TryGetProperty("metalness", out textureProperty)) { SetMaterialTextureProperty("_MetallicGlossMap", material, textureProperty); material.EnableKeyword("_METALLICGLOSSMAP"); RemapCurve(description, clips, "metalness", "_MetallicGlossMap"); } if (description.TryGetProperty("emission", out floatProperty) && floatProperty > 0.0f) { material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; Color emissiveColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); if (description.TryGetProperty("emissionColor", out textureProperty)) { emissiveColor *= floatProperty; SetMaterialTextureProperty("_EmissionMap", material, textureProperty); material.SetColor("_EmissionColor", emissiveColor); } else if (description.TryGetProperty("emissionColor", out vectorProperty)) { emissiveColor = vectorProperty * floatProperty; material.SetColor("_EmissionColor", emissiveColor); } } if (description.HasAnimationCurve("emissionColor.x")) { if (description.HasAnimationCurve("emission")) { // combine color and intensity. AnimationCurve curve; for (int i = 0; i < clips.Length; i++) { AnimationCurve intensityCurve; description.TryGetAnimationCurve(clips[i].name, "emission", out intensityCurve); description.TryGetAnimationCurve(clips[i].name, "emissionColor.x", out curve); MultiplyCurves(curve, intensityCurve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.r", curve); description.TryGetAnimationCurve(clips[i].name, "emissionColor.y", out curve); MultiplyCurves(curve, intensityCurve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.g", curve); description.TryGetAnimationCurve(clips[i].name, "emissionColor.z", out curve); MultiplyCurves(curve, intensityCurve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.b", curve); } } else { RemapColorCurves(description, clips, "emission", "_EmissionColor"); } } else if (description.HasAnimationCurve("emission")) { Vector4 emissiveColor; description.TryGetProperty("emissionColor", out emissiveColor); AnimationCurve curve; for (int i = 0; i < clips.Length; i++) { description.TryGetAnimationCurve(clips[i].name, "emission", out curve); // remap emissive intensity to emission color AnimationCurve curveR = new AnimationCurve(); ConvertAndCopyKeys(curveR, curve, value => ConvertFloatMultiply(emissiveColor.x, value)); clips[i].SetCurve("", typeof(Material), "_EmissionColor.r", curveR); AnimationCurve curveG = new AnimationCurve(); ConvertAndCopyKeys(curveG, curve, value => ConvertFloatMultiply(emissiveColor.y, value)); clips[i].SetCurve("", typeof(Material), "_EmissionColor.g", curveG); AnimationCurve curveB = new AnimationCurve(); ConvertAndCopyKeys(curveB, curve, value => ConvertFloatMultiply(emissiveColor.z, value)); clips[i].SetCurve("", typeof(Material), "_EmissionColor.b", curveB); } } }
public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] clips) { var pipelineAsset = GraphicsSettings.currentRenderPipeline; if (!pipelineAsset || pipelineAsset.GetType() != typeof(UniversalRenderPipelineAsset)) { return; } var lowerCasePath = Path.GetExtension(assetPath).ToLower(); if (lowerCasePath != ".3ds") { return; } string path = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(ShaderPathID.Lit)); var shader = AssetDatabase.LoadAssetAtPath <Shader>(path); if (shader == null) { return; } material.shader = shader; TexturePropertyDescription textureProperty; float floatProperty; Vector4 vectorProperty; description.TryGetProperty("diffuse", out vectorProperty); vectorProperty.x /= 255.0f; vectorProperty.y /= 255.0f; vectorProperty.z /= 255.0f; vectorProperty.w /= 255.0f; description.TryGetProperty("transparency", out floatProperty); bool isTransparent = vectorProperty.w <= 0.99f || floatProperty > .0f; if (isTransparent) { material.SetFloat("_Mode", (float)3.0); // From C# enum BlendMode material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; material.SetInt("_Surface", 1); } else { material.SetFloat("_Mode", (float)0.0); // From C# enum BlendMode material.SetOverrideTag("RenderType", ""); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = -1; material.SetInt("_Surface", 0); } if (floatProperty > .0f) { vectorProperty.w = 1.0f - floatProperty; } Color diffuseColor = vectorProperty; material.SetColor("_Color", PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor); material.SetColor("_BaseColor", PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor); if (description.TryGetProperty("EmissiveColor", out vectorProperty)) { material.SetColor("_EmissionColor", vectorProperty); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; material.EnableKeyword("_EMISSION"); } if (description.TryGetProperty("texturemap1", out textureProperty)) { SetMaterialTextureProperty("_BaseMap", material, textureProperty); } if (description.TryGetProperty("bumpmap", out textureProperty)) { if (material.HasProperty("_BumpMap")) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); material.EnableKeyword("_NORMALMAP"); } } }
static bool IsAutodeskInteractiveMaterial(MaterialDescription description) { return(description.TryGetProperty("renderAPI", out string stringValue) && stringValue == "SFX_PBS_SHADER"); }
public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] clips) { var pipelineAsset = GraphicsSettings.currentRenderPipeline; if (!pipelineAsset || pipelineAsset.GetType() != typeof(HDRenderPipelineAsset)) { return; } var lowerCasePath = Path.GetExtension(assetPath).ToLower(); if (lowerCasePath != ".3ds") { return; } var shader = Shader.Find("HDRP/Lit"); if (shader == null) { return; } material.shader = shader; material.SetShaderPassEnabled("DistortionVectors", false); material.SetShaderPassEnabled("TransparentDepthPrepass", false); material.SetShaderPassEnabled("TransparentDepthPostpass", false); material.SetShaderPassEnabled("TransparentBackface", false); material.SetShaderPassEnabled("MOTIONVECTORS", false); TexturePropertyDescription textureProperty; float floatProperty; Vector4 vectorProperty; description.TryGetProperty("diffuse", out vectorProperty); vectorProperty.x /= 255.0f; vectorProperty.y /= 255.0f; vectorProperty.z /= 255.0f; vectorProperty.w /= 255.0f; description.TryGetProperty("transparency", out floatProperty); bool isTransparent = vectorProperty.w <= 0.99f || floatProperty > .0f; if (isTransparent) { material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_ALPHA"); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; } else { material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.renderQueue = -1; } if (floatProperty > .0f) { vectorProperty.w = 1.0f - floatProperty; } Color diffuseColor = vectorProperty; material.SetColor("_Color", PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor); material.SetColor("_BaseColor", PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor); if (description.TryGetProperty("EmissiveColor", out vectorProperty)) { material.SetColor("_EmissionColor", vectorProperty); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; material.EnableKeyword("_EMISSION"); } if (description.TryGetProperty("texturemap1", out textureProperty)) { SetMaterialTextureProperty("_MainTex", material, textureProperty); SetMaterialTextureProperty("_BaseColorMap", material, textureProperty); } if (description.TryGetProperty("bumpmap", out textureProperty) && textureProperty.texture != null) { if (material.HasProperty("_BumpMap")) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); material.EnableKeyword("_NORMALMAP_TANGENT_SPACE"); } } }
public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] clips) { var pipelineAsset = GraphicsSettings.currentRenderPipeline; if (!pipelineAsset || pipelineAsset.GetType() != typeof(HDRenderPipelineAsset)) return; var lowerCaseExtension = Path.GetExtension(assetPath).ToLower(); if (lowerCaseExtension != ".fbx" && lowerCaseExtension != ".obj" && lowerCaseExtension != ".dae" && lowerCaseExtension != ".obj" && lowerCaseExtension != ".blend" && lowerCaseExtension != ".mb" && lowerCaseExtension != ".ma" && lowerCaseExtension != ".max") return; var shader = AssetDatabase.LoadAssetAtPath<Shader>(k_ShaderPath); if (shader == null) return; material.shader = shader; Vector4 vectorProperty; float floatProperty; TexturePropertyDescription textureProperty; bool isTransparent = false; float opacity; float transparencyFactor; if (!description.TryGetProperty("Opacity", out opacity)) { if (description.TryGetProperty("TransparencyFactor", out transparencyFactor)) { opacity = transparencyFactor == 1.0f ? 1.0f : 1.0f - transparencyFactor; } if (opacity == 1.0f && description.TryGetProperty("TransparentColor", out vectorProperty)) { opacity = vectorProperty.x == 1.0f ? 1.0f : 1.0f - vectorProperty.x; } } if (opacity < 1.0f || (opacity == 1.0f && description.TryGetProperty("TransparentColor", out textureProperty))) { isTransparent = true; } else if (description.HasAnimationCurve("TransparencyFactor") || description.HasAnimationCurve("TransparentColor")) { isTransparent = true; } if (isTransparent) { material.SetFloat("_BlendMode", (float)BlendMode.Alpha); material.SetFloat("_EnableBlendModePreserveSpecularLighting", 1.0f); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; material.SetFloat("_SurfaceType", (float)SurfaceType.Transparent); material.SetFloat("_Cutoff", .0f); material.SetFloat("_AlphaCutoffEnable", 1.0f); material.SetFloat("_AlphaCutoff", .0f); material.SetFloat("_AlphaCutoffShadow", 1.0f); material.SetFloat("_UseShadowThreshold", 1.0f); } else { material.renderQueue = -1; } if (description.TryGetProperty("ReflectionFactor", out floatProperty)) material.SetFloat("_Metallic", floatProperty); if (description.TryGetProperty("DiffuseColor", out textureProperty) && textureProperty.texture != null) { Color diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); if (description.TryGetProperty("DiffuseFactor", out floatProperty)) diffuseColor *= floatProperty; diffuseColor.a = opacity; SetMaterialTextureProperty("_BaseColorMap", material, textureProperty); material.SetColor("_BaseColor", diffuseColor); } else if (description.TryGetProperty("DiffuseColor", out vectorProperty)) { Color diffuseColor = vectorProperty; if (description.TryGetProperty("DiffuseFactor", out floatProperty)) diffuseColor *= floatProperty; diffuseColor.a = opacity; material.SetColor("_BaseColor", PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor); } if (description.TryGetProperty("Bump", out textureProperty) && textureProperty.texture != null) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); if (description.TryGetProperty("BumpFactor", out floatProperty)) material.SetFloat("_BumpScale", floatProperty); } else if (description.TryGetProperty("NormalMap", out textureProperty) && textureProperty.texture != null) { SetMaterialTextureProperty("_BumpMap", material, textureProperty); if (description.TryGetProperty("BumpFactor", out floatProperty)) material.SetFloat("_BumpScale", floatProperty); } if (description.TryGetProperty("EmissiveColor", out textureProperty)) { Color emissiveColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); material.SetColor("_EmissionColor", emissiveColor); material.SetColor("_EmissiveColor", emissiveColor); SetMaterialTextureProperty("_EmissionMap", material, textureProperty); if (description.TryGetProperty("EmissiveFactor", out floatProperty) && floatProperty > 0.0f) { material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } } else if ( description.TryGetProperty("EmissiveColor", out vectorProperty) && vectorProperty.magnitude > vectorProperty.w || description.HasAnimationCurve("EmissiveColor.x")) { if (description.TryGetProperty("EmissiveFactor", out floatProperty)) vectorProperty *= floatProperty; material.SetColor("_EmissionColor", vectorProperty); material.SetColor("_EmissiveColor", vectorProperty); if (floatProperty > 0.0f) { material.EnableKeyword("_EMISSION"); material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; } } material.SetFloat("_Glossiness", 0.0f); if (PlayerSettings.colorSpace == ColorSpace.Linear) RemapAndTransformColorCurves(description, clips, "DiffuseColor", "_BaseColor", ConvertFloatLinearToGamma); else RemapColorCurves(description, clips, "DiffuseColor", "_BaseColor"); RemapTransparencyCurves(description, clips); RemapColorCurves(description, clips, "EmissiveColor", "_EmissionColor"); RemapColorCurves(description, clips, "EmissiveColor", "_EmissiveColor"); HDShaderUtils.ResetMaterialKeywords(material); }
public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] clips) { if (IsAutodeskInteractiveMaterial(description)) { float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; bool isMasked = description.TryGetProperty("mask_threshold", out floatProperty); bool isTransparent = description.TryGetProperty("opacity", out floatProperty); Shader shader; if (isMasked) { shader = GraphicsSettings.currentRenderPipeline.autodeskInteractiveMaskedShader; } else if (isTransparent) { shader = GraphicsSettings.currentRenderPipeline.autodeskInteractiveTransparentShader; } else { shader = GraphicsSettings.currentRenderPipeline.autodeskInteractiveShader; } if (shader == null) { return; } material.shader = shader; foreach (var clip in clips) { clip.ClearCurves(); } if (description.TryGetProperty("base_color", out vectorProperty)) { material.SetColor("_Color", vectorProperty); } if (description.TryGetProperty("emissive", out vectorProperty)) { material.SetColor("_EmissionColor", vectorProperty); } if (description.TryGetProperty("roughness", out floatProperty)) { material.SetFloat("_Roughness", floatProperty); } if (description.TryGetProperty("metallic", out floatProperty)) { material.SetFloat("_Metallic", floatProperty); } if (description.TryGetProperty("uvTransform", out vectorProperty)) { material.SetVector("_UvOffset", new Vector4(vectorProperty.x, vectorProperty.y, .0f, .0f)); material.SetVector("_UvTiling", new Vector4(vectorProperty.w, vectorProperty.z, .0f, .0f)); } if (description.TryGetProperty("TEX_color_map", out textureProperty)) { material.SetTexture("_MainTex", textureProperty.texture); material.SetFloat("_UseColorMap", 1.0f); } else { material.SetFloat("_UseColorMap", 0.0f); } if (description.TryGetProperty("TEX_normal_map", out textureProperty)) { material.SetTexture("_BumpMap", textureProperty.texture); material.SetFloat("_UseNormalMap", 1.0f); } else { material.SetFloat("_UseNormalMap", 0.0f); } if (description.TryGetProperty("TEX_roughness_map", out textureProperty)) { material.SetTexture("RoughnessMap", textureProperty.texture); material.SetFloat("_UseRoughnessMap", 1.0f); } else { material.SetFloat("_UseRoughnessMap", 0.0f); } if (description.TryGetProperty("TEX_metallic_map", out textureProperty)) { material.SetTexture("_MetallicMap", textureProperty.texture); material.SetFloat("_UseMetallicMap", 1.0f); } else { material.SetFloat("_UseMetallicMap", 0.0f); } if (description.TryGetProperty("TEX_emissive_map", out textureProperty)) { material.SetTexture("_EmissionMap", textureProperty.texture); material.SetFloat("_UseEmissiveMap", 1.0f); } else { material.SetFloat("_UseEmissiveMap", 0.0f); } if (description.TryGetProperty("hasTransparencyTexture", out floatProperty)) { material.SetFloat("_UseOpacityMap", floatProperty); } if (description.TryGetProperty("transparencyMaskThreshold", out floatProperty)) { material.SetFloat("_OpacityThreshold", floatProperty); } if (description.TryGetProperty("TEX_ao_map", out textureProperty)) { var tex = AssetDatabase.LoadAssetAtPath <Texture>(textureProperty.relativePath); material.SetTexture("AoMap", tex); material.SetFloat("UseAoMap", 1.0f); } else { material.SetFloat("UseAoMap", 0.0f); } RemapColorCurves(description, clips, "base_color", "_Color"); RemapCurve(description, clips, "mask_threshold", "_Cutoff"); RemapCurve(description, clips, "metallic", "_Metallic"); RemapCurve(description, clips, "roughness", "_Glossiness"); for (int i = 0; i < clips.Length; i++) { if (description.HasAnimationCurveInClip(clips[i].name, "uv_scale.x") || description.HasAnimationCurveInClip(clips[i].name, "uv_scale.y")) { AnimationCurve curve; if (description.TryGetAnimationCurve(clips[i].name, "uv_scale.x", out curve)) { clips[i].SetCurve("", typeof(Material), "_UvTiling.x", curve); } else { clips[i].SetCurve("", typeof(Material), "_UvTiling.x", AnimationCurve.Constant(0.0f, 1.0f, 1.0f)); } if (description.TryGetAnimationCurve(clips[i].name, "uv_scale.y", out curve)) { clips[i].SetCurve("", typeof(Material), "_UvTiling.y", curve); } else { clips[i].SetCurve("", typeof(Material), "_UvTiling.y", AnimationCurve.Constant(0.0f, 1.0f, 1.0f)); } } if (description.HasAnimationCurveInClip(clips[i].name, "uv_offset.x") || description.HasAnimationCurveInClip(clips[i].name, "uv_offset.y")) { AnimationCurve curve; if (description.TryGetAnimationCurve(clips[i].name, "uv_offset.x", out curve)) { clips[i].SetCurve("", typeof(Material), "_UvOffset.x", curve); } else { clips[i].SetCurve("", typeof(Material), "_UvOffset.x", AnimationCurve.Constant(0.0f, 1.0f, 0.0f)); } if (description.TryGetAnimationCurve(clips[i].name, "uv_offset.y", out curve)) { ConvertKeys(curve, ConvertFloatNegate); clips[i].SetCurve("", typeof(Material), "_UvOffset.y", curve); } else { clips[i].SetCurve("", typeof(Material), "_UvOffset.y", AnimationCurve.Constant(0.0f, 1.0f, 0.0f)); } } } if (description.HasAnimationCurve("emissive_intensity")) { Vector4 emissiveColor; description.TryGetProperty("emissive", out emissiveColor); for (int i = 0; i < clips.Length; i++) { AnimationCurve curve; description.TryGetAnimationCurve(clips[i].name, "emissive_intensity", out curve); // remap emissive intensity to emission color clips[i].SetCurve("", typeof(Material), "_EmissionColor.r", curve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.g", curve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.b", curve); } } else if (description.TryGetProperty("emissive", out vectorProperty)) { if (vectorProperty.x > 0.0f || vectorProperty.y > 0.0f || vectorProperty.z > 0.0f) { material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive; material.EnableKeyword("_EMISSION"); } if (description.TryGetProperty("emissive_intensity", out floatProperty)) { vectorProperty *= floatProperty; } material.SetColor("_EmissionColor", vectorProperty); if (description.HasAnimationCurve("emissive.x")) { if (description.HasAnimationCurve("emissive_intensity")) { // combine color and intensity. for (int i = 0; i < clips.Length; i++) { AnimationCurve curve; AnimationCurve intensityCurve; description.TryGetAnimationCurve(clips[i].name, "emissive_intensity", out intensityCurve); description.TryGetAnimationCurve(clips[i].name, "emissive.x", out curve); MultiplyCurves(curve, intensityCurve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.r", curve); description.TryGetAnimationCurve(clips[i].name, "emissive.y", out curve); MultiplyCurves(curve, intensityCurve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.g", curve); description.TryGetAnimationCurve(clips[i].name, "emissive.z", out curve); MultiplyCurves(curve, intensityCurve); clips[i].SetCurve("", typeof(Material), "_EmissionColor.b", curve); } } else { RemapColorCurves(description, clips, "emissive", "_EmissionColor"); } } else if (description.HasAnimationCurve("emissive_intensity")) { Vector4 emissiveColor; description.TryGetProperty("emissive", out emissiveColor); for (int i = 0; i < clips.Length; i++) { AnimationCurve curve; description.TryGetAnimationCurve(clips[i].name, "emissive_intensity", out curve); // remap emissive intensity to emission color AnimationCurve curveR = new AnimationCurve(); ConvertAndCopyKeys(curveR, curve, value => ConvertFloatMultiply(emissiveColor.x, value)); clips[i].SetCurve("", typeof(Material), "_EmissionColor.r", curveR); AnimationCurve curveG = new AnimationCurve(); ConvertAndCopyKeys(curveG, curve, value => ConvertFloatMultiply(emissiveColor.y, value)); clips[i].SetCurve("", typeof(Material), "_EmissionColor.g", curveG); AnimationCurve curveB = new AnimationCurve(); ConvertAndCopyKeys(curveB, curve, value => ConvertFloatMultiply(emissiveColor.z, value)); clips[i].SetCurve("", typeof(Material), "_EmissionColor.b", curveB); } } } } }
void CreateFrom3DsPhysicalMaterial(MaterialDescription description, Material material, AnimationClip[] clips) { float floatProperty; Vector4 vectorProperty; TexturePropertyDescription textureProperty; var shader = AssetDatabase.LoadAssetAtPath <Shader>(k_ShaderPath); if (shader == null) { return; } material.shader = shader; foreach (var clip in clips) { clip.ClearCurves(); } description.TryGetProperty("transparency", out floatProperty); bool hasTransparencyMap = description.TryGetProperty("transparency_map", out textureProperty); if (floatProperty > 0.0f || hasTransparencyMap) { if (hasTransparencyMap) { material.SetTexture("_TRANSPARENCY_MAP", textureProperty.texture); material.SetFloat("_TRANSPARENCY", 1.0f); } else { material.SetFloat("_TRANSPARENCY", floatProperty); } material.SetInt("_SrcBlend", 1); material.SetInt("_DstBlend", 10); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING"); material.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT"); material.EnableKeyword("_BLENDMODE_ALPHA"); material.renderQueue = 3000; } else { material.EnableKeyword("_DOUBLESIDED_ON"); material.SetInt("_CullMode", 0); material.SetInt("_CullModeForward", 0); material.doubleSidedGI = true; } RemapPropertyFloat(description, material, "base_weight", "_BASE_COLOR_WEIGHT"); if (description.TryGetProperty("base_color_map", out textureProperty)) { SetMaterialTextureProperty("_BASE_COLOR_MAP", material, textureProperty); } else if (description.TryGetProperty("base_color", out vectorProperty)) { if (QualitySettings.activeColorSpace == ColorSpace.Gamma) { vectorProperty.x = Mathf.LinearToGammaSpace(vectorProperty.x); vectorProperty.y = Mathf.LinearToGammaSpace(vectorProperty.y); vectorProperty.z = Mathf.LinearToGammaSpace(vectorProperty.z); vectorProperty.w = Mathf.LinearToGammaSpace(vectorProperty.w); } material.SetColor("_BASE_COLOR", vectorProperty); } RemapPropertyFloat(description, material, "reflectivity", "_REFLECTIONS_WEIGHT"); RemapPropertyTextureOrColor(description, material, "refl_color", "_REFLECTIONS_COLOR"); RemapPropertyTextureOrFloat(description, material, "metalness", "_METALNESS"); RemapPropertyTextureOrFloat(description, material, "roughness", "_REFLECTIONS_ROUGHNESS"); RemapPropertyTextureOrFloat(description, material, "trans_ior", "_REFLECTIONS_IOR"); RemapPropertyFloat(description, material, "emission", "_EMISSION_WEIGHT"); RemapPropertyTextureOrColor(description, material, "emit_color", "_EMISSION_COLOR"); RemapPropertyTextureOrFloat(description, material, "anisotropy", "_ANISOTROPY"); RemapPropertyFloat(description, material, "bump_map_amt", "_BUMP_MAP_STRENGTH"); RemapPropertyTexture(description, material, "bump_map", "_BUMP_MAP"); }