void InitResources() { // Volume InitVolume(ref m_VolumeInject); InitVolume(ref m_VolumeScatter); // Compute buffers int pointLightCount = 0, tubeLightCount = 0, areaLightCount = 0; HashSet <FogLight> fogLights = LightManagerFogLights.Get(); for (var x = fogLights.GetEnumerator(); x.MoveNext();) { var fl = x.Current; if (fl == null) { continue; } bool isOn = fl.isOn; switch (fl.type) { case FogLight.Type.Point: if (isOn) { pointLightCount++; } break; case FogLight.Type.Tube: if (isOn) { tubeLightCount++; } break; case FogLight.Type.Area: if (isOn) { areaLightCount++; } break; } } // PointLightParams {float3 float float3 float} -> 32 bytes CreateBuffer(ref m_PointLightParamsCB, pointLightCount, 32); // TubeLightParams {float3 float float3 float float3 float} -> 48 bytes CreateBuffer(ref m_TubeLightParamsCB, tubeLightCount, 48); // TubeLightShadowPlaneParams {float4 float4 float float float float} -> 48 bytes CreateBuffer(ref m_TubeLightShadowPlaneParamsCB, tubeLightCount, 48); // TubeLightParams {float4x4 float4 float3 float} -> 96 bytes CreateBuffer(ref m_AreaLightParamsCB, areaLightCount, 96); // FogEllipsoidParams {float3 float float3 9xfloat} -> 64 bytes HashSet <FogEllipsoid> fogEllipsoids = LightManagerFogEllipsoids.Get(); CreateBuffer(ref m_FogEllipsoidParamsCB, fogEllipsoids == null ? 0 : fogEllipsoids.Count, 64); }
void SetUpFogEllipsoidBuffers(int kernel) { int count = 0; HashSet <FogEllipsoid> fogEllipsoids = LightManagerFogEllipsoids.Get(); for (var x = fogEllipsoids.GetEnumerator(); x.MoveNext();) { var fe = x.Current; if (fe != null && fe.enabled && fe.gameObject.activeSelf) { count++; } } m_InjectLightingAndDensity.SetFloat("_FogEllipsoidsCount", count); if (count == 0) { // Can't not set the buffer m_InjectLightingAndDensity.SetBuffer(kernel, "_FogEllipsoids", m_DummyCB); return; } if (m_FogEllipsoidParams == null || m_FogEllipsoidParams.Length != count) { m_FogEllipsoidParams = new FogEllipsoidParams[count]; } int j = 0; for (var x = fogEllipsoids.GetEnumerator(); x.MoveNext();) { var fe = x.Current; if (fe == null || !fe.enabled || !fe.gameObject.activeSelf) { continue; } Transform t = fe.transform; m_FogEllipsoidParams[j].pos = t.position; m_FogEllipsoidParams[j].radius = fe.m_Radius * fe.m_Radius; m_FogEllipsoidParams[j].axis = -t.up; m_FogEllipsoidParams[j].stretch = 1.0f / fe.m_Stretch - 1.0f; m_FogEllipsoidParams[j].density = fe.m_Density; m_FogEllipsoidParams[j].noiseAmount = fe.m_NoiseAmount; m_FogEllipsoidParams[j].noiseSpeed = fe.m_NoiseSpeed; m_FogEllipsoidParams[j].noiseScale = fe.m_NoiseScale; m_FogEllipsoidParams[j].feather = 1.0f - fe.m_Feather; m_FogEllipsoidParams[j].blend = fe.m_Blend == FogEllipsoid.Blend.Additive ? 0 : 1; j++; } m_FogEllipsoidParamsCB.SetData(m_FogEllipsoidParams); m_InjectLightingAndDensity.SetBuffer(kernel, "_FogEllipsoids", m_FogEllipsoidParamsCB); }
void InitResources() { // Volume InitVolume(ref m_VolumeInject); InitVolume(ref m_VolumeScatter); // Compute buffers int pointLightCount = 0, tubeLightCount = 0, areaLightCount = 0; HashSet <FogLight> fogLights = LightManagerFogLights.Get(); for (var x = fogLights.GetEnumerator(); x.MoveNext();) { var fl = x.Current; if (fl == null) { continue; } bool isOn = fl.isOn; switch (fl.type) { case FogLight.Type.Point: if (isOn) { pointLightCount++; } break; case FogLight.Type.Tube: if (isOn) { tubeLightCount++; } break; case FogLight.Type.Area: if (isOn) { areaLightCount++; } break; } } CreateBuffer(ref m_PointLightParamsCB, pointLightCount, Marshal.SizeOf(typeof(PointLightParams))); CreateBuffer(ref m_TubeLightParamsCB, tubeLightCount, Marshal.SizeOf(typeof(TubeLightParams))); CreateBuffer(ref m_TubeLightShadowPlaneParamsCB, tubeLightCount, Marshal.SizeOf(typeof(TubeLightShadowPlaneParams))); CreateBuffer(ref m_AreaLightParamsCB, areaLightCount, Marshal.SizeOf(typeof(AreaLightParams))); HashSet <FogEllipsoid> fogEllipsoids = LightManagerFogEllipsoids.Get(); CreateBuffer(ref m_FogEllipsoidParamsCB, fogEllipsoids == null ? 0 : fogEllipsoids.Count, Marshal.SizeOf(typeof(FogEllipsoidParams))); CreateBuffer(ref m_DummyCB, 1, 4); }