Files
AsanoRema ffa1064063 Squashed commit of the following:
commit 428243f4a6
Author: AsanoRema <asanorema2036@gmail.com>
Date:   Sat Aug 29 13:43:13 2026 +0300

    Squashed commit of the following:

    commit 68e78fa464
    Author: AsanoRema <asanorema2036@gmail.com>
    Date:   Sat Aug 29 13:41:49 2026 +0300

        Updated .gitignore

commit 9f87122a34
Author: AsanoRema <asanorema2036@gmail.com>
Date:   Sat Aug 29 13:34:57 2026 +0300

    Added Dohya

commit f6a7547e84
Author: AsanoRema <asanorema2036@gmail.com>
Date:   Fri Aug 21 17:59:13 2026 +0300

    Fixed

commit b98901c366
Author: AsanoRema <asanorema2036@gmail.com>
Date:   Tue Aug 18 17:37:22 2026 +0300

    Added new particle Package

commit bb2f4a3b16
Author: AsanoRema <asanorema2036@gmail.com>
Date:   Tue Aug 18 17:17:48 2026 +0300

    Map mehanic ready to multiplayer

commit c01ff800f6
Author: AsanoRema <asanorema2036@gmail.com>
Date:   Tue Aug 18 16:16:19 2026 +0300

    Squashed commit of the following:

    commit 173bbb165c
    Author: henjkey <henjkey@gmail.com>
    Date:   Fri Aug 14 18:51:23 2026 +0500

        Mappp

    commit d559ab338a
    Author: henjkey <henjkey@gmail.com>
    Date:   Thu Aug 13 18:42:41 2026 +0500

        Map

        Controller
        Coordinates
        Target System
        Crosshair System
        Radar System
2026-08-29 13:45:55 +03:00

147 lines
5.7 KiB
C#

#if UNITY_5_6_OR_NEWER
#define VLB_GPU_INSTANCING_SUPPORT
#endif
// Force isDepthBlendEnabled at true when GPU Instancing is enabled, to prevent from breaking the batch if 1 beam has it at 0 and 1 has it at > 0
#define FORCE_ENABLE_DEPTHBLEND_FOR_BATCHING
using UnityEngine;
namespace VLB
{
public static class BatchingHelper
{
/// <summary>
/// Returns if GPU Instancing feature is supported on this Unity version or not.
/// </summary>
#if VLB_GPU_INSTANCING_SUPPORT
public const bool isGpuInstancingSupported = true;
#else
public static bool isGpuInstancingSupported { get; private set; }
#endif
#if FORCE_ENABLE_DEPTHBLEND_FOR_BATCHING
public static bool forceEnableDepthBlend { get { return Config.Instance.actualRenderingMode == RenderingMode.GPUInstancing || Config.Instance.actualRenderingMode == RenderingMode.SRPBatcher; } }
#else
public const bool forceEnableDepthBlend = false;
#endif
public static bool IsGpuInstancingEnabled(Material material)
{
#if VLB_GPU_INSTANCING_SUPPORT
return material.enableInstancing;
#else
return false;
#endif
}
public static void SetMaterialProperties(Material material, bool enableGpuInstancing)
{
#if VLB_GPU_INSTANCING_SUPPORT
Debug.Assert(material != null);
material.enableInstancing = enableGpuInstancing;
#endif
}
public static bool CanBeBatched(VolumetricLightBeam beamA, VolumetricLightBeam beamB, ref string reasons)
{
#pragma warning disable 0162 // warning CS0162: Unreachable code detected
if (Config.Instance.renderPipeline == RenderPipeline.BuiltIn && !isGpuInstancingSupported)
{
reasons = "'GPU Instancing' is not supported on your setup.";
return false;
}
#pragma warning restore 0162
if (Config.Instance.actualRenderingMode != RenderingMode.GPUInstancing && Config.Instance.actualRenderingMode != RenderingMode.SRPBatcher)
{
reasons = string.Format("Current Render Pipeline is '{0}'. To enable batching, use 'GPU Instancing'", Config.Instance.renderPipeline);
if(Config.Instance.renderPipeline != RenderPipeline.BuiltIn)
reasons += " or 'SRP Batcher'";
return false;
}
bool ret = true;
if (!CanBeBatched(beamA, ref reasons))
ret = false;
if (!CanBeBatched(beamB, ref reasons))
ret = false;
if (Config.Instance.featureEnabledDynamicOcclusion)
{
if ((beamA.GetComponent<DynamicOcclusionAbstractBase>() == null) != (beamB.GetComponent<DynamicOcclusionAbstractBase>() == null))
{
AppendErrorMessage(ref reasons, string.Format("{0}/{1}: dynamically occluded and non occluded beams cannot be batched together", beamA.name, beamB.name));
ret = false;
}
}
if (Config.Instance.featureEnabledColorGradient != FeatureEnabledColorGradient.Off && beamA.colorMode != beamB.colorMode)
{
AppendErrorMessage(ref reasons, string.Format("'Color Mode' mismatch: {0} / {1}", beamA.colorMode, beamB.colorMode));
ret = false;
}
if (beamA.blendingMode != beamB.blendingMode)
{
AppendErrorMessage(ref reasons, string.Format("'Blending Mode' mismatch: {0} / {1}", beamA.blendingMode, beamB.blendingMode));
ret = false;
}
if (Config.Instance.featureEnabledNoise3D && beamA.isNoiseEnabled != beamB.isNoiseEnabled)
{
AppendErrorMessage(ref reasons, string.Format("'3D Noise' enabled mismatch: {0} / {1}", beamA.noiseMode, beamB.noiseMode));
ret = false;
}
if (Config.Instance.featureEnabledDepthBlend && !forceEnableDepthBlend)
{
#pragma warning disable 0162
if ((beamA.depthBlendDistance > 0) != (beamB.depthBlendDistance > 0))
{
AppendErrorMessage(ref reasons, string.Format("'Opaque Geometry Blending' mismatch: {0} / {1}", beamA.depthBlendDistance, beamB.depthBlendDistance));
ret = false;
}
#pragma warning restore 0162
}
if (Config.Instance.featureEnabledShaderAccuracyHigh && beamA.shaderAccuracy != beamB.shaderAccuracy)
{
AppendErrorMessage(ref reasons, string.Format("'Shader Accuracy' mismatch: {0} / {1}", beamA.shaderAccuracy, beamB.shaderAccuracy));
ret = false;
}
return ret;
}
public static bool CanBeBatched(VolumetricLightBeam beam, ref string reasons)
{
bool ret = true;
if (Config.Instance.actualRenderingMode == RenderingMode.GPUInstancing)
{
if (beam.geomMeshType != MeshType.Shared)
{
AppendErrorMessage(ref reasons, string.Format("{0} is not using shared mesh", beam.name));
ret = false;
}
}
if (Config.Instance.featureEnabledDynamicOcclusion && beam.GetComponent<DynamicOcclusionDepthBuffer>() != null)
{
AppendErrorMessage(ref reasons, string.Format("{0} is using the DynamicOcclusion DepthBuffer feature", beam.name));
ret = false;
}
return ret;
}
static void AppendErrorMessage(ref string message, string toAppend)
{
if (message != "") message += "\n";
message += "- " + toAppend;
}
}
}