Skip to content

Prevent material from having infinite intensity #5132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed a nullref in volume system after deleting a volume object (case 1348374).
- Fixed the APV UI loosing focus when the helpbox about baking appears in the probe volume.
- Fixed update order in Graphics Compositor causing jumpy camera updates (case 1345566).
- Fixed material inspector that allowed setting intensity to an infinite value.

### Changed
- Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace UnityEditor.Rendering.HighDefinition
/// </summary>
public class EmissionUIBlock : MaterialUIBlock
{
static float s_MaxEvValue = Mathf.Floor(LightUtils.ConvertLuminanceToEv(float.MaxValue));

/// <summary>Options for emission block features. Use this to control which fields are visible.</summary>
[Flags]
public enum Features
Expand Down Expand Up @@ -131,7 +133,7 @@ internal static void UpdateEmissiveColorLDRFromIntensityAndEmissiveColor(Materia

internal static void UpdateEmissiveColorLDRFromIntensityAndEmissiveColor(MaterialProperty emissiveColorLDR, MaterialProperty emissiveIntensity, MaterialProperty emissiveColor)
{
Color emissiveColorLDRLinear = emissiveColorLDR.colorValue / emissiveIntensity.floatValue;
Color emissiveColorLDRLinear = emissiveColor.colorValue / emissiveIntensity.floatValue;
emissiveColorLDR.colorValue = emissiveColorLDRLinear.gamma;
}

Expand All @@ -156,7 +158,7 @@ internal static void DoEmissiveIntensityGUI(MaterialEditor materialEditor, Mater
{
float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue);
evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue);
evValue = Mathf.Clamp(evValue, 0, float.MaxValue);
evValue = Mathf.Clamp(evValue, 0, s_MaxEvValue);
emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace UnityEngine.Rendering.HighDefinition
/// </summary>
class LightUtils
{
static float s_LuminanceToEvFactor = Mathf.Log(100f / ColorUtils.s_LightMeterCalibrationConstant);
static float s_EvToLuminanceFactor = -Mathf.Log(100f / ColorUtils.s_LightMeterCalibrationConstant);

// Physical light unit helper
// All light unit are in lumen (Luminous power)
// Punctual light (point, spot) are convert to candela (cd = lumens / steradian)
Expand Down Expand Up @@ -164,7 +167,7 @@ public static float ConvertCandelaToLux(float candela, float distance)
public static float ConvertEvToLuminance(float ev)
{
float k = ColorUtils.s_LightMeterCalibrationConstant;
return (k / 100.0f) * Mathf.Pow(2, ev);
return Mathf.Pow(2, ev + s_EvToLuminanceFactor);
}

/// <summary>
Expand Down Expand Up @@ -194,7 +197,7 @@ public static float ConvertEvToLux(float ev, float distance)
public static float ConvertLuminanceToEv(float luminance)
{
float k = ColorUtils.s_LightMeterCalibrationConstant;
return (float)Math.Log((luminance * 100f) / k, 2);
return Mathf.Log(luminance, 2) + s_LuminanceToEvFactor;
}

/// <summary>
Expand Down