Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
UnlitShader.cs
浏览该文件的文档.
1#if !ANDROID
2using System.Reflection;
3#endif
4
5namespace Engine.Graphics {
8
10
12
14
16
18
20
22 set => m_textureParameter.SetValue(value);
23 }
24
26 set => m_samplerStateParameter.SetValue(value);
27 }
28
29 public Vector4 Color {
30 set => m_colorParameter.SetValue(value);
31 }
32
34 set => m_additiveColorParameter.SetValue(value);
35 }
36
37 public float AlphaThreshold {
38 set => m_alphaThresholdParameter.SetValue(value);
39 }
40
41 public float Time {
42 set => m_time.SetValue(value);
43 }
44
45 public UnlitShader(string vsc, string psc, bool useVertexColor, bool useTexture, bool useAdditiveColor, bool useAlphaThreshold) : base(
46 vsc,
47 psc,
48 1,
49 PrepareShaderMacros(useVertexColor, useTexture, useAdditiveColor, useAlphaThreshold)
50 ) {
51 m_worldViewProjectionMatrixParameter = GetParameter("u_worldViewProjectionMatrix", true);
52 m_textureParameter = GetParameter("u_texture", true);
53 m_samplerStateParameter = GetParameter("u_samplerState", true);
54 m_colorParameter = GetParameter("u_color", true);
55 m_additiveColorParameter = GetParameter("u_additiveColor", true);
56 m_alphaThresholdParameter = GetParameter("u_alphaThreshold", true);
57 m_time = GetParameter("u_time", true);
59 }
60
61 public UnlitShader(bool useVertexColor, bool useTexture, bool useAdditiveColor, bool useAlphaThreshold) : base(
64 1,
65 PrepareShaderMacros(useVertexColor, useTexture, useAdditiveColor, useAlphaThreshold)
66 ) {
67 m_worldViewProjectionMatrixParameter = GetParameter("u_worldViewProjectionMatrix", true);
68 m_textureParameter = GetParameter("u_texture", true);
69 m_samplerStateParameter = GetParameter("u_samplerState", true);
70 m_colorParameter = GetParameter("u_color", true);
71 m_additiveColorParameter = GetParameter("u_additiveColor", true);
72 m_alphaThresholdParameter = GetParameter("u_alphaThreshold", true);
74 }
75
76 public static string GetUnlitVshString() {
77#if ANDROID
78 Stream stream = Storage.OpenFile("app:Unlit.vsh", OpenFileMode.Read);
79#else
80 Stream stream = typeof(Shader).GetTypeInfo().Assembly.GetManifestResourceStream("Engine.Resources.Unlit.vsh");
81#endif
82 ArgumentNullException.ThrowIfNull(stream);
83 return new StreamReader(stream).ReadToEnd();
84 }
85
86 public static string GetUnlitPshString() {
87#if ANDROID
88 Stream stream = Storage.OpenFile("app:Unlit.psh", OpenFileMode.Read);
89#else
90 Stream stream = typeof(Shader).GetTypeInfo().Assembly.GetManifestResourceStream("Engine.Resources.Unlit.psh");
91#endif
92 ArgumentNullException.ThrowIfNull(stream);
93 return new StreamReader(stream).ReadToEnd();
94 }
95
96 public override void PrepareForDrawingOverride() {
97 Transforms.UpdateMatrices(1, false, false, true);
98 m_worldViewProjectionMatrixParameter.SetValue(Transforms.WorldViewProjection, 1);
99 }
100
101 public static ShaderMacro[] PrepareShaderMacros(bool useVertexColor, bool useTexture, bool useAdditiveColor, bool useAlphaThreshold) {
102 List<ShaderMacro> list = [];
103 if (useVertexColor) {
104 list.Add(new ShaderMacro("USE_VERTEXCOLOR"));
105 }
106 if (useTexture) {
107 list.Add(new ShaderMacro("USE_TEXTURE"));
108 }
109 if (useAdditiveColor) {
110 list.Add(new ShaderMacro("USE_ADDITIVECOLOR"));
111 }
112 if (useAlphaThreshold) {
113 list.Add(new ShaderMacro("USE_ALPHATHRESHOLD"));
114 }
115 return list.ToArray();
116 }
117 }
118}
virtual ShaderParameter GetParameter(string name, bool allowNull=false)
ShaderParameter m_additiveColorParameter
ShaderParameter m_worldViewProjectionMatrixParameter
static ShaderMacro[] PrepareShaderMacros(bool useVertexColor, bool useTexture, bool useAdditiveColor, bool useAlphaThreshold)
UnlitShader(bool useVertexColor, bool useTexture, bool useAdditiveColor, bool useAlphaThreshold)
override void PrepareForDrawingOverride()
ShaderParameter m_samplerStateParameter
UnlitShader(string vsc, string psc, bool useVertexColor, bool useTexture, bool useAdditiveColor, bool useAlphaThreshold)
ShaderParameter m_alphaThresholdParameter
static Stream OpenFile(string path, OpenFileMode openFileMode)
static readonly Vector4 One