浏览代码

Merge remote-tracking branch 'refs/remotes/origin/master' into Support-forward-SSS

/main
sebastienlagarde 7 年前
当前提交
e89a930f
共有 16 个文件被更改,包括 164 次插入289 次删除
  1. 4
      SampleScenes/Common/Scripts/CompressBC6HAndDisplay.cs
  2. 18
      ScriptableRenderPipeline/Core/Editor/CoreEditorUtils.cs
  3. 2
      ScriptableRenderPipeline/Core/EncodeBC6H.cs
  4. 2
      ScriptableRenderPipeline/Core/ShaderLibrary/BC6H.hlsl
  5. 10
      ScriptableRenderPipeline/Core/TextureCache.cs
  6. 10
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDAssetFactory.cs
  7. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  8. 14
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Editor/HDLightEditor.Styles.cs
  9. 319
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Editor/HDLightEditor.cs
  10. 1
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
  11. 18
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/ReflectionProbeCache.cs
  12. 1
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset
  13. 3
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs
  14. 2
      ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc
  15. 38
      ScriptableRenderPipeline/Core/Resources/BC6H.compute
  16. 10
      ScriptableRenderPipeline/Core/Resources/BC6H.compute.meta

4
SampleScenes/Common/Scripts/CompressBC6HAndDisplay.cs


m_EncodeBC6H = new EncodeBC6H(m_BC6HShader);
}
void OnPreRender(CommandBuffer cmb)
void EncodeBC6HTest(CommandBuffer cmb)
{
if (m_SourceTexture == null
|| m_SourceMaterial == null

void Update()
{
var cmd = new CommandBuffer { name = "EncodeBC6H Compress" };
OnPreRender(cmd);
EncodeBC6HTest(cmd);
Graphics.ExecuteCommandBuffer(cmd);
}

18
ScriptableRenderPipeline/Core/Editor/CoreEditorUtils.cs


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

public static void RemoveMaterialKeywords(Material material)
{
material.shaderKeywords = null;
}
public static T[] GetAdditionalData<T>(params UnityEngine.Object[] targets)
where T : Component
{
// Handles multi-selection
var data = targets.Cast<Component>()
.Select(t => t.GetComponent<T>())
.ToArray();
for (int i = 0; i < data.Length; i++)
{
if (data[i] == null)
data[i] = Undo.AddComponent<T>(((Component)targets[i]).gameObject);
}
return data;
}
}
}

2
ScriptableRenderPipeline/Core/EncodeBC6H.cs


}
var startSlice = 6 * targetArrayIndex;
for (var mip = fromMip; mip <= toMip; ++mip)
for (var mip = actualFromMip; mip <= actualToMip; ++mip)
{
var rtMip = Mathf.Clamp(mip, actualFromMip, actualToMip);
for (var faceId = 0; faceId < 6; ++faceId)

2
ScriptableRenderPipeline/Core/ShaderLibrary/BC6H.hlsl


// Ref: https://github.com/knarkowicz/GPURealTimeBC6H/blob/master/bin/compress.hlsl
// Doc: https://msdn.microsoft.com/en-us/library/windows/desktop/hh308952(v=vs.85).aspx
#include "Common.hlsl"
// Measure compression error
float CalcMSLE(float3 a, float3 b)
{

10
ScriptableRenderPipeline/Core/TextureCache.cs


// In case the texture content with which we update the cache is not the input texture, we need to provide the right update count.
public void UpdateSlice(CommandBuffer cmd, int sliceIndex, Texture content, uint textureHash)
{
{
m_SliceArray[sliceIndex].sliceEntryHash = textureHash;
SetSliceHash(sliceIndex, textureHash);
}
public void SetSliceHash(int sliceIndex, uint hash)
{
// transfer new slice to sliceIndex from source texture
m_SliceArray[sliceIndex].sliceEntryHash = hash;
}
public void UpdateSlice(CommandBuffer cmd, int sliceIndex, Texture content)

10
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDAssetFactory.cs


newAsset.buildMaterialFlagsShader = Load<ComputeShader>(HDRenderPipelinePath + "Lighting/LightLoop/materialflags.compute");
newAsset.deferredComputeShader = Load<ComputeShader>(HDRenderPipelinePath + "Lighting/LightLoop/Deferred.compute");
newAsset.deferredDirectionalShadowComputeShader = Load<ComputeShader>(HDRenderPipelinePath + "Lighting/LightLoop/DeferredDirectionalShadow.compute");
newAsset.deferredDirectionalShadowComputeShader = Load<ComputeShader>(HDRenderPipelinePath + "Lighting/DeferredDirectionalShadow.compute");
// SceneSettings
// These shaders don't need to be reference by RenderPipelineResource as they are not use at runtime (only to draw in editor)

// Sky
newAsset.blitCubemap = Load<Shader>(HDRenderPipelinePath + "Sky/BlitCubemap.shader");
newAsset.buildProbabilityTables = Load<ComputeShader>(HDRenderPipelinePath + "Sky/BuildProbabilityTables.compute");
newAsset.computeGgxIblSampleData = Load<ComputeShader>(HDRenderPipelinePath + "Sky/ComputeGgxIblSampleData.compute");
newAsset.GGXConvolve = Load<Shader>(HDRenderPipelinePath + "Sky/GGXConvolve.shader");
newAsset.buildProbabilityTables = Load<ComputeShader>(HDRenderPipelinePath + "Material/GGXConvolution/BuildProbabilityTables.compute");
newAsset.computeGgxIblSampleData = Load<ComputeShader>(HDRenderPipelinePath + "Material/GGXConvolution/ComputeGgxIblSampleData.compute");
newAsset.GGXConvolve = Load<Shader>(HDRenderPipelinePath + "Material/GGXConvolution/GGXConvolve.shader");
newAsset.encodeBC6HCS = Load<ComputeShader>(CorePath + "Resources/EncodeBC6H.compute");
// Skybox/Cubemap is a builtin shader, must use Sahder.Find to access it. It is fine because we are in the editor
newAsset.skyboxCubemap = Shader.Find("Skybox/Cubemap");

1
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


{
m_Asset = asset;
m_GPUCopy = new GPUCopy(asset.renderPipelineResources.copyChannelCS);
EncodeBC6H.DefaultInstance = EncodeBC6H.DefaultInstance ?? new EncodeBC6H(asset.renderPipelineResources.encodeBC6HCS);
// Scan material list and assign it
m_MaterialList = HDUtils.GetRenderPipelineMaterialList();

14
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Editor/HDLightEditor.Styles.cs


sealed class Styles
{
// Base
public readonly GUIContent range = new GUIContent("Range", "Controls how far the light is emitted from the center of the object.");
public readonly GUIContent color = new GUIContent("Color", "Controls the color being emitted by the light.");
public readonly GUIContent spotAngle = new GUIContent("Angle", "Controls the angle in degrees at the base of a Spot light's cone.");
public readonly GUIContent useColorTemperature = new GUIContent("Use Color Temperature", "Choose between RGB and temperature mode for light's color.");
public readonly GUIContent colorFilter = new GUIContent("Filter", "A colored gel can be put in front of the light source to tint the light.");
public readonly GUIContent colorTemperature = new GUIContent("Temperature", "Also known as CCT (Correlated color temperature). The color temperature of the electromagnetic radiation emitted from an ideal black body is defined as its surface temperature in Kelvin. White is 6500K");
public readonly GUIContent intensity = new GUIContent("Intensity", "Controls the brightness of the light. Light color is multiplied by this value.");
public readonly GUIContent lightmappingMode = new GUIContent("Mode", "Specifies the light mode used to determine if and how a light will be baked. Possible modes are Baked, Mixed, and Realtime.");
public readonly GUIContent lightBounceIntensity = new GUIContent("Indirect Multiplier", "Controls the intensity of indirect light being contributed to the scene. A value of 0 will cause Realtime lights to be removed from realtime global illumination and Baked and Mixed lights to no longer emit indirect lighting. Has no effect when both Realtime and Baked Global Illumination are disabled.");
public readonly GUIContent cookie = new GUIContent("Cookie", "Specifies the Texture mask to cast shadows, create silhouettes, or patterned illumination for the light.");
public readonly GUIContent cookieSizeX = new GUIContent("Size X", "Controls the size of the cookie mask currently assigned to the light.");
public readonly GUIContent cookieSizeY = new GUIContent("Size Y", "Controls the size of the cookie mask currently assigned to the light.");
public readonly GUIContent shadowBias = new GUIContent("Bias", "Controls the distance at which the shadows will be pushed away from the light. Useful for avoiding false self-shadowing artifacts.");

public readonly GUIContent bakedShadowAngle = new GUIContent("Baked Shadow Angle", "Controls the amount of artificial softening applied to the edges of shadows cast by directional lights.");
public readonly GUIContent bakingWarning = new GUIContent("Light mode is currently overridden to Realtime mode. Enable Baked Global Illumination to use Mixed or Baked light modes.");
public readonly GUIContent indirectBounceShadowWarning = new GUIContent("Realtime indirect bounce shadowing is not supported for Spot and Point lights.");
public readonly GUIContent cookieWarning = new GUIContent("Cookie textures for spot lights should be set to clamp, not repeat, to avoid artifacts.");
// Additional light data
public readonly GUIContent maxSmoothness = new GUIContent("Max Smoothness", "Very low cost way of faking spherical area lighting. This will modify the roughness of the material lit. This is useful when the specular highlight is too small or too sharp.");

319
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Editor/HDLightEditor.cs


using System;
using System.Linq;
using UnityEngine.Rendering;
// TODO: Simplify this editor once we can target 2018.1
sealed class SerializedBaseData
{
public SerializedProperty type;
public SerializedProperty range;
public SerializedProperty spotAngle;
public SerializedProperty cookie;
public SerializedProperty cookieSize;
public SerializedProperty color;
public SerializedProperty intensity;
public SerializedProperty bounceIntensity;
public SerializedProperty colorTemperature;
public SerializedProperty useColorTemperature;
public SerializedProperty shadowsType;
public SerializedProperty shadowsBias;
public SerializedProperty shadowsNormalBias;
public SerializedProperty shadowsNearPlane;
public SerializedProperty lightmapping;
public SerializedProperty areaSizeX;
public SerializedProperty areaSizeY;
public SerializedProperty bakedShadowRadius;
public SerializedProperty bakedShadowAngle;
}
sealed class SerializedLightData
{
public SerializedProperty spotInnerPercent;

SerializedObject m_SerializedAdditionalLightData;
SerializedObject m_SerializedAdditionalShadowData;
SerializedBaseData m_BaseData;
// Copied over from teh original LightEditor class. Will go away once we can target 2018.1
bool m_TypeIsSame { get { return !m_BaseData.type.hasMultipleDifferentValues; } }
bool m_LightmappingTypeIsSame { get { return !m_BaseData.lightmapping.hasMultipleDifferentValues; } }
bool m_IsCompletelyBaked { get { return m_BaseData.lightmapping.intValue == 2; } }
bool m_IsRealtime { get { return m_BaseData.lightmapping.intValue == 4; } }
Light light { get { return serializedObject.targetObject as Light; } }
Texture m_Cookie { get { return m_BaseData.cookie.objectReferenceValue as Texture; } }
bool m_BakingWarningValue { get { return !UnityEditor.Lightmapping.bakedGI && m_LightmappingTypeIsSame && !m_IsRealtime; } }
bool m_BounceWarningValue
{
get
{
return m_TypeIsSame && (light.type == LightType.Point || light.type == LightType.Spot) &&
m_LightmappingTypeIsSame && m_IsRealtime && !m_BaseData.bounceIntensity.hasMultipleDifferentValues
&& m_BaseData.bounceIntensity.floatValue > 0.0f;
}
}
public bool cookieWarningValue
{
get
{
return m_TypeIsSame && light.type == LightType.Spot &&
!m_BaseData.cookie.hasMultipleDifferentValues && m_Cookie && m_Cookie.wrapMode != TextureWrapMode.Clamp;
}
}
// LightType + LightTypeExtent combined
enum LightShape
{

// Used for UI only; the processing code must use LightTypeExtent and LightType
LightShape m_LightShape;
void OnEnable()
protected override void OnEnable()
base.OnEnable();
var lightData = GetAdditionalData<HDAdditionalLightData>();
var shadowData = GetAdditionalData<AdditionalShadowData>();
var lightData = CoreEditorUtils.GetAdditionalData<HDAdditionalLightData>(targets);
var shadowData = CoreEditorUtils.GetAdditionalData<AdditionalShadowData>(targets);
// Grab all the serialized data we need
m_BaseData = new SerializedBaseData
{
type = serializedObject.FindProperty("m_Type"),
range = serializedObject.FindProperty("m_Range"),
spotAngle = serializedObject.FindProperty("m_SpotAngle"),
cookie = serializedObject.FindProperty("m_Cookie"),
cookieSize = serializedObject.FindProperty("m_CookieSize"),
color = serializedObject.FindProperty("m_Color"),
intensity = serializedObject.FindProperty("m_Intensity"),
bounceIntensity = serializedObject.FindProperty("m_BounceIntensity"),
colorTemperature = serializedObject.FindProperty("m_ColorTemperature"),
useColorTemperature = serializedObject.FindProperty("m_UseColorTemperature"),
shadowsType = serializedObject.FindProperty("m_Shadows.m_Type"),
shadowsBias = serializedObject.FindProperty("m_Shadows.m_Bias"),
shadowsNormalBias = serializedObject.FindProperty("m_Shadows.m_NormalBias"),
shadowsNearPlane = serializedObject.FindProperty("m_Shadows.m_NearPlane"),
lightmapping = serializedObject.FindProperty("m_Lightmapping"),
areaSizeX = serializedObject.FindProperty("m_AreaSize.x"),
areaSizeY = serializedObject.FindProperty("m_AreaSize.y"),
bakedShadowRadius = serializedObject.FindProperty("m_ShadowRadius"),
bakedShadowAngle = serializedObject.FindProperty("m_ShadowAngle")
};
using (var o = new PropertyFetcher<HDAdditionalLightData>(m_SerializedAdditionalLightData))
m_AdditionalLightData = new SerializedLightData
{

ApplyAdditionalComponentsVisibility(true);
CheckStyles();
serializedObject.Update();
settings.Update();
DrawFoldout(m_BaseData.type, "Shape", DrawShape);
DrawFoldout(m_BaseData.intensity, "Light", DrawLightSettings);
DrawFoldout(settings.lightType, "Shape", DrawShape);
DrawFoldout(settings.intensity, "Light", DrawLightSettings);
if (m_BaseData.shadowsType.enumValueIndex != (int)LightShadows.None)
DrawFoldout(m_BaseData.shadowsType, "Shadows", DrawShadows);
if (settings.shadowsType.enumValueIndex != (int)LightShadows.None)
DrawFoldout(settings.shadowsType, "Shadows", DrawShadows);
CoreEditorUtils.DrawSplitter();
EditorGUILayout.Space();

serializedObject.ApplyModifiedProperties();
settings.ApplyModifiedProperties();
}
void DrawFoldout(SerializedProperty foldoutProperty, string title, Action func)

void DrawFeatures()
{
EditorGUILayout.PropertyField(m_AdditionalLightData.showAdditionalSettings);
bool disabledScope = m_IsCompletelyBaked
bool disabledScope = settings.isCompletelyBaked
bool shadowsEnabled = EditorGUILayout.Toggle(new GUIContent("Enable Shadows"), m_BaseData.shadowsType.enumValueIndex != 0);
m_BaseData.shadowsType.enumValueIndex = shadowsEnabled ? (int)LightShadows.Hard : (int)LightShadows.None;
bool shadowsEnabled = EditorGUILayout.Toggle(CoreEditorUtils.GetContent("Enable Shadows"), settings.shadowsType.enumValueIndex != 0);
settings.shadowsType.enumValueIndex = shadowsEnabled ? (int)LightShadows.Hard : (int)LightShadows.None;
EditorGUILayout.PropertyField(m_AdditionalLightData.showAdditionalSettings);
}
void DrawShape()

switch (m_LightShape)
{
case LightShape.Directional:
m_BaseData.type.enumValueIndex = (int)LightType.Directional;
settings.lightType.enumValueIndex = (int)LightType.Directional;
m_BaseData.type.enumValueIndex = (int)LightType.Point;
settings.lightType.enumValueIndex = (int)LightType.Point;
m_BaseData.type.enumValueIndex = (int)LightType.Spot;
settings.lightType.enumValueIndex = (int)LightType.Spot;
m_AdditionalLightData.lightTypeExtent.enumValueIndex = (int)LightTypeExtent.Punctual;
EditorGUILayout.PropertyField(m_AdditionalLightData.spotLightShape, s_Styles.spotLightShape);
var spotLightShape = (SpotLightShape)m_AdditionalLightData.spotLightShape.enumValueIndex;

EditorGUILayout.Slider(m_BaseData.spotAngle, 0f, 179.9f, s_Styles.spotAngle);
settings.DrawSpotAngle();
EditorGUILayout.Slider(m_BaseData.spotAngle, 0f, 179.9f, s_Styles.spotAngle);
settings.DrawSpotAngle();
EditorGUILayout.Slider(m_AdditionalLightData.aspectRatio, 0.05f, 20.0f, s_Styles.aspectRatioPyramid);
}
else if (spotLightShape == SpotLightShape.Box)

case LightShape.Rectangle:
// TODO: Currently if we use Area type as it is offline light in legacy, the light will not exist at runtime
//m_BaseData.type.enumValueIndex = (int)LightType.Area;
m_BaseData.type.enumValueIndex = (int)LightType.Point;
settings.lightType.enumValueIndex = (int)LightType.Point;
m_BaseData.areaSizeX.floatValue = m_AdditionalLightData.shapeLength.floatValue;
m_BaseData.areaSizeY.floatValue = m_AdditionalLightData.shapeWidth.floatValue;
m_BaseData.shadowsType.enumValueIndex = (int)LightShadows.None;
settings.areaSizeX.floatValue = m_AdditionalLightData.shapeLength.floatValue;
settings.areaSizeY.floatValue = m_AdditionalLightData.shapeWidth.floatValue;
settings.shadowsType.enumValueIndex = (int)LightShadows.None;
m_BaseData.type.enumValueIndex = (int)LightType.Point;
settings.lightType.enumValueIndex = (int)LightType.Point;
m_BaseData.areaSizeX.floatValue = m_AdditionalLightData.shapeLength.floatValue;
m_BaseData.areaSizeY.floatValue = 0.01f;
m_BaseData.shadowsType.enumValueIndex = (int)LightShadows.None;
settings.areaSizeX.floatValue = m_AdditionalLightData.shapeLength.floatValue;
settings.areaSizeY.floatValue = 0.01f;
settings.shadowsType.enumValueIndex = (int)LightShadows.None;
break;
case (LightShape)(-1):

void DrawLightSettings()
{
if (GraphicsSettings.lightsUseLinearIntensity && GraphicsSettings.lightsUseColorTemperature)
{
EditorGUILayout.PropertyField(m_BaseData.useColorTemperature, s_Styles.useColorTemperature);
if (m_BaseData.useColorTemperature.boolValue)
{
const float kMinKelvin = 1000f;
const float kMaxKelvin = 20000f;
EditorGUILayout.LabelField(s_Styles.color);
EditorGUI.indentLevel += 1;
EditorGUILayout.PropertyField(m_BaseData.color, s_Styles.colorFilter);
EditorGUILayout.Slider(m_BaseData.colorTemperature, kMinKelvin, kMaxKelvin, s_Styles.colorTemperature);
EditorGUI.indentLevel -= 1;
}
else EditorGUILayout.PropertyField(m_BaseData.color, s_Styles.color);
}
else EditorGUILayout.PropertyField(m_BaseData.color, s_Styles.color);
EditorGUILayout.PropertyField(m_BaseData.intensity, s_Styles.intensity);
EditorGUILayout.PropertyField(m_BaseData.bounceIntensity, s_Styles.lightBounceIntensity);
// Indirect shadows warning (Should be removed when we support realtime indirect shadows)
if (m_BounceWarningValue)
EditorGUILayout.HelpBox(s_Styles.indirectBounceShadowWarning.text, MessageType.Info);
EditorGUILayout.PropertyField(m_BaseData.range, s_Styles.range);
EditorGUILayout.PropertyField(m_BaseData.lightmapping, s_Styles.lightmappingMode);
// Warning if GI Baking disabled and m_Lightmapping isn't realtime
if (m_BakingWarningValue)
EditorGUILayout.HelpBox(s_Styles.bakingWarning.text, MessageType.Info);
settings.DrawColor();
settings.DrawIntensity();
settings.DrawBounceIntensity();
settings.DrawRange(false);
settings.DrawLightmapping();
EditorGUILayout.PropertyField(m_BaseData.cookie, s_Styles.cookie);
// Warn on spotlights if the cookie is set to repeat
if (cookieWarningValue)
EditorGUILayout.HelpBox(s_Styles.cookieWarning.text, MessageType.Warning);
settings.DrawCookie();
if (m_Cookie != null && m_LightShape == LightShape.Directional)
if (settings.cookie != null && m_LightShape == LightShape.Directional)
EditorGUI.indentLevel++;
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.LabelField("Additional Settings", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_AdditionalLightData.affectDiffuse, s_Styles.affectDiffuse);

}
}
void DrawShadows()
void DrawBakedShadowParameters()
if (m_IsCompletelyBaked)
switch ((LightType)settings.lightType.enumValueIndex)
switch ((LightType)m_BaseData.type.enumValueIndex)
{
case LightType.Directional:
EditorGUILayout.Slider(m_BaseData.bakedShadowAngle, 0f, 90f, s_Styles.bakedShadowAngle);
break;
case LightType.Spot:
case LightType.Point:
EditorGUILayout.PropertyField(m_BaseData.bakedShadowRadius, s_Styles.bakedShadowRadius);
break;
}
case LightType.Directional:
EditorGUILayout.Slider(settings.bakedShadowAngleProp, 0f, 90f, s_Styles.bakedShadowAngle);
break;
case LightType.Spot:
case LightType.Point:
EditorGUILayout.PropertyField(settings.bakedShadowRadiusProp, s_Styles.bakedShadowRadius);
break;
}
}
void DrawShadows()
{
if (settings.isCompletelyBaked)
{
DrawBakedShadowParameters();
EditorGUILayout.Slider(m_BaseData.shadowsBias, 0.001f, 1f, s_Styles.shadowBias);
EditorGUILayout.Slider(m_BaseData.shadowsNormalBias, 0.001f, 1f, s_Styles.shadowNormalBias);
EditorGUILayout.Slider(m_BaseData.shadowsNearPlane, 0.01f, 10f, s_Styles.shadowNearPlane);
if (m_BaseData.type.enumValueIndex != (int)LightType.Directional)
return;
EditorGUILayout.Slider(settings.shadowsBias, 0.001f, 1f, s_Styles.shadowBias);
EditorGUILayout.Slider(settings.shadowsNormalBias, 0.001f, 1f, s_Styles.shadowNormalBias);
EditorGUILayout.Slider(settings.shadowsNearPlane, 0.01f, 10f, s_Styles.shadowNearPlane);
using (var scope = new EditorGUI.ChangeCheckScope())
if (settings.lightType.enumValueIndex == (int)LightType.Directional)
EditorGUILayout.IntSlider(m_AdditionalShadowData.cascadeCount, 1, 4, s_Styles.shadowCascadeCount);
if (scope.changed)
using (var scope = new EditorGUI.ChangeCheckScope())
int len = m_AdditionalShadowData.cascadeCount.intValue;
m_AdditionalShadowData.cascadeRatios.arraySize = len - 1;
m_AdditionalShadowData.cascadeBorders.arraySize = len;
EditorGUILayout.IntSlider(m_AdditionalShadowData.cascadeCount, 1, 4, s_Styles.shadowCascadeCount);
if (scope.changed)
{
int len = m_AdditionalShadowData.cascadeCount.intValue;
m_AdditionalShadowData.cascadeRatios.arraySize = len - 1;
m_AdditionalShadowData.cascadeBorders.arraySize = len;
}
}
EditorGUI.indentLevel++;
EditorGUI.indentLevel++;
using (var scope = new EditorGUI.ChangeCheckScope())
{
// Draw each field first...
int arraySize = m_AdditionalShadowData.cascadeRatios.arraySize;
for (int i = 0; i < arraySize; i++)
EditorGUILayout.Slider(m_AdditionalShadowData.cascadeRatios.GetArrayElementAtIndex(i), 0f, 1f, s_Styles.shadowCascadeRatios[i]);
if (scope.changed)
using (var scope = new EditorGUI.ChangeCheckScope())
// ...then clamp values to avoid out of bounds cascade ratios
// Draw each field first...
int arraySize = m_AdditionalShadowData.cascadeRatios.arraySize;
{
var ratios = m_AdditionalShadowData.cascadeRatios;
var ratioProp = ratios.GetArrayElementAtIndex(i);
float val = ratioProp.floatValue;
EditorGUILayout.Slider(m_AdditionalShadowData.cascadeRatios.GetArrayElementAtIndex(i), 0f, 1f, s_Styles.shadowCascadeRatios[i]);
if (i > 0)
if (scope.changed)
{
// ...then clamp values to avoid out of bounds cascade ratios
for (int i = 0; i < arraySize; i++)
var prevRatioProp = ratios.GetArrayElementAtIndex(i - 1);
float prevVal = prevRatioProp.floatValue;
val = Mathf.Max(val, prevVal);
}
var ratios = m_AdditionalShadowData.cascadeRatios;
var ratioProp = ratios.GetArrayElementAtIndex(i);
float val = ratioProp.floatValue;
if (i > 0)
{
var prevRatioProp = ratios.GetArrayElementAtIndex(i - 1);
float prevVal = prevRatioProp.floatValue;
val = Mathf.Max(val, prevVal);
}
if (i < arraySize - 1)
{
var nextRatioProp = ratios.GetArrayElementAtIndex(i + 1);
float nextVal = nextRatioProp.floatValue;
val = Mathf.Min(val, nextVal);
}
if (i < arraySize - 1)
{
var nextRatioProp = ratios.GetArrayElementAtIndex(i + 1);
float nextVal = nextRatioProp.floatValue;
val = Mathf.Min(val, nextVal);
ratioProp.floatValue = val;
ratioProp.floatValue = val;
EditorGUI.indentLevel--;
EditorGUI.indentLevel--;
if (settings.isBakedOrMixed)
DrawBakedShadowParameters();
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_AdditionalShadowData.fadeDistance, s_Styles.shadowFadeDistance);
if (settings.lightType.enumValueIndex == (int)LightType.Point || settings.lightType.enumValueIndex == (int)LightType.Spot)
EditorGUILayout.PropertyField(m_AdditionalShadowData.fadeDistance, s_Styles.shadowFadeDistance);
EditorGUILayout.PropertyField(m_AdditionalShadowData.dimmer, s_Styles.shadowDimmer);
EditorGUI.indentLevel--;
}

void ResolveLightShape()
{
var type = m_BaseData.type;
var type = settings.lightType;
// Special case for multi-selection: don't resolve light shape or it'll corrupt lights
if (type.hasMultipleDifferentValues)

break;
}
}
}
// TODO: Move this to a generic EditorUtilities class
T[] GetAdditionalData<T>()
where T : Component
{
// Handles multi-selection
var data = targets.Cast<Component>()
.Select(t => t.GetComponent<T>())
.ToArray();
for (int i = 0; i < data.Length; i++)
{
if (data[i] == null)
data[i] = Undo.AddComponent<T>(((Component)targets[i]).gameObject);
}
return data;
}
}
}

1
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


else if (light.lightType == LightType.Spot && additionalLightData.spotLightShape != SpotLightShape.Cone)
{
// Projectors lights must always have a cookie texture.
// As long as the cache is a texture array and not an atlas, the 4x4 white texture will be rescaled to 128
lightData.cookieIndex = m_CookieTexArray.FetchSlice(cmd, Texture2D.whiteTexture);
}

18
ScriptableRenderPipeline/HDRenderPipeline/Lighting/ReflectionProbeCache.cs


ProbeFilteringState[] m_ProbeBakingState;
Material m_ConvertTextureMaterial;
MaterialPropertyBlock m_ConvertTextureMPB;
bool m_PerformBC6HCompression;
// BC6H requires CPP feature not yet available
probeFormat = TextureFormat.RGBAHalf;
Debug.Assert(probeFormat == TextureFormat.BC6H || probeFormat == TextureFormat.RGBAHalf, "Reflection Probe Cache format for HDRP can only be BC6H or FP16.");
m_ProbeSize = probeSize;

m_IBLFilterGGX = iblFilter;
m_PerformBC6HCompression = probeFormat == TextureFormat.BC6H;
InitializeProbeBakingStates();
}

if (result == null)
return -1;
m_TextureCache.UpdateSlice(cmd, sliceIndex, result, m_TextureCache.GetTextureHash(texture)); // Be careful to provide the update count from the input texture, not the temporary one used for convolving.
if (m_PerformBC6HCompression)
{
cmd.BC6HEncodeFastCubemap(
result, m_ProbeSize, m_TextureCache.GetTexCache(),
0, int.MaxValue, sliceIndex);
m_TextureCache.SetSliceHash(sliceIndex, m_TextureCache.GetTextureHash(texture));
}
else
{
m_TextureCache.UpdateSlice(cmd, sliceIndex, result, m_TextureCache.GetTextureHash(texture)); // Be careful to provide the update count from the input texture, not the temporary one used for convolving.
}
m_ProbeBakingState[sliceIndex] = ProbeFilteringState.Ready;
}

1
ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset


opaqueAtmosphericScattering: {fileID: 4800000, guid: 326059e48e5735e46a98047eff4f0295,
type: 3}
skyboxCubemap: {fileID: 103, guid: 0000000000000000f000000000000000, type: 0}
encodeBC6HCS: {fileID: 7200000, guid: aa922d239de60304f964e24488559eeb, type: 3}

3
ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs


public Shader opaqueAtmosphericScattering;
public Shader skyboxCubemap;
// Utilities
public ComputeShader encodeBC6HCS;
}
}

2
ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightShadows.cginc


half3 subtractedLightmap = lightmap - estimatedLightContributionMaskedByInverseOfShadow;
// 2) Allows user to define overall ambient of the scene and control situation when realtime shadow becomes too dark.
half3 realtimeShadow = max(subtractedLightmap, _SubtractiveShadowColor);
half3 realtimeShadow = max(subtractedLightmap, _SubtractiveShadowColor.xyz);
realtimeShadow = lerp(realtimeShadow, lightmap, shadowStrength);
// 3) Pick darkest color

38
ScriptableRenderPipeline/Core/Resources/BC6H.compute


#include "../ShaderLibrary/BC6H.hlsl"
Texture2D<float4> _Source;
RWTexture2D<uint4> _Target;
#pragma kernel KEncodeFast
[numthreads(4, 4, 1)]
void KEncodeFast(uint2 groupId : SV_GroupID, uint2 groupThreadId : SV_GroupThreadID, uint2 dispatchThreadId : SV_DispatchThreadID)
{
// Load 4x4 pixel block
float3 texels[16];
uint2 topLeftSourceID = dispatchThreadId << 2;
texels[0] = _Source.Load(uint3(topLeftSourceID , 0)).rgb;
texels[1] = _Source.Load(uint3(topLeftSourceID + uint2(1, 0), 0)).rgb;
texels[2] = _Source.Load(uint3(topLeftSourceID + uint2(2, 0), 0)).rgb;
texels[3] = _Source.Load(uint3(topLeftSourceID + uint2(3, 0), 0)).rgb;
texels[4] = _Source.Load(uint3(topLeftSourceID + uint2(0, 1), 0)).rgb;
texels[5] = _Source.Load(uint3(topLeftSourceID + uint2(1, 1), 0)).rgb;
texels[6] = _Source.Load(uint3(topLeftSourceID + uint2(2, 1), 0)).rgb;
texels[7] = _Source.Load(uint3(topLeftSourceID + uint2(3, 1), 0)).rgb;
texels[8] = _Source.Load(uint3(topLeftSourceID + uint2(0, 2), 0)).rgb;
texels[9] = _Source.Load(uint3(topLeftSourceID + uint2(1, 2), 0)).rgb;
texels[10] = _Source.Load(uint3(topLeftSourceID + uint2(2, 2), 0)).rgb;
texels[11] = _Source.Load(uint3(topLeftSourceID + uint2(3, 2), 0)).rgb;
texels[12] = _Source.Load(uint3(topLeftSourceID + uint2(0, 3), 0)).rgb;
texels[13] = _Source.Load(uint3(topLeftSourceID + uint2(1, 3), 0)).rgb;
texels[14] = _Source.Load(uint3(topLeftSourceID + uint2(2, 3), 0)).rgb;
texels[15] = _Source.Load(uint3(topLeftSourceID + uint2(3, 3), 0)).rgb;
uint4 block = uint4(0, 0, 0, 0);
float blockMSLE = 0;
EncodeMode11(block, blockMSLE, texels);
_Target[dispatchThreadId] = block;
}

10
ScriptableRenderPipeline/Core/Resources/BC6H.compute.meta


fileFormatVersion: 2
guid: b69b95b3420fd904e8530b79f665a1f8
timeCreated: 1507123133
licenseType: Pro
ComputeShaderImporter:
externalObjects: {}
currentAPIMask: 4
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存