protected override void SetAlphaModeMask(Schema.Material gltfMaterial, Material material) { base.SetAlphaModeMask(gltfMaterial, material); material.SetFloat(k_AlphaCutoffEnable, 1); material.SetOverrideTag(TAG_MOTION_VECTOR, TAG_MOTION_VECTOR_USER); material.SetShaderPassEnabled(k_MotionVectorsPass, false); if (gltfMaterial.extensions?.KHR_materials_unlit != null) { material.EnableKeyword(KW_SURFACE_TYPE_TRANSPARENT); material.EnableKeyword(KW_DISABLE_SSR_TRANSPARENT); material.EnableKeyword(KW_ENABLE_FOG_ON_TRANSPARENT); material.SetOverrideTag(TAG_RENDER_TYPE, TAG_RENDER_TYPE_TRANSPARENT); material.SetShaderPassEnabled(k_ShaderPassTransparentDepthPrepass, false); material.SetShaderPassEnabled(k_ShaderPassTransparentDepthPostpass, false); material.SetShaderPassEnabled(k_ShaderPassTransparentBackface, false); material.SetShaderPassEnabled(k_ShaderPassRayTracingPrepass, false); material.SetShaderPassEnabled(k_ShaderPassDepthOnlyPass, false); material.SetShaderPassEnabled(k_DistortionVectorsPass, false); material.SetFloat(k_AlphaDstBlendPropId, (int)BlendMode.OneMinusSrcAlpha); //10 material.SetFloat(dstBlendPropId, (int)BlendMode.OneMinusSrcAlpha); //10 material.SetFloat(srcBlendPropId, (int)BlendMode.One); // material.SetFloat(k_RenderQueueType, 4); // material.SetFloat(k_SurfaceType, 1); material.SetFloat(k_ZTestDepthEqualForOpaque, (int)CompareFunction.LessEqual); material.SetFloat(zWritePropId, 0); } }
protected override void SetShaderModeBlend(Schema.Material gltfMaterial, Material material) { material.DisableKeyword(KW_ALPHATEST_ON); material.EnableKeyword(KW_SURFACE_TYPE_TRANSPARENT); // material.EnableKeyword(KW_DISABLE_DECALS); material.EnableKeyword(KW_DISABLE_SSR_TRANSPARENT); material.EnableKeyword(KW_ENABLE_FOG_ON_TRANSPARENT); material.SetOverrideTag(TAG_RENDER_TYPE, TAG_RENDER_TYPE_TRANSPARENT); material.SetShaderPassEnabled(k_ShaderPassTransparentDepthPrepass, false); material.SetShaderPassEnabled(k_ShaderPassTransparentDepthPostpass, false); material.SetShaderPassEnabled(k_ShaderPassTransparentBackface, false); material.SetShaderPassEnabled(k_ShaderPassRayTracingPrepass, false); material.SetShaderPassEnabled(k_ShaderPassDepthOnlyPass, false); material.SetFloat(k_AlphaCutoffEnable, 0); material.SetFloat(k_RenderQueueType, (int)CustomPass.RenderQueueType.PreRefraction); // 4 material.SetFloat(k_SurfaceType, 1); material.SetFloat(zWritePropId, 0); material.SetFloat(k_ZTestGBufferPropId, (int)CompareFunction.LessEqual); //4 material.SetFloat(k_ZTestDepthEqualForOpaque, (int)CompareFunction.LessEqual); //4 material.SetFloat(k_AlphaDstBlendPropId, (int)BlendMode.OneMinusSrcAlpha); //10 material.SetFloat(dstBlendPropId, (int)BlendMode.OneMinusSrcAlpha); //10 material.SetFloat(srcBlendPropId, (int)BlendMode.SrcAlpha); //5 }
protected override void SetShaderModeBlend(Schema.Material gltfMaterial, Material material) { material.EnableKeyword(KW_ALPHATEST_ON); material.EnableKeyword(k_SurfaceTypeTransparent); material.renderQueue = (int)RenderQueue.Transparent; material.SetFloat(k_DstBlendPropId, (int)BlendMode.OneMinusSrcAlpha); //10 material.SetFloat(k_SrcBlendPropId, (int)BlendMode.SrcAlpha); //5 material.SetFloat(k_SurfacePropId, 1); material.SetFloat(k_ZWritePropId, 0); }
protected override void SetDoubleSided(Schema.Material gltfMaterial, Material material) { base.SetDoubleSided(gltfMaterial, material); material.EnableKeyword(KW_DOUBLESIDED_ON); material.SetFloat(k_DoubleSidedEnablePropId, 1); // UnityEditor.Rendering.HighDefinition.DoubleSidedNormalMode.Flip material.SetFloat(k_DoubleSidedNormalModePropId, 0); material.SetVector(k_DoubleSidedConstantsPropId, new Vector4(-1, -1, -1, 0)); material.SetFloat(cullModePropId, (int)CullMode.Off); material.SetFloat(cullModeForwardPropId, (int)CullMode.Off); }
public override void PostExportMaterial(int index, Material unityMaterial) { var info = this.exporter.pbrMaterialManager.ConvertToSpecular(unityMaterial).GetInfo <SpecularInfo>(); if (info._SmoothnessTextureChannel != 0) { throw new NotImplementedException(); } var specularGlossiness = new Schema.Material { DiffuseFactor = ColorToArray(info._Color.linear, 4), }; if (info._MainTex != null) { specularGlossiness.DiffuseTexture = new Gltf.Schema.MaterialTexture { Index = this.exporter.ExportTexture(info._MainTex, FormatMaterialTextureName("diffuse", index)), }; } if (info._SpecGlossMap == null) { specularGlossiness.SpecularFactor = ColorToArray(info._SpecColor.linear, 3); specularGlossiness.GlossinessFactor = info._Glossiness; } else { specularGlossiness.GlossinessFactor = info._GlossMapScale; specularGlossiness.SpecularGlossinessTexture = new Gltf.Schema.MaterialTexture { Index = this.exporter.ExportTexture(info._SpecGlossMap, FormatMaterialTextureName("specularGlossiness", index)), }; } var material = this.exporter.materials[index]; if (material.Extensions == null) { material.Extensions = new Dictionary <string, object>(); } material.Extensions.Add(this.GetType().Name, specularGlossiness); }
protected override void SetShaderModeBlend(Schema.Material gltfMaterial, Material material) { material.EnableKeyword(KW_ALPHATEST_ON); material.EnableKeyword(KW_SURFACE_TYPE_TRANSPARENT); // material.EnableKeyword(KW_DISABLE_DECALS); material.EnableKeyword(KW_DISABLE_SSR_TRANSPARENT); material.EnableKeyword(KW_ENABLE_FOG_ON_TRANSPARENT); material.SetOverrideTag(TAG_RENDER_TYPE, TAG_RENDER_TYPE_TRANSPARENT); material.SetShaderPassEnabled(k_ShaderPassTransparentDepthPrepass, false); material.SetShaderPassEnabled(k_ShaderPassTransparentDepthPostpass, false); material.SetShaderPassEnabled(k_ShaderPassTransparentBackface, false); material.SetShaderPassEnabled(k_ShaderPassRayTracingPrepass, false); material.SetShaderPassEnabled(k_ShaderPassDepthOnlyPass, false); material.SetFloat(k_ZTestGBufferPropId, (int)CompareFunction.Equal); //3 material.SetFloat(k_AlphaDstBlendPropId, (int)BlendMode.OneMinusSrcAlpha); //10 material.SetFloat(dstBlendPropId, (int)BlendMode.OneMinusSrcAlpha); //10 material.SetFloat(srcBlendPropId, (int)BlendMode.SrcAlpha); //5 }
public abstract UnityEngine.Material GenerateMaterial(Schema.Material gltfMaterial, IGltfReadable gltf);
private void ExportMaterialCore(Material unityMaterial, bool packOcclusion, out int index) { var info = new OcclusionMetallicInfo { Metallic = this.pbrMaterialManager.ConvertToMetallic(unityMaterial).GetInfo <MetallicInfo>(), Occlusion = packOcclusion ? unityMaterial.GetInfo <OcclusionInfo>() : default(OcclusionInfo), }; if (info.Metallic._SmoothnessTextureChannel != 0) { throw new NotImplementedException(); } if (info.Occlusion._OcclusionMap == null) { packOcclusion = false; } index = this.materials.Count; var material = new Schema.Material { Name = unityMaterial.name, PbrMetallicRoughness = new Schema.MaterialPbrMetallicRoughness { BaseColorFactor = ColorToArray(info.Metallic._Color.linear, 4), }, }; if (info.Metallic._MainTex != null) { material.PbrMetallicRoughness.BaseColorTexture = new Schema.MaterialTexture { Index = this.ExportTexture(info.Metallic._MainTex, FormatMaterialTextureName("baseColor", index)), }; } if (info.Metallic._MetallicGlossMap == null && !packOcclusion) { material.PbrMetallicRoughness.MetallicFactor = Mathf.GammaToLinearSpace(info.Metallic._Metallic); material.PbrMetallicRoughness.RoughnessFactor = 1.0f - info.Metallic._Glossiness; } else { material.PbrMetallicRoughness.MetallicFactor = 1.0f; material.PbrMetallicRoughness.RoughnessFactor = 1.0f; Texture2D texture; if (!this.occlusionMetallicInfoToTextureCache.TryGetValue(info, out texture)) { var pixels = info.Metallic._MetallicGlossMap.GetPixels(); for (int i = 0; i < pixels.Length; i++) { pixels[i] = new Color(0.0f, 1.0f - (pixels[i].a * info.Metallic._GlossMapScale), Mathf.GammaToLinearSpace(pixels[i].grayscale)); } if (packOcclusion) { var occlusionPixels = info.Occlusion._OcclusionMap.GetPixels(); if (occlusionPixels.Length != pixels.Length) { throw new NotSupportedException(); } for (int i = 0; i < pixels.Length; i++) { pixels[i].r = Mathf.GammaToLinearSpace(occlusionPixels[i].grayscale); } } texture = this.objectTracker.Add(new Texture2D(info.Metallic._MetallicGlossMap.width, info.Metallic._MetallicGlossMap.height, TextureFormat.RGB24, false)); texture.SetPixels(pixels); texture.Apply(); this.occlusionMetallicInfoToTextureCache.Add(info, texture); } var textureName = packOcclusion ? "occlusionRoughnessMetallic" : "roughnessMetallic"; var textureIndex = this.ExportTexture(texture, FormatMaterialTextureName(textureName, index)); material.PbrMetallicRoughness.MetallicRoughnessTexture = new Schema.MaterialTexture { Index = textureIndex, }; if (packOcclusion) { material.OcclusionTexture = new Schema.MaterialOcclusionTexture { Index = textureIndex, Strength = info.Occlusion._OcclusionStrength, }; } } this.materials.Add(material); this.ExportMaterialAlpha(unityMaterial, index); this.ExportMaterialNormal(unityMaterial, index); this.ExportMaterialEmissive(unityMaterial, index); // For now, assume MASK materials are always double-sided if (material.AlphaMode == Schema.AlphaMode.MASK) { material.DoubleSided = true; } }
public abstract UnityEngine.Material GenerateMaterial( Schema.Material gltfMaterial, ref Schema.Texture[] textures, ref Schema.Image[] schemaImages, ref Dictionary <int, Texture2D>[] imageVariants );
protected override void SetDoubleSided(Schema.Material gltfMaterial, Material material) { base.SetDoubleSided(gltfMaterial, material); material.SetFloat(k_CullModePropId, (int)CullMode.Off); }