static uint GetLightMaterialIndex(Light2D light, bool isVolume) { int bitIndex = 0; uint volumeBit = isVolume ? 1u << bitIndex : 0u; bitIndex++; uint shapeBit = light.IsShapeLight() ? 1u << bitIndex : 0u; bitIndex++; uint additiveBit = light.alphaBlendOnOverlap ? 0u : 1u << bitIndex; bitIndex++; uint spriteBit = light.lightType == Light2D.LightType.Sprite ? 1u << bitIndex : 0u; bitIndex++; uint pointCookieBit = (!light.IsShapeLight() && light.lightCookieSprite != null && light.lightCookieSprite.texture != null) ? 1u << bitIndex : 0u; bitIndex++; uint pointFastQualityBit = (!light.IsShapeLight() && light.pointLightQuality == Light2D.PointLightQuality.Fast) ? 1u << bitIndex : 0u; bitIndex++; uint useNormalMap = light.useNormalMap ? 1u << bitIndex : 0u; return(pointFastQualityBit | pointCookieBit | spriteBit | additiveBit | shapeBit | volumeBit | useNormalMap); }
static uint GetLightMaterialIndex(Light2D light, bool isVolume) { int bitIndex = 0; uint volumeBit = isVolume ? 1u << bitIndex : 0u; bitIndex++; uint shapeBit = light.IsShapeLight() ? 1u << bitIndex : 0u; bitIndex++; uint additiveBit = (light.IsShapeLight() && light.shapeLightOverlapMode == Light2D.LightOverlapMode.Additive) ? 1u << bitIndex : 0u; bitIndex++; uint spriteBit = light.lightType == Light2D.LightType.Sprite ? 1u << bitIndex : 0u; bitIndex++; uint pointCookieBit = (!light.IsShapeLight() && light.lightCookieSprite != null && light.lightCookieSprite.texture != null) ? 1u << bitIndex : 0u; bitIndex++; uint pointFastQualityBit = (!light.IsShapeLight() && light.pointLightQuality == Light2D.PointLightQuality.Fast) ? 1u << bitIndex : 0u; return(pointFastQualityBit | pointCookieBit | spriteBit | additiveBit | shapeBit | volumeBit); }
static Material CreateLightMaterial(Light2D light, bool isVolume) { bool isShape = light.IsShapeLight(); Material material; if (isVolume) { material = CoreUtils.CreateEngineMaterial(isShape ? s_RendererData.shapeLightVolumeShader : s_RendererData.pointLightVolumeShader); } else { material = CoreUtils.CreateEngineMaterial(isShape ? s_RendererData.shapeLightShader : s_RendererData.pointLightShader); if (!light.alphaBlendOnOverlap) { SetBlendModes(material, BlendMode.One, BlendMode.One); material.EnableKeyword(k_UseAdditiveBlendingKeyword); } else { SetBlendModes(material, BlendMode.SrcAlpha, BlendMode.OneMinusSrcAlpha); } } if (light.lightType == Light2D.LightType.Sprite) { material.EnableKeyword(k_SpriteLightKeyword); } if (!isShape && light.lightCookieSprite != null && light.lightCookieSprite.texture != null) { material.EnableKeyword(k_UsePointLightCookiesKeyword); } if (!isShape && light.pointLightQuality == Light2D.PointLightQuality.Fast) { material.EnableKeyword(k_LightQualityFastKeyword); } if (light.useNormalMap) { material.EnableKeyword(k_UseNormalMap); } return(material); }