static private void RenderLightVolumeSet(Camera camera, int lightOpIndex, CommandBuffer cmdBuffer, int layerToRender, RenderTargetIdentifier renderTexture, List <Light2D> lights) { if (lights.Count > 0) { for (int i = 0; i < lights.Count; i++) { Light2D light = lights[i]; int topMostLayer = light.GetTopMostLitLayer(); if (layerToRender == topMostLayer) { if (light != null && light.lightType != Light2D.LightType.Global && light.volumeOpacity > 0.0f && light.lightOperationIndex == lightOpIndex && light.IsLitLayer(layerToRender) && light.IsLightVisible(camera)) { Material lightVolumeMaterial = GetLightMaterial(light, true); if (lightVolumeMaterial != null) { Mesh lightMesh = light.GetMesh(); if (lightMesh != null) { if (light.lightType == Light2D.LightType.Sprite && light.lightCookieSprite != null && light.lightCookieSprite.texture != null) { cmdBuffer.SetGlobalTexture("_CookieTex", light.lightCookieSprite.texture); } cmdBuffer.SetGlobalFloat("_FalloffIntensity", light.falloffIntensity); cmdBuffer.SetGlobalFloat("_FalloffDistance", light.shapeLightFalloffSize); cmdBuffer.SetGlobalVector("_FalloffOffset", light.shapeLightFalloffOffset); cmdBuffer.SetGlobalColor("_LightColor", light.intensity * light.color); cmdBuffer.SetGlobalFloat("_VolumeOpacity", light.volumeOpacity); // Is this needed if (light.useNormalMap || light.lightType == Light2D.LightType.Point) { RendererLighting.SetPointLightShaderGlobals(cmdBuffer, light); } // Could be combined... if (light.lightType == Light2D.LightType.Parametric || light.lightType == Light2D.LightType.Freeform || light.lightType == Light2D.LightType.Sprite) { cmdBuffer.DrawMesh(lightMesh, light.transform.localToWorldMatrix, lightVolumeMaterial); } else if (light.lightType == Light2D.LightType.Point) { Vector3 scale = new Vector3(light.pointLightOuterRadius, light.pointLightOuterRadius, light.pointLightOuterRadius); Matrix4x4 matrix = Matrix4x4.TRS(light.transform.position, Quaternion.identity, scale); cmdBuffer.DrawMesh(lightMesh, matrix, lightVolumeMaterial); } } } } } } } }
static private void RenderLightVolumeSet(Camera camera, int lightOpIndex, CommandBuffer cmdBuffer, int layerToRender, RenderTargetIdentifier renderTexture, List <Light2D> lights) { if (lights.Count > 0) { for (int i = 0; i < lights.Count; i++) { Light2D light = lights[i]; int topMostLayer = light.GetTopMostLitLayer(); if (layerToRender == topMostLayer) { if (light != null && light.lightType != Light2D.LightType.Global && light.volumeOpacity > 0.0f && light.lightOperationIndex == lightOpIndex && light.IsLitLayer(layerToRender) && light.IsLightVisible(camera)) { Material shapeLightVolumeMaterial = GetLightMaterial(light, true); if (shapeLightVolumeMaterial != null) { Mesh lightMesh = light.GetMesh(); if (lightMesh != null) { if (light.lightType == Light2D.LightType.Sprite && light.lightCookieSprite != null && light.lightCookieSprite.texture != null) { cmdBuffer.SetGlobalTexture("_CookieTex", light.lightCookieSprite.texture); } cmdBuffer.SetGlobalFloat("_FalloffCurve", light.falloffCurve); if (!light.hasDirection) { cmdBuffer.DrawMesh(lightMesh, light.transform.localToWorldMatrix, shapeLightVolumeMaterial); } else { RendererLighting.SetPointLightShaderGlobals(cmdBuffer, light); //Vector3 scale = new Vector3(2 * light.m_PointLightOuterRadius, 2 * light.m_PointLightOuterRadius, 1); Vector3 scale = new Vector3(light.pointLightOuterRadius, light.pointLightOuterRadius, light.pointLightOuterRadius); Matrix4x4 matrix = Matrix4x4.TRS(light.transform.position, Quaternion.identity, scale); cmdBuffer.DrawMesh(lightMesh, matrix, shapeLightVolumeMaterial); } } } } } } } }