diff options
author | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
commit | 6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch) | |
tree | 7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/ShadowMapInfo.cs |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/ShadowMapInfo.cs')
-rw-r--r-- | Client/Assets/Scripts/XMainClient/ShadowMapInfo.cs | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XMainClient/ShadowMapInfo.cs b/Client/Assets/Scripts/XMainClient/ShadowMapInfo.cs new file mode 100644 index 00000000..0c1a6b12 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ShadowMapInfo.cs @@ -0,0 +1,124 @@ +using System;
+using UnityEngine;
+
+namespace XMainClient
+{
+ public class ShadowMapInfo
+ {
+ private const int m_shadowMapWidth = 512;
+
+ private const int m_shadowMapHeight = 512;
+
+ public RenderTexture shadowMap = null;
+
+ public const int RChannel = 1;
+
+ public const int GChannel = 2;
+
+ public const int BChannel = 4;
+
+ public const int AChannel = 8;
+
+ public const int EmpytChannel = 0;
+
+ private int m_shadowChannelState = 0;
+
+ private static bool hasShadowMap = false;
+
+ public void CreateShadowMap()
+ {
+ this.shadowMap = new RenderTexture(512, 512, 0,(RenderTextureFormat)16, 0);
+ this.shadowMap.name = "ShadowMap";
+ this.shadowMap.autoGenerateMips = false;
+ this.shadowMap.Create();
+ Shader.SetGlobalTexture("_CustomShadowMapTexture", this.shadowMap);
+ Shader.SetGlobalFloat("shadowScale", XCustomShadow.scale);
+ ShadowMapInfo.hasShadowMap = true;
+ ShadowMapInfo.EnableShadow(true);
+ }
+
+ public void DestroyShadowMap()
+ {
+ bool flag = this.shadowMap != null;
+ if (flag)
+ {
+ this.shadowMap.Release();
+ this.shadowMap = null;
+ ShadowMapInfo.hasShadowMap = false;
+ }
+ }
+
+ public static void ClearShadowRes()
+ {
+ Shader.SetGlobalTexture("_CustomShadowMapTexture", null);
+ ShadowMapInfo.EnableShadow(false);
+ }
+
+ public static void EnableShadow(bool enable)
+ {
+ bool flag = enable && ShadowMapInfo.hasShadowMap;
+ if (flag)
+ {
+ Shader.EnableKeyword("CUSTOM_SHADOW_ON");
+ }
+ else
+ {
+ Shader.DisableKeyword("CUSTOM_SHADOW_ON");
+ }
+ }
+
+ public int AllocChannel()
+ {
+ bool flag = (this.m_shadowChannelState & 1) == 0;
+ int result;
+ if (flag)
+ {
+ this.m_shadowChannelState |= 1;
+ result = 1;
+ }
+ else
+ {
+ bool flag2 = (this.m_shadowChannelState & 2) == 0;
+ if (flag2)
+ {
+ this.m_shadowChannelState |= 2;
+ result = 2;
+ }
+ else
+ {
+ bool flag3 = (this.m_shadowChannelState & 4) == 0;
+ if (flag3)
+ {
+ this.m_shadowChannelState |= 4;
+ result = 4;
+ }
+ else
+ {
+ bool flag4 = (this.m_shadowChannelState & 8) == 0;
+ if (flag4)
+ {
+ this.m_shadowChannelState |= 8;
+ result = 8;
+ }
+ else
+ {
+ result = 0;
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ public void FreeChannel(int channle)
+ {
+ this.m_shadowChannelState &= ~channle;
+ }
+
+ public void Clear()
+ {
+ this.m_shadowChannelState = 0;
+ this.DestroyShadowMap();
+ }
+ }
+}
|