浏览代码

[ReflectionProbeEditor] Fixed blend normal

/feature-ReflectionProbeFit
Frédéric Vauchelles 7 年前
当前提交
ce05c4be
共有 11 个文件被更改,包括 200 次插入128 次删除
  1. 67
      ScriptableRenderPipeline/Core/Editor/CoreEditorUtils.cs
  2. 20
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs
  3. 30
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs
  4. 16
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs
  5. 16
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs
  6. 22
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs
  7. 13
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs
  8. 44
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs.hlsl
  9. 28
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
  10. 25
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightUtilities.hlsl
  11. 47
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl

67
ScriptableRenderPipeline/Core/Editor/CoreEditorUtils.cs


return group.isExpanded;
}
static readonly GUIContent[] k_DrawVector6Slider_Labels =
static readonly GUIContent[] k_DrawVector6Slider_LabelPositives =
};
static readonly GUIContent[] k_DrawVector6Slider_LabelNegatives =
{
const int k_DrawVector6Slider_LabelSize = 60;
const int k_DrawVector6Slider_FieldSize = 80;
negative.isExpanded = EditorGUILayout.Foldout(negative.isExpanded, label, true);
if (negative.isExpanded)
{
var labelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 60;
EditorGUILayout.LabelField(label);
++EditorGUI.indentLevel;
++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();
var rect = GUILayoutUtility.GetRect(0, float.MaxValue, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight);
var v = positive.vector3Value;
EditorGUI.BeginChangeCheck();
v = DrawVector3Slider(rect, k_DrawVector6Slider_LabelPositives, v, min, max);
if (EditorGUI.EndChangeCheck())
positive.vector3Value = v;
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
rect = GUILayoutUtility.GetRect(0, float.MaxValue, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight);
v = negative.vector3Value;
EditorGUI.BeginChangeCheck();
v = DrawVector3Slider(rect, k_DrawVector6Slider_LabelNegatives, v, min, max);
if (EditorGUI.EndChangeCheck())
negative.vector3Value = v;
--EditorGUI.indentLevel;
GUILayout.EndVertical();
}
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;
static Vector3 DrawVector3Slider(Rect rect, GUIContent[] labels, Vector3 value, Vector3 min, Vector3 max)
{
// Use a corrected width due to the hacks used for layouting the slider properly below
rect.width -= 20;
var fieldWidth = rect.width / 3f;
EditorGUIUtility.labelWidth = labelWidth;
for (var i = 0; i < 3; ++i)
{
var c = new Rect(rect.x + fieldWidth * i, rect.y, fieldWidth, rect.height);
var labelRect = new Rect(c.x, c.y, k_DrawVector6Slider_LabelSize, c.height);
var sliderRect = new Rect(labelRect.x + labelRect.width, c.y, c.width - k_DrawVector6Slider_LabelSize - k_DrawVector6Slider_FieldSize + 45, c.height);
var fieldRect = new Rect(sliderRect.x + sliderRect.width - 25, c.y, k_DrawVector6Slider_FieldSize, c.height);
EditorGUI.LabelField(labelRect, labels[i]);
value[i] = GUI.HorizontalSlider(sliderRect, value[i], min[i], max[i]);
value[i] = EditorGUI.FloatField(fieldRect, value[i]);
GUILayout.EndVertical();
return value;
}
public static void RemoveMaterialKeywords(Material material)

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


internal SerializedProperty boxReprojectionVolumeSize;
internal SerializedProperty boxReprojectionVolumeCenter;
internal SerializedProperty sphereReprojectionVolumeRadius;
internal SerializedProperty blendDistance;
internal SerializedProperty blendDistance2;
internal SerializedProperty blendNormalDistance;
internal SerializedProperty blendNormalDistance2;
internal SerializedProperty blendDistancePositive;
internal SerializedProperty blendDistanceNegative;
internal SerializedProperty blendNormalDistancePositive;
internal SerializedProperty blendNormalDistanceNegative;
internal SerializedProperty boxSideFadePositive;
internal SerializedProperty boxSideFadeNegative;
internal SerializedProperty dimmer;
public SerializedReflectionProbe(SerializedObject so, SerializedObject addso)

boxReprojectionVolumeCenter = addso.Find((HDAdditionalReflectionData d) => d.boxReprojectionVolumeCenter);
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);
blendNormalDistance = addso.Find((HDAdditionalReflectionData d) => d.blendNormalDistance);
blendNormalDistance2 = addso.Find((HDAdditionalReflectionData d) => d.blendNormalDistance2);
blendDistancePositive = addso.Find((HDAdditionalReflectionData d) => d.blendDistancePositive);
blendDistanceNegative = addso.Find((HDAdditionalReflectionData d) => d.blendDistanceNegative);
blendNormalDistancePositive = addso.Find((HDAdditionalReflectionData d) => d.blendNormalDistancePositive);
blendNormalDistanceNegative = addso.Find((HDAdditionalReflectionData d) => d.blendNormalDistanceNegative);
boxSideFadePositive = addso.Find((HDAdditionalReflectionData d) => d.boxSideFadePositive);
boxSideFadeNegative = addso.Find((HDAdditionalReflectionData d) => d.boxSideFadeNegative);
}
}

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


static readonly CED.IDrawer k_InfluenceVolumeSection = CED.FoldoutGroup(
"Influence volume settings",
(s, p, o) => p.blendDistance,
(s, p, o) => p.blendDistancePositive,
true,
CED.FadeGroup(
(s, p, o, i) => s.GetShapeFaded((ReflectionInfluenceShape)i),

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);
p.blendDistancePositive, p.blendDistanceNegative, Vector3.zero, maxBlendDistance);
p.blendNormalDistance, p.blendNormalDistance2, Vector3.zero, maxBlendDistance);
p.blendNormalDistancePositive, p.blendNormalDistanceNegative, Vector3.zero, maxBlendDistance);
CoreEditorUtils.DrawVector6Slider(
CoreEditorUtils.GetContent("Face fade|Fade faces of the cubemap."),
p.boxSideFadePositive, p.boxSideFadeNegative, Vector3.zero, Vector3.one);
EditorGUILayout.Space();
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."));

{
var maxBlendDistance = CalculateSphereMaxBlendDistance(s, p, owner);
var blendDistance = p.blendDistance.vector3Value.x;
var blendDistance = p.blendDistancePositive.vector3Value.x;
p.blendDistance.vector3Value = Vector3.one * blendDistance;
p.blendDistance2.vector3Value = Vector3.one * blendDistance;
p.blendDistancePositive.vector3Value = Vector3.one * blendDistance;
p.blendDistanceNegative.vector3Value = Vector3.one * blendDistance;
var blendNormalDistance = p.blendNormalDistance.vector3Value.x;
var blendNormalDistance = p.blendNormalDistancePositive.vector3Value.x;
p.blendNormalDistance.vector3Value = Vector3.one * blendNormalDistance;
p.blendNormalDistance2.vector3Value = Vector3.one * blendNormalDistance;
p.blendNormalDistancePositive.vector3Value = Vector3.one * blendNormalDistance;
p.blendNormalDistanceNegative.vector3Value = Vector3.one * blendNormalDistance;
}
EditorGUILayout.PropertyField(p.influenceSphereRadius, CoreEditorUtils.GetContent("Radius"));

{
return s_Toolbar_Contents ?? (s_Toolbar_Contents = new []
{
EditorGUIUtility.IconContent("EditCollider", "|Modify the extents of the reflection probe."),
EditorGUIUtility.IconContent("PreMatCube", "|Modify the influence volume of the reflection probe."),
EditorGUIUtility.IconContent("SceneViewOrtho", "|Modify the influence normal volume of the reflection probe."),
EditorGUIUtility.IconContent("EditCollider", "|Modify the extents of the reflection probe. (SHIFT+1)"),
EditorGUIUtility.IconContent("PreMatCube", "|Modify the influence volume of the reflection probe. (SHIFT+2)"),
EditorGUIUtility.IconContent("SceneViewOrtho", "|Modify the influence normal volume of the reflection probe. (SHIFT+3)"),
EditorGUIUtility.IconContent("MoveTool", "|Move the selected objects.")
});
}

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


{
blendBox = s.boxBlendHandle;
sphereHandle = s.sphereBlendHandle;
probeBlendDistancePositive = sp.targetData.blendDistance;
probeBlendDistanceNegative = sp.targetData.blendDistance2;
probeBlendDistancePositive = sp.targetData.blendDistancePositive;
probeBlendDistanceNegative = sp.targetData.blendDistanceNegative;
color = k_GizmoThemeColorInfluenceBlend;
break;
}

sphereHandle = s.sphereBlendNormalHandle;
probeBlendDistancePositive = sp.targetData.blendNormalDistance;
probeBlendDistanceNegative = sp.targetData.blendNormalDistance2;
probeBlendDistancePositive = sp.targetData.blendNormalDistancePositive;
probeBlendDistanceNegative = sp.targetData.blendNormalDistanceNegative;
color = k_GizmoThemeColorInfluenceNormalBlend;
break;
}

default:
case InfluenceType.Standard:
{
sp.targetData.blendDistance = probeBlendDistancePositive;
sp.targetData.blendDistance2 = probeBlendDistanceNegative;
sp.targetData.blendDistancePositive = probeBlendDistancePositive;
sp.targetData.blendDistanceNegative = probeBlendDistanceNegative;
sp.targetData.blendNormalDistance = probeBlendDistancePositive;
sp.targetData.blendNormalDistance2 = probeBlendDistanceNegative;
sp.targetData.blendNormalDistancePositive = probeBlendDistancePositive;
sp.targetData.blendNormalDistanceNegative = probeBlendDistanceNegative;
break;
}
}

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


case ReflectionInfluenceShape.Box:
{
var maxBlendDistance = CalculateBoxMaxBlendDistance(s, sp, o);
sp.targetData.blendDistance = Vector3.Min(sp.targetData.blendDistance, maxBlendDistance);
sp.targetData.blendDistance2 = Vector3.Min(sp.targetData.blendDistance2, maxBlendDistance);
sp.targetData.blendNormalDistance = Vector3.Min(sp.targetData.blendNormalDistance, maxBlendDistance);
sp.targetData.blendNormalDistance2 = Vector3.Min(sp.targetData.blendNormalDistance2, maxBlendDistance);
sp.targetData.blendDistancePositive = Vector3.Min(sp.targetData.blendDistancePositive, maxBlendDistance);
sp.targetData.blendDistanceNegative = Vector3.Min(sp.targetData.blendDistanceNegative, maxBlendDistance);
sp.targetData.blendNormalDistancePositive = Vector3.Min(sp.targetData.blendNormalDistancePositive, maxBlendDistance);
sp.targetData.blendNormalDistanceNegative = Vector3.Min(sp.targetData.blendNormalDistanceNegative, maxBlendDistance);
sp.targetData.blendDistance = Vector3.Min(sp.targetData.blendDistance, maxBlendDistance);
sp.targetData.blendDistance2 = Vector3.Min(sp.targetData.blendDistance2, maxBlendDistance);
sp.targetData.blendNormalDistance = Vector3.Min(sp.targetData.blendNormalDistance, maxBlendDistance);
sp.targetData.blendNormalDistance2 = Vector3.Min(sp.targetData.blendNormalDistance2, maxBlendDistance);
sp.targetData.blendDistancePositive = Vector3.Min(sp.targetData.blendDistancePositive, maxBlendDistance);
sp.targetData.blendDistanceNegative = Vector3.Min(sp.targetData.blendDistanceNegative, maxBlendDistance);
sp.targetData.blendNormalDistancePositive = Vector3.Min(sp.targetData.blendNormalDistancePositive, maxBlendDistance);
sp.targetData.blendNormalDistanceNegative = Vector3.Min(sp.targetData.blendNormalDistanceNegative, maxBlendDistance);
break;
}
}

22
ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs


public Vector3 boxReprojectionVolumeCenter = Vector3.zero;
public float maxSearchDistance = 8.0f;
public Texture previewCubemap;
public Vector3 blendDistance = Vector3.zero;
public Vector3 blendDistance2 = Vector3.zero;
public Vector3 blendNormalDistance = Vector3.zero;
public Vector3 blendNormalDistance2 = Vector3.zero;
public Vector3 blendDistancePositive = Vector3.zero;
public Vector3 blendDistanceNegative = Vector3.zero;
public Vector3 blendNormalDistancePositive = Vector3.zero;
public Vector3 blendNormalDistanceNegative = Vector3.zero;
public Vector3 boxSideFadePositive = Vector3.one;
public Vector3 boxSideFadeNegative = Vector3.one;
public Vector3 boxBlendCenterOffset { get { return (blendDistance2 - blendDistance) * 0.5f; } }
public Vector3 boxBlendSizeOffset { get { return -(blendDistance + blendDistance2); } }
public Vector3 boxBlendNormalCenterOffset { get { return (blendNormalDistance2 - blendNormalDistance) * 0.5f; } }
public Vector3 boxBlendNormalSizeOffset { get { return -(blendNormalDistance + blendNormalDistance2); } }
public Vector3 boxBlendCenterOffset { get { return (blendDistanceNegative - blendDistancePositive) * 0.5f; } }
public Vector3 boxBlendSizeOffset { get { return -(blendDistancePositive + blendDistanceNegative); } }
public Vector3 boxBlendNormalCenterOffset { get { return (blendNormalDistanceNegative - blendNormalDistancePositive) * 0.5f; } }
public Vector3 boxBlendNormalSizeOffset { get { return -(blendNormalDistancePositive + blendNormalDistanceNegative); } }
public float sphereBlendRadiusOffset { get { return -blendDistance.x; } }
public float sphereBlendNormalRadiusOffset { get { return -blendNormalDistance.x; } }
public float sphereBlendRadiusOffset { get { return -blendDistancePositive.x; } }
public float sphereBlendNormalRadiusOffset { get { return -blendNormalDistancePositive.x; } }
}
}

13
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs


public Vector3 offsetLS;
public float unused1;
public Vector3 blendDistance; //+X,+Y,+Z
public Vector3 blendDistancePositive; //+X,+Y,+Z
public Vector3 blendDistance2; //-X,-Y,-Z
public Vector3 blendDistanceNegative; //-X,-Y,-Z
public Vector3 blendNormalDistance; //+X,+Y,+Z
public Vector3 blendNormalDistancePositive; //+X,+Y,+Z
public Vector3 blendNormalDistance2; //-X,-Y,-Z
public Vector3 blendNormalDistanceNegative; //-X,-Y,-Z
public Vector3 boxSideFadePositive; //+X,+Y,+Z
public float unused6;
public Vector3 boxSideFadeNegative; //-X,-Y,-Z
public float unused7;
};
// Usage of StencilBits.Lighting on 2 bits.

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


float unused0;
float3 offsetLS;
float unused1;
float3 blendDistance;
float3 blendDistancePositive;
float3 blendDistance2;
float3 blendDistanceNegative;
float3 blendNormalDistance;
float3 blendNormalDistancePositive;
float3 blendNormalDistance2;
float3 blendNormalDistanceNegative;
float3 boxSideFadePositive;
float unused6;
float3 boxSideFadeNegative;
float unused7;
};
//

{
return value.unused1;
}
float3 GetBlendDistance(EnvLightData value)
float3 GetBlendDistancePositive(EnvLightData value)
return value.blendDistance;
return value.blendDistancePositive;
float3 GetBlendDistance2(EnvLightData value)
float3 GetBlendDistanceNegative(EnvLightData value)
return value.blendDistance2;
return value.blendDistanceNegative;
float3 GetBlendNormalDistance(EnvLightData value)
float3 GetBlendNormalDistancePositive(EnvLightData value)
return value.blendNormalDistance;
return value.blendNormalDistancePositive;
float3 GetBlendNormalDistance2(EnvLightData value)
float3 GetBlendNormalDistanceNegative(EnvLightData value)
return value.blendNormalDistance2;
return value.blendNormalDistanceNegative;
}
float3 GetBoxSideFadePositive(EnvLightData value)
{
return value.boxSideFadePositive;
}
float GetUnused6(EnvLightData value)
{
return value.unused6;
}
float3 GetBoxSideFadeNegative(EnvLightData value)
{
return value.boxSideFadeNegative;
}
float GetUnused7(EnvLightData value)
{
return value.unused7;
}

28
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


{
var additionalData = probe.probe.GetComponent<HDAdditionalReflectionData>();
var extents = probe.bounds.extents;
var influenceBlendDistance = Vector3.one * probe.blendDistance;
var influenceBlendDistance2 = Vector3.one * probe.blendDistance;
var influenceBlendDistancePositive = Vector3.one * probe.blendDistance;
var influenceBlendDistanceNegative = 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).

// CAUTION: localToWorld is the transform for the widget of the reflection probe. i.e the world position of the point use to do the cubemap capture (mean it include the local offset)
envLightData.positionWS = probe.localToWorld.GetColumn(3);
envLightData.boxSideFadePositive = Vector3.one;
envLightData.boxSideFadeNegative = Vector3.one;
if (additionalData != null)
{

case ReflectionInfluenceShape.Box:
{
envLightData.envShapeType = EnvShapeType.Box;
envLightData.boxSideFadePositive = additionalData.boxSideFadePositive;
envLightData.boxSideFadeNegative = additionalData.boxSideFadeNegative;
break;
}
case ReflectionInfluenceShape.Sphere:

envLightData.minProjectionDistance = 65504.0f;
envLightData.dimmer = additionalData.dimmer;
envLightData.blendNormalDistance = additionalData.blendNormalDistance;
envLightData.blendNormalDistance2 = additionalData.blendNormalDistance2;
influenceBlendDistance = additionalData.blendDistance;
influenceBlendDistance2 = additionalData.blendDistance2;
envLightData.blendNormalDistancePositive = additionalData.blendNormalDistancePositive;
envLightData.blendNormalDistanceNegative = additionalData.blendNormalDistanceNegative;
influenceBlendDistancePositive = additionalData.blendDistancePositive;
influenceBlendDistanceNegative = additionalData.blendDistanceNegative;
}
else
{

}
envLightData.dimmer = 1;
envLightData.blendNormalDistance = Vector3.zero;
envLightData.blendNormalDistance2 = Vector3.zero;
envLightData.blendDistancePositive = Vector3.zero;
envLightData.blendDistanceNegative = 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 blendDistance = Vector3.Min(probe.bounds.extents, influenceBlendDistance);
var blendDistance2 = Vector3.Min(probe.bounds.extents, influenceBlendDistance2);
var blendDistancePositive = Vector3.Min(probe.bounds.extents, influenceBlendDistancePositive);
var blendDistanceNegative = Vector3.Min(probe.bounds.extents, influenceBlendDistanceNegative);
envLightData.blendDistance = blendDistance;
envLightData.blendDistance2 = blendDistance2;
envLightData.blendDistancePositive = blendDistancePositive;
envLightData.blendDistanceNegative = blendDistanceNegative;
m_lightList.envLights.Add(envLightData);

25
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightUtilities.hlsl


EnvLightData InitSkyEnvLightData(int envIndex)
{
EnvLightData output;
output.envShapeType = ENVSHAPETYPE_SKY;
output.envIndex = envIndex;
output.forward = float3(0.0, 0.0, 1.0);
output.up = float3(0.0, 1.0, 0.0);
output.right = float3(1.0, 0.0, 0.0);
output.positionWS = float3(0.0, 0.0, 0.0);
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;
output.envShapeType = ENVSHAPETYPE_SKY;
output.envIndex = envIndex;
output.forward = float3(0.0, 0.0, 1.0);
output.up = float3(0.0, 1.0, 0.0);
output.right = float3(1.0, 0.0, 0.0);
output.positionWS = float3(0.0, 0.0, 0.0);
output.offsetLS = float3(0.0, 0.0, 0.0);
output.innerDistance = float3(0.0, 0.0, 0.0);
output.blendDistancePositive = float3(0.0, 0.0, 0.0);
output.blendDistanceNegative = float3(0.0, 0.0, 0.0);
output.blendNormalDistancePositive = float3(0.0, 0.0, 0.0);
output.blendNormalDistanceNegative = float3(0.0, 0.0, 0.0);
output.boxSideFadePositive = float3(0.0, 0.0, 0.0);
output.boxSideFadeNegative = float3(0.0, 0.0, 0.0);
output.dimmer = 1.0;
return output;
}

47
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


return positionWS + rayWS * hitDistanceFromPosition;
}
//------------------------------------------------------------------------------------
// Little helper to share code between sphere and box.
// These function will fade the mask of a reflection volume based on normal orientation compare to direction define by the center of the reflection volume.
//-----------------------------------------------------------------------------
float InfluenceFadeNormalWeight(float3 normal, float3 centerToPos)
{
// Start weight from 0.6f (1 fully transparent) to 0.2f (fully opaque).
return saturate((-1.0f / 0.4f) * dot(normal, centerToPos) + (0.6f / 0.4f));
}
//-----------------------------------------------------------------------------
// Ligth and material classification for the deferred rendering path
// Configure what kind of combination is supported

}
}
//------------------------------------------------------------------------------------
// Little helper to share code between sphere and box.
// These function will fade the mask of a reflection volume based on normal orientation compare to direction define by the center of the reflection volume.
float influenceFadeNormalWeight(float3 normal, float3 centerToPos)
{
// Start weight from 0.6f (1 fully transparent) to 0.2f (fully opaque).
return saturate((-1.0f / 0.4f) * dot(normal, centerToPos) + (0.6f / 0.4f));
}
//-----------------------------------------------------------------------------
// EvaluateBSDF_Env
// ----------------------------------------------------------------------------

// 2. Process the position influence
float lengthPositionLS = length(positionLS);
float sphereInfluenceDistance = lightData.innerDistance.x - lightData.blendDistance.x;
float sphereInfluenceDistance = lightData.innerDistance.x - lightData.blendDistancePositive.x;
float alpha = saturate(1.0 - distFade / max(lightData.blendDistance.x, 0.0001)); // avoid divide by zero
float alpha = saturate(1.0 - distFade / max(lightData.blendDistancePositive.x, 0.0001)); // avoid divide by zero
float insideInfluenceNormalVolume = lengthPositionLS <= (lightData.innerDistance.x - lightData.blendNormalDistance.x) ? 1.0 : 0.0;
float insideWeight = influenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.positionWS));
float insideInfluenceNormalVolume = lengthPositionLS <= (lightData.innerDistance.x - lightData.blendNormalDistancePositive.x) ? 1.0 : 0.0;
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.positionWS));
alpha *= insideInfluenceNormalVolume ? 1.0 : insideWeight;
weight = alpha;

float3 positiveDistance = boxOuterDistance - positionLS;
// Influence falloff for each face
float3 negativeFalloff = negativeDistance / max(0.0001, lightData.blendDistance2);
float3 positiveFalloff = positiveDistance / max(0.0001, lightData.blendDistance);
float3 negativeFalloff = negativeDistance / max(0.0001, lightData.blendDistanceNegative);
float3 positiveFalloff = positiveDistance / max(0.0001, lightData.blendDistancePositive);
// Fallof is the min for all faces
float influenceFalloff = min(

// 3. Process the normal influence
// Calculate a falloff value to discard normals pointing outward the center of the environment light
float3 belowPositiveInfluenceNormalVolume = positiveDistance / max(0.0001, lightData.blendNormalDistance);
float3 aboveNegativeInfluenceNormalVolume = negativeDistance / max(0.0001, lightData.blendNormalDistance2);
float3 belowPositiveInfluenceNormalVolume = positiveDistance / max(0.0001, lightData.blendNormalDistancePositive);
float3 aboveNegativeInfluenceNormalVolume = negativeDistance / max(0.0001, lightData.blendNormalDistanceNegative);
float insideWeight = influenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.positionWS));
float insideWeight = InfluenceFadeNormalWeight(bsdfData.normalWS, normalize(positionWS - lightData.positionWS));
// 4. Fade specific cubemap faces
// For each axes (both positive and negative ones), we want to fade from the center of one face to another
// So we normalized the sample direction (R) and use its component to fade for each axis
// We consider R.x as cos(X) and then fade as angle from 60°(=acos(1/2)) to 75°(=acos(1/4))
// For positive axes: axisFade = (R - 1/4) / (1/2 - 1/4)
// <=> axisFace = 4 * R - 1;
R = normalize(R);
float3 faceFade = saturate((4 * R - 1) * lightData.boxSideFadePositive) + saturate((-4 * R - 1) * lightData.boxSideFadeNegative);
alpha *= saturate(faceFade.x + faceFade.y + faceFade.z);
weight = alpha;
}

正在加载...
取消
保存