using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace UnityEngine.Rendering
{
///
/// Packing Rules for structs.
///
public enum PackingRules
{
///
/// Exact Packing
///
Exact,
///
/// Aggressive Packing
///
Aggressive
};
///
/// Field packing scheme.
///
public enum FieldPacking
{
///
/// No Packing
///
NoPacking = 0,
///
/// R11G11B10 Packing
///
R11G11B10,
///
/// Packed Float
///
PackedFloat,
///
/// Packed UInt
///
PackedUint
}
///
/// Field Precision
///
public enum FieldPrecision
{
///
/// Half Precision
///
Half,
///
/// Real Precision
///
Real,
///
/// Default Precision
///
Default
}
///
/// Attribute specifying that HLSL code should be generated.
///
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Enum)]
public class GenerateHLSL : System.Attribute
{
///
/// Packing rules for the struct.
///
public PackingRules packingRules;
///
/// Structure contains packed fields.
///
public bool containsPackedFields;
///
/// Structure needs generated accessors.
///
public bool needAccessors;
///
/// Structure needs generated setters.
///
public bool needSetters;
///
/// Structure needs generated debug defines and functions.
///
public bool needParamDebug;
///
/// Start value of generated defines.
///
public int paramDefinesStart;
///
/// Generate structure declaration or not.
///
public bool omitStructDeclaration;
///
/// Generate constant buffer declaration or not.
///
public bool generateCBuffer;
///
/// If specified, when generating a constant buffer, use this explicit register.
///
public int constantRegister;
///
/// Path of the generated file
///
public string sourcePath;
///
/// GenerateHLSL attribute constructor.
///
/// Packing rules.
/// Need accessors.
/// Need setters.
/// Need debug defines.
/// Start value of debug defines.
/// Omit structure declaration.
/// Contains packed fields.
/// Generate a constant buffer.
/// When generating a constant buffer, specify the optional constant register.
/// Location of the source file defining the C# type. (Automatically filled by compiler)
public GenerateHLSL(PackingRules rules = PackingRules.Exact, bool needAccessors = true, bool needSetters = false, bool needParamDebug = false, int paramDefinesStart = 1,
bool omitStructDeclaration = false, bool containsPackedFields = false, bool generateCBuffer = false, int constantRegister = -1,
[CallerFilePath] string sourcePath = null)
{
this.sourcePath = sourcePath;
packingRules = rules;
this.needAccessors = needAccessors;
this.needSetters = needSetters;
this.needParamDebug = needParamDebug;
this.paramDefinesStart = paramDefinesStart;
this.omitStructDeclaration = omitStructDeclaration;
this.containsPackedFields = containsPackedFields;
this.generateCBuffer = generateCBuffer;
this.constantRegister = constantRegister;
}
}
///
/// Attribute specifying the parameters of a surface data field.
///
[AttributeUsage(AttributeTargets.Field)]
public class SurfaceDataAttributes : System.Attribute
{
///
/// Display names overrides for the field.
///
public string[] displayNames;
///
/// True if the field is a direction.
///
public bool isDirection;
///
/// True if the field is an sRGB value.
///
public bool sRGBDisplay;
///
/// Field precision.
///
public FieldPrecision precision;
///
/// Field is a normalized vector.
///
public bool checkIsNormalized;
///
/// If not empty, add a preprocessor #if / #endif with the string provided around the generated hlsl code
///
public string preprocessor;
///
/// SurfaceDataAttributes constructor.
///
/// Display name.
/// Field is a direction.
/// Field is an sRGB value.
/// Field precision.
/// Field checkIsNormalized.
/// Field preprocessor.
public SurfaceDataAttributes(string displayName = "", bool isDirection = false, bool sRGBDisplay = false, FieldPrecision precision = FieldPrecision.Default, bool checkIsNormalized = false, string preprocessor = "")
{
displayNames = new string[1];
displayNames[0] = displayName;
this.isDirection = isDirection;
this.sRGBDisplay = sRGBDisplay;
this.precision = precision;
this.checkIsNormalized = checkIsNormalized;
this.preprocessor = preprocessor;
}
// We allow users to add several names for one field, so user can override the auto behavior and do something else with the same data
// typical example is normal that you want to draw in view space or world space. So user can override view space case and do the transform.
///
/// SurfaceDataAttributes constructor.
///
/// List of names for the field.
/// Field is a direction.
/// Field is an sRGB value.
/// Field precision.
/// Field checkIsNormalized.
/// Field preprocessor.
public SurfaceDataAttributes(string[] displayNames, bool isDirection = false, bool sRGBDisplay = false, FieldPrecision precision = FieldPrecision.Default, bool checkIsNormalized = false, string preprocessor = "")
{
this.displayNames = displayNames;
this.isDirection = isDirection;
this.sRGBDisplay = sRGBDisplay;
this.precision = precision;
this.checkIsNormalized = checkIsNormalized;
this.preprocessor = preprocessor;
}
}
///
/// Attribute defining an HLSL array.
///
[AttributeUsage(AttributeTargets.Field)]
public class HLSLArray : System.Attribute
{
///
/// Size of the array.
///
public int arraySize;
///
/// Type of the array elements.
///
public Type elementType;
///
/// HLSLSArray constructor.
///
/// Size of the array.
/// Type of the array elements.
public HLSLArray(int arraySize, Type elementType)
{
this.arraySize = arraySize;
this.elementType = elementType;
}
}
///
/// Attribute defining packing.
///
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
public class PackingAttribute : System.Attribute
{
///
/// Display names.
///
public string[] displayNames;
///
/// Minimum and Maximum value.
///
public float[] range;
///
/// Packing scheme.
///
public FieldPacking packingScheme;
///
/// Offset in source.
///
public int offsetInSource;
///
/// Size in bits.
///
public int sizeInBits;
///
/// True if the field is a direction.
///
public bool isDirection;
///
/// True if the field is an sRGB value.
///
public bool sRGBDisplay;
///
/// True if the field is an sRGB value.
///
public bool checkIsNormalized;
///
/// If not empty, add a preprocessor #if / #endif with the string provided around the generated hlsl code
///
public string preprocessor;
///
/// Packing Attribute constructor.
///
/// Display names.
/// Packing scheme.
/// Size in bits.
/// Offset in source.
/// Minimum value.
/// Maximum value.
/// Field is a direction.
/// Field is an sRGB value.
/// Field checkIsNormalized.
/// Field preprocessor.
public PackingAttribute(string[] displayNames, FieldPacking packingScheme = FieldPacking.NoPacking, int bitSize = 32, int offsetInSource = 0, float minValue = 0.0f, float maxValue = 1.0f, bool isDirection = false, bool sRGBDisplay = false, bool checkIsNormalized = false, string preprocessor = "")
{
this.displayNames = displayNames;
this.packingScheme = packingScheme;
this.offsetInSource = offsetInSource;
this.isDirection = isDirection;
this.sRGBDisplay = sRGBDisplay;
this.checkIsNormalized = checkIsNormalized;
this.sizeInBits = bitSize;
this.range = new float[] { minValue, maxValue };
this.preprocessor = preprocessor;
}
///
/// Packing Attribute constructor.
///
/// Display name.
/// Packing scheme.
/// Size in bits.
/// Offset in source.
/// Minimum value.
/// Maximum value.
/// Field is a direction.
/// Field is an sRGB value.
/// Field checkIsNormalized.
/// Field preprocessor.
public PackingAttribute(string displayName = "", FieldPacking packingScheme = FieldPacking.NoPacking, int bitSize = 0, int offsetInSource = 0, float minValue = 0.0f, float maxValue = 1.0f, bool isDirection = false, bool sRGBDisplay = false, bool checkIsNormalized = false, string preprocessor = "")
{
displayNames = new string[1];
displayNames[0] = displayName;
this.packingScheme = packingScheme;
this.offsetInSource = offsetInSource;
this.isDirection = isDirection;
this.sRGBDisplay = sRGBDisplay;
this.checkIsNormalized = checkIsNormalized;
this.sizeInBits = bitSize;
this.range = new float[] { minValue, maxValue };
this.preprocessor = preprocessor;
}
}
///
/// This type needs to be used when generating unsigned integer arrays for constant buffers.
///
public struct ShaderGenUInt4
{
}
}