浏览代码

[ReflectionProbeEditor] (wip) Blend distance per face

/feature-ReflectionProbeFit
Frédéric Vauchelles 7 年前
当前提交
b8ba7123
共有 10 个文件被更改,包括 249 次插入115 次删除
  1. 45
      ScriptableRenderPipeline/Core/Editor/CoreEditorUtils.cs
  2. 4
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs
  3. 71
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs
  4. 113
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs
  5. 3
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs
  6. 15
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs
  7. 20
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs
  8. 58
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
  9. 15
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
  10. 20
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl

45
ScriptableRenderPipeline/Core/Editor/CoreEditorUtils.cs


using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

}
return group.isExpanded;
}
static readonly GUIContent[] k_DrawVector6Slider_Labels =
{
new GUIContent("+X"),
new GUIContent("+Y"),
new GUIContent("+Z"),
new GUIContent("-X"),
new GUIContent("-Y"),
new GUIContent("-Z"),
};
public static void DrawVector6Slider(GUIContent label, SerializedProperty positive, SerializedProperty negative, Vector3 min, Vector3 max)
{
GUILayout.BeginVertical();
negative.isExpanded = EditorGUILayout.Foldout(negative.isExpanded, label, true);
if (negative.isExpanded)
{
var labelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 60;
++EditorGUI.indentLevel;
GUILayout.BeginHorizontal();
var v = positive.vector3Value;
EditorGUI.BeginChangeCheck();
for (var i = 0; i < 3; ++i)
v[i] = EditorGUILayout.Slider(k_DrawVector6Slider_Labels[i], v[i], min[i], max[i]);
if (EditorGUI.EndChangeCheck())
positive.vector3Value = v;
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
v = negative.vector3Value;
EditorGUI.BeginChangeCheck();
for (var i = 0; i < 3; ++i)
v[i] = EditorGUILayout.Slider(k_DrawVector6Slider_Labels[i + 3], v[i], min[i], max[i]);
if (EditorGUI.EndChangeCheck())
negative.vector3Value = v;
GUILayout.EndHorizontal();
--EditorGUI.indentLevel;
EditorGUIUtility.labelWidth = labelWidth;
}
GUILayout.EndVertical();
}
public static void RemoveMaterialKeywords(Material material)

4
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs


internal SerializedProperty boxReprojectionVolumeCenter;
internal SerializedProperty sphereReprojectionVolumeRadius;
internal SerializedProperty blendDistance;
internal SerializedProperty blendDistance2;
internal SerializedProperty blendNormalDistance2;
internal SerializedProperty dimmer;
public SerializedReflectionProbe(SerializedObject so, SerializedObject addso)

sphereReprojectionVolumeRadius = addso.Find((HDAdditionalReflectionData d) => d.sphereReprojectionVolumeRadius);
dimmer = addso.Find((HDAdditionalReflectionData d) => d.dimmer);
blendDistance = addso.Find((HDAdditionalReflectionData d) => d.blendDistance);
blendDistance2 = addso.Find((HDAdditionalReflectionData d) => d.blendDistance2);
blendNormalDistance2 = addso.Find((HDAdditionalReflectionData d) => d.blendNormalDistance2);
}
}

71
ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs


"Influence volume settings",
(s, p, o) => p.blendDistance,
true,
CED.Action(Drawer_DistanceBlend),
CED.FadeGroup(
(s, p, o, i) => s.GetShapeFaded((ReflectionInfluenceShape)i),
false,

CED.Action(Drawer_UseSeparateProjectionVolume)*/
);
static readonly CED.IDrawer k_InfluenceNormalVolumeSection = CED.FoldoutGroup(
"Influence normal volume settings",
(s, p, o) => p.blendNormalDistance,
true,
CED.Action(Drawer_DistanceBlendNormal)
);
static readonly CED.IDrawer k_SeparateProjectionVolumeSection = CED.FadeGroup(

{
if (p.mode.intValue == (int)ReflectionProbeMode.Realtime)
{
EditorGUILayout.HelpBox("Baking of this reflection probe should be initiated from the scripting API because the type is 'Realtime'", MessageType.Info);
EditorGUILayout.HelpBox("Refresh of this reflection probe should be initiated from the scripting API because the type is 'Realtime'", MessageType.Info);
if (!QualitySettings.realtimeReflectionProbes)
EditorGUILayout.HelpBox("Realtime reflection probes are disabled in Quality Settings", MessageType.Warning);

}
#region Influence Volume
static void Drawer_DistanceBlend(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUILayout.Slider(p.blendDistance, 0, CalculateMaxBlendDistance(s, p, owner), CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes."));
EditorGUI.BeginChangeCheck();
}
static void Drawer_DistanceBlendNormal(UIState s, SerializedReflectionProbe p, Editor owner)
{
EditorGUILayout.Slider(p.blendNormalDistance, 0, CalculateMaxBlendDistance(s, p, owner), CoreEditorUtils.GetContent("Blend Normal Distance|Area around the probe where the normals influence the probe. Only used in deferred probes."));
EditorGUI.BeginChangeCheck();
}
var maxBlendDistance = CalculateBoxMaxBlendDistance(s, p, owner);
CoreEditorUtils.DrawVector6Slider(
CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes."),
p.blendDistance, p.blendDistance2, Vector3.zero, maxBlendDistance);
CoreEditorUtils.DrawVector6Slider(
CoreEditorUtils.GetContent("Blend Normal Distance|Area around the probe where the normals influence the probe. Only used in deferred probes."),
p.blendNormalDistance, p.blendNormalDistance2, Vector3.zero, maxBlendDistance);
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(p.boxSize, CoreEditorUtils.GetContent("Box Size|The size of the box in which the reflections will be applied to objects. The value is not affected by the Transform of the Game Object."));
EditorGUILayout.PropertyField(p.boxOffset, CoreEditorUtils.GetContent("Box Offset|The center of the box in which the reflections will be applied to objects. The value is relative to the position of the Game Object."));

static void Drawer_InfluenceSphereSettings(UIState s, SerializedReflectionProbe p, Editor owner)
{
var maxBlendDistance = CalculateSphereMaxBlendDistance(s, p, owner);
var blendDistance = p.blendDistance.vector3Value.x;
EditorGUI.BeginChangeCheck();
blendDistance = EditorGUILayout.Slider(CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes."), blendDistance, 0, maxBlendDistance);
if (EditorGUI.EndChangeCheck())
{
p.blendDistance.vector3Value = Vector3.one * blendDistance;
p.blendDistance2.vector3Value = Vector3.one * blendDistance;
}
var blendNormalDistance = p.blendNormalDistance.vector3Value.x;
EditorGUI.BeginChangeCheck();
blendNormalDistance = EditorGUILayout.Slider(CoreEditorUtils.GetContent("Blend Normal Distance|Area around the probe where the normals influence the probe. Only used in deferred probes."), blendNormalDistance, 0, maxBlendDistance);
if (EditorGUI.EndChangeCheck())
{
p.blendNormalDistance.vector3Value = Vector3.one * blendNormalDistance;
p.blendNormalDistance2.vector3Value = Vector3.one * blendNormalDistance;
}
EditorGUILayout.PropertyField(p.influenceSphereRadius, CoreEditorUtils.GetContent("Radius"));
EditorGUILayout.PropertyField(p.boxProjection, CoreEditorUtils.GetContent("Sphere Projection|Sphere projection causes reflections to appear to change based on the object's position within the probe's sphere, while still using a single probe as the source of the reflection. This works well for reflections on objects that are moving through enclosed spaces such as corridors and rooms. Setting sphere projection to False and the cubemap reflection will be treated as coming from infinitely far away. Note that this feature can be globally disabled from Graphics Settings -> Tier Settings"));
}

}
#endregion
static float CalculateMaxBlendDistance(UIState s, SerializedReflectionProbe p, Editor o)
static float CalculateSphereMaxBlendDistance(UIState s, SerializedReflectionProbe p, Editor o)
{
return p.influenceSphereRadius.floatValue * 0.5f;
}
static Vector3 CalculateBoxMaxBlendDistance(UIState s, SerializedReflectionProbe p, Editor o)
var shape = (ReflectionInfluenceShape)p.influenceShape.intValue;
switch (shape)
{
case ReflectionInfluenceShape.Sphere:
return p.influenceSphereRadius.floatValue * 0.5f;
default:
case ReflectionInfluenceShape.Box:
{
var size = p.boxSize.vector3Value;
var v = Mathf.Min(size.x, Mathf.Min(size.y, size.z));
return v * 0.5f;
}
}
return p.boxSize.vector3Value * 0.5f;
}
static MethodInfo k_EditorGUI_ButtonWithDropdownList = typeof(EditorGUI).GetMethod("ButtonWithDropdownList", BindingFlags.Static | BindingFlags.NonPublic, null, CallingConventions.Any, new [] { typeof(GUIContent), typeof(string[]), typeof(GenericMenu.MenuFunction2), typeof(GUILayoutOption[]) }, new ParameterModifier[0]);

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


static void Handle_InfluenceBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
Handle_InfluenceBoxEditing_Internal(s, sp, o, s.boxBlendHandle, k_GizmoThemeColorInfluenceBlend, ref sp.targetData.blendDistance);
Handle_InfluenceBoxEditing_Internal(
s, sp, o,
s.boxBlendHandle, k_GizmoThemeColorInfluenceBlend,
ref sp.targetData.blendDistance, ref sp.targetData.blendDistance2);
Handle_InfluenceBoxEditing_Internal(s, sp, o, s.boxBlendHandle, k_GizmoThemeColorInfluenceNormalBlend, ref sp.targetData.blendNormalDistance);
Handle_InfluenceBoxEditing_Internal(
s, sp, o,
s.boxBlendHandle, k_GizmoThemeColorInfluenceNormalBlend,
ref sp.targetData.blendNormalDistance, ref sp.targetData.blendNormalDistance2);
Color blendHandleColor,
ref float probeBlendDistance)
Color blendHandleColor,
ref Vector3 probeBlendDistancePositive,
ref Vector3 probeBlendDistanceNegative)
var p = (ReflectionProbe)sp.so.targetObject;
var p = sp.target;
blendBox.center = p.center;
blendBox.size = p.size - Vector3.one * probeBlendDistance * 2;
blendBox.center = p.center - (probeBlendDistancePositive - probeBlendDistanceNegative) * 0.5f;
blendBox.size = p.size - probeBlendDistancePositive - probeBlendDistanceNegative;
var influenceChanged = EditorGUI.EndChangeCheck();
var extentChanged = EditorGUI.EndChangeCheck();
if (influenceChanged || EditorGUI.EndChangeCheck())
if (extentChanged || EditorGUI.EndChangeCheck())
var influenceSize = s.boxExtentHandle.size;
var blendSize = blendBox.size;
ValidateAABB(p, ref center, ref influenceSize);
var blendDistance = influenceChanged
? probeBlendDistance
: ((influenceSize.x - blendSize.x) * 0.5f + (influenceSize.y - blendSize.y) * 0.5f + (influenceSize.z - blendSize.z) * 0.5f) / 3;
var extents = s.boxExtentHandle.size;
ValidateAABB(p, ref center, ref extents);
Vector3 blendDistancePositive, blendDistanceNegative;
if (extentChanged)
{
blendDistancePositive = Vector3.Min(probeBlendDistancePositive, extents);
blendDistanceNegative = Vector3.Min(probeBlendDistanceNegative, extents);
}
else
{
var diff = 2 * (blendBox.center - center);
var sum = extents - blendBox.size;
var positive = (sum - diff) * 0.5f;
var negative = (sum + diff) * 0.5f;
blendDistancePositive = Vector3.Max(Vector3.zero, Vector3.Min(positive, extents));
blendDistanceNegative = Vector3.Max(Vector3.zero, Vector3.Min(negative, extents));
}
p.size = influenceSize;
probeBlendDistance = Mathf.Max(blendDistance, 0);
p.size = extents;
probeBlendDistancePositive = blendDistancePositive;
probeBlendDistanceNegative = blendDistanceNegative;
EditorUtility.SetDirty(p);
}
}

static void Handle_InfluenceSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o)
{
Handle_InfluenceSphereEditing_Internal(s, sp, o, s.sphereBlendHandle, k_GizmoThemeColorInfluenceBlend, ref sp.targetData.blendDistance);
var blendDistance = sp.targetData.blendDistance.x;
Handle_InfluenceSphereEditing_Internal(s, sp, o, s.sphereBlendHandle, k_GizmoThemeColorInfluenceBlend, ref blendDistance);
sp.targetData.blendDistance.x = blendDistance;
Handle_InfluenceSphereEditing_Internal(s, sp, o, s.sphereBlendHandle, k_GizmoThemeColorInfluenceNormalBlend, ref sp.targetData.blendNormalDistance);
var blendDistance = sp.targetData.blendNormalDistance.x;
Handle_InfluenceSphereEditing_Internal(s, sp, o, s.sphereBlendHandle, k_GizmoThemeColorInfluenceNormalBlend, ref blendDistance);
sp.targetData.blendNormalDistance.x = blendDistance;
}
static void Handle_InfluenceSphereEditing_Internal(

if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
{
Gizmos.color = k_GizmoThemeColorExtentFace;
Gizmos.DrawCube(reflectionProbe.center, -1f * reflectionProbe.size);
Gizmos.DrawCube(reflectionProbe.center, reflectionProbe.size);
Gizmos.DrawCube(reflectionProbe.center, -1f * reflectionProbe.size + Vector3.one * 2f * reflectionData.blendDistance);
Gizmos.DrawCube(reflectionProbe.center + reflectionData.boxBlendCenterOffset, reflectionProbe.size + reflectionData.boxBlendSizeOffset);
}
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere)
{

Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - reflectionData.blendDistance * 2f);
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - reflectionData.sphereBlendRadiusOffset);
}
Gizmos.matrix = Matrix4x4.identity;

Gizmos.matrix = GetLocalSpace(reflectionProbe);
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box)
Gizmos.DrawCube(reflectionProbe.center, -1f * reflectionProbe.size + Vector3.one * 2f * reflectionData.blendNormalDistance);
Gizmos.DrawCube(reflectionProbe.center + reflectionData.boxBlendNormalCenterOffset, reflectionProbe.size + reflectionData.boxBlendNormalSizeOffset);
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - reflectionData.blendNormalDistance * 2f);
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - reflectionData.sphereBlendNormalRadiusOffset);
Gizmos.matrix = Matrix4x4.identity;
Gizmos.color = oldColor;

Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorExtent : k_GizmoThemeColorDisabled;
Gizmos.matrix = GetLocalSpace(reflectionProbe);
Gizmos.DrawWireCube(reflectionProbe.center, reflectionProbe.size);
if (reflectionData.blendDistance > 0)
{
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireCube(reflectionProbe.center, GetBlendBoxSize(reflectionProbe, reflectionData.blendDistance));
}
if (reflectionData.blendNormalDistance > 0)
{
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceNormalBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireCube(reflectionProbe.center, GetBlendBoxSize(reflectionProbe, reflectionData.blendNormalDistance));
}
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireCube(reflectionProbe.center + reflectionData.boxBlendCenterOffset, reflectionProbe.size + reflectionData.boxBlendSizeOffset);
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceNormalBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireCube(reflectionProbe.center + reflectionData.boxBlendNormalCenterOffset, reflectionProbe.size + reflectionData.boxBlendNormalSizeOffset);
static Vector3 GetBlendBoxSize(ReflectionProbe reflectionProbe, float blendDistance)
{
return new Vector3(reflectionProbe.size.x - blendDistance * 2, reflectionProbe.size.y - blendDistance * 2, reflectionProbe.size.z - blendDistance * 2);
}
if (reflectionData.blendDistance > 0)
{
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - 2 * reflectionData.blendDistance);
}
if (reflectionData.blendNormalDistance > 0)
{
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceNormalBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - 2 * reflectionData.blendNormalDistance);
}
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - reflectionData.sphereBlendRadiusOffset);
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoThemeColorInfluenceNormalBlend : k_GizmoThemeColorDisabled;
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - reflectionData.sphereBlendNormalRadiusOffset);
Gizmos.matrix = Matrix4x4.identity;
}

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


k_PrimarySection.Draw(s, p, this);
k_InfluenceVolumeSection.Draw(s, p, this);
k_InfluenceNormalVolumeSection.Draw(s, p, this);
//k_InfluenceNormalVolumeSection.Draw(s, p, this);
k_SeparateProjectionVolumeSection.Draw(s, p, this);
k_CaptureSection.Draw(s, p, this);
k_AdditionalSection.Draw(s, p, this);

k_GizmoThemeColorProjectionFace = EditorGUILayout.ColorField("Projection Face", k_GizmoThemeColorProjectionFace);
k_GizmoThemeColorDisabled = EditorGUILayout.ColorField("Disabled", k_GizmoThemeColorDisabled);
k_GizmoThemeColorDisabledFace = EditorGUILayout.ColorField("Disabled Face", k_GizmoThemeColorDisabledFace);
EditorGUILayout.Space();
}
static void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath, bool custom)

15
ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs


public Vector3 boxReprojectionVolumeCenter = Vector3.zero;
public float maxSearchDistance = 8.0f;
public Texture previewCubemap;
public float blendDistance = 0f;
public float blendNormalDistance = 0f;
public Vector3 blendDistance = Vector3.zero;
public Vector3 blendDistance2 = Vector3.zero;
public Vector3 blendNormalDistance = Vector3.zero;
public Vector3 blendNormalDistance2 = Vector3.zero;
public Vector3 boxBlendCenterOffset { get { return (-blendDistance + blendDistance2) * 0.5f; } }
public Vector3 boxBlendSizeOffset { get { return -(blendDistance + blendDistance2); } }
public Vector3 boxBlendNormalCenterOffset { get { return -(blendNormalDistance + blendNormalDistance2) * 0.5f; } }
public Vector3 boxBlendNormalSizeOffset { get { return -(blendNormalDistance + blendNormalDistance2); } }
public float sphereBlendRadiusOffset { get { return -blendDistance.x * 2; } }
public float sphereBlendNormalRadiusOffset { get { return -blendNormalDistance.x * 2; } }
}
}

20
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs


using UnityEngine;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

public int envIndex;
public Vector3 up;
public float blendDistance; // blend transition outside the volume
public float dimmer;
public Vector3 innerDistance; // equivalent to volume scale
public float blendNormalDistance;
public Vector3 innerDistance; // extents of the env light
public float unused0;
public float dimmer;
public float unused1;
public Vector3 blendDistance; //+X,+Y,+Z
public float unused2;
public Vector3 blendDistance2; //-X,-Y,-Z
public float unused3;
public Vector3 blendNormalDistance; //+X,+Y,+Z
public float unused4;
public Vector3 blendNormalDistance2; //-X,-Y,-Z
public float unused5;
};
// Usage of StencilBits.Lighting on 2 bits.

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


float3 forward;
int envIndex;
float3 up;
float blendDistance;
float dimmer;
float blendNormalDistance;
float unused0;
float dimmer;
float unused1;
float3 blendDistance;
float unused2;
float3 blendDistance2;
float unused3;
float3 blendNormalDistance;
float unused4;
float3 blendNormalDistance2;
float unused5;
};
//

{
return value.up;
}
float GetBlendDistance(EnvLightData value)
float GetDimmer(EnvLightData value)
return value.blendDistance;
return value.dimmer;
}
float3 GetRight(EnvLightData value)
{

{
return value.innerDistance;
}
float GetBlendNormalDistance(EnvLightData value)
float GetUnused0(EnvLightData value)
return value.blendNormalDistance;
return value.unused0;
float GetDimmer(EnvLightData value)
float GetUnused1(EnvLightData value)
return value.dimmer;
return value.unused1;
}
float3 GetBlendDistance(EnvLightData value)
{
return value.blendDistance;
}
float GetUnused2(EnvLightData value)
{
return value.unused2;
}
float3 GetBlendDistance2(EnvLightData value)
{
return value.blendDistance2;
}
float GetUnused3(EnvLightData value)
{
return value.unused3;
}
float3 GetBlendNormalDistance(EnvLightData value)
{
return value.blendNormalDistance;
}
float GetUnused4(EnvLightData value)
{
return value.unused4;
}
float3 GetBlendNormalDistance2(EnvLightData value)
{
return value.blendNormalDistance2;
}
float GetUnused5(EnvLightData value)
{
return value.unused5;
}

15
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


{
var additionalData = probe.probe.GetComponent<HDAdditionalReflectionData>();
var extents = probe.bounds.extents;
var influenceBlendDistance = probe.blendDistance;
var influenceBlendDistance = Vector3.one * probe.blendDistance;
var influenceBlendDistance2 = Vector3.one * probe.blendDistance;
// For now we won't display real time probe when rendering one.
// TODO: We may want to display last frame result but in this case we need to be careful not to update the atlas before all realtime probes are rendered (for frame coherency).

envLightData.dimmer = additionalData.dimmer;
envLightData.blendNormalDistance = additionalData.blendNormalDistance;
envLightData.blendNormalDistance2 = additionalData.blendNormalDistance2;
influenceBlendDistance2 = additionalData.blendDistance2;
}
else
{

}
envLightData.dimmer = 1;
envLightData.blendNormalDistance = 0;
envLightData.blendNormalDistance = Vector3.zero;
envLightData.blendNormalDistance2 = Vector3.zero;
}
// remove scale from the matrix (Scale in this matrix is use to scale the widget)

// So we let the current UI but we assume blendDistance is an inside factor instead
// Blend distance can't be larger than the max radius
// probe.bounds.extents is BoxSize / 2
var maxBlendDist = Mathf.Min(probe.bounds.extents.x, Mathf.Min(probe.bounds.extents.y, probe.bounds.extents.z));
var blendDistance = Mathf.Min(maxBlendDist, influenceBlendDistance);
envLightData.innerDistance = extents - new Vector3(blendDistance, blendDistance, blendDistance);
var blendDistance = Vector3.Min(probe.bounds.extents, influenceBlendDistance);
var blendDistance2 = Vector3.Min(probe.bounds.extents, influenceBlendDistance2);
envLightData.innerDistance = extents;
envLightData.blendDistance2 = blendDistance2;
m_lightList.envLights.Add(envLightData);

20
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


{
// 1. First process the projection
float3 dirLS = mul(R, worldToLocal);
float sphereOuterDistance = lightData.innerDistance.x + lightData.blendDistance;
float sphereOuterDistance = lightData.innerDistance.x;
float sphereInnerDistance = sphereOuterDistance - lightData.blendDistance.x;
float dist = SphereRayIntersectSimple(positionLS, dirLS, sphereOuterDistance);
dist = max(dist, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
// We can reuse dist calculate in LS directly in WS as there is no scaling. Also the offset is already include in lightData.positionWS

}
// 2. Process the influence
float distFade = max(length(positionLS) - lightData.innerDistance.x, 0.0);
weight = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero
float distFade = max(length(positionLS) - sphereInnerDistance, 0.0);
weight = saturate(1.0 - distFade / max(lightData.blendDistance.x, 0.0001)); // avoid divide by zero
float3 boxOuterDistance = lightData.innerDistance + float3(lightData.blendDistance, lightData.blendDistance, lightData.blendDistance);
float3 boxOuterDistance = lightData.innerDistance;
float dist = BoxRayIntersectSimple(positionLS, dirLS, -boxOuterDistance, boxOuterDistance);
dist = max(dist, lightData.minProjectionDistance); // Setup projection to infinite if requested (mean no projection shape)
// No need to normalize for fetching cubemap

// Influence volume
// Calculate falloff value, so reflections on the edges of the volume would gradually blend to previous reflection.
float distFade = DistancePointBox(positionLS, -lightData.innerDistance, lightData.innerDistance);
float alpha = saturate(1.0 - distFade / max(lightData.blendDistance, 0.0001)); // avoid divide by zero
float distFade = DistancePointBox(positionLS, -lightData.innerDistance - lightData.blendDistance2, lightData.innerDistance + lightData.blendDistance);
float alpha = saturate(1.0 - distFade / max(lightData.blendDistance.x, 0.0001)); // avoid divide by zero
float3 insideBox = saturate(abs(positionLS) - lightData.innerDistance + float3(lightData.blendNormalDistance, lightData.blendNormalDistance, lightData.blendNormalDistance));
float insideWeight = influenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.positionWS));
alpha *= any(insideBox > 0.0) ? insideWeight : 1.0;
//float3 insideBox = saturate(abs(positionLS) - lightData.innerDistance + float3(lightData.blendNormalDistance, lightData.blendNormalDistance, lightData.blendNormalDistance));
//float insideWeight = influenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.positionWS));
//alpha *= any(insideBox > 0.0) ? insideWeight : 1.0;
//float3 rn = normalize(R);
//float3 faceFade = saturate(float3(6.0, 6.0, 6.0) * rn - float3(2.0, 2.0, 2.0));

正在加载...
取消
保存