浏览代码

Merge remote-tracking branch 'origin/master' into HDRP_GraphicTests

/main
Remy 7 年前
当前提交
3d76f69e
共有 34 个文件被更改,包括 262 次插入103 次删除
  1. 14
      ScriptableRenderPipeline/Core/CoreRP/CoreUtils.cs
  2. 23
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Packing.hlsl
  3. 2
      ScriptableRenderPipeline/Core/package.json
  4. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDAdditionalCameraData.cs
  5. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.cs
  6. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl
  7. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs
  8. 36
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebugPanel.cs
  9. 18
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalProjectorComponent.cs
  10. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalSystem.cs
  11. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs
  12. 56
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  13. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  14. 15
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionSystemInternal.cs
  15. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs
  16. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs.hlsl
  17. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.hlsl
  18. 21
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/DecalUtilities.hlsl
  19. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs
  20. 68
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  21. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
  22. 17
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassDBuffer.hlsl
  23. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassForward.hlsl
  24. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassForwardUnlit.hlsl
  25. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassGBuffer.hlsl
  26. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassLightTransport.hlsl
  27. 4
      ScriptableRenderPipeline/HDRenderPipeline/package.json
  28. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandard.shader
  29. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader
  30. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardTerrain.shader
  31. 1
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardUnlit.shader
  32. 4
      ScriptableRenderPipeline/LightweightPipeline/package.json
  33. 2
      ScriptableRenderPipeline/master-package.json
  34. 1
      TestbedPipelines/BasicRenderPipeline/BasicRenderPipelineShader.shader

14
ScriptableRenderPipeline/Core/CoreRP/CoreUtils.cs


mesh.triangles = triangles;
return mesh;
}
public static void ResizeHTile(ref RenderTexture hTile, ref RenderTargetIdentifier hTileRT, RenderTextureDescriptor desc)
{
// We must use a RenderTexture and not GetTemporaryRT() as currently Unity only aloow to bind a RenderTexture for a UAV in a pixel shader
// We use 8x8 tiles in order to match the native GCN HTile as closely as possible.
desc.width = (desc.width + 7) / 8;
desc.height = (desc.height + 7) / 8;
// TODO: This fails allocation with MSAA enabled?
hTile = CreateRenderTexture(desc, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Linear); // DXGI_FORMAT_R8_UINT is not supported by Unity
hTile.filterMode = FilterMode.Point;
hTile.enableRandomWrite = true;
hTile.Create();
hTileRT = new RenderTargetIdentifier(hTile);
}
}
}

23
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Packing.hlsl


return PackShort(cb);
}
// Pack float2 (each of 12 bit) in 888
real3 PackFloat2To888(real2 f)
{
uint2 i = (uint2)(f * 4095.5);
uint2 hi = i >> 8;
uint2 lo = i & 255;
// 8 bit in lo, 4 bit in hi
uint3 cb = uint3(lo, hi.x | (hi.y << 4));
return cb / 255.0;
}
// Unpack 2 float of 12bit packed into a 888
real2 Unpack888ToFloat2(real3 x)
{
uint3 i = (uint3)(x * 255.0);
// 8 bit in lo, 4 bit in hi
uint hi = i.z >> 4;
uint lo = i.z & 15;
uint2 cb = i.xy | uint2(lo << 8, hi << 8);
return cb / 4095.0;
}
#endif // SHADER_API_GLES
#endif // UNITY_PACKING_INCLUDED

2
ScriptableRenderPipeline/Core/package.json


{
"name": "com.unity.render-pipelines.core",
"description": "Core library for Unity render pipelines.",
"version": "0.1.27",
"version": "0.1.28",
"unity": "2018.1",
"dependencies": {
"com.unity.postprocessing": "0.1.8"

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDAdditionalCameraData.cs


{
// Note that we register m_FrameSettingsRuntime, so manipulating it in the Debug windows
// doesn't affect the serialized version
if (m_camera.cameraType != CameraType.Preview)
if (m_camera.cameraType != CameraType.Preview && m_camera.cameraType != CameraType.Reflection)
{
FrameSettings.RegisterDebug(m_camera.name, GetFrameSettings());
}

{
if (m_IsDebugRegistered)
{
if (m_camera.cameraType != CameraType.Preview)
if (m_camera.cameraType != CameraType.Preview && m_camera.cameraType != CameraType.Reflection)
{
FrameSettings.UnRegisterDebug(m_CameraRegisterName);
}

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


public static string kShadowMinValueDebug = "Shadow Range Min Value";
public static string kShadowMaxValueDebug = "Shadow Range Max Value";
public static string kLightingDebugMode = "Lighting Debug Mode";
public static string kOverrideAlbedoDebug = "Override Albedo";
public static string kOverrideAlbedoValueDebug = "Override Albedo Value";
public static string kOverrideSmoothnessValueDebug = "Override Smoothness Value";
public static string kOverrideSmoothnessValueDebug = "Override Smoothness Value";
public static string kOverrideNormalDebug = "Override normal";
public static string kDebugLightingAlbedo = "Debug Lighting Albedo";
public static string kFullScreenDebugMode = "Fullscreen Debug Mode";
public static string kFullScreenDebugMip = "Fullscreen Debug Mip";
public static string kDisplaySkyReflectionDebug = "Display Sky Reflection";

DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, DebugLightingMode>(kLightingDebugMode, () => lightingDebugSettings.debugLightingMode, (value) => SetDebugLightingMode((DebugLightingMode)value));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>(kOverrideSmoothnessDebug, () => lightingDebugSettings.overrideSmoothness, (value) => lightingDebugSettings.overrideSmoothness = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kOverrideSmoothnessValueDebug, () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, DebugItemFlag.None, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, Color>(kDebugLightingAlbedo, () => lightingDebugSettings.debugLightingAlbedo, (value) => lightingDebugSettings.debugLightingAlbedo = (Color)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>(kOverrideAlbedoDebug, () => lightingDebugSettings.overrideAlbedo, (value) => lightingDebugSettings.overrideAlbedo = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, Color>(kOverrideAlbedoValueDebug, () => lightingDebugSettings.overrideAlbedoValue, (value) => lightingDebugSettings.overrideAlbedoValue = (Color)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>(kOverrideNormalDebug, () => lightingDebugSettings.overrideNormal, (value) => lightingDebugSettings.overrideNormal = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>("Lighting", kDisplaySkyReflectionDebug, () => lightingDebugSettings.displaySkyReflection, (value) => lightingDebugSettings.displaySkyReflection = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>(kSkyReflectionMipmapDebug, () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, DebugItemFlag.None, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, LightLoop.TileClusterDebug>(kTileClusterDebug,() => lightingDebugSettings.tileClusterDebug, (value) => lightingDebugSettings.tileClusterDebug = (LightLoop.TileClusterDebug)value);

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl


int _DebugLightingMode; // Match enum DebugLightingMode
int _DebugViewMaterial; // Contain the id (define in various materialXXX.cs.hlsl) of the property to display
int _DebugMipMapMode; // Match enum DebugMipMapMode
float4 _DebugLightingAlbedo; // xyz = albedo for diffuse, w unused
float4 _DebugLightingAlbedo; // x == bool override, yzw = albedo for diffuse
float4 _DebugLightingNormal; // x == bool override
float4 _MousePixelCoord; // xy unorm, zw norm
float _DebugEnvironmentProxyDepthScale;
CBUFFER_END

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebug.cs


{
public bool IsDebugDisplayEnabled()
{
return debugLightingMode != DebugLightingMode.None;
return debugLightingMode != DebugLightingMode.None || overrideSmoothness || overrideAlbedo || overrideNormal;
}
public DebugLightingMode debugLightingMode = DebugLightingMode.None;

public bool overrideSmoothness = false;
public float overrideSmoothnessValue = 0.5f;
public Color debugLightingAlbedo = new Color(0.5f, 0.5f, 0.5f);
public bool overrideAlbedo = false;
public Color overrideAlbedoValue = new Color(0.5f, 0.5f, 0.5f);
public bool overrideNormal = false;
public bool displaySkyReflection = false;
public float skyReflectionMipmap = 0.0f;

36
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/LightingDebugPanel.cs


lightingDebugModeItem.handler.OnEditorGUI();
switch ((DebugLightingMode)lightingDebugModeItem.GetValue())
{
case DebugLightingMode.SpecularLighting:
{
EditorGUI.indentLevel++;
DebugItem overrideSmoothnessItem = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideSmoothnessDebug);
overrideSmoothnessItem.handler.OnEditorGUI();
if ((bool)overrideSmoothnessItem.GetValue())
{
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideSmoothnessValueDebug).handler.OnEditorGUI();
}
EditorGUI.indentLevel--;
break;
}
case DebugLightingMode.DiffuseLighting:
{
EditorGUI.indentLevel++;
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kDebugLightingAlbedo).handler.OnEditorGUI();
EditorGUI.indentLevel--;
break;
}
case DebugLightingMode.EnvironmentProxyVolume:
{
++EditorGUI.indentLevel;

}
}
DebugItem overrideSmoothnessItem = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideSmoothnessDebug);
overrideSmoothnessItem.handler.OnEditorGUI();
if ((bool)overrideSmoothnessItem.GetValue())
{
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideSmoothnessValueDebug).handler.OnEditorGUI();
}
DebugItem overrideAlbedoItem = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideAlbedoDebug);
overrideAlbedoItem.handler.OnEditorGUI();
if ((bool)overrideAlbedoItem.GetValue())
{
m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideAlbedoValueDebug).handler.OnEditorGUI();
}
DebugItem overrideNormalItem = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kOverrideNormalDebug);
overrideNormalItem.handler.OnEditorGUI();
var fullScreenDebugModeHandler = m_DebugPanel.GetDebugItem(DebugDisplaySettings.kFullScreenDebugMode);
fullScreenDebugModeHandler.handler.OnEditorGUI();

18
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalProjectorComponent.cs


DecalSystem.instance.RemoveDecal(this);
}
// Declare the method signature of the delegate to call.
public delegate void OnMaterialChangeDelegate();
// Declare the event to which editor code will hook itself.
public event OnMaterialChangeDelegate OnMaterialChange;
public void OnValidate()
{
// handle material changes

m_Material = tempMaterial;
DecalSystem.instance.AddDecal(this);
m_OldMaterial = m_Material;
// notify the editor that material has changed so it can update the shader foldout
if (OnMaterialChange != null)
{
OnMaterialChange();
}
}
if (m_Material != null)

public bool IsValid()
{
// don't draw if no material or if material is the default decal material (empty)
var hdrp = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
if ((hdrp != null) && (m_Material == hdrp.GetDefaultDecalMaterial()))
return false;
return true;
}
}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalSystem.cs


decalRotation.m02 = y0;
decalRotation.m12 = y1;
decalRotation.m22 = y2;
m_CachedNormalToWorld[decal.CullIndex] = decalRotation;
m_BoundingSpheres[decal.CullIndex] = GetDecalProjectBoundingSphere(m_CachedTransforms[decal.CullIndex]);

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Decal/DecalProjectorComponentEditor.cs


// Create an instance of the MaterialEditor
m_DecalProjectorComponent = (DecalProjectorComponent)target;
m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
m_DecalProjectorComponent.OnMaterialChange += OnMaterialChange;
private void OnDisable()
{
m_DecalProjectorComponent.OnMaterialChange -= OnMaterialChange;
}
public void OnMaterialChange()
{
// Update material editor with the new material
m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
}
public override void OnInspectorGUI()
{

56
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


RenderTargetIdentifier[] m_ColorMRTs;
RenderTargetIdentifier[] m_RTIDs = new RenderTargetIdentifier[k_MaxDbuffer];
RenderTexture m_HTile;
RenderTargetIdentifier m_HTileRT;
public void InitDBuffers(RenderTextureDescriptor rtDesc, CommandBuffer cmd)
{
dbufferCount = Decal.GetMaterialDBufferCount();

return m_ColorMRTs;
}
public void ClearNormalTarget(Color clearColor, CommandBuffer cmd)
public void ClearNormalTargetAndHTile(Color clearColor, CommandBuffer cmd)
CoreUtils.SetRenderTarget(cmd, m_HTileRT, ClearFlag.Color, CoreUtils.clearColorAllBlack);
public void SetHTile(int bindSlot, CommandBuffer cmd)
{
cmd.SetRandomWriteTarget(bindSlot, m_HTile);
}
public void UnSetHTile(CommandBuffer cmd)
{
cmd.ClearRandomWriteTargets();
}
}
public void Resize(HDCamera camera)
{
CoreUtils.ResizeHTile(ref m_HTile, ref m_HTileRT, camera.renderTextureDesc);
}
}

m_VolumetricLightingModule.Build(asset);
m_DebugDisplaySettings.RegisterDebug();
#if UNITY_EDITOR
// We don't need the debug of Default camera at runtime (each camera have its own debug settings)
#endif
m_DebugColorPickerRT = HDShaderIDs._DebugColorPickerTexture;
m_DebugFullScreenTempRT = HDShaderIDs._DebugFullScreenTexture;

var texHeight = desc.height;
var sampleCount = desc.msaaSamples;
bool resolutionChanged = (texWidth != m_CurrentWidth) ||
(texHeight != m_CurrentHeight) ||
bool resolutionChanged = (texWidth != m_CurrentWidth) ||
(texHeight != m_CurrentHeight) ||
if (m_FrameSettings.enableDBuffer)
{
m_DbufferManager.Resize(hdCamera);
}
if (m_FrameSettings.enableSubsurfaceScattering)
{

m_ShadowSettings.maxShadowDistance = shadowSettings.maxShadowDistance;
//m_ShadowSettings.directionalLightNearPlaneOffset = commonSettings.shadowNearPlaneOffset;
m_ShadowSettings.enabled = m_FrameSettings.enableShadow;
}
public void ConfigureForShadowMask(bool enableBakeShadowMask, CommandBuffer cmd)

{
// setup GBuffer for rendering
CoreUtils.SetRenderTarget(cmd, m_GbufferManager.GetGBuffers(), m_CameraDepthStencilBufferRT);
if (m_FrameSettings.enableDBuffer)
{
m_DbufferManager.SetHTile(m_GbufferManager.gbufferCount, cmd);
}
// Render opaque objects into GBuffer
if (m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled())

RenderOpaqueRenderList(cull, camera, renderContext, cmd, HDShaderPassNames.s_GBufferName, m_currentRendererConfigurationBakedLighting, HDRenderQueue.k_RenderQueue_AllOpaque, m_DepthStateOpaque);
}
}
if (m_FrameSettings.enableDBuffer)
{
m_DbufferManager.UnSetHTile(cmd);
}
}
}

// we need to do a separate clear for normals, because they are cleared to a different color
Color clearColorNormal = new Color(0.5f, 0.5f, 0.5f, 1.0f); // for normals 0.5 is neutral
m_DbufferManager.ClearNormalTarget(clearColorNormal, cmd);
m_DbufferManager.ClearNormalTargetAndHTile(clearColorNormal, cmd);
m_DbufferManager.SetHTile(m_DbufferManager.dbufferCount, cmd);
m_DbufferManager.UnSetHTile(cmd);
}
}

m_CurrentDebugDisplaySettings.fullScreenDebugMode != FullScreenDebugMode.None ||
m_CurrentDebugDisplaySettings.colorPickerDebugSettings.colorPickerMode != ColorPickerDebugMode.None)
{
m_ShadowSettings.enabled = m_FrameSettings.enableShadow;
var debugAlbedo = new Vector4(lightingDebugSettings.debugLightingAlbedo.r, lightingDebugSettings.debugLightingAlbedo.g, lightingDebugSettings.debugLightingAlbedo.b, 0.0f);
var debugAlbedo = new Vector4(lightingDebugSettings.overrideAlbedo ? 1.0f : 0.0f, lightingDebugSettings.overrideAlbedoValue.r, lightingDebugSettings.overrideAlbedoValue.g, lightingDebugSettings.overrideAlbedoValue.b);
var debugNormal = new Vector4(lightingDebugSettings.overrideNormal ? 1.0f : 0.0f, 0.0f, 0.0f, 0.0f);
cmd.SetGlobalVector(HDShaderIDs._DebugLightingAlbedo, debugAlbedo);
cmd.SetGlobalVector(HDShaderIDs._DebugLightingAlbedo, debugAlbedo);
cmd.SetGlobalVector(HDShaderIDs._DebugLightingNormal, debugNormal);
Vector2 mousePixelCoord = MousePositionDebug.instance.GetMousePosition(hdCamera.screenSize.y);
var mouseParam = new Vector4(mousePixelCoord.x, mousePixelCoord.y, mousePixelCoord.x / hdCamera.screenSize.x, mousePixelCoord.y / hdCamera.screenSize.y);

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _DebugLightingMode = Shader.PropertyToID("_DebugLightingMode");
public static readonly int _DebugLightingAlbedo = Shader.PropertyToID("_DebugLightingAlbedo");
public static readonly int _DebugLightingSmoothness = Shader.PropertyToID("_DebugLightingSmoothness");
public static readonly int _DebugLightingNormal = Shader.PropertyToID("_DebugLightingNormal");
public static readonly int _AmbientOcclusionTexture = Shader.PropertyToID("_AmbientOcclusionTexture");
public static readonly int _DebugMipMapMode = Shader.PropertyToID("_DebugMipMapMode");

15
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/ReflectionSystemInternal.cs


Quaternion captureRotation;
Matrix4x4 worldToCamera, projection;
CalculateCaptureCameraProperties(probe,
out nearClipPlane, out farClipPlane,
out aspect, out fov, out clearFlags, out backgroundColor,
out worldToCamera, out projection,
CalculateCaptureCameraProperties(probe,
out nearClipPlane, out farClipPlane,
out aspect, out fov, out clearFlags, out backgroundColor,
out worldToCamera, out projection,
out capturePosition, out captureRotation, viewerCamera);
camera.farClipPlane = farClipPlane;

nearClipPlane = viewerCamera.nearClipPlane;
farClipPlane = viewerCamera.farClipPlane;
aspect = 1;
fov = probe.overrideFieldOfView
fov = probe.overrideFieldOfView
? probe.fieldOfViewOverride
: Mathf.Max(viewerCamera.fieldOfView, viewerCamera.fieldOfView * viewerCamera.aspect);
clearFlags = viewerCamera.clearFlags;

if (s_RenderCamera == null || s_RenderCamera.Equals(null))
s_RenderCamera = go.AddComponent<Camera>();
// We need to setup cameraType before adding additional camera
s_RenderCamera.cameraType = CameraType.Reflection;
s_RenderCamera.cameraType = CameraType.Reflection;
}
return s_RenderCamera;

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs


Count = 3
};
[GenerateHLSL(PackingRules.Exact)]
public enum DBufferHTileBit
{
Diffuse = 1,
Normal = 2,
Mask = 4
};
//-----------------------------------------------------------------------------
// DBuffer management
//-----------------------------------------------------------------------------

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.cs.hlsl


//
#define DBUFFERMATERIAL_COUNT (3)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Decal+DBufferHTileBit: static fields
//
#define DBUFFERHTILEBIT_DIFFUSE (1)
#define DBUFFERHTILEBIT_NORMAL (2)
#define DBUFFERHTILEBIT_MASK (4)
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Decal+DecalSurfaceData
// PackingRules = Exact
struct DecalSurfaceData

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/Decal.hlsl


UNITY_DEFINE_INSTANCED_PROP(float4x4, normalToWorld)
UNITY_INSTANCING_BUFFER_END(matrix)
RW_TEXTURE2D(float, _DecalHTile); // DXGI_FORMAT_R8_UINT is not supported by Unity
// Must be in sync with RT declared in HDRenderPipeline.cs ::Rebuild
void EncodeIntoDBuffer( DecalSurfaceData surfaceData,

21
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Decal/DecalUtilities.hlsl


{
if(_EnableDBuffer)
{
// the code in the macros, gets moved inside the conditionals by the compiler
uint mask = UnpackByte(_DecalHTile[unPositionSS / 8]);
surfaceData.baseColor.xyz = surfaceData.baseColor.xyz * decalSurfaceData.baseColor.w + decalSurfaceData.baseColor.xyz;
surfaceData.normalWS.xyz = normalize(surfaceData.normalWS.xyz * decalSurfaceData.normalWS.w + decalSurfaceData.normalWS.xyz);
surfaceData.metallic = surfaceData.metallic * decalSurfaceData.mask.w + decalSurfaceData.mask.x;
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.mask.w + decalSurfaceData.mask.y;
surfaceData.perceptualSmoothness = surfaceData.perceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
if(mask & DBUFFERHTILEBIT_DIFFUSE)
{
surfaceData.baseColor.xyz = surfaceData.baseColor.xyz * decalSurfaceData.baseColor.w + decalSurfaceData.baseColor.xyz;
}
if(mask & DBUFFERHTILEBIT_NORMAL)
{
surfaceData.normalWS.xyz = normalize(surfaceData.normalWS.xyz * decalSurfaceData.normalWS.w + decalSurfaceData.normalWS.xyz);
}
if(mask & DBUFFERHTILEBIT_MASK)
{
surfaceData.metallic = surfaceData.metallic * decalSurfaceData.mask.w + decalSurfaceData.mask.x;
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.mask.w + decalSurfaceData.mask.y;
surfaceData.perceptualSmoothness = surfaceData.perceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
}
}
}

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


public override int GetMaterialGBufferCount() { return (int)GBufferMaterial.Count; }
RenderTextureFormat[] m_RTFormat4 = { RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB2101010, RenderTextureFormat.ARGB32, RenderTextureFormat.RGB111110Float };
RenderTextureFormat[] m_RTFormat4 = { RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32, RenderTextureFormat.RGB111110Float };
RenderTextureReadWrite[] m_RTReadWrite4 = { RenderTextureReadWrite.sRGB, RenderTextureReadWrite.Linear, RenderTextureReadWrite.Linear, RenderTextureReadWrite.Linear };
public override void GetMaterialGBufferDescription(out RenderTextureFormat[] RTFormat, out RenderTextureReadWrite[] RTReadWrite)

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


#define GBUFFER_LIT_STANDARD 0
// we have not enough space (3bit) to store mat feature to have SSS and Transmission as bitmask, such why we have all variant
#define GBUFFER_LIT_SSS 1
#define GBUFFER_LIT_TRANSMISSION 2
#define GBUFFER_LIT_TRANSMISSION 2
#define GBUFFER_LIT_TRANSMISSION_SSS 3
#define GBUFFER_LIT_ANISOTROPIC 4
#define GBUFFER_LIT_IRIDESCENCE 5 // TODO

bsdfData.fresnel0 = _TransmissionTintsAndFresnel0[diffusionProfile].a;
bsdfData.thickness = _ThicknessRemaps[diffusionProfile].x + _ThicknessRemaps[diffusionProfile].y * thickness;
#if SHADEROPTIONS_USE_DISNEY_SSS
bsdfData.transmittance = ComputeTransmittanceDisney( _ShapeParams[diffusionProfile].rgb,
_TransmissionTintsAndFresnel0[diffusionProfile].rgb,

reflectivity = preFGD.y;
}
void ApplyDebugToSurfaceData(inout SurfaceData surfaceData)
// This function is use to help with debugging and must be implemented by any lit material
// Implementer must take into account what are the current override component and
// adjust SurfaceData properties accordingdly
void ApplyDebugToSurfaceData(float3x3 worldToTangent, inout SurfaceData surfaceData)
if (_DebugLightingMode == DEBUGLIGHTINGMODE_SPECULAR_LIGHTING)
// Override value if requested by user
// this can be use also in case of debug lighting mode like diffuse only
bool overrideAlbedo = _DebugLightingAlbedo.x != 0.0;
bool overrideSmoothness = _DebugLightingSmoothness.x != 0.0;
bool overrideNormal = _DebugLightingNormal.x != 0.0;
if (overrideAlbedo)
{
float3 overrideAlbedoValue = _DebugLightingAlbedo.yzw;
surfaceData.baseColor = overrideAlbedoValue;
}
if (overrideSmoothness)
bool overrideSmoothness = _DebugLightingSmoothness.x != 0.0;
if (overrideSmoothness)
{
surfaceData.perceptualSmoothness = overrideSmoothnessValue;
}
surfaceData.perceptualSmoothness = overrideSmoothnessValue;
if (_DebugLightingMode == DEBUGLIGHTINGMODE_DIFFUSE_LIGHTING)
if (overrideNormal)
surfaceData.baseColor = _DebugLightingAlbedo.xyz;
float overrideNormalValue = _DebugLightingNormal.yzw;
surfaceData.normalWS = worldToTangent[2];
}
#endif
}

BSDFData ConvertSurfaceDataToBSDFData(SurfaceData surfaceData)
{
ApplyDebugToSurfaceData(surfaceData);
BSDFData bsdfData;
ZERO_INITIALIZE(BSDFData, bsdfData);

out GBufferType3 outGBuffer3
)
{
ApplyDebugToSurfaceData(surfaceData);
// RT1 - 10:10:10:2
// RT1 - 8:8:8:8
// Our tangent encoding is based on our normal.
// With octahedral quad packing we get an artifact for reconstructed tangent at the center of this quad. We use rect packing instead to avoid it.
// To have better precision encode the sign of XY separately.
uint octNormalSign = (octNormalWS.x < 0.0 ? 1 : 0) | (octNormalWS.y < 0.0 ? 2 : 0);
float3 packNormalWS = PackFloat2To888(saturate(octNormalWS * 0.5 + 0.5));
outGBuffer1 = float4(PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness), abs(octNormalWS), PackInt(octNormalSign, 2));
outGBuffer1 = float4(packNormalWS, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
// RT2 - 8:8:8:8
uint materialFeatureId;

}
else // Standard
{
// In the case of standard or specular color we always convert to specular color parametrization before encoding,
// In the case of standard or specular color we always convert to specular color parametrization before encoding,
// so decoding is more efficient (it allow better optimization for the compiler and save VGPR)
// This mean that on the decode side, MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR doesn't exist anymore
materialFeatureId = GBUFFER_LIT_STANDARD;

float3 baseColor = inGBuffer0.rgb;
bsdfData.specularOcclusion = inGBuffer0.a; // Later possibly overwritten by SSS
bsdfData.perceptualRoughness = inGBuffer1.r;
float2 octNormalWS = inGBuffer1.gb;
uint octNormalSign = UnpackInt(inGBuffer1.a, 2);
octNormalWS.x = (octNormalSign & 1) ? -octNormalWS.x : octNormalWS.x;
octNormalWS.y = (octNormalSign & 2) ? -octNormalWS.y : octNormalWS.y;
bsdfData.perceptualRoughness = inGBuffer1.a;
bsdfData.normalWS = UnpackNormalOctRectEncode(octNormalWS);
float3 packNormalWS = inGBuffer1.rgb;
float2 octNormalWS = Unpack888ToFloat2(packNormalWS);
bsdfData.normalWS = UnpackNormalOctRectEncode(octNormalWS * 2.0 - 1.0);
bakeDiffuseLighting = inGBuffer3.rgb;

// Overwrite the diffusion profile/subsurfaceMask extracted by DecodeFromSSSBuffer().
// We must do this so the compiler can optimize away the read from the G-Buffer 0 to the very end (in PostEvaluateBSDF)
// Note that we don't use sssData.subsurfaceMask here. But it is still assign so we can have the information in the
// material debug view + If we require it in the future.
// Note that we don't use sssData.subsurfaceMask here. But it is still assign so we can have the information in the
// material debug view + If we require it in the future.
UnpackFloatInt8bit(inGBuffer2.b, 16, sssData.subsurfaceMask, sssData.diffusionProfile);
// Reminder: when using SSS we exchange specular occlusion and subsurfaceMask/profileID

// _preIntegratedFGD and _CubemapLD are unique for each BRDF
IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, EnvLightData lightData, BSDFData bsdfData,
PreLightData preLightData, EnvLightData lightData, BSDFData bsdfData,
int influenceShapeType, int GPUImageBasedLightingType,
inout float hierarchyWeight)
{

12
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs


public void Resize(HDCamera hdCamera)
{
// We must use a RenderTexture and not GetTemporaryRT() as currently Unity only aloow to bind a RenderTexture for a UAV in a pixel shader
// We use 8x8 tiles in order to match the native GCN HTile as closely as possible.
var desc = hdCamera.renderTextureDesc;
desc.width = (desc.width + 7) / 8;
desc.height = (desc.height + 7) / 8;
// TODO: This fails allocation with MSAA enabled?
m_HTile = CoreUtils.CreateRenderTexture(desc, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Linear); // DXGI_FORMAT_R8_UINT is not supported by Unity
m_HTile.filterMode = FilterMode.Point;
m_HTile.enableRandomWrite = true;
m_HTile.Create();
m_HTileRT = new RenderTargetIdentifier(m_HTile);
CoreUtils.ResizeHTile(ref m_HTile, ref m_HTileRT, hdCamera.renderTextureDesc);
}
public void PushGlobalParams(CommandBuffer cmd, DiffusionProfileSettings sssParameters, FrameSettings frameSettings)

17
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassDBuffer.hlsl


float3x3 decalToWorld = (float3x3)UNITY_ACCESS_INSTANCED_PROP(matrix, normalToWorld);
GetSurfaceData(positionDS.xz, decalToWorld, surfaceData);
// have to do explicit test since compiler behavior is not defined for RW resources and discard instructions
if((all(positionDS.xyz > 0.0f) && all(1.0f - positionDS.xyz > 0.0f)))
{
uint mask = 0;
#if _COLORMAP
mask |= DBUFFERHTILEBIT_DIFFUSE;
#endif
#if _NORMALMAP
mask |= DBUFFERHTILEBIT_NORMAL;
#endif
#if _MASKMAP
mask |= DBUFFERHTILEBIT_MASK;
#endif
uint oldVal = UnpackByte(_DecalHTile[posInput.positionSS.xy / 8]);
oldVal |= mask;
_DecalHTile[posInput.positionSS.xy / 8] = PackByte(oldVal);
}
ENCODE_INTO_DBUFFER(surfaceData, outDBuffer);
}

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassForward.hlsl


BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
#ifdef DEBUG_DISPLAY
ApplyDebugToSurfaceData(input.worldToTangent, surfaceData);
#endif
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassForwardUnlit.hlsl


GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
// Not lit here (but emissive is allowed)
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
// TODO: we must not access bsdfData here, it break the genericity of the code!

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassGBuffer.hlsl


BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
#ifdef DEBUG_DISPLAY
ApplyDebugToSurfaceData(input.worldToTangent, surfaceData);
#endif
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderPass/ShaderPassLightTransport.hlsl


BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
// no debug apply during light transport pass
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData);

4
ScriptableRenderPipeline/HDRenderPipeline/package.json


{
"name": "com.unity.render-pipelines.high-definition",
"description": "HD Render Pipeline for Unity.",
"version": "0.1.27",
"version": "0.1.28",
"com.unity.render-pipelines.core": "0.1.27"
"com.unity.render-pipelines.core": "0.1.28"
}
}

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandard.shader


// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED LIGHTMAP_ON
//--------------------------------------

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader


// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED LIGHTMAP_ON
//--------------------------------------

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardTerrain.shader


// -------------------------------------
// Unity defined keywords
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED LIGHTMAP_ON
#pragma multi_compile __ _TERRAIN_NORMAL_MAP

1
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardUnlit.shader


#pragma prefer_hlslcc gles
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ENABLE STEREO_MULTIVIEW_ENABLE
#pragma multi_compile_fog
#pragma shader_feature _SAMPLE_GI
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON

4
ScriptableRenderPipeline/LightweightPipeline/package.json


{
"name": "com.unity.render-pipelines.lightweight",
"description": "Lightweight Render Pipeline for Unity.",
"version": "0.1.27",
"version": "0.1.28",
"com.unity.render-pipelines.core": "0.1.27"
"com.unity.render-pipelines.core": "0.1.28"
}
}

2
ScriptableRenderPipeline/master-package.json


{
"version": "0.1.27",
"version": "0.1.28",
"unity": "2018.1",
"dependencies": {
"com.unity.postprocessing": "0.1.8"

1
TestbedPipelines/BasicRenderPipeline/BasicRenderPipelineShader.shader


#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON
#pragma shader_feature _METALLICGLOSSMAP
#include "UnityCG.cginc"
#include "UnityStandardBRDF.cginc"

正在加载...
取消
保存