Skip to content

IES Code path refactoring to support multiple SRP #929

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 4 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 9 additions & 9 deletions com.unity.render-pipelines.core/Editor/Lighting/IESImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace UnityEditor.Rendering
/// Common class use to share code between implementation of IES Importeres
/// </summary>
[System.Serializable]
public class IESImporter
[ScriptedImporter(1, "ies")]
public partial class IESImporter : ScriptedImporter
{
/// <summary>
/// IES Engine
Expand All @@ -23,16 +24,18 @@ public class IESImporter

/// <summary>
/// Delegate prototype which will be sent by the pipeline implementation of the IES Importer
/// Must be initialized during the creation of the SRP
/// </summary>
public delegate void SetupRenderPipelinePrefabLight(IESEngine engine, Light light, Texture ies);
public static event System.Action<AssetImportContext, string, bool, string, float, Light, Texture> createRenderPipelinePrefabLight;

/// <summary>
/// Common method performing the import of the asset
/// </summary>
/// <param name="ctx">Asset importer context.</param>
/// <param name="setupRenderPipelinePrefabLight">Delegate needed to perform operation which are "Render Pipeline specific" here setuping the prefab of light</param>
public void CommonOnImportAsset(AssetImportContext ctx, SetupRenderPipelinePrefabLight setupRenderPipelinePrefabLight)
public override void OnImportAsset(AssetImportContext ctx)
{
engine.TextureGenerationType = TextureImporterType.Default;

Texture cookieTextureCube = null;
Texture cookieTexture2D = null;

Expand Down Expand Up @@ -76,7 +79,7 @@ public void CommonOnImportAsset(AssetImportContext ctx, SetupRenderPipelinePrefa

var iesObject = ScriptableObject.CreateInstance<IESObject>();
iesObject.iesMetaData = iesMetaData;
var lightObject = new GameObject(iesFileName);
GameObject lightObject = new GameObject(iesFileName);

lightObject.transform.localEulerAngles = new Vector3(90f, 0f, iesMetaData.LightAimAxisRotation);

Expand All @@ -86,13 +89,10 @@ public void CommonOnImportAsset(AssetImportContext ctx, SetupRenderPipelinePrefa
light.range = 10f; // would need a better range value formula
light.spotAngle = iesMetaData.SpotAngle;

setupRenderPipelinePrefabLight(engine, light, (iesMetaData.PrefabLightType == IESLightType.Point) ? cookieTextureCube : cookieTexture2D);

ctx.AddObjectToAsset("IES", iesObject);
ctx.SetMainObject(iesObject);

// The light object will be automatically converted into a prefab.
ctx.AddObjectToAsset(iesFileName, lightObject);
IESImporter.createRenderPipelinePrefabLight?.Invoke(ctx, iesFileName, iesMetaData.UseIESMaximumIntensity, iesMetaData.IESMaximumIntensityUnit, iesMetaData.IESMaximumIntensity, light, (iesMetaData.PrefabLightType == IESLightType.Point) ? cookieTextureCube : cookieTexture2D);

if (cookieTextureCube != null)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public override void OnEnable()
{
base.OnEnable();

PropertyFetcher<HDIESImporter> entryPoint0 = new PropertyFetcher<HDIESImporter>(serializedObject);
SerializedProperty entryPoint1 = entryPoint0.Find<IESImporter>(x => x.commonIESImporter);
SerializedProperty entryPoint = entryPoint1.FindPropertyRelative("iesMetaData");
PropertyFetcher<IESImporter> entryPoint0 = new PropertyFetcher<IESImporter>(serializedObject);
SerializedProperty entryPoint1 = entryPoint0.Find<IESMetaData>(x => x.iesMetaData);
//SerializedProperty entryPoint = entryPoint1.FindPropertyRelative("iesMetaData");

iesImporterEditor.CommonOnEnable(entryPoint);
iesImporterEditor.CommonOnEnable(entryPoint1);
}

/// <summary>
Expand Down Expand Up @@ -142,7 +142,7 @@ public override GUIContent GetPreviewTitle()
/// <param name="background">Style of the background of the preview.</param>
public override void OnPreviewGUI(Rect r, GUIStyle background)
{
iesImporterEditor.CommonOnPreviewGUI(r, background, target as HDIESImporter,
iesImporterEditor.CommonOnPreviewGUI(r, background, target as IESImporter,
delegate (Light light, SerializedProperty useIESMaximumIntensityProp, SerializedProperty iesMaximumIntensityUnitProp, SerializedProperty iesMaximumIntensityProp)
{
SetupRenderPipelinePreviewLightIntensity(light, useIESMaximumIntensityProp, iesMaximumIntensityUnitProp, iesMaximumIntensityProp);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering;
using UnityEditor;

namespace UnityEditor.Rendering.HighDefinition
{
/// <summary>
/// Class to describe an IES file
/// </summary>
[InitializeOnLoad]
public static class HDIESImporter
{
static HDIESImporter()
{
UnityEditor.Rendering.IESImporter.createRenderPipelinePrefabLight += CreateRenderPipelinePrefabLight;
}

static public void CreateRenderPipelinePrefabLight(UnityEditor.Experimental.AssetImporters.AssetImportContext ctx, string iesFileName, bool useIESMaximumIntensity, string iesMaximumIntensityUnit, float iesMaximumIntensity, Light light, Texture ies)
{
HDLightTypeAndShape hdLightTypeAndShape = (light.type == LightType.Point) ? HDLightTypeAndShape.Point : HDLightTypeAndShape.ConeSpot;

HDAdditionalLightData hdLight = GameObjectExtension.AddHDLight(light.gameObject, hdLightTypeAndShape);

if (useIESMaximumIntensity)
{
LightUnit lightUnit = (iesMaximumIntensityUnit == "Lumens") ? LightUnit.Lumen : LightUnit.Candela;
hdLight.SetIntensity(iesMaximumIntensity, lightUnit);
if (light.type == LightType.Point)
hdLight.IESPoint = ies;
else
hdLight.IESSpot = ies;
}

// The light object will be automatically converted into a prefab.
ctx.AddObjectToAsset(iesFileName + "-HDRP", light.gameObject);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using UnityEngine.Experimental.Rendering.RenderGraphModule;
#if UNITY_EDITOR
using UnityEditorInternal;
using UnityEditor.Rendering;
#endif

#if ENABLE_VIRTUALTEXTURES
Expand Down Expand Up @@ -1693,7 +1694,7 @@ void AddVisibleProbeVisibleIndexIfUpdateIsRequired(HDProbe probe, int visibleInI
// NOTE: If the probe was rendered on the very first frame, we could have some data that was used and it wasn't in a fully initialized state, which is fine on PC, but on console
// might lead to NaNs due to lack of complete initialization. To circumvent this, we force the probe to render again only if it was rendered on the first frame. Note that the problem
// doesn't apply if probe is enable any frame other than the very first. Also note that we are likely to be re-rendering the probe anyway due to the issue on sky ambient probe
// (see m_SkyManager.HasSetValidAmbientProbe in this function).
// (see m_SkyManager.HasSetValidAmbientProbe in this function).
if (m_FrameCount > 1)
probe.SetIsRendered(m_FrameCount);

Expand Down Expand Up @@ -2150,7 +2151,7 @@ ref _cullingResults

// Render XR mirror view once all render requests have been completed
if (i == 0 && renderRequest.hdCamera.camera.cameraType == CameraType.Game && renderRequest.hdCamera.camera.targetTexture == null)
{
{
if (HDUtils.TryGetAdditionalCameraDataOrDefault(renderRequest.hdCamera.camera).xrRendering)
{
m_XRSystem.RenderMirrorView(cmd);
Expand Down