// SPDX-FileCopyrightText: 2024 Unity Technologies and the glTFast authors
// SPDX-License-Identifier: Apache-2.0
using System;
using Unity.Mathematics;
using UnityEngine;
namespace GLTFast.Schema
{
///
/// This extension allows configuring the specular reflection.
///
///
[Serializable]
public class MaterialSpecular
{
///
/// The strength of the specular reflection.
///
public float specularFactor = 1f;
///
/// A texture that defines the strength of the specular reflection, stored in the alpha (A) channel.
/// This will be multiplied by specularFactor.
///
public TextureInfo specularTexture;
///
/// The F0 color of the specular reflection (linear RGB).
///
public float[] specularColorFactor = { 1, 1, 1 };
///
public Color SpecularColor
{
get =>
new Color(
specularColorFactor[0],
specularColorFactor[1],
specularColorFactor[2]
);
set
{
specularColorFactor = new[] { value.r, value.g, value.b };
}
}
///
/// A texture that defines the F0 color of the specular reflection, stored in the RGB channels and encoded in
/// sRGB. This texture will be multiplied by specularColorFactor.
///
public TextureInfo specularColorTexture;
internal void GltfSerialize(JsonWriter writer)
{
writer.AddObject();
if (math.abs(specularFactor - 1f) > Constants.epsilon)
{
writer.AddProperty("specularFactor", specularFactor);
}
if (specularTexture != null)
{
writer.AddProperty("specularTexture");
specularTexture.GltfSerialize(writer);
}
if (specularColorFactor != null && specularColorFactor.Length > 2 && (
math.abs(specularColorFactor[0] - 1f) > Constants.epsilon ||
math.abs(specularColorFactor[1] - 1f) > Constants.epsilon ||
math.abs(specularColorFactor[2] - 1f) > Constants.epsilon
))
{
writer.AddArrayProperty("specularColorFactor", specularColorFactor);
}
if (specularColorTexture != null)
{
writer.AddProperty("specularColorTexture");
specularColorTexture.GltfSerialize(writer);
}
writer.Close();
}
}
}