// SPDX-FileCopyrightText: 2023 Unity Technologies and the glTFast authors
// SPDX-License-Identifier: Apache-2.0
using Unity.Mathematics;
using UnityEngine;
namespace GLTFast.Schema
{
///
/// This extension defines a sheen that can be layered on top of an
/// existing glTF material definition. A sheen layer is a common technique
/// used in Physically-Based Rendering to represent cloth and fabric
/// materials, for example.
///
///
[System.Serializable]
public class Sheen
{
///
/// The sheen color red, green and blue components in linear space.
///
public float[] sheenColorFactor = { 1, 1, 1 };
///
/// The sheen color in linear space.
///
public Color SheenColor
{
get =>
new Color(
sheenColorFactor[0],
sheenColorFactor[1],
sheenColorFactor[2]
);
set
{
sheenColorFactor = new[] { value.r, value.g, value.b };
}
}
///
/// The sheen color texture.
///
public TextureInfo sheenColorTexture;
///
/// The sheen roughness.
///
public float sheenRoughnessFactor;
///
/// The sheen roughness (Alpha) texture.
///
public TextureInfo sheenRoughnessTexture;
internal void GltfSerialize(JsonWriter writer)
{
writer.AddObject();
if (sheenColorFactor != null && sheenColorFactor.Length > 2 && (
math.abs(sheenColorFactor[0] - 1f) > Constants.epsilon ||
math.abs(sheenColorFactor[1] - 1f) > Constants.epsilon ||
math.abs(sheenColorFactor[2] - 1f) > Constants.epsilon
))
{
writer.AddArrayProperty("sheenColorFactor", sheenColorFactor);
}
if (sheenColorTexture != null)
{
writer.AddProperty("sheenColorTexture");
sheenColorTexture.GltfSerialize(writer);
}
if (sheenRoughnessFactor > 0)
{
writer.AddProperty("sheenRoughnessFactor", sheenRoughnessFactor);
}
if (sheenRoughnessTexture != null)
{
writer.AddProperty("sheenRoughnessTexture");
sheenRoughnessTexture.GltfSerialize(writer);
}
writer.Close();
}
}
}