/// <summary> /// Checks if UMAMaterials are effectively equal. /// Useful when comparing materials from asset bundles, that would otherwise say they are different to ones in the binary /// And procedural materials which can be output compatible even if they are generated from different sources /// </summary> /// <param name="material">The material to compare</param> /// <returns></returns> public bool Equals(UMAMaterial material) { if (this.GetInstanceID() == material.GetInstanceID()) { return(true); } else { if (this.material.name != material.material.name) { return(false); } if (this.material.shader != material.material.shader) { return(false); } if (this.material.renderQueue != material.material.renderQueue) { return(false); } if (this.materialType != material.materialType) { return(false); } if (this.channels.Length != material.channels.Length) { return(false); } for (int i = 0; i < this.channels.Length; i++) { MaterialChannel thisChannel = this.channels[i]; MaterialChannel otherChannel = material.channels[i]; if (thisChannel.channelType != otherChannel.channelType) { return(false); } if (thisChannel.materialPropertyName != otherChannel.materialPropertyName) { return(false); } } return(true); } }
private SamplerParameters?TransfromSamplerParameters(MaterialChannel materialChannel, ReaderContext context) { var materialChannelTexture = materialChannel.Texture; if (materialChannelTexture == null) { return(null); } var primaryImage = materialChannelTexture.PrimaryImage; if (primaryImage == null) { return(null); } return(new SamplerParameters { Image = context.Images[primaryImage.LogicalIndex], TextureCoordinate = materialChannel.TextureCoordinate, TextureTransform = TransformTextureTransform(materialChannel.TextureTransform) }); }
private IEnumerable <IShaderParameter> TransformShaderParameter(MaterialChannel materialChannel, ReaderContext context) { var parameter = materialChannel.Parameter; switch (materialChannel.Key) { case "BaseColor": { var samplerParameters = TransfromSamplerParameters(materialChannel, context); if (samplerParameters.HasValue) { yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.BaseColorTexture, samplerParameters.Value)); } } yield return(new ShaderParameter <Vector4>(ShaderParameterKey.BaseColorFactor, parameter)); yield break; case "Diffuse": { var samplerParameters = TransfromSamplerParameters(materialChannel, context); if (samplerParameters.HasValue) { yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.DiffuseTexture, samplerParameters.Value)); } } yield return(new ShaderParameter <Vector4>(ShaderParameterKey.DiffuseFactor, parameter)); yield break; case "MetallicRoughness": { var samplerParameters = TransfromSamplerParameters(materialChannel, context); if (samplerParameters.HasValue) { yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.MetallicRoughnessTexture, samplerParameters.Value)); } } yield return(new ShaderParameter <float>(ShaderParameterKey.MetallicFactor, parameter.X)); yield return(new ShaderParameter <float>(ShaderParameterKey.RoughnessFactor, parameter.Y)); yield break; case "SpecularGlossiness": { var samplerParameters = TransfromSamplerParameters(materialChannel, context); if (samplerParameters.HasValue) { yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.SpecularGlossinessTexture, samplerParameters.Value)); } } yield return(new ShaderParameter <Vector3>(ShaderParameterKey.SpecularFactor, new Vector3(parameter.X, parameter.Y, parameter.Z))); yield return(new ShaderParameter <float>(ShaderParameterKey.GlossinessFactor, parameter.W)); yield break; case "Normal": { var samplerParameters = TransfromSamplerParameters(materialChannel, context); if (samplerParameters.HasValue) { yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.NormalTexture, samplerParameters.Value)); } } yield return(new ShaderParameter <float>(ShaderParameterKey.NormalTextureScale, parameter.X)); yield break; case "Occlusion": { var samplerParameters = TransfromSamplerParameters(materialChannel, context); if (samplerParameters.HasValue) { yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.OcclusionTexture, samplerParameters.Value)); } } yield return(new ShaderParameter <float>(ShaderParameterKey.OcclusionTextureStrength, parameter.X)); yield break; case "Emissive": { var samplerParameters = TransfromSamplerParameters(materialChannel, context); if (samplerParameters.HasValue) { yield return(new ShaderParameter <SamplerParameters>(ShaderParameterKey.EmissiveTexture, samplerParameters.Value)); } } { yield return(new ShaderParameter <Vector3>(ShaderParameterKey.EmissiveFactor, new Vector3(parameter.X, parameter.Y, parameter.Z))); } yield break; default: throw new NotImplementedException($"Material channel {materialChannel.Key} is not supported yet"); } }