A game about forced loneliness, made by TACStudios
1using NUnit.Framework;
2using UnityEngine.Serialization;
3
4namespace UnityEngine.Rendering
5{
6 /// <summary>
7 /// SRPLensFlareBlendMode defined the available blend mode for each LensFlareElement
8 /// </summary>
9 [System.Serializable]
10 public enum SRPLensFlareBlendMode
11 {
12 /// <summary>
13 /// Additive: Blend One One
14 /// </summary>
15 Additive,
16 /// <summary>
17 /// Screen:
18 /// Blend One OneMinusSrcColor
19 /// </summary>
20 Screen,
21 /// <summary>
22 /// Premultiply:
23 /// Blend One OneMinusSrcAlpha
24 /// ColorMask RGB
25 /// </summary>
26 Premultiply,
27 /// <summary>
28 /// Lerp: Blend SrcAlpha OneMinusSrcAlpha
29 /// </summary>
30 Lerp
31 }
32
33 /// <summary>
34 /// SRPLensFlareDistribution defined how we spread the flare element when count > 1
35 /// </summary>
36 [System.Serializable]
37 public enum SRPLensFlareDistribution
38 {
39 /// <summary>
40 /// Uniformly spread
41 /// </summary>
42 Uniform,
43 /// <summary>
44 /// Controlled with curved
45 /// </summary>
46 Curve,
47 /// <summary>
48 /// Random distribution
49 /// </summary>
50 Random
51 }
52
53 /// <summary>
54 /// SRPLensFlareType which can be an image of a procedural shape
55 /// If change order or add new member, need to update preview
56 /// shader: LensFlareDataDrivenPreview.shader
57 /// </summary>
58 [System.Serializable]
59 [GenerateHLSL]
60 public enum SRPLensFlareType
61 {
62 /// <summary>
63 /// Image from a file or a RenderTexture
64 /// </summary>
65 Image,
66 /// <summary>
67 /// Procedural Circle
68 /// </summary>
69 Circle,
70 /// <summary>
71 /// Polygon
72 /// </summary>
73 Polygon,
74 /// <summary>
75 /// shape as a ring
76 /// </summary>
77 Ring,
78 /// <summary>
79 /// Hoop
80 /// </summary>
81 LensFlareDataSRP
82 }
83
84 /// <summary>
85 /// SRPLensFlareColorType describe how to colorize LensFlare
86 /// </summary>
87 [System.Serializable]
88 [GenerateHLSL]
89 public enum SRPLensFlareColorType
90 {
91 /// <summary>
92 /// Constant Color
93 /// </summary>
94 Constant = 0,
95 /// <summary>
96 /// Radial Gradient
97 /// </summary>
98 RadialGradient,
99 /// <summary>
100 /// Angular Gradient
101 /// </summary>
102 AngularGradient
103 }
104
105 /// <summary>
106 /// LensFlareDataElementSRP defines collection of parameters describing the behavior a Lens Flare Element.
107 /// </summary>
108 [System.Serializable]
109 public sealed class LensFlareDataElementSRP
110 {
111 /// <summary> Initialize default values </summary>
112 public LensFlareDataElementSRP()
113 {
114 lensFlareDataSRP = null;
115
116 visible = true;
117
118 localIntensity = 1.0f;
119 position = 0.0f;
120 positionOffset = new Vector2(0.0f, 0.0f);
121 angularOffset = 0.0f;
122 translationScale = new Vector2(1.0f, 1.0f);
123 lensFlareTexture = null;
124 uniformScale = 1.0f;
125 sizeXY = Vector2.one;
126 allowMultipleElement = false;
127 count = 5;
128 rotation = 0.0f;
129 preserveAspectRatio = false;
130
131 // Ring
132 ringThickness = 0.25f;
133
134 // Hoop
135 hoopFactor = 1.0f;
136
137 // Shimmer
138 noiseAmplitude = 1.0f;
139 noiseFrequency = 1;
140 noiseSpeed = 0;
141
142 shapeCutOffSpeed = 0.0f;
143 shapeCutOffRadius = 10.0f;
144
145 tintColorType = SRPLensFlareColorType.Constant;
146 tint = new Color(1.0f, 1.0f, 1.0f, 0.5f);
147 tintGradient = new TextureGradient(
148 new GradientColorKey[] { new GradientColorKey(Color.black, 0.0f), new GradientColorKey(Color.white, 1.0f) },
149 new GradientAlphaKey[] { new GradientAlphaKey(0.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) });
150 blendMode = SRPLensFlareBlendMode.Additive;
151
152 autoRotate = false;
153 isFoldOpened = true;
154 flareType = SRPLensFlareType.Circle;
155
156 distribution = SRPLensFlareDistribution.Uniform;
157
158 lengthSpread = 1f;
159 colorGradient = new Gradient();
160 colorGradient.SetKeys(new GradientColorKey[] { new GradientColorKey(Color.white, 0.0f), new GradientColorKey(Color.white, 1.0f) },
161 new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) });
162 positionCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f, 1.0f, 1.0f), new Keyframe(1.0f, 1.0f, 1.0f, -1.0f));
163 scaleCurve = new AnimationCurve(new Keyframe(0.0f, 1.0f), new Keyframe(1.0f, 1.0f));
164 uniformAngle = 0.0f;
165 uniformAngleCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 0.0f));
166
167 // Random
168 seed = 0;
169 intensityVariation = 0.75f;
170 positionVariation = new Vector2(1.0f, 0.0f);
171 scaleVariation = 1.0f;
172 rotationVariation = 180.0f;
173
174 // Distortion
175 enableRadialDistortion = false;
176 targetSizeDistortion = Vector2.one;
177 distortionCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f, 1.0f, 1.0f), new Keyframe(1.0f, 1.0f, 1.0f, -1.0f));
178 distortionRelativeToCenter = false;
179
180 // Parameters for Procedural
181 fallOff = 1.0f;
182 edgeOffset = 0.1f;
183 sdfRoundness = 0.0f;
184 sideCount = 6;
185 inverseSDF = false;
186 }
187
188 /// <summary>
189 /// Clone the current LensFlareDataElementSRP.
190 /// </summary>
191 /// <returns>Cloned LensFlareDataElementSRP.</returns>
192 public LensFlareDataElementSRP Clone()
193 {
194 LensFlareDataElementSRP clone = new LensFlareDataElementSRP();
195 clone.lensFlareDataSRP = lensFlareDataSRP;
196
197 clone.visible = visible;
198
199 clone.localIntensity = localIntensity;
200 clone.position = position;
201 clone.positionOffset = positionOffset;
202 clone.angularOffset = angularOffset;
203 clone.translationScale = translationScale;
204 clone.lensFlareTexture = lensFlareTexture;
205 clone.uniformScale = uniformScale;
206 clone.sizeXY = sizeXY;
207 clone.allowMultipleElement = allowMultipleElement;
208 clone.count = count;
209 clone.rotation = rotation;
210 clone.preserveAspectRatio = preserveAspectRatio;
211
212 clone.ringThickness = ringThickness;
213
214 clone.hoopFactor = hoopFactor;
215
216 clone.noiseAmplitude = noiseAmplitude;
217 clone.noiseFrequency = noiseFrequency;
218 clone.noiseSpeed = noiseSpeed;
219
220 clone.shapeCutOffSpeed = shapeCutOffSpeed;
221 clone.shapeCutOffRadius = shapeCutOffRadius;
222
223 clone.tintColorType = tintColorType;
224 clone.tint = tint;
225 clone.tintGradient = new TextureGradient(tintGradient.colorKeys, tintGradient.alphaKeys, tintGradient.mode, tintGradient.colorSpace, tintGradient.textureSize);
226 clone.tintGradient = new TextureGradient(tintGradient.colorKeys, tintGradient.alphaKeys);
227 clone.blendMode = blendMode;
228
229 clone.autoRotate = autoRotate;
230 clone.isFoldOpened = isFoldOpened;
231 clone.flareType = flareType;
232
233 clone.distribution = distribution;
234
235 clone.lengthSpread = lengthSpread;
236 clone.colorGradient = new Gradient();
237 clone.colorGradient.SetKeys(colorGradient.colorKeys, colorGradient.alphaKeys);
238 clone.colorGradient.mode = colorGradient.mode;
239 clone.colorGradient.colorSpace = colorGradient.colorSpace;
240 clone.positionCurve = new AnimationCurve(positionCurve.keys);
241 clone.scaleCurve = new AnimationCurve(scaleCurve.keys);
242 clone.uniformAngle = uniformAngle;
243 clone.uniformAngleCurve = new AnimationCurve(uniformAngleCurve.keys);
244
245 clone.seed = seed;
246 clone.intensityVariation = intensityVariation;
247 clone.positionVariation = positionVariation;
248 clone.scaleVariation = scaleVariation;
249 clone.rotationVariation = rotationVariation;
250
251 clone.enableRadialDistortion = enableRadialDistortion;
252 clone.targetSizeDistortion = targetSizeDistortion;
253 clone.distortionCurve = new AnimationCurve(distortionCurve.keys);
254 clone.distortionRelativeToCenter = distortionRelativeToCenter;
255
256 clone.fallOff = fallOff;
257 clone.edgeOffset = edgeOffset;
258 clone.sdfRoundness = sdfRoundness;
259 clone.sideCount = sideCount;
260 clone.inverseSDF = inverseSDF;
261
262 return clone;
263 }
264
265 /// <summary> Current Element is himselft another LensFlareDataSRP </summary>
266 public LensFlareDataSRP lensFlareDataSRP;
267
268 /// <summary> Visibility checker for current element </summary>
269 public bool visible;
270
271 /// <summary> Position </summary>
272 public float position;
273
274 /// <summary> Position offset </summary>
275 public Vector2 positionOffset;
276
277 /// <summary> Angular offset </summary>
278 public float angularOffset;
279
280 /// <summary> Translation Scale </summary>
281 public Vector2 translationScale;
282
283 // For Hoop
284 /// <summary>Ring thickness</summary>
285 [Range(0.0f, 1.0f)]
286 public float ringThickness;
287
288 /// <summary>Hoop thickness</summary>
289 [Range(-1.0f, 1.0f)]
290 public float hoopFactor;
291
292 // For Ring
293 /// <summary>Noise parameter amplitude</summary>
294 public float noiseAmplitude;
295 /// <summary>Noise parameter frequency</summary>
296 public int noiseFrequency;
297 /// <summary>Noise parameter Speed</summary>
298 public float noiseSpeed;
299
300 /// <summary>To simulate the cutoff of the flare by the circular shape of the lens. How quickly this cutoff happen.</summary>
301 public float shapeCutOffSpeed;
302 /// <summary>To simulate the cutoff of the flare by the circular shape of the lens.</summary>
303 public float shapeCutOffRadius;
304
305 [Min(0), SerializeField, FormerlySerializedAs("localIntensity")]
306 float m_LocalIntensity;
307
308 /// <summary> Intensity of this element </summary>
309 public float localIntensity
310 {
311 get => m_LocalIntensity;
312 set => m_LocalIntensity = Mathf.Max(0, value);
313 }
314
315 /// <summary> Texture used to for this Lens Flare Element </summary>
316 public Texture lensFlareTexture;
317
318 /// <summary> Uniform scale applied </summary>
319 public float uniformScale;
320
321 /// <summary> Scale size on each dimension </summary>
322 public Vector2 sizeXY;
323
324 /// <summary> Enable multiple elements </summary>
325 public bool allowMultipleElement;
326
327 [Min(1), SerializeField, FormerlySerializedAs("count")]
328 int m_Count;
329
330 /// <summary> Element can be repeated 'count' times </summary>
331 public int count
332 {
333 get => m_Count;
334 set => m_Count = Mathf.Max(1, value);
335 }
336
337 /// <summary> Preserve Aspect Ratio </summary>
338 public bool preserveAspectRatio;
339
340 /// <summary> Local rotation of the texture </summary>
341 public float rotation;
342
343 /// <summary>Specify how to tint flare.</summary>
344 public SRPLensFlareColorType tintColorType;
345
346 /// <summary> Tint of the texture can be modulated by the light we are attached to</summary>
347 public Color tint;
348
349 /// <summary> Tint radially of the texture can be modulated by the light we are attached to . </summary>
350 public TextureGradient tintGradient;
351
352 /// <summary> Blend mode used </summary>
353 public SRPLensFlareBlendMode blendMode;
354
355 /// <summary> Rotate the texture relative to the angle on the screen (the rotation will be added to the parameter 'rotation') </summary>
356 public bool autoRotate;
357
358 /// <summary> FlareType used </summary>
359 public SRPLensFlareType flareType;
360
361 /// <summary> Modulate by light color if the asset is used in a 'SRP Lens Flare Source Override' </summary>
362 public bool modulateByLightColor;
363
364#pragma warning disable 0414 // never used (editor state)
365 /// <summary> Internal value use to store the state of minimized or maximized LensFlareElement </summary>
366 [SerializeField]
367 bool isFoldOpened;
368#pragma warning restore 0414
369
370 /// <summary> SRPLensFlareDistribution defined how we spread the flare element when count > 1 </summary>
371 public SRPLensFlareDistribution distribution;
372
373 /// <summary> Length to spread the distribution of flares, spread start at 'starting position' </summary>
374 public float lengthSpread;
375
376 /// <summary> Curve describing how to place flares distribution (Used only for Uniform and Curve 'distribution') </summary>
377 public AnimationCurve positionCurve;
378
379 /// <summary> Curve describing how to scale flares distribution (Used only for Uniform and Curve 'distribution') </summary>
380 public AnimationCurve scaleCurve;
381
382 /// <summary> Seed used to seed randomness </summary>
383 public int seed;
384
385 /// <summary> Colors used uniformly for Uniform or Curve Distribution and Random when the distribution is 'Random'. </summary>
386 public Gradient colorGradient;
387
388 [Range(0, 1), SerializeField, FormerlySerializedAs("intensityVariation")]
389 float m_IntensityVariation;
390
391 /// <summary> Scale factor applied on the variation of the intensities. </summary>
392 public float intensityVariation
393 {
394 get => m_IntensityVariation;
395 set => m_IntensityVariation = Mathf.Max(0, value);
396 }
397
398 /// <summary> Scale factor applied on the variation of the positions. </summary>
399 public Vector2 positionVariation;
400
401 /// <summary> Coefficient applied on the variation of the scale (relative to the current scale). </summary>
402 public float scaleVariation;
403
404 /// <summary> Scale factor applied on the variation of the rotation (relative to the current rotation or auto-rotate). </summary>
405 public float rotationVariation;
406
407 /// <summary> True to use or not the radial distortion. </summary>
408 public bool enableRadialDistortion;
409
410 /// <summary> Target size used on the edge of the screen. </summary>
411 public Vector2 targetSizeDistortion;
412
413 /// <summary> Curve blending from screen center to the edges of the screen. </summary>
414 public AnimationCurve distortionCurve;
415
416 /// <summary> If true the distortion is relative to center of the screen otherwise relative to lensFlare source screen position. </summary>
417 public bool distortionRelativeToCenter;
418
419 [Range(0, 1), SerializeField, FormerlySerializedAs("fallOff")]
420 float m_FallOff;
421
422 /// <summary> Fall of the gradient used for the Procedural Flare. </summary>
423 public float fallOff
424 {
425 get => m_FallOff;
426 set => m_FallOff = Mathf.Clamp01(value);
427 }
428
429 [Range(0, 1), SerializeField, FormerlySerializedAs("edgeOffset")]
430 float m_EdgeOffset;
431
432 /// <summary> Gradient Offset used for the Procedural Flare. </summary>
433 public float edgeOffset
434 {
435 get => m_EdgeOffset;
436 set => m_EdgeOffset = Mathf.Clamp01(value);
437 }
438
439 [Min(3), SerializeField, FormerlySerializedAs("sideCount")]
440 int m_SideCount;
441
442 /// <summary> Side count of the regular polygon generated. </summary>
443 public int sideCount
444 {
445 get => m_SideCount;
446 set => m_SideCount = Mathf.Max(3, value);
447 }
448
449 [Range(0, 1), SerializeField, FormerlySerializedAs("sdfRoundness")]
450 float m_SdfRoundness;
451
452 /// <summary> Roundness of the polygon flare (0: Sharp Polygon, 1: Circle). </summary>
453 public float sdfRoundness
454 {
455 get => m_SdfRoundness;
456 set => m_SdfRoundness = Mathf.Clamp01(value);
457 }
458
459 /// <summary> Inverse the gradient direction. </summary>
460 public bool inverseSDF;
461
462 /// <summary> Uniform angle (in degrees) used with multiple element enabled with Uniform distribution. </summary>
463 public float uniformAngle;
464
465 /// <summary> Uniform angle (remap from -180.0f to 180.0f) used with multiple element enabled with Curve distribution. </summary>
466 public AnimationCurve uniformAngleCurve;
467 }
468
469 /// <summary> LensFlareDataSRP defines a Lens Flare with a set of LensFlareDataElementSRP </summary>
470 [System.Serializable]
471 public sealed class LensFlareDataSRP : ScriptableObject
472 {
473 /// <summary> Initialize default value </summary>
474 public LensFlareDataSRP()
475 {
476 elements = null;
477 }
478
479 /// <summary>
480 /// Check if we have at last one 'modulatedByLightColor' enabled.
481 /// </summary>
482 /// <returns>true if we have at least one 'modulatedByLightColor' on the asset.</returns>
483 public bool HasAModulateByLightColorElement()
484 {
485 if (elements != null)
486 {
487 foreach (LensFlareDataElementSRP e in elements)
488 {
489 if (e.modulateByLightColor)
490 return true;
491 }
492 }
493
494 return false;
495 }
496
497 /// <summary> List of LensFlareDataElementSRP </summary>
498 public LensFlareDataElementSRP[] elements;
499 }
500}