Squashed commit of the following:
commit428243f4a6Author: AsanoRema <asanorema2036@gmail.com> Date: Sat Aug 29 13:43:13 2026 +0300 Squashed commit of the following: commit68e78fa464Author: AsanoRema <asanorema2036@gmail.com> Date: Sat Aug 29 13:41:49 2026 +0300 Updated .gitignore commit9f87122a34Author: AsanoRema <asanorema2036@gmail.com> Date: Sat Aug 29 13:34:57 2026 +0300 Added Dohya commitf6a7547e84Author: AsanoRema <asanorema2036@gmail.com> Date: Fri Aug 21 17:59:13 2026 +0300 Fixed commitb98901c366Author: AsanoRema <asanorema2036@gmail.com> Date: Tue Aug 18 17:37:22 2026 +0300 Added new particle Package commitbb2f4a3b16Author: AsanoRema <asanorema2036@gmail.com> Date: Tue Aug 18 17:17:48 2026 +0300 Map mehanic ready to multiplayer commitc01ff800f6Author: AsanoRema <asanorema2036@gmail.com> Date: Tue Aug 18 16:16:19 2026 +0300 Squashed commit of the following: commit173bbb165cAuthor: henjkey <henjkey@gmail.com> Date: Fri Aug 14 18:51:23 2026 +0500 Mappp commitd559ab338aAuthor: henjkey <henjkey@gmail.com> Date: Thu Aug 13 18:42:41 2026 +0500 Map Controller Coordinates Target System Crosshair System Radar System
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace VLB
|
||||
{
|
||||
public static class MaterialManager
|
||||
{
|
||||
public static MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();
|
||||
|
||||
public enum BlendingMode
|
||||
{
|
||||
Additive,
|
||||
SoftAdditive,
|
||||
TraditionalTransparency,
|
||||
Count
|
||||
}
|
||||
|
||||
public enum Noise3D
|
||||
{
|
||||
Off,
|
||||
On,
|
||||
Count
|
||||
}
|
||||
|
||||
public enum DepthBlend
|
||||
{
|
||||
Off,
|
||||
On,
|
||||
Count
|
||||
}
|
||||
|
||||
public enum ColorGradient
|
||||
{
|
||||
Off,
|
||||
MatrixLow,
|
||||
MatrixHigh,
|
||||
Count
|
||||
}
|
||||
|
||||
public enum DynamicOcclusion
|
||||
{
|
||||
Off,
|
||||
ClippingPlane,
|
||||
DepthTexture,
|
||||
Count
|
||||
}
|
||||
|
||||
public enum MeshSkewing
|
||||
{
|
||||
Off,
|
||||
On,
|
||||
Count
|
||||
}
|
||||
|
||||
public enum ShaderAccuracy
|
||||
{
|
||||
Fast,
|
||||
High,
|
||||
Count
|
||||
}
|
||||
|
||||
static readonly UnityEngine.Rendering.BlendMode[] BlendingMode_SrcFactor = new UnityEngine.Rendering.BlendMode[(int)BlendingMode.Count]
|
||||
{
|
||||
UnityEngine.Rendering.BlendMode.One, // Additive
|
||||
UnityEngine.Rendering.BlendMode.OneMinusDstColor, // SoftAdditive
|
||||
UnityEngine.Rendering.BlendMode.SrcAlpha, // TraditionalTransparency
|
||||
};
|
||||
|
||||
static readonly UnityEngine.Rendering.BlendMode[] BlendingMode_DstFactor = new UnityEngine.Rendering.BlendMode[(int)BlendingMode.Count]
|
||||
{
|
||||
UnityEngine.Rendering.BlendMode.One, // Additive
|
||||
UnityEngine.Rendering.BlendMode.One, // SoftAdditive
|
||||
UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha, // TraditionalTransparency
|
||||
};
|
||||
|
||||
static readonly bool[] BlendingMode_AlphaAsBlack = new bool[(int)BlendingMode.Count]
|
||||
{
|
||||
true, // Additive
|
||||
true, // SoftAdditive
|
||||
false, // TraditionalTransparency
|
||||
};
|
||||
|
||||
static int kStaticPropertiesCount = (int)BlendingMode.Count * (int)Noise3D.Count * (int)DepthBlend.Count * (int)ColorGradient.Count * (int)DynamicOcclusion.Count * (int)MeshSkewing.Count * (int)ShaderAccuracy.Count;
|
||||
|
||||
public struct StaticProperties
|
||||
{
|
||||
public BlendingMode blendingMode;
|
||||
public Noise3D noise3D;
|
||||
public DepthBlend depthBlend;
|
||||
public ColorGradient colorGradient;
|
||||
public DynamicOcclusion dynamicOcclusion;
|
||||
public MeshSkewing meshSkewing;
|
||||
public ShaderAccuracy shaderAccuracy;
|
||||
|
||||
int blendingModeID { get { return (int)blendingMode; } }
|
||||
int noise3DID { get { return Config.Instance.featureEnabledNoise3D ? (int)noise3D : 0; } }
|
||||
int depthBlendID { get { return Config.Instance.featureEnabledDepthBlend ? (int)depthBlend : 0; } }
|
||||
int colorGradientID { get { return Config.Instance.featureEnabledColorGradient != FeatureEnabledColorGradient.Off ? (int)colorGradient : 0; } }
|
||||
int dynamicOcclusionID { get { return Config.Instance.featureEnabledDynamicOcclusion ? (int)dynamicOcclusion : 0; } }
|
||||
int meshSkewingID { get { return Config.Instance.featureEnabledMeshSkewing ? (int)meshSkewing : 0; } }
|
||||
int shaderAccuracyID { get { return Config.Instance.featureEnabledShaderAccuracyHigh ? (int)shaderAccuracy : 0; } }
|
||||
|
||||
public int materialID
|
||||
{
|
||||
get
|
||||
{
|
||||
return (((((((blendingModeID)
|
||||
* (int)Noise3D.Count + noise3DID)
|
||||
* (int)DepthBlend.Count + depthBlendID)
|
||||
* (int)ColorGradient.Count + colorGradientID)
|
||||
* (int)DynamicOcclusion.Count + dynamicOcclusionID)
|
||||
* (int)MeshSkewing.Count + meshSkewingID)
|
||||
* (int)ShaderAccuracy.Count + shaderAccuracyID)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyToMaterial(Material mat)
|
||||
{
|
||||
mat.SetKeywordEnabled(ShaderKeywords.AlphaAsBlack, BlendingMode_AlphaAsBlack[(int)blendingMode]);
|
||||
mat.SetKeywordEnabled(ShaderKeywords.ColorGradientMatrixLow, colorGradient == ColorGradient.MatrixLow);
|
||||
mat.SetKeywordEnabled(ShaderKeywords.ColorGradientMatrixHigh, colorGradient == ColorGradient.MatrixHigh);
|
||||
mat.SetKeywordEnabled(ShaderKeywords.DepthBlend, depthBlend == DepthBlend.On);
|
||||
mat.SetKeywordEnabled(ShaderKeywords.Noise3D, noise3D == Noise3D.On);
|
||||
mat.SetKeywordEnabled(ShaderKeywords.OcclusionClippingPlane, dynamicOcclusion == DynamicOcclusion.ClippingPlane);
|
||||
mat.SetKeywordEnabled(ShaderKeywords.OcclusionDepthTexture, dynamicOcclusion == DynamicOcclusion.DepthTexture);
|
||||
mat.SetKeywordEnabled(ShaderKeywords.MeshSkewing, meshSkewing == MeshSkewing.On);
|
||||
mat.SetKeywordEnabled(ShaderKeywords.ShaderAccuracyHigh, shaderAccuracy == ShaderAccuracy.High);
|
||||
|
||||
mat.SetInt(ShaderProperties.BlendSrcFactor, (int)BlendingMode_SrcFactor[(int)blendingMode]);
|
||||
mat.SetInt(ShaderProperties.BlendDstFactor, (int)BlendingMode_DstFactor[(int)blendingMode]);
|
||||
}
|
||||
}
|
||||
|
||||
public static Material NewMaterialTransient(bool gpuInstanced)
|
||||
{
|
||||
var material = NewMaterialPersistent(Config.Instance.beamShader, gpuInstanced);
|
||||
if (material)
|
||||
{
|
||||
material.hideFlags = Consts.Internal.ProceduralObjectsHideFlags;
|
||||
material.renderQueue = Config.Instance.geometryRenderQueue;
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
public static Material NewMaterialPersistent(Shader shader, bool gpuInstanced)
|
||||
{
|
||||
if (!shader)
|
||||
{
|
||||
Debug.LogError("Invalid VLB Shader. Please try to reset the VLB Config asset or reinstall the plugin.");
|
||||
return null;
|
||||
}
|
||||
|
||||
var material = new Material(shader);
|
||||
BatchingHelper.SetMaterialProperties(material, gpuInstanced);
|
||||
return material;
|
||||
}
|
||||
|
||||
class MaterialsGroup
|
||||
{
|
||||
public Material[] materials = new Material[kStaticPropertiesCount];
|
||||
}
|
||||
|
||||
static Hashtable ms_MaterialsGroup = new Hashtable(1);
|
||||
|
||||
public static Material GetInstancedMaterial(uint groupID, ref StaticProperties staticProps) // pass StaticProperties by ref to avoid per value arg copy
|
||||
{
|
||||
MaterialsGroup group = (MaterialsGroup)ms_MaterialsGroup[groupID];
|
||||
if (group == null)
|
||||
{
|
||||
group = new MaterialsGroup();
|
||||
ms_MaterialsGroup[groupID] = group;
|
||||
}
|
||||
|
||||
int matID = staticProps.materialID;
|
||||
Debug.Assert(matID < kStaticPropertiesCount);
|
||||
var mat = group.materials[matID];
|
||||
if (mat == null)
|
||||
{
|
||||
mat = NewMaterialTransient(gpuInstanced:true);
|
||||
if(mat)
|
||||
{
|
||||
group.materials[matID] = mat;
|
||||
staticProps.ApplyToMaterial(mat);
|
||||
}
|
||||
}
|
||||
|
||||
return mat;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user