mirror of
https://github.com/maxartz15/VolumetricLighting.git
synced 2024-11-21 22:15:34 +01:00
Fix issues with empty compute buffers.
This commit is contained in:
parent
65f66084db
commit
fe8a53f50a
@ -145,6 +145,8 @@ public class VolumetricFog : MonoBehaviour
|
|||||||
FogEllipsoidParams[] m_FogEllipsoidParams;
|
FogEllipsoidParams[] m_FogEllipsoidParams;
|
||||||
ComputeBuffer m_FogEllipsoidParamsCB;
|
ComputeBuffer m_FogEllipsoidParamsCB;
|
||||||
|
|
||||||
|
ComputeBuffer m_DummyCB;
|
||||||
|
|
||||||
Camera cam{ get { if (m_Camera == null) m_Camera = GetComponent<Camera>(); return m_Camera; }}
|
Camera cam{ get { if (m_Camera == null) m_Camera = GetComponent<Camera>(); return m_Camera; }}
|
||||||
|
|
||||||
float nearClip { get { return Mathf.Max(0, m_NearClip); } }
|
float nearClip { get { return Mathf.Max(0, m_NearClip); } }
|
||||||
@ -176,6 +178,7 @@ public class VolumetricFog : MonoBehaviour
|
|||||||
ReleaseComputeBuffer(ref m_TubeLightShadowPlaneParamsCB);
|
ReleaseComputeBuffer(ref m_TubeLightShadowPlaneParamsCB);
|
||||||
ReleaseComputeBuffer(ref m_AreaLightParamsCB);
|
ReleaseComputeBuffer(ref m_AreaLightParamsCB);
|
||||||
ReleaseComputeBuffer(ref m_FogEllipsoidParamsCB);
|
ReleaseComputeBuffer(ref m_FogEllipsoidParamsCB);
|
||||||
|
ReleaseComputeBuffer(ref m_DummyCB);
|
||||||
m_VolumeInject = null;
|
m_VolumeInject = null;
|
||||||
m_VolumeScatter = null;
|
m_VolumeScatter = null;
|
||||||
}
|
}
|
||||||
@ -192,7 +195,11 @@ public class VolumetricFog : MonoBehaviour
|
|||||||
int count = m_PointLightParamsCB == null ? 0 : m_PointLightParamsCB.count;
|
int count = m_PointLightParamsCB == null ? 0 : m_PointLightParamsCB.count;
|
||||||
m_InjectLightingAndDensity.SetFloat("_PointLightsCount", count);
|
m_InjectLightingAndDensity.SetFloat("_PointLightsCount", count);
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
|
{
|
||||||
|
// Can't not set the buffer
|
||||||
|
m_InjectLightingAndDensity.SetBuffer(kernel, "_PointLights", m_DummyCB);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_PointLightParams == null || m_PointLightParams.Length != count)
|
if (m_PointLightParams == null || m_PointLightParams.Length != count)
|
||||||
m_PointLightParams = new PointLightParams[count];
|
m_PointLightParams = new PointLightParams[count];
|
||||||
@ -226,7 +233,12 @@ public class VolumetricFog : MonoBehaviour
|
|||||||
int count = m_TubeLightParamsCB == null ? 0 : m_TubeLightParamsCB.count;
|
int count = m_TubeLightParamsCB == null ? 0 : m_TubeLightParamsCB.count;
|
||||||
m_InjectLightingAndDensity.SetFloat("_TubeLightsCount", count);
|
m_InjectLightingAndDensity.SetFloat("_TubeLightsCount", count);
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
|
{
|
||||||
|
// Can't not set the buffer
|
||||||
|
m_InjectLightingAndDensity.SetBuffer(kernel, "_TubeLights", m_DummyCB);
|
||||||
|
m_InjectLightingAndDensity.SetBuffer(kernel, "_TubeLightShadowPlanes", m_DummyCB);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_TubeLightParams == null || m_TubeLightParams.Length != count)
|
if (m_TubeLightParams == null || m_TubeLightParams.Length != count)
|
||||||
m_TubeLightParams = new TubeLightParams[count];
|
m_TubeLightParams = new TubeLightParams[count];
|
||||||
@ -277,7 +289,11 @@ public class VolumetricFog : MonoBehaviour
|
|||||||
int count = m_AreaLightParamsCB == null ? 0 : m_AreaLightParamsCB.count;
|
int count = m_AreaLightParamsCB == null ? 0 : m_AreaLightParamsCB.count;
|
||||||
m_InjectLightingAndDensity.SetFloat("_AreaLightsCount", count);
|
m_InjectLightingAndDensity.SetFloat("_AreaLightsCount", count);
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
|
{
|
||||||
|
// Can't not set the buffer
|
||||||
|
m_InjectLightingAndDensity.SetBuffer(kernel, "_AreaLights", m_DummyCB);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_AreaLightParams == null || m_AreaLightParams.Length != count)
|
if (m_AreaLightParams == null || m_AreaLightParams.Length != count)
|
||||||
m_AreaLightParams = new AreaLightParams[count];
|
m_AreaLightParams = new AreaLightParams[count];
|
||||||
@ -330,7 +346,11 @@ public class VolumetricFog : MonoBehaviour
|
|||||||
|
|
||||||
m_InjectLightingAndDensity.SetFloat("_FogEllipsoidsCount", count);
|
m_InjectLightingAndDensity.SetFloat("_FogEllipsoidsCount", count);
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
|
{
|
||||||
|
// Can't not set the buffer
|
||||||
|
m_InjectLightingAndDensity.SetBuffer(kernel, "_FogEllipsoids", m_DummyCB);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_FogEllipsoidParams == null || m_FogEllipsoidParams.Length != count)
|
if (m_FogEllipsoidParams == null || m_FogEllipsoidParams.Length != count)
|
||||||
m_FogEllipsoidParams = new FogEllipsoidParams[count];
|
m_FogEllipsoidParams = new FogEllipsoidParams[count];
|
||||||
@ -473,6 +493,8 @@ public class VolumetricFog : MonoBehaviour
|
|||||||
m_ambientLight[2] = ambient.b;
|
m_ambientLight[2] = ambient.b;
|
||||||
m_InjectLightingAndDensity.SetFloats("_AmbientLight", m_ambientLight);
|
m_InjectLightingAndDensity.SetFloats("_AmbientLight", m_ambientLight);
|
||||||
|
|
||||||
|
m_DummyCB = new ComputeBuffer(1, 4);
|
||||||
|
|
||||||
SetUpPointLightBuffers(kernel);
|
SetUpPointLightBuffers(kernel);
|
||||||
SetUpTubeLightBuffers(kernel);
|
SetUpTubeLightBuffers(kernel);
|
||||||
SetUpAreaLightBuffers(kernel);
|
SetUpAreaLightBuffers(kernel);
|
||||||
|
Loading…
Reference in New Issue
Block a user