Skip to content

[Fogbugz # 380357] Fixing negative overflowing of IES attenuation spline #6669

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 1 commit into from
Jan 11, 2022
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.core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed XR support in CoreUtils.DrawFullscreen function.
- Fixed issue in DynamicResolutionHandler when camera request was turned off at runtime, the ScalableBufferManager would leak state and not unset DRS state (case 1383093).
- Fixed `DebugUI.Enum` fields collapsing their parent `DebugUI.Foldout`
- Fixed IES profile importer handling of overflow (outside 0-1 range) of attenutation splines values.

## [13.1.2] - 2021-11-05

Expand Down
18 changes: 12 additions & 6 deletions com.unity.render-pipelines.core/Editor/Lighting/IESEngine.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;
using Unity.Collections;
using UnityEditor;
Expand Down Expand Up @@ -228,6 +229,11 @@ public string GetPhotometricType()
return (output.importInspectorWarnings, output.output);
}

private static byte PackIESValue(float value)
{
return (byte)Math.Clamp(value * 255, 0, 255);
}

NativeArray<Color32> BuildTypeACylindricalTexture(int width, int height)
{
float stepU = 360f / (width - 1);
Expand All @@ -249,7 +255,7 @@ NativeArray<Color32> BuildTypeACylindricalTexture(int width, int height)

float horizontalAnglePosition = m_iesReader.ComputeTypeAorBHorizontalAnglePosition(longitude);

byte value = (byte)((m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / m_iesReader.MaxCandelas) * 255);
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / m_iesReader.MaxCandelas);
slice[x] = new Color32(value, value, value, value);
}
}
Expand Down Expand Up @@ -287,7 +293,7 @@ NativeArray<Color32> BuildTypeBCylindricalTexture(int width, int height)
float horizontalAnglePosition = m_iesReader.ComputeTypeAorBHorizontalAnglePosition(longitude);
float verticalAnglePosition = m_iesReader.ComputeVerticalAnglePosition(latitude);

byte value = (byte)((m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / m_iesReader.MaxCandelas) * 255);
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / m_iesReader.MaxCandelas);
slice[x] = new Color32(value, value, value, value);
}
}
Expand Down Expand Up @@ -325,7 +331,7 @@ NativeArray<Color32> BuildTypeCCylindricalTexture(int width, int height)
float horizontalAnglePosition = m_iesReader.ComputeTypeCHorizontalAnglePosition(longitude);
float verticalAnglePosition = m_iesReader.ComputeVerticalAnglePosition(latitude);

byte value = (byte)((m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / m_iesReader.MaxCandelas) * 255);
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / m_iesReader.MaxCandelas);
slice[x] = new Color32(value, value, value, value);
}
}
Expand Down Expand Up @@ -362,7 +368,7 @@ NativeArray<Color32> BuildTypeAGnomonicTexture(float coneAngle, int size, bool a
// Factor in the light attenuation further from the texture center.
float lightAttenuation = applyLightAttenuation ? rayLengthSquared : 1f;

byte value = (byte)((m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / (m_iesReader.MaxCandelas * lightAttenuation)) * 255);
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / (m_iesReader.MaxCandelas * lightAttenuation));
slice[x] = new Color32(value, value, value, value);
}
}
Expand Down Expand Up @@ -400,7 +406,7 @@ NativeArray<Color32> BuildTypeBGnomonicTexture(float coneAngle, int size, bool a
// Factor in the light attenuation further from the texture center.
float lightAttenuation = applyLightAttenuation ? rayLengthSquared : 1f;

byte value = (byte)((m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / (m_iesReader.MaxCandelas * lightAttenuation)) * 255);
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / (m_iesReader.MaxCandelas * lightAttenuation));
slice[x] = new Color32(value, value, value, value);
}
}
Expand Down Expand Up @@ -437,7 +443,7 @@ NativeArray<Color32> BuildTypeCGnomonicTexture(float coneAngle, int size, bool a
// Factor in the light attenuation further from the texture center.
float lightAttenuation = applyLightAttenuation ? (uvLength * uvLength + 1) : 1f;

byte value = (byte)((m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / (m_iesReader.MaxCandelas * lightAttenuation)) * 255);
byte value = PackIESValue(m_iesReader.InterpolateBilinear(horizontalAnglePosition, verticalAnglePosition) / (m_iesReader.MaxCandelas * lightAttenuation));
slice[x] = new Color32(value, value, value, value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace UnityEditor.Rendering
/// Common class use to share code between implementation of IES Importeres
/// </summary>
[System.Serializable]
[ScriptedImporter(1, "ies")]
[ScriptedImporter(2, "ies")]
public partial class IESImporter : ScriptedImporter
{
/// <summary>
Expand Down