| | 1 | | // Copyright (c) 2020-2023 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace GDX.Rendering |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// A provider of GDX built-in shader references and properties. |
| | 11 | | /// </summary> |
| | 12 | | public static class ShaderProvider |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// The cached reference to the dotted line shader. |
| | 16 | | /// </summary> |
| | 17 | | static Shader s_DottedLineShader; |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// The cached reference to the unlit colored shader. |
| | 21 | | /// </summary> |
| | 22 | | static Shader s_UnlitColorShader; |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// The cached "_Color" property ID. |
| | 26 | | /// </summary> |
| 2 | 27 | | public static readonly int ColorPropertyID = Shader.PropertyToID("_Color"); |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// A reference to a clip-space sin wave discard based shader, which cheaply provides a dotted line effect. |
| | 31 | | /// </summary> |
| | 32 | | public static Shader DottedLine |
| | 33 | | { |
| | 34 | | get |
| 4 | 35 | | { |
| 4 | 36 | | if (s_DottedLineShader == null) |
| 2 | 37 | | { |
| 2 | 38 | | s_DottedLineShader = Shader.Find("GDX/DottedLine"); |
| 2 | 39 | | } |
| | 40 | |
|
| 4 | 41 | | return s_DottedLineShader; |
| 4 | 42 | | } |
| | 43 | | } |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// A reference to a unlit single color shader. |
| | 47 | | /// </summary> |
| | 48 | | public static Shader UnlitColor |
| | 49 | | { |
| | 50 | | get |
| 4 | 51 | | { |
| 4 | 52 | | if (s_UnlitColorShader == null) |
| 2 | 53 | | { |
| 2 | 54 | | s_UnlitColorShader = Shader.Find("GDX/UnlitColor"); |
| 2 | 55 | | } |
| | 56 | |
|
| 4 | 57 | | return s_UnlitColorShader; |
| 4 | 58 | | } |
| | 59 | | } |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// Get all shaders which <see cref="ShaderProvider"/> is aware of. |
| | 63 | | /// </summary> |
| | 64 | | /// <returns>An array of the known shaders to <see cref="ShaderProvider"/>.</returns> |
| | 65 | | public static Shader[] GetProvidedShaders() |
| 2 | 66 | | { |
| 2 | 67 | | return new[] { DottedLine, UnlitColor }; |
| 2 | 68 | | } |
| | 69 | | } |
| | 70 | | } |