Skip to content

Commit

Permalink
feat: add checks and documentation for SupportedInformationKind and API
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Oct 17, 2024
1 parent 232ef78 commit d116e99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions API-Editor/ShaderInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ internal MaterialInformationCallback()
/// Avatar Optimizer will preserve the integer part (floor(x, y)) of the UV Value while optimization for each primitive.
/// If your usage only use integer part of the UV like UV Tile Discard, you should not register the UV Usage as Other UV Usage.
/// </summary>
/// <remarks>This API is to provide <see cref="ShaderInformationKind.TextureAndUVUsage"/>.</remarks>
/// <param name="uvChannel">The UVChannels that are used in the shader.</param>
[PublicAPI]
public abstract void RegisterOtherUVUsage(UsingUVChannels uvChannel);
Expand All @@ -233,6 +234,7 @@ internal MaterialInformationCallback()
///
/// The texture might go to the atlas / UV Packing if the UsingUVChannels is set and the UV Matrix is known
/// </summary>
/// <remarks>This API is to provide <see cref="ShaderInformationKind.TextureAndUVUsage"/>.</remarks>
/// <param name="textureMaterialPropertyName">The name of the texture property in the material.</param>
/// <param name="samplerState">The information about the sampler state used for the specified texture.</param>
/// <param name="uvChannels">The UVChannels that are used in the shader to determine the UV for the texture.</param>
Expand Down
19 changes: 16 additions & 3 deletions Editor/Processors/ShaderMaterialInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ public MaterialInformation(Material material, List<Renderer> renderers, BuildCon
if (ShaderInformationRegistry.GetShaderInformation(material.shader) is { } information)
{
HasShaderInformation = true;


var supportedKind = information.SupportedInformationKind;
var provider = new MaterialInformationCallbackImpl(
material,
supportedKind,
renderers.Select(renderer => context.GetAnimationComponent(renderer)).ToList());
information.GetMaterialInformation(provider);
TextureUsageInformationList = provider.TextureUsageInformations;
Expand All @@ -94,14 +96,20 @@ class MaterialInformationCallbackImpl : MaterialInformationCallback
{
private readonly Material _material;
private readonly List<AnimationComponentInfo<PropertyInfo>> _infos;
private List<TextureUsageInformation>? _textureUsageInformations = new();
private List<TextureUsageInformation>? _textureUsageInformations;
private readonly ShaderInformationKind _supportedKind;

public List<TextureUsageInformation>? TextureUsageInformations => _textureUsageInformations;

public MaterialInformationCallbackImpl(Material material, List<AnimationComponentInfo<PropertyInfo>> infos)
public MaterialInformationCallbackImpl(Material material, ShaderInformationKind supportedKind,
List<AnimationComponentInfo<PropertyInfo>> infos)
{
_material = material;
_supportedKind = supportedKind;
_infos = infos;

if ((_supportedKind & ShaderInformationKind.TextureAndUVUsage) != 0)
_textureUsageInformations = new List<TextureUsageInformation>();
}

public Shader Shader => _material.shader;
Expand Down Expand Up @@ -130,6 +138,9 @@ public MaterialInformationCallbackImpl(Material material, List<AnimationComponen

public override void RegisterOtherUVUsage(UsingUVChannels uvChannel)
{
if ((_supportedKind & ShaderInformationKind.TextureAndUVUsage) == 0)
throw new InvalidOperationException("RegisterOtherUVUsage is not registered as supported information");

// no longer atlasing is not supported
_textureUsageInformations = null;
}
Expand All @@ -140,6 +151,8 @@ public override void RegisterTextureUVUsage(
UsingUVChannels uvChannels,
Matrix2x3? uvMatrix)
{
if ((_supportedKind & ShaderInformationKind.TextureAndUVUsage) == 0)
throw new InvalidOperationException("RegisterOtherUVUsage is not registered as supported information");
if (_textureUsageInformations == null) return;
UVChannel uvChannel;
switch (uvChannels)
Expand Down

0 comments on commit d116e99

Please sign in to comment.