void SetLightIntensityPunctual(float intensity) { switch (m_Light.type) { case LightType.Directional: m_Light.intensity = intensity; // Always in lux break; case LightType.Point: if (lightUnit == LightUnit.Candela) { m_Light.intensity = intensity; } else { m_Light.intensity = LightUtils.ConvertPointLightLumenToCandela(intensity); } break; case LightType.Spot: if (lightUnit == LightUnit.Candela) { // When using candela, reflector don't have any effect. Our intensity is candela = lumens/steradian and the user // provide desired value for an angle of 1 steradian. m_Light.intensity = intensity; } else // lumen { if (enableSpotReflector) { // If reflector is enabled all the lighting from the sphere is focus inside the solid angle of current shape if (spotLightShape == SpotLightShape.Cone) { m_Light.intensity = LightUtils.ConvertSpotLightLumenToCandela(intensity, m_Light.spotAngle * Mathf.Deg2Rad, true); } else if (spotLightShape == SpotLightShape.Pyramid) { float angleA, angleB; LightUtils.CalculateAnglesForPyramid(aspectRatio, m_Light.spotAngle * Mathf.Deg2Rad, out angleA, out angleB); m_Light.intensity = LightUtils.ConvertFrustrumLightLumenToCandela(intensity, angleA, angleB); } else // Box shape, fallback to punctual light. { m_Light.intensity = LightUtils.ConvertPointLightLumenToCandela(intensity); } } else { // No reflector, angle act as occlusion of point light. m_Light.intensity = LightUtils.ConvertPointLightLumenToCandela(intensity); } } break; } }
// Helper for punctual and area light unit conversion public static float ConvertPunctualLightLumenToCandela(LightType lightType, float lumen, float initialIntensity, bool enableSpotReflector) { if (lightType == LightType.Spot && enableSpotReflector) { // We have already calculate the correct value, just assign it return(initialIntensity); } return(LightUtils.ConvertPointLightLumenToCandela(lumen)); }