Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ModelShader.cs
浏览该文件的文档.
1using System.Globalization;
2using Engine;
4
5namespace Game {
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
41 public int m_instancesCount;
42
44 set => m_textureParameter.SetValue(value);
45 }
46
48 set => m_samplerStateParameter.SetValue(value);
49 }
50
52 set => m_materialColorParameter.SetValue(value);
53 }
54
56 set => m_emissionColorParameter.SetValue(value);
57 }
58
59 public float AlphaThreshold {
60 set => m_alphaThresholdParameter.SetValue(value);
61 }
62
64 set => m_ambientLightColorParameter.SetValue(value);
65 }
66
68 set => m_diffuseLightColor1Parameter.SetValue(value);
69 }
70
72 set => m_diffuseLightColor2Parameter.SetValue(value);
73 }
74
76 set => m_directionToLight1Parameter.SetValue(-value);
77 }
78
80 set => m_directionToLight2Parameter.SetValue(-value);
81 }
82
84 set => m_fogColorParameter.SetValue(value);
85 }
86
88 set => m_fogBottomTopDensityParameter.SetValue(value);
89 }
90
92 set => m_hazeStartDensityParameter.SetValue(value);
93 }
94
95 public float FogYMultiplier {
96 set => m_fogYMultiplierParameter.SetValue(value);
97 }
98
100 set => m_worldUpParameter.SetValue(value);
101 }
102
103 public int InstancesCount {
104 get => m_instancesCount;
105 set {
106 if (value < 0
107 || value > Transforms.MaxWorldMatrices) {
108 throw new InvalidOperationException("Invalid instances count.");
109 }
110 m_instancesCount = value;
111 }
112 }
113
114 public ModelShader(string vsc, string psc, bool useAlphaThreshold, int maxInstancesCount = 1) : base(
115 vsc,
116 psc,
117 maxInstancesCount,
118 PrepareShaderMacros(useAlphaThreshold, maxInstancesCount)
119 ) {
120 SetParameter();
121 }
122
123 public ModelShader(string vsc, string psc, bool useAlphaThreshold, int maxInstancesCount = 1, ShaderMacro[] shaderMacros = null) : base(
124 vsc,
125 psc,
126 maxInstancesCount,
127 PrepareShaderMacros(useAlphaThreshold, maxInstancesCount, shaderMacros)
128 ) {
129 SetParameter();
130 }
131
132 public virtual void SetParameter() {
133 m_worldMatrixParameter = GetParameter("u_worldMatrix");
134 m_worldViewProjectionMatrixParameter = GetParameter("u_worldViewProjectionMatrix");
135 m_textureParameter = GetParameter("u_texture");
136 m_samplerStateParameter = GetParameter("u_samplerState");
137 m_materialColorParameter = GetParameter("u_materialColor");
138 m_emissionColorParameter = GetParameter("u_emissionColor");
139 m_alphaThresholdParameter = GetParameter("u_alphaThreshold", true);
140 m_ambientLightColorParameter = GetParameter("u_ambientLightColor");
141 m_diffuseLightColor1Parameter = GetParameter("u_diffuseLightColor1");
142 m_directionToLight1Parameter = GetParameter("u_directionToLight1");
143 m_diffuseLightColor2Parameter = GetParameter("u_diffuseLightColor2");
144 m_directionToLight2Parameter = GetParameter("u_directionToLight2");
145 m_fogColorParameter = GetParameter("u_fogColor");
146 m_fogBottomTopDensityParameter = GetParameter("u_fogBottomTopDensity");
147 m_hazeStartDensityParameter = GetParameter("u_hazeStartDensity");
148 m_fogYMultiplierParameter = GetParameter("u_fogYMultiplier");
149 m_worldUpParameter = GetParameter("u_worldUp");
150 }
151
152 public override void PrepareForDrawingOverride() {
153 Transforms.UpdateMatrices(m_instancesCount, false, false, true);
156 }
157
158 public static ShaderMacro[] PrepareShaderMacros(bool useAlphaThreshold, int maxInstancesCount, ShaderMacro[] shaderMacros = null) {
159 List<ShaderMacro> list = new();
160 if (useAlphaThreshold) {
161 list.Add(new ShaderMacro("ALPHATESTED"));
162 }
163 list.Add(new ShaderMacro("MAX_INSTANCES_COUNT", maxInstancesCount.ToString(CultureInfo.InvariantCulture)));
164 if (shaderMacros != null
165 && shaderMacros.Length > 0) {
166 foreach (ShaderMacro shaderMacro in shaderMacros) {
167 list.Add(shaderMacro);
168 }
169 }
170 return list.ToArray();
171 }
172 }
173}
virtual ShaderParameter GetParameter(string name, bool allowNull=false)
ShaderParameter m_fogYMultiplierParameter
ShaderParameter m_ambientLightColorParameter
virtual void SetParameter()
ShaderParameter m_samplerStateParameter
ShaderParameter m_alphaThresholdParameter
ShaderParameter m_worldMatrixParameter
ShaderParameter m_fogColorParameter
SamplerState SamplerState
ShaderParameter m_diffuseLightColor1Parameter
ShaderParameter m_hazeStartDensityParameter
ShaderParameter m_directionToLight2Parameter
ShaderParameter m_directionToLight1Parameter
ShaderParameter m_emissionColorParameter
ShaderParameter m_textureParameter
static ShaderMacro[] PrepareShaderMacros(bool useAlphaThreshold, int maxInstancesCount, ShaderMacro[] shaderMacros=null)
ShaderParameter m_fogBottomTopDensityParameter
ModelShader(string vsc, string psc, bool useAlphaThreshold, int maxInstancesCount=1)
ShaderParameter m_materialColorParameter
ShaderParameter m_worldUpParameter
ShaderParameter m_diffuseLightColor2Parameter
override void PrepareForDrawingOverride()
ModelShader(string vsc, string psc, bool useAlphaThreshold, int maxInstancesCount=1, ShaderMacro[] shaderMacros=null)
ShaderParameter m_worldViewProjectionMatrixParameter