internal static void ConvertLightIntensity(LightUnit oldLightUnit, LightUnit newLightUnit, HDAdditionalLightData hdLight, Light light) { float intensity = hdLight.intensity; float luxAtDistance = hdLight.luxAtDistance; HDLightType lightType = hdLight.ComputeLightType(light); // For punctual lights if (lightType != HDLightType.Area) { // Lumen -> if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Candela) { intensity = LightUtils.ConvertPunctualLightLumenToCandela(lightType, intensity, light.intensity, hdLight.enableSpotReflector); } else if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Lux) { intensity = LightUtils.ConvertPunctualLightLumenToLux(lightType, intensity, light.intensity, hdLight.enableSpotReflector, hdLight.luxAtDistance); } else if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertPunctualLightLumenToEv(lightType, intensity, light.intensity, hdLight.enableSpotReflector); } // Candela -> else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertPunctualLightCandelaToLumen(lightType, hdLight.spotLightShape, intensity, hdLight.enableSpotReflector, light.spotAngle, hdLight.aspectRatio); } else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Lux) { intensity = LightUtils.ConvertCandelaToLux(intensity, hdLight.luxAtDistance); } else if (oldLightUnit == LightUnit.Candela && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertCandelaToEv(intensity); } // Lux -> else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertPunctualLightLuxToLumen(lightType, hdLight.spotLightShape, intensity, hdLight.enableSpotReflector, light.spotAngle, hdLight.aspectRatio, hdLight.luxAtDistance); } else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Candela) { intensity = LightUtils.ConvertLuxToCandela(intensity, hdLight.luxAtDistance); } else if (oldLightUnit == LightUnit.Lux && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertLuxToEv(intensity, hdLight.luxAtDistance); } // EV100 -> else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertPunctualLightEvToLumen(lightType, hdLight.spotLightShape, intensity, hdLight.enableSpotReflector, light.spotAngle, hdLight.aspectRatio); } else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Candela) { intensity = LightUtils.ConvertEvToCandela(intensity); } else if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lux) { intensity = LightUtils.ConvertEvToLux(intensity, hdLight.luxAtDistance); } } else // For area lights { if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Nits) { intensity = LightUtils.ConvertAreaLightLumenToLuminance(hdLight.areaLightShape, intensity, hdLight.shapeWidth, hdLight.shapeHeight); } if (oldLightUnit == LightUnit.Nits && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertAreaLightLuminanceToLumen(hdLight.areaLightShape, intensity, hdLight.shapeWidth, hdLight.shapeHeight); } if (oldLightUnit == LightUnit.Nits && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertLuminanceToEv(intensity); } if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Nits) { intensity = LightUtils.ConvertEvToLuminance(intensity); } if (oldLightUnit == LightUnit.Ev100 && newLightUnit == LightUnit.Lumen) { intensity = LightUtils.ConvertAreaLightEvToLumen(hdLight.areaLightShape, intensity, hdLight.shapeWidth, hdLight.shapeHeight); } if (oldLightUnit == LightUnit.Lumen && newLightUnit == LightUnit.Ev100) { intensity = LightUtils.ConvertAreaLightLumenToEv(hdLight.areaLightShape, intensity, hdLight.shapeWidth, hdLight.shapeHeight); } } hdLight.intensity = intensity; }
static void RenderLightVolume( CommandBuffer cmd, Material debugLightVolumeMaterial, HDAdditionalLightData currentHDRLight, Light currentLegacyLight, MaterialPropertyBlock mpb) { Matrix4x4 positionMat = Matrix4x4.Translate(currentLegacyLight.transform.position); switch (currentHDRLight.ComputeLightType(currentLegacyLight)) { case HDLightType.Point: mpb.SetColor(_ColorShaderID, new Color(0.0f, 0.5f, 0.0f, 1.0f)); mpb.SetVector(_OffsetShaderID, new Vector3(0, 0, 0)); mpb.SetVector(_RangeShaderID, new Vector3(currentLegacyLight.range, currentLegacyLight.range, currentLegacyLight.range)); cmd.DrawMesh(DebugShapes.instance.RequestSphereMesh(), positionMat, debugLightVolumeMaterial, 0, 0, mpb); break; case HDLightType.Spot: switch (currentHDRLight.spotLightShape) { case SpotLightShape.Cone: float bottomRadius = Mathf.Tan(currentLegacyLight.spotAngle * Mathf.PI / 360.0f) * currentLegacyLight.range; mpb.SetColor(_ColorShaderID, new Color(1.0f, 0.5f, 0.0f, 1.0f)); mpb.SetVector(_RangeShaderID, new Vector3(bottomRadius, bottomRadius, currentLegacyLight.range)); mpb.SetVector(_OffsetShaderID, new Vector3(0, 0, 0)); cmd.DrawMesh(DebugShapes.instance.RequestConeMesh(), currentLegacyLight.gameObject.transform.localToWorldMatrix, debugLightVolumeMaterial, 0, 0, mpb); break; case SpotLightShape.Box: mpb.SetColor(_ColorShaderID, new Color(1.0f, 0.5f, 0.0f, 1.0f)); mpb.SetVector(_RangeShaderID, new Vector3(currentHDRLight.shapeWidth, currentHDRLight.shapeHeight, currentLegacyLight.range)); mpb.SetVector(_OffsetShaderID, new Vector3(0, 0, currentLegacyLight.range / 2.0f)); cmd.DrawMesh(DebugShapes.instance.RequestBoxMesh(), currentLegacyLight.gameObject.transform.localToWorldMatrix, debugLightVolumeMaterial, 0, 0, mpb); break; case SpotLightShape.Pyramid: float bottomWidth = Mathf.Tan(currentLegacyLight.spotAngle * Mathf.PI / 360.0f) * currentLegacyLight.range; mpb.SetColor(_ColorShaderID, new Color(1.0f, 0.5f, 0.0f, 1.0f)); mpb.SetVector(_RangeShaderID, new Vector3(currentHDRLight.aspectRatio * bottomWidth * 2, bottomWidth * 2, currentLegacyLight.range)); mpb.SetVector(_OffsetShaderID, new Vector3(0, 0, 0)); cmd.DrawMesh(DebugShapes.instance.RequestPyramidMesh(), currentLegacyLight.gameObject.transform.localToWorldMatrix, debugLightVolumeMaterial, 0, 0, mpb); break; } break; case HDLightType.Area: switch (currentHDRLight.areaLightShape) { case AreaLightShape.Rectangle: mpb.SetColor(_ColorShaderID, new Color(0.0f, 1.0f, 1.0f, 1.0f)); mpb.SetVector(_OffsetShaderID, new Vector3(0, 0, 0)); mpb.SetVector(_RangeShaderID, new Vector3(currentLegacyLight.range, currentLegacyLight.range, currentLegacyLight.range)); cmd.DrawMesh(DebugShapes.instance.RequestSphereMesh(), positionMat, debugLightVolumeMaterial, 0, 0, mpb); break; case AreaLightShape.Tube: mpb.SetColor(_ColorShaderID, new Color(1.0f, 0.0f, 0.5f, 1.0f)); mpb.SetVector(_OffsetShaderID, new Vector3(0, 0, 0)); mpb.SetVector(_RangeShaderID, new Vector3(currentLegacyLight.range, currentLegacyLight.range, currentLegacyLight.range)); cmd.DrawMesh(DebugShapes.instance.RequestSphereMesh(), positionMat, debugLightVolumeMaterial, 0, 0, mpb); break; default: break; } break; } }