浏览代码

Merge pull request #700 from Unity-Technologies/feature/ReflectionProbeEditor

Reflection Probe Editor improvements
/feature-ReflectionProbeFit
GitHub 7 年前
当前提交
7bfbe6b8
共有 17 个文件被更改,包括 94 次插入31 次删除
  1. 4
      ScriptableRenderPipeline/Core/Resources/GPUCopy.compute
  2. 4
      ScriptableRenderPipeline/Core/Resources/GPUCopy.cs
  3. 6
      ScriptableRenderPipeline/Core/Resources/GPUCopyAsset.cs
  4. 16
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDCubemapInspector.cs
  5. 32
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs
  6. 2
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Preview.cs
  7. 19
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.ProbeUtility.cs
  8. 19
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs
  9. 2
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs
  10. 6
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
  11. 4
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
  12. 1
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightUtilities.hlsl
  13. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  14. 8
      ScriptableRenderPipeline/HDRenderPipeline/Editor/EditorRenderPipelineResources.meta
  15. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Editor/EditorRenderPipelineResources/ReflectionProbesPreview.shader
  16. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Editor/EditorRenderPipelineResources/ReflectionProbesPreview.shader.meta

4
ScriptableRenderPipeline/Core/Resources/GPUCopy.compute


// Autogenerated file. Do not edit by hand
#include "ShaderLibrary/Common.hlsl"
#include "../ShaderLibrary/Common.hlsl"
SamplerState sampler_LinearClamp;

RWTexture2D<float1> _Result1;
TEXTURE2D(_Source4);
Texture2D<float4> _Source4;
#pragma kernel KSampleCopy4_1_x

4
ScriptableRenderPipeline/Core/Resources/GPUCopy.cs


static readonly int _Size = Shader.PropertyToID("_Size");
public void SampleCopyChannel_xyzw2x(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier target, Vector2 size)
{
if (size.x < 8 || size.y < 8)
Debug.LogWarning("Trying to copy a channel from a texture smaller than 8x* or *x8. ComputeShader cannot perform it.");
cmd.DispatchCompute(m_Shader, k_SampleKernel_xyzw2x, (int)(size.x) / 8, (int)(size.y) / 8, 1);
cmd.DispatchCompute(m_Shader, k_SampleKernel_xyzw2x, (int)Mathf.Max((size.x) / 8, 1), (int)Mathf.Max((size.y) / 8, 1), 1);
}
}

6
ScriptableRenderPipeline/Core/Resources/GPUCopyAsset.cs


using System;
using System;
using System.Collections.Generic;
using System.Text;

// CSharp method
csm.AppendLine(string.Format(@" public void SampleCopyChannel_{0}2{1}(CommandBuffer cmd, RenderTargetIdentifier source, RenderTargetIdentifier target, Vector2 size)", channelName, o.subscript));
csm.AppendLine(" {");
csm.AppendLine(string.Format(" if (size.x < {0} || size.y < {0})", k_KernelSize.ToString()));
csm.AppendLine(" Debug.LogWarning(\"Trying to copy a channel from a texture smaller than 8x* or *x8. ComputeShader cannot perform it.\");");
csm.AppendLine(string.Format(" cmd.DispatchCompute(m_Shader, {0}, (int)(size.x) / {1}, (int)(size.y) / {1}, 1);", kernelIndexName, k_KernelSize.ToString()));
csm.AppendLine(string.Format(" cmd.DispatchCompute(m_Shader, {0}, (int)Mathf.Max((size.x) / {1}, 1), (int)Mathf.Max((size.y) / {1}, 1), 1);", kernelIndexName, k_KernelSize.ToString()));
csm.AppendLine(" }");
}
csc.AppendLine(" }");

16
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDCubemapInspector.cs


{
hideFlags = HideFlags.HideAndDontSave
};
InitIcons();
}
void OnEnable()

if (s_MipMapLow == null)
InitIcons();
m_ReflectiveMaterial.SetTexture("_Cubemap", target as Texture);
}

public override void OnPreviewSettings()
{
var mipmapCount = 0;
var cubemap = target as Cubemap;
var rt = target as RenderTexture;
if (cubemap != null)
mipmapCount = cubemap.mipmapCount;
if (rt != null)
mipmapCount = rt.useMipMap
? (int)(Mathf.Log(Mathf.Max(rt.width, rt.height)) / Mathf.Log(2))
: 1;
GUI.enabled = true;
GUILayout.Box(s_ExposureLow, s_PreLabel, GUILayout.MaxWidth(20));

GUILayout.Box(s_MipMapHigh, s_PreLabel, GUILayout.MaxWidth(20));
GUI.changed = false;
mipLevelPreview = GUILayout.HorizontalSlider(mipLevelPreview, 0, ((Cubemap)target).mipmapCount, GUILayout.MaxWidth(80));
mipLevelPreview = GUILayout.HorizontalSlider(mipLevelPreview, 0, mipmapCount, GUILayout.MaxWidth(80));
GUILayout.Box(s_MipMapLow, s_PreLabel, GUILayout.MaxWidth(20));
}

m_PreviewUtility.camera.farClipPlane = 20.0f;
m_PreviewUtility.camera.transform.position = new Vector3(0, 0, 2);
m_PreviewUtility.camera.transform.LookAt(Vector3.zero);
//m_PreviewUtility.camera.clearFlags = CameraClearFlags.Skybox;
}
bool HandleMouse(Rect Viewport)

32
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs


using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
namespace UnityEditor.Experimental.Rendering
{

var s = m_UIState;
var p = m_SerializedReflectionProbe;
var o = this;
BakeRealtimeProbeIfPositionChanged(s, p, o);
if (!s.sceneViewEditing)
return;

if (EditorGUI.EndChangeCheck())
Repaint();
}
void BakeRealtimeProbeIfPositionChanged(UIState s, SerializedReflectionProbe sp, Editor o)
{
if (Application.isPlaying
|| ((ReflectionProbeMode)sp.mode.intValue) != ReflectionProbeMode.Realtime)
{
m_PositionHash = 0;
return;
}
var hash = 0;
for (var i = 0; i < sp.so.targetObjects.Length; i++)
{
var p = (ReflectionProbe)sp.so.targetObjects[i];
var tr = p.GetComponent<Transform>();
hash ^= tr.position.GetHashCode();
}
if (hash != m_PositionHash)
{
m_PositionHash = hash;
for (var i = 0; i < sp.so.targetObjects.Length; i++)
{
var p = (ReflectionProbe)sp.so.targetObjects[i];
p.RenderProbe();
}
}
}
static void Handle_InfluenceBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)

2
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Preview.cs


if (ValidPreviewSetup())
{
Editor editor = m_CubemapEditor;
CreateCachedEditor(((ReflectionProbe)target).texture, null, ref editor);
CreateCachedEditor(((ReflectionProbe)target).texture, typeof(HDCubemapInspector), ref editor);
m_CubemapEditor = editor as HDCubemapInspector;
}

19
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.ProbeUtility.cs


static Mesh s_SphereMesh;
static int _Cubemap = Shader.PropertyToID("_Cubemap");
void ChangeVisibilityOfAllTargets(bool visibility)
{
for (var i = 0; i < targets.Length; ++i)
{
var p = (ReflectionProbe)targets[i];
ChangeVisibility(p, visibility);
}
}
void InitializeAllTargetProbes()
{
for (var i = 0; i < targets.Length; ++i)
{
var p = (ReflectionProbe)targets[i];
var a = (HDAdditionalReflectionData)m_AdditionalDataSerializedObject.targetObjects[i];
InitializeProbe(p, a);
}
}
[InitializeOnLoadMethod]
static void Initialize()

19
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs


SerializedObject m_AdditionalDataSerializedObject;
UIState m_UIState = new UIState();
int m_PositionHash = 0;
public bool sceneViewEditing
{
get { return IsReflectionProbeEditMode(EditMode.editMode) && EditMode.IsOwner(this); }

s_ReflectionProbeEditors[p] = this;
}
for (var i = 0; i < targets.Length; ++i)
{
var p = (ReflectionProbe)targets[i];
var a = additionalData[i];
InitializeProbe(p, a);
ChangeVisibility(p, true);
}
InitializeAllTargetProbes();
ChangeVisibilityOfAllTargets(true);
for (var i = 0; i < targets.Length; ++i)
{
var p = (ReflectionProbe)targets[i];
ChangeVisibility(p, false);
}
ChangeVisibilityOfAllTargets(false);
}
public override void OnInspectorGUI()

k_InfluenceVolumeSection.Draw(s, p, this);
k_SeparateProjectionVolumeSection.Draw(s, p, this);
k_CaptureSection.Draw(s, p, this);
//k_AdditionalSection.Draw(s, p, this);
k_AdditionalSection.Draw(s, p, this);
k_BakingActions.Draw(s, p, this);
PerformOperations(s, p, this);

2
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs


public float unused0;
public Vector3 offsetLS;
public float unused1;
public float dimmer;
};
// Usage of StencilBits.Lighting on 2 bits.

6
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl


float3 innerDistance;
float unused0;
float3 offsetLS;
float unused1;
float dimmer;
};
//

{
return value.offsetLS;
}
float GetUnused1(EnvLightData value)
float GetDimmer(EnvLightData value)
return value.unused1;
return value.dimmer;
}

4
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


if (probe.boxProjection == 0)
envLightData.minProjectionDistance = 65504.0f;
envLightData.dimmer = additionalData.dimmer;
}
else
{

envLightData.envShapeType = EnvShapeType.Box;
envLightData.minProjectionDistance = 0.0f;
}
envLightData.dimmer = 1;
}
// remove scale from the matrix (Scale in this matrix is use to scale the widget)

1
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightUtilities.hlsl


output.offsetLS = float3(0.0, 0.0, 0.0);
output.innerDistance = float3(0.0, 0.0, 0.0);
output.blendDistance = 1.0;
output.dimmer = 1.0;
return output;
}

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


#endif
UpdateLightingHierarchyWeights(hierarchyWeight, weight);
envLighting *= weight;
envLighting *= weight * lightData.dimmer;
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFLECTION)
lighting.specularReflected = envLighting * preLightData.specularFGD;

8
ScriptableRenderPipeline/HDRenderPipeline/Editor/EditorRenderPipelineResources.meta


fileFormatVersion: 2
guid: cd55d3b3ff494fe499fb93a56e21fb9f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

/ScriptableRenderPipeline/HDRenderPipeline/Debug/ReflectionProbesPreview.shader → /ScriptableRenderPipeline/HDRenderPipeline/Editor/EditorRenderPipelineResources/ReflectionProbesPreview.shader

/ScriptableRenderPipeline/HDRenderPipeline/Debug/ReflectionProbesPreview.shader.meta → /ScriptableRenderPipeline/HDRenderPipeline/Editor/EditorRenderPipelineResources/ReflectionProbesPreview.shader.meta

正在加载...
取消
保存