// Caution: this function must match the one in HDLightEditor.UpdateLightIntensity - any change need to be replicated public void ConvertPhysicalLightIntensityToLightIntensity() { var light = gameObject.GetComponent <Light>(); if (lightTypeExtent == LightTypeExtent.Punctual) { switch (light.type) { case LightType.Directional: light.intensity = Mathf.Max(0, directionalIntensity); break; case LightType.Point: light.intensity = LightUtils.ConvertPointLightIntensity(Mathf.Max(0, punctualIntensity)); break; case LightType.Spot: if (enableSpotReflector) { if (spotLightShape == SpotLightShape.Cone) { light.intensity = LightUtils.ConvertSpotLightIntensity(Mathf.Max(0, punctualIntensity), light.spotAngle * Mathf.Deg2Rad, true); } else if (spotLightShape == SpotLightShape.Pyramid) { float angleA, angleB; LightUtils.CalculateAnglesForPyramid(aspectRatio, light.spotAngle, out angleA, out angleB); light.intensity = LightUtils.ConvertFrustrumLightIntensity(Mathf.Max(0, punctualIntensity), angleA, angleB); } else // Box shape, fallback to punctual light. { light.intensity = LightUtils.ConvertPointLightIntensity(Mathf.Max(0, punctualIntensity)); } } else { // Spot should used conversion which take into account the angle, and thus the intensity vary with angle. // This is not easy to manipulate for lighter, so we simply consider any spot light as just occluded point light. So reuse the same code. light.intensity = LightUtils.ConvertPointLightIntensity(Mathf.Max(0, punctualIntensity)); // TODO: What to do with box shape ? // var spotLightShape = (SpotLightShape)m_AdditionalspotLightShape.enumValueIndex; } break; } } else if (lightTypeExtent == LightTypeExtent.Rectangle) { light.intensity = LightUtils.ConvertRectLightIntensity(Mathf.Max(0, areaIntensity), shapeWidth, shapeHeight); } else if (lightTypeExtent == LightTypeExtent.Line) { light.intensity = LightUtils.CalculateLineLightIntensity(Mathf.Max(0, areaIntensity), shapeWidth); } }
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; } }
public static float ConvertPunctualLightCandelaToLumen(LightType lightType, SpotLightShape spotLigthShape, float candela, bool enableSpotReflector, float spotAngle, float aspectRatio) { if (lightType == LightType.Spot && enableSpotReflector) { // We just need to multiply candela by solid angle in this case if (spotLigthShape == SpotLightShape.Cone) { return(LightUtils.ConvertSpotLightCandelaToLumen(candela, spotAngle * Mathf.Deg2Rad, true)); } else if (spotLigthShape == SpotLightShape.Pyramid) { float angleA, angleB; LightUtils.CalculateAnglesForPyramid(aspectRatio, spotAngle * Mathf.Deg2Rad, out angleA, out angleB); return(LightUtils.ConvertFrustrumLightCandelaToLumen(candela, angleA, angleB)); } else // Box { return(LightUtils.ConvertPointLightCandelaToLumen(candela)); } } return(LightUtils.ConvertPointLightCandelaToLumen(candela)); }