mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Add load parameter support to RSIs. Currently only supports turning sRGB off. RSIs with custom load parameters are not thrown into the meta-atlas. As part of this, TextureLoadParameters and TextureSampleParameters has been made to support equality. * Add UV2 channel to vertices. This is a bad hack to make displacement maps work in Robust. The UV2 channel goes from 0 -> 1 across the draw and can therefore be used by displacement maps to map a separate displacement map layer on top of the regular meta-atlas RSI texture. This creates float inaccuracy issues but they weren't bad enough to completely void the feature. I'm thinking I learn from this experience and completely re-do how UVs work with the renderer rewrite, so that hopefully won't happen anymore. This required dumping the optimized PadVerticesV2 because the changed struct size made it impractical. RIP. I don't like this approach at all but the renderer is slated for a rewrite anyways, and all shaders will need to be rewritten regardless. * Add CopyToShaderParameters for sprite layers. This effectively allows copying the parameters of a sprite layer into another layer's shader parameters. The use case is to copy texture coordinates for displacement maps, as the exact map used changes depending on orientation. It also enables animations to be used though I didn't use that personally.
71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
using System;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.Utility;
|
|
using YamlDotNet.RepresentationModel;
|
|
|
|
namespace Robust.Shared.Graphics;
|
|
|
|
/// <summary>
|
|
/// Flags for loading of textures.
|
|
/// </summary>
|
|
[PublicAPI]
|
|
public struct TextureLoadParameters : IEquatable<TextureLoadParameters>
|
|
{
|
|
/// <summary>
|
|
/// The default sampling parameters for the texture.
|
|
/// </summary>
|
|
public TextureSampleParameters SampleParameters { get; set; }
|
|
|
|
/// <summary>
|
|
/// If true, the image data will be treated as sRGB.
|
|
/// </summary>
|
|
public bool Srgb { get; set; }
|
|
|
|
public static TextureLoadParameters FromYaml(YamlMappingNode yaml)
|
|
{
|
|
var loadParams = Default;
|
|
if (yaml.TryGetNode("sample", out YamlMappingNode? sampleNode))
|
|
{
|
|
loadParams.SampleParameters = TextureSampleParameters.FromYaml(sampleNode);
|
|
}
|
|
|
|
if (yaml.TryGetNode("srgb", out var srgb))
|
|
{
|
|
loadParams.Srgb = srgb.AsBool();
|
|
}
|
|
|
|
return loadParams;
|
|
}
|
|
|
|
public static readonly TextureLoadParameters Default = new()
|
|
{
|
|
SampleParameters = TextureSampleParameters.Default,
|
|
Srgb = true
|
|
};
|
|
|
|
public bool Equals(TextureLoadParameters other)
|
|
{
|
|
return SampleParameters.Equals(other.SampleParameters) && Srgb == other.Srgb;
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
return obj is TextureLoadParameters other && Equals(other);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(SampleParameters, Srgb);
|
|
}
|
|
|
|
public static bool operator ==(TextureLoadParameters left, TextureLoadParameters right)
|
|
{
|
|
return left.Equals(right);
|
|
}
|
|
|
|
public static bool operator !=(TextureLoadParameters left, TextureLoadParameters right)
|
|
{
|
|
return !left.Equals(right);
|
|
}
|
|
}
|