123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- using NUnit.Framework;
- using UnityEngine.Serialization;
-
- namespace UnityEngine.Rendering
- {
- /// <summary>
- /// SRPLensFlareBlendMode defined the available blend mode for each LensFlareElement
- /// </summary>
- [System.Serializable]
- public enum SRPLensFlareBlendMode
- {
- /// <summary>
- /// Additive: Blend One One
- /// </summary>
- Additive,
- /// <summary>
- /// Screen:
- /// Blend One OneMinusSrcColor
- /// </summary>
- Screen,
- /// <summary>
- /// Premultiply:
- /// Blend One OneMinusSrcAlpha
- /// ColorMask RGB
- /// </summary>
- Premultiply,
- /// <summary>
- /// Lerp: Blend SrcAlpha OneMinusSrcAlpha
- /// </summary>
- Lerp
- }
-
- /// <summary>
- /// SRPLensFlareDistribution defined how we spread the flare element when count > 1
- /// </summary>
- [System.Serializable]
- public enum SRPLensFlareDistribution
- {
- /// <summary>
- /// Uniformly spread
- /// </summary>
- Uniform,
- /// <summary>
- /// Controlled with curved
- /// </summary>
- Curve,
- /// <summary>
- /// Random distribution
- /// </summary>
- Random
- }
-
- /// <summary>
- /// SRPLensFlareType which can be an image of a procedural shape
- /// If change order or add new member, need to update preview
- /// shader: LensFlareDataDrivenPreview.shader
- /// </summary>
- [System.Serializable]
- [GenerateHLSL]
- public enum SRPLensFlareType
- {
- /// <summary>
- /// Image from a file or a RenderTexture
- /// </summary>
- Image,
- /// <summary>
- /// Procedural Circle
- /// </summary>
- Circle,
- /// <summary>
- /// Polygon
- /// </summary>
- Polygon,
- /// <summary>
- /// shape as a ring
- /// </summary>
- Ring,
- /// <summary>
- /// Hoop
- /// </summary>
- LensFlareDataSRP
- }
-
- /// <summary>
- /// SRPLensFlareColorType describe how to colorize LensFlare
- /// </summary>
- [System.Serializable]
- [GenerateHLSL]
- public enum SRPLensFlareColorType
- {
- /// <summary>
- /// Constant Color
- /// </summary>
- Constant = 0,
- /// <summary>
- /// Radial Gradient
- /// </summary>
- RadialGradient,
- /// <summary>
- /// Angular Gradient
- /// </summary>
- AngularGradient
- }
-
- /// <summary>
- /// LensFlareDataElementSRP defines collection of parameters describing the behavior a Lens Flare Element.
- /// </summary>
- [System.Serializable]
- public sealed class LensFlareDataElementSRP
- {
- /// <summary> Initialize default values </summary>
- public LensFlareDataElementSRP()
- {
- lensFlareDataSRP = null;
-
- visible = true;
-
- localIntensity = 1.0f;
- position = 0.0f;
- positionOffset = new Vector2(0.0f, 0.0f);
- angularOffset = 0.0f;
- translationScale = new Vector2(1.0f, 1.0f);
- lensFlareTexture = null;
- uniformScale = 1.0f;
- sizeXY = Vector2.one;
- allowMultipleElement = false;
- count = 5;
- rotation = 0.0f;
- preserveAspectRatio = false;
-
- // Ring
- ringThickness = 0.25f;
-
- // Hoop
- hoopFactor = 1.0f;
-
- // Shimmer
- noiseAmplitude = 1.0f;
- noiseFrequency = 1;
- noiseSpeed = 0;
-
- shapeCutOffSpeed = 0.0f;
- shapeCutOffRadius = 10.0f;
-
- tintColorType = SRPLensFlareColorType.Constant;
- tint = new Color(1.0f, 1.0f, 1.0f, 0.5f);
- tintGradient = new TextureGradient(
- new GradientColorKey[] { new GradientColorKey(Color.black, 0.0f), new GradientColorKey(Color.white, 1.0f) },
- new GradientAlphaKey[] { new GradientAlphaKey(0.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) });
- blendMode = SRPLensFlareBlendMode.Additive;
-
- autoRotate = false;
- isFoldOpened = true;
- flareType = SRPLensFlareType.Circle;
-
- distribution = SRPLensFlareDistribution.Uniform;
-
- lengthSpread = 1f;
- colorGradient = new Gradient();
- colorGradient.SetKeys(new GradientColorKey[] { new GradientColorKey(Color.white, 0.0f), new GradientColorKey(Color.white, 1.0f) },
- new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) });
- positionCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f, 1.0f, 1.0f), new Keyframe(1.0f, 1.0f, 1.0f, -1.0f));
- scaleCurve = new AnimationCurve(new Keyframe(0.0f, 1.0f), new Keyframe(1.0f, 1.0f));
- uniformAngle = 0.0f;
- uniformAngleCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 0.0f));
-
- // Random
- seed = 0;
- intensityVariation = 0.75f;
- positionVariation = new Vector2(1.0f, 0.0f);
- scaleVariation = 1.0f;
- rotationVariation = 180.0f;
-
- // Distortion
- enableRadialDistortion = false;
- targetSizeDistortion = Vector2.one;
- distortionCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f, 1.0f, 1.0f), new Keyframe(1.0f, 1.0f, 1.0f, -1.0f));
- distortionRelativeToCenter = false;
-
- // Parameters for Procedural
- fallOff = 1.0f;
- edgeOffset = 0.1f;
- sdfRoundness = 0.0f;
- sideCount = 6;
- inverseSDF = false;
- }
-
- /// <summary>
- /// Clone the current LensFlareDataElementSRP.
- /// </summary>
- /// <returns>Cloned LensFlareDataElementSRP.</returns>
- public LensFlareDataElementSRP Clone()
- {
- LensFlareDataElementSRP clone = new LensFlareDataElementSRP();
- clone.lensFlareDataSRP = lensFlareDataSRP;
-
- clone.visible = visible;
-
- clone.localIntensity = localIntensity;
- clone.position = position;
- clone.positionOffset = positionOffset;
- clone.angularOffset = angularOffset;
- clone.translationScale = translationScale;
- clone.lensFlareTexture = lensFlareTexture;
- clone.uniformScale = uniformScale;
- clone.sizeXY = sizeXY;
- clone.allowMultipleElement = allowMultipleElement;
- clone.count = count;
- clone.rotation = rotation;
- clone.preserveAspectRatio = preserveAspectRatio;
-
- clone.ringThickness = ringThickness;
-
- clone.hoopFactor = hoopFactor;
-
- clone.noiseAmplitude = noiseAmplitude;
- clone.noiseFrequency = noiseFrequency;
- clone.noiseSpeed = noiseSpeed;
-
- clone.shapeCutOffSpeed = shapeCutOffSpeed;
- clone.shapeCutOffRadius = shapeCutOffRadius;
-
- clone.tintColorType = tintColorType;
- clone.tint = tint;
- clone.tintGradient = new TextureGradient(tintGradient.colorKeys, tintGradient.alphaKeys, tintGradient.mode, tintGradient.colorSpace, tintGradient.textureSize);
- clone.tintGradient = new TextureGradient(tintGradient.colorKeys, tintGradient.alphaKeys);
- clone.blendMode = blendMode;
-
- clone.autoRotate = autoRotate;
- clone.isFoldOpened = isFoldOpened;
- clone.flareType = flareType;
-
- clone.distribution = distribution;
-
- clone.lengthSpread = lengthSpread;
- clone.colorGradient = new Gradient();
- clone.colorGradient.SetKeys(colorGradient.colorKeys, colorGradient.alphaKeys);
- clone.colorGradient.mode = colorGradient.mode;
- clone.colorGradient.colorSpace = colorGradient.colorSpace;
- clone.positionCurve = new AnimationCurve(positionCurve.keys);
- clone.scaleCurve = new AnimationCurve(scaleCurve.keys);
- clone.uniformAngle = uniformAngle;
- clone.uniformAngleCurve = new AnimationCurve(uniformAngleCurve.keys);
-
- clone.seed = seed;
- clone.intensityVariation = intensityVariation;
- clone.positionVariation = positionVariation;
- clone.scaleVariation = scaleVariation;
- clone.rotationVariation = rotationVariation;
-
- clone.enableRadialDistortion = enableRadialDistortion;
- clone.targetSizeDistortion = targetSizeDistortion;
- clone.distortionCurve = new AnimationCurve(distortionCurve.keys);
- clone.distortionRelativeToCenter = distortionRelativeToCenter;
-
- clone.fallOff = fallOff;
- clone.edgeOffset = edgeOffset;
- clone.sdfRoundness = sdfRoundness;
- clone.sideCount = sideCount;
- clone.inverseSDF = inverseSDF;
-
- return clone;
- }
-
- /// <summary> Current Element is himselft another LensFlareDataSRP </summary>
- public LensFlareDataSRP lensFlareDataSRP;
-
- /// <summary> Visibility checker for current element </summary>
- public bool visible;
-
- /// <summary> Position </summary>
- public float position;
-
- /// <summary> Position offset </summary>
- public Vector2 positionOffset;
-
- /// <summary> Angular offset </summary>
- public float angularOffset;
-
- /// <summary> Translation Scale </summary>
- public Vector2 translationScale;
-
- // For Hoop
- /// <summary>Ring thickness</summary>
- [Range(0.0f, 1.0f)]
- public float ringThickness;
-
- /// <summary>Hoop thickness</summary>
- [Range(-1.0f, 1.0f)]
- public float hoopFactor;
-
- // For Ring
- /// <summary>Noise parameter amplitude</summary>
- public float noiseAmplitude;
- /// <summary>Noise parameter frequency</summary>
- public int noiseFrequency;
- /// <summary>Noise parameter Speed</summary>
- public float noiseSpeed;
-
- /// <summary>To simulate the cutoff of the flare by the circular shape of the lens. How quickly this cutoff happen.</summary>
- public float shapeCutOffSpeed;
- /// <summary>To simulate the cutoff of the flare by the circular shape of the lens.</summary>
- public float shapeCutOffRadius;
-
- [Min(0), SerializeField, FormerlySerializedAs("localIntensity")]
- float m_LocalIntensity;
-
- /// <summary> Intensity of this element </summary>
- public float localIntensity
- {
- get => m_LocalIntensity;
- set => m_LocalIntensity = Mathf.Max(0, value);
- }
-
- /// <summary> Texture used to for this Lens Flare Element </summary>
- public Texture lensFlareTexture;
-
- /// <summary> Uniform scale applied </summary>
- public float uniformScale;
-
- /// <summary> Scale size on each dimension </summary>
- public Vector2 sizeXY;
-
- /// <summary> Enable multiple elements </summary>
- public bool allowMultipleElement;
-
- [Min(1), SerializeField, FormerlySerializedAs("count")]
- int m_Count;
-
- /// <summary> Element can be repeated 'count' times </summary>
- public int count
- {
- get => m_Count;
- set => m_Count = Mathf.Max(1, value);
- }
-
- /// <summary> Preserve Aspect Ratio </summary>
- public bool preserveAspectRatio;
-
- /// <summary> Local rotation of the texture </summary>
- public float rotation;
-
- /// <summary>Specify how to tint flare.</summary>
- public SRPLensFlareColorType tintColorType;
-
- /// <summary> Tint of the texture can be modulated by the light we are attached to</summary>
- public Color tint;
-
- /// <summary> Tint radially of the texture can be modulated by the light we are attached to . </summary>
- public TextureGradient tintGradient;
-
- /// <summary> Blend mode used </summary>
- public SRPLensFlareBlendMode blendMode;
-
- /// <summary> Rotate the texture relative to the angle on the screen (the rotation will be added to the parameter 'rotation') </summary>
- public bool autoRotate;
-
- /// <summary> FlareType used </summary>
- public SRPLensFlareType flareType;
-
- /// <summary> Modulate by light color if the asset is used in a 'SRP Lens Flare Source Override' </summary>
- public bool modulateByLightColor;
-
- #pragma warning disable 0414 // never used (editor state)
- /// <summary> Internal value use to store the state of minimized or maximized LensFlareElement </summary>
- [SerializeField]
- bool isFoldOpened;
- #pragma warning restore 0414
-
- /// <summary> SRPLensFlareDistribution defined how we spread the flare element when count > 1 </summary>
- public SRPLensFlareDistribution distribution;
-
- /// <summary> Length to spread the distribution of flares, spread start at 'starting position' </summary>
- public float lengthSpread;
-
- /// <summary> Curve describing how to place flares distribution (Used only for Uniform and Curve 'distribution') </summary>
- public AnimationCurve positionCurve;
-
- /// <summary> Curve describing how to scale flares distribution (Used only for Uniform and Curve 'distribution') </summary>
- public AnimationCurve scaleCurve;
-
- /// <summary> Seed used to seed randomness </summary>
- public int seed;
-
- /// <summary> Colors used uniformly for Uniform or Curve Distribution and Random when the distribution is 'Random'. </summary>
- public Gradient colorGradient;
-
- [Range(0, 1), SerializeField, FormerlySerializedAs("intensityVariation")]
- float m_IntensityVariation;
-
- /// <summary> Scale factor applied on the variation of the intensities. </summary>
- public float intensityVariation
- {
- get => m_IntensityVariation;
- set => m_IntensityVariation = Mathf.Max(0, value);
- }
-
- /// <summary> Scale factor applied on the variation of the positions. </summary>
- public Vector2 positionVariation;
-
- /// <summary> Coefficient applied on the variation of the scale (relative to the current scale). </summary>
- public float scaleVariation;
-
- /// <summary> Scale factor applied on the variation of the rotation (relative to the current rotation or auto-rotate). </summary>
- public float rotationVariation;
-
- /// <summary> True to use or not the radial distortion. </summary>
- public bool enableRadialDistortion;
-
- /// <summary> Target size used on the edge of the screen. </summary>
- public Vector2 targetSizeDistortion;
-
- /// <summary> Curve blending from screen center to the edges of the screen. </summary>
- public AnimationCurve distortionCurve;
-
- /// <summary> If true the distortion is relative to center of the screen otherwise relative to lensFlare source screen position. </summary>
- public bool distortionRelativeToCenter;
-
- [Range(0, 1), SerializeField, FormerlySerializedAs("fallOff")]
- float m_FallOff;
-
- /// <summary> Fall of the gradient used for the Procedural Flare. </summary>
- public float fallOff
- {
- get => m_FallOff;
- set => m_FallOff = Mathf.Clamp01(value);
- }
-
- [Range(0, 1), SerializeField, FormerlySerializedAs("edgeOffset")]
- float m_EdgeOffset;
-
- /// <summary> Gradient Offset used for the Procedural Flare. </summary>
- public float edgeOffset
- {
- get => m_EdgeOffset;
- set => m_EdgeOffset = Mathf.Clamp01(value);
- }
-
- [Min(3), SerializeField, FormerlySerializedAs("sideCount")]
- int m_SideCount;
-
- /// <summary> Side count of the regular polygon generated. </summary>
- public int sideCount
- {
- get => m_SideCount;
- set => m_SideCount = Mathf.Max(3, value);
- }
-
- [Range(0, 1), SerializeField, FormerlySerializedAs("sdfRoundness")]
- float m_SdfRoundness;
-
- /// <summary> Roundness of the polygon flare (0: Sharp Polygon, 1: Circle). </summary>
- public float sdfRoundness
- {
- get => m_SdfRoundness;
- set => m_SdfRoundness = Mathf.Clamp01(value);
- }
-
- /// <summary> Inverse the gradient direction. </summary>
- public bool inverseSDF;
-
- /// <summary> Uniform angle (in degrees) used with multiple element enabled with Uniform distribution. </summary>
- public float uniformAngle;
-
- /// <summary> Uniform angle (remap from -180.0f to 180.0f) used with multiple element enabled with Curve distribution. </summary>
- public AnimationCurve uniformAngleCurve;
- }
-
- /// <summary> LensFlareDataSRP defines a Lens Flare with a set of LensFlareDataElementSRP </summary>
- [System.Serializable]
- public sealed class LensFlareDataSRP : ScriptableObject
- {
- /// <summary> Initialize default value </summary>
- public LensFlareDataSRP()
- {
- elements = null;
- }
-
- /// <summary>
- /// Check if we have at last one 'modulatedByLightColor' enabled.
- /// </summary>
- /// <returns>true if we have at least one 'modulatedByLightColor' on the asset.</returns>
- public bool HasAModulateByLightColorElement()
- {
- if (elements != null)
- {
- foreach (LensFlareDataElementSRP e in elements)
- {
- if (e.modulateByLightColor)
- return true;
- }
- }
-
- return false;
- }
-
- /// <summary> List of LensFlareDataElementSRP </summary>
- public LensFlareDataElementSRP[] elements;
- }
- }
|