浏览代码

Moved algorithm selection to shader variant

/feature-ScreenSpaceProjection
Frédéric Vauchelles 7 年前
当前提交
5ab7101f
共有 12 个文件被更改,包括 80 次插入58 次删除
  1. 5
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/ScreenSpaceRaymarching.hlsl
  2. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
  3. 28
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/LitUI.cs
  4. 9
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Unlit/BaseUnlitUI.cs
  5. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/RenderPipelineSettingsUI.cs
  6. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/SerializedRenderPipelineSettings.cs
  7. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  8. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs
  9. 57
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  10. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader
  11. 5
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader
  12. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipeline/RenderPipelineSettings.cs

5
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/ScreenSpaceRaymarching.hlsl


CBUFFER_START(ScreenSpaceRaymarching)
int _SSRayMinLevel;
int _SSRayMaxLevel;
int _SSRayAlgorithm;
CBUFFER_END
struct ScreenSpaceHiZRaymarchInput

ZERO_INITIALIZE(ScreenSpaceRayHit, hit);
bool hitSuccessful = true;
int iteration = 0;
int level = _SSRayMinLevel;
float3 startPositionTXS;
float3 rayTXS;

{
// DDA step
rayTXS /= max(abs(rayTXS.x), abs(rayTXS.y));
rayTXS *= _SSRayMinLevel;
float3 positionTXS = startPositionTXS;
// TODO: We should have a for loop from the starting point to the far/near plane

#endif
positionTXS += rayTXS;
float invHiZDepth = SampleHiZDepth(positionTXS.xy, 0);
float invHiZDepth = SampleHiZDepth(positionTXS.xy, _SSRayMinLevel);
#ifdef DEBUG_DISPLAY
FillScreenSpaceRaymarchingPostIterationDebug(

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs


break;
}
}
list.Add(
new DebugUI.FloatField
{
displayName = "SSRayAlgorithm",
getter = () => lightingDebugSettings.ssRayAlgorithm,
setter = value => lightingDebugSettings.ssRayAlgorithm = value,
}
);
list.Add(new DebugUI.EnumField { displayName = "Fullscreen Debug Mode", getter = () => (int)fullScreenDebugMode, setter = value => fullScreenDebugMode = (FullScreenDebugMode)value, enumNames = lightingFullScreenDebugStrings, enumValues = lightingFullScreenDebugValues, onValueChanged = RefreshLightingDebug });
switch (fullScreenDebugMode)

28
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/LitUI.cs


public static GUIContent normalMapSpaceWarning = new GUIContent("Object space normal can't be use with triplanar mapping.");
// Transparency
public static string ssRayRefractionMethodText = "SS ray Refraction Method";
public static string ssRayMinLevel = "SS ray min mip level";
public static string ssRayMaxLevel = "SS ray max mip level";
public static string ssRayLevel = "SS ray mip level";
public static string refractionModeText = "Refraction Mode";
public static GUIContent refractionIorText = new GUIContent("Index of refraction", "Index of refraction");
public static GUIContent refractionThicknessText = new GUIContent("Refraction Thickness", "Thickness for rough refraction");

if (mode != Lit.RefractionMode.None)
{
m_MaterialEditor.ShaderProperty(ior, Styles.refractionIorText);
if (ssRayRefractionMethod != null)
m_MaterialEditor.ShaderProperty(ssRayRefractionMethod, Styles.ssRayRefractionMethodText);
var ssRayMethod = (Lit.SSRayMethod)ssRayRefractionMethod.floatValue;
switch (ssRayMethod)
{
case Lit.SSRayMethod.HiZ:
if (ssRayMinLevel != null)
m_MaterialEditor.ShaderProperty(ssRayMinLevel, Styles.ssRayMinLevel);
if (ssRayMaxLevel != null)
m_MaterialEditor.ShaderProperty(ssRayMaxLevel, Styles.ssRayMaxLevel);
break;
case Lit.SSRayMethod.Linear:
if (ssRayMinLevel != null)
m_MaterialEditor.ShaderProperty(ssRayMinLevel, Styles.ssRayLevel);
break;
default:
break;
}
blendMode.floatValue = (float)BlendMode.Alpha;
if (thicknessMap[0].textureValue == null)

var refractionModeValue = (Lit.RefractionMode)material.GetFloat(kRefractionMode);
// We can't have refraction in pre-refraction queue
var canHaveRefraction = !material.HasProperty(kPreRefractionPass) || material.GetFloat(kPreRefractionPass) <= 0.0;
var ssRayMethod = material.HasProperty(kSsRayRefractionMethod) ? (Lit.SSRayMethod)material.GetFloat(kSsRayRefractionMethod) : Lit.SSRayMethod.HiZ;
CoreUtils.SetKeyword(material, "SSRAY_REFRACTION_HIZ", ssRayMethod == Lit.SSRayMethod.HiZ);
CoreUtils.SetKeyword(material, "SSRAY_REFRACTION_LINEAR", ssRayMethod == Lit.SSRayMethod.Linear);
}
}
} // namespace UnityEditor

9
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Unlit/BaseUnlitUI.cs


protected const string kDistortionBlurRemapMax = "_DistortionBlurRemapMax";
protected MaterialProperty preRefractionPass = null;
protected const string kPreRefractionPass = "_PreRefractionPass";
protected MaterialProperty ssRayRefractionMethod = null;
protected const string kSsRayRefractionMethod = "_SSRayRefractionMethod";
protected MaterialProperty ssRayMinLevel = null;
protected const string kSsRayMinLevel = "_SSRayMinLevel";
protected MaterialProperty ssRayMaxLevel = null;
protected const string kSsRayMaxLevel = "_SSRayMaxLevel";
protected MaterialProperty enableFogOnTransparent = null;
protected const string kEnableFogOnTransparent = "_EnableFogOnTransparent";
protected MaterialProperty enableBlendModePreserveSpecularLighting = null;

distortionBlurRemapMin = FindProperty(kDistortionBlurRemapMin, props, false);
distortionBlurRemapMax = FindProperty(kDistortionBlurRemapMax, props, false);
preRefractionPass = FindProperty(kPreRefractionPass, props, false);
ssRayRefractionMethod = FindProperty(kSsRayRefractionMethod, props, false);
ssRayMinLevel = FindProperty(kSsRayMinLevel, props, false);
ssRayMaxLevel = FindProperty(kSsRayMaxLevel, props, false);
enableFogOnTransparent = FindProperty(kEnableFogOnTransparent, props, false);
enableBlendModePreserveSpecularLighting = FindProperty(kEnableBlendModePreserveSpecularLighting, props, false);

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/RenderPipelineSettingsUI.cs


EditorGUILayout.PropertyField(d.supportStereo, _.GetContent("Support Stereo Rendering"));
EditorGUILayout.PropertyField(d.enableUltraQualitySSS, _.GetContent("Increase SSS Sample Count"));
EditorGUILayout.PropertyField(d.ssRayMinLevel, _.GetContent("Screen Space Raymarching Min Level"));
EditorGUILayout.PropertyField(d.ssRayMaxLevel, _.GetContent("Screen Space Raymarching Max Level"));
--EditorGUI.indentLevel;
}
}

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/SerializedRenderPipelineSettings.cs


supportStereo = root.Find((RenderPipelineSettings s) => s.supportStereo);
enableUltraQualitySSS = root.Find((RenderPipelineSettings s) => s.enableUltraQualitySSS);
ssRayMinLevel = root.Find((RenderPipelineSettings s) => s.ssRayMinLevel);
ssRayMaxLevel = root.Find((RenderPipelineSettings s) => s.ssRayMaxLevel);
lightLoopSettings = new SerializedGlobalLightLoopSettings(root.Find((RenderPipelineSettings s) => s.lightLoopSettings));
shadowInitParams = new SerializedShadowInitParameters(root.Find((RenderPipelineSettings s) => s.shadowInitParams));
decalSettings = new SerializedGlobalDecalSettings(root.Find((RenderPipelineSettings s) => s.decalSettings));

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


m_DbufferManager.PushGlobalParams(cmd, m_FrameSettings);
m_VolumetricLightingModule.PushGlobalParams(hdCamera, cmd);
cmd.SetGlobalInt(HDShaderIDs._SSRayMinLevel, m_Asset.renderPipelineSettings.ssRayMinLevel);
cmd.SetGlobalInt(HDShaderIDs._SSRayMaxLevel, m_Asset.renderPipelineSettings.ssRayMaxLevel);
}
}

public void ApplyDebugDisplaySettings(HDCamera hdCamera, CommandBuffer cmd)
{
// Temporary
cmd.SetGlobalInt(HDShaderIDs._SSRayAlgorithm, (int)m_CurrentDebugDisplaySettings.lightingDebugSettings.ssRayAlgorithm);
if (m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled() ||
m_CurrentDebugDisplaySettings.fullScreenDebugMode != FullScreenDebugMode.None ||
m_CurrentDebugDisplaySettings.colorPickerDebugSettings.colorPickerMode != ColorPickerDebugMode.None)

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs


Sphere = 2
};
public enum SSRayMethod
{
HiZ,
Linear
}
//-----------------------------------------------------------------------------
// SurfaceData
//-----------------------------------------------------------------------------

57
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


ZERO_INITIALIZE(ScreenSpaceRayHit, hit);
bool hitSuccessful = false;
switch (_SSRayAlgorithm)
{
case 0:
{
ScreenSpaceHiZRaymarchInput ssInput;
ZERO_INITIALIZE(ScreenSpaceHiZRaymarchInput, ssInput);
ssInput.startPositionVS = positionVS;
ssInput.startLinearDepth = posInput.linearDepth;
ssInput.dirVS = transparentRefractVVS;
ssInput.projectionMatrix = UNITY_MATRIX_P;
ssInput.bufferSize = depthSize;
ssInput.minLevel = 0;
ssInput.maxLevel = int(_PyramidDepthMipSize.z);
#if SSRAY_REFRACTION_HIZ
ScreenSpaceHiZRaymarchInput ssInput;
ZERO_INITIALIZE(ScreenSpaceHiZRaymarchInput, ssInput);
ssInput.startPositionVS = positionVS;
ssInput.startLinearDepth = posInput.linearDepth;
ssInput.dirVS = transparentRefractVVS;
ssInput.projectionMatrix = UNITY_MATRIX_P;
ssInput.bufferSize = depthSize;
ssInput.minLevel = 0;
ssInput.maxLevel = int(_PyramidDepthMipSize.z);
ssInput.writeStepDebug = !any(int2(_MouseClickPixelCoord.xy) - int2(posInput.positionSS));
ssInput.writeStepDebug = !any(int2(_MouseClickPixelCoord.xy) - int2(posInput.positionSS));
hitSuccessful = ScreenSpaceHiZRaymarch(ssInput, hit);
break;
}
case 1:
{
ScreenSpaceLinearRaymarchInput ssInput;
ZERO_INITIALIZE(ScreenSpaceLinearRaymarchInput, ssInput);
hitSuccessful = ScreenSpaceHiZRaymarch(ssInput, hit);
#elif SSRAY_REFRACTION_LINEAR
ScreenSpaceLinearRaymarchInput ssInput;
ZERO_INITIALIZE(ScreenSpaceLinearRaymarchInput, ssInput);
ssInput.startPositionVS = positionVS;
ssInput.startLinearDepth = posInput.linearDepth;
ssInput.dirVS = transparentRefractVVS;
ssInput.projectionMatrix = UNITY_MATRIX_P;
ssInput.bufferSize = depthSize;
ssInput.startPositionVS = positionVS;
ssInput.startLinearDepth = posInput.linearDepth;
ssInput.dirVS = transparentRefractVVS;
ssInput.projectionMatrix = UNITY_MATRIX_P;
ssInput.bufferSize = depthSize;
ssInput.writeStepDebug = !any(int2(_MouseClickPixelCoord.xy) - int2(posInput.positionSS));
ssInput.writeStepDebug = !any(int2(_MouseClickPixelCoord.xy) - int2(posInput.positionSS));
hitSuccessful = ScreenSpaceLinearRaymarch(ssInput, hit);
break;
}
}
hitSuccessful = ScreenSpaceLinearRaymarch(ssInput, hit);
#endif
#ifdef DEBUG_DISPLAY
if (_DebugLightingMode == DEBUGLIGHTINGMODE_SCREEN_SPACE_TRACING_REFRACTION)

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader


// Transparency
[Enum(None, 0, Plane, 1, Sphere, 2)]_RefractionMode("Refraction Mode", Int) = 0
[Enum(HiZ, 0, Linear, 1)]_SSRayRefractionMethod("SS Ray Refraction Method", Int) = 0
_SSRayMinLevel ("SS Ray Min Mip Level", Int) = 1
_SSRayMaxLevel ("SS Ray Max Mip Level", Int) = 10
_Ior("Index Of Refraction", Range(1.0, 2.5)) = 1.0
_ThicknessMultiplier("Thickness Multiplier", Float) = 1.0
_TransmittanceColor("Transmittance Color", Color) = (1.0, 1.0, 1.0)

#pragma shader_feature _MATERIAL_FEATURE_CLEAR_COAT
#pragma shader_feature _MATERIAL_FEATURE_IRIDESCENCE
#pragma shader_feature _MATERIAL_FEATURE_SPECULAR_COLOR
#pragma shader_feature SSRAY_REFRACTION_HIZ SSRAY_REFRACTION_LINEAR
// enable dithering LOD crossfade
#pragma multi_compile _ LOD_FADE_CROSSFADE

5
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader


// Transparency
[Enum(None, 0, Plane, 1, Sphere, 2)]_RefractionMode("Refraction Mode", Int) = 0
[Enum(HiZ, 0, Linear, 1)]_SSRayRefractionMethod("SS Ray Refraction Method", Int) = 0
_SSRayMinLevel ("SS Ray Min Mip Level", Int) = 1
_SSRayMaxLevel ("SS Ray Max Mip Level", Int) = 10
_Ior("Index Of Refraction", Range(1.0, 2.5)) = 1.0
_ThicknessMultiplier("Thickness Multiplier", Float) = 1.0
_TransmittanceColor("Transmittance Color", Color) = (1.0, 1.0, 1.0)

#pragma shader_feature _MATERIAL_FEATURE_CLEAR_COAT
#pragma shader_feature _MATERIAL_FEATURE_IRIDESCENCE
#pragma shader_feature _MATERIAL_FEATURE_SPECULAR_COLOR
#pragma shader_feature SSRAY_REFRACTION_HIZ SSRAY_REFRACTION_LINEAR
// enable dithering LOD crossfade
#pragma multi_compile _ LOD_FADE_CROSSFADE

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipeline/RenderPipelineSettings.cs


public GlobalLightLoopSettings lightLoopSettings = new GlobalLightLoopSettings();
public ShadowInitParameters shadowInitParams = new ShadowInitParameters();
public GlobalDecalSettings decalSettings = new GlobalDecalSettings();
public int ssRayMinLevel = 2;
public int ssRayMaxLevel = 10;
}
}
正在加载...
取消
保存