浏览代码

Make improvements based on feedback

/main
Evgenii Golubev 8 年前
当前提交
60731810
共有 10 个文件被更改,包括 65 次插入56 次删除
  1. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/DefaultCommonSettings.asset
  2. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  3. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader
  4. 41
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  5. 29
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs
  6. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs
  7. 16
      Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs
  8. 9
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  9. 6
      Assets/ScriptableRenderLoop/ShaderLibrary/Hammersley.hlsl
  10. 2
      ProjectSettings/GraphicsSettings.asset

4
Assets/ScriptableRenderLoop/HDRenderPipeline/DefaultCommonSettings.asset


m_ShadowCascadeSplit0: 0.05
m_ShadowCascadeSplit1: 0.2
m_ShadowCascadeSplit2: 0.3
m_SssProfileStdDev1: {r: 0.3, g: 0.3, b: 0.3, a: 0}
m_SssProfileStdDev2: {r: 1, g: 1, b: 1, a: 0}
m_SssProfileLerpWeight: 0.5
m_SssBilateralScale: 0.1

1
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


MaterialPropertyBlock properties = new MaterialPropertyBlock();
var cmd = new CommandBuffer() { name = "Combine Subsurface Scattering" };
cmd.SetGlobalTexture("_CameraDepthTexture", m_CameraDepthStencilBufferRT);
// Perform the vertical SSS filtering pass.
properties.SetFloat("_DstBlend", (float)BlendMode.Zero); // TODO: this doesn't work for some reason...

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader


struct Attributes
{
uint vertexId : SV_VertexID;
uint vertexID : SV_VertexID;
};
struct Varyings

Varyings Vert(Attributes input)
{
Varyings output;
// Generate a triangle in homogeneous clip space, s.t.
// v0 = (-1, -1, 1), v1 = (3, -1, 1), v2 = (-1, 3, 1).
float2 uv = float2((input.vertexId << 1) & 2, input.vertexId & 2);
output.positionCS = float4(uv * 2.0 - 1.0, 1.0, 1.0);
output.positionCS = GetFullscreenTriangleVertexPosition(input.vertexID);
return output;
}

41
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader


struct Attributes
{
uint vertexId : SV_VertexID;
uint vertexID : SV_VertexID;
};
struct Varyings

Varyings Vert(Attributes input)
{
Varyings output;
// Generate a triangle in homogeneous clip space, s.t.
// v0 = (-1, -1, 1), v1 = (3, -1, 1), v2 = (-1, 3, 1).
float2 uv = float2((input.vertexId << 1) & 2, input.vertexId & 2);
output.positionCS = float4(uv * 2 - 1, 1, 1);
output.positionCS = GetFullscreenTriangleVertexPosition(input.vertexID);
return output;
}

float rawDepth = LOAD_TEXTURE2D(_CameraDepthTexture, posInput.unPositionSS).r;
float cDepth = LinearEyeDepth(rawDepth, _ZBufferParams);
float radiusScale = _FilterRadius * _DistToProjWindow / cDepth;
float centerDepth = LinearEyeDepth(rawDepth, _ZBufferParams);
float radiusScale = _FilterRadius * _DistToProjWindow / centerDepth;
// Compute the filtering direction.
float2 unitDirection = _FilterHorizontal ? float2(1, 0) : float2(0, 1);

scaledDirection *= _ScreenSize.zw;
// Take the first (central) sample.
float3 sWeight = _FilterKernel[0].rgb;
float2 sPosition = posInput.unPositionSS;
float3 sampleWeight = _FilterKernel[0].rgb;
float2 samplePosition = posInput.unPositionSS;
float3 sIrradiance = LOAD_TEXTURE2D(_IrradianceSource, sPosition).rgb;
float3 cIrradiance = sIrradiance;
float3 sampleIrradiance = LOAD_TEXTURE2D(_IrradianceSource, samplePosition).rgb;
float3 centerIrradiance = sampleIrradiance;
float3 filteredIrradiance = sIrradiance * sWeight;
float3 filteredIrradiance = sampleIrradiance * sampleWeight;
sWeight = _FilterKernel[i].rgb; // TODO: normalize weights
sPosition = posInput.positionSS + scaledDirection * _FilterKernel[i].a;
sampleWeight = _FilterKernel[i].rgb;
samplePosition = posInput.positionSS + scaledDirection * _FilterKernel[i].a;
sIrradiance = SAMPLE_TEXTURE2D_LOD(_IrradianceSource, bilinearSampler, sPosition, 0).rgb;
rawDepth = SAMPLE_TEXTURE2D_LOD(_CameraDepthTexture, bilinearSampler, sPosition, 0).r;
sampleIrradiance = SAMPLE_TEXTURE2D_LOD(_IrradianceSource, bilinearSampler, samplePosition, 0).rgb;
rawDepth = SAMPLE_TEXTURE2D_LOD(_CameraDepthTexture, bilinearSampler, samplePosition, 0).r;
float sDepth = LinearEyeDepth(rawDepth, _ZBufferParams);
float dDepth = abs(sDepth - cDepth);
float dScale = _BilateralScale * _FilterRadius * _DistToProjWindow;
float t = saturate(dDepth / dScale);
float sampleDepth = LinearEyeDepth(rawDepth, _ZBufferParams);
float depthDiff = abs(sampleDepth - centerDepth);
float scaleDiff = _BilateralScale * _FilterRadius * _DistToProjWindow;
float t = saturate(depthDiff / scaleDiff);
filteredIrradiance += lerp(sIrradiance, cIrradiance, t) * sWeight;
filteredIrradiance += lerp(sampleIrradiance, centerIrradiance, t) * sampleWeight;
}
return float4(filteredIrradiance, 1.0);

29
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs


public struct Settings
{
// Shadows
[SerializeField] float m_ShadowMaxDistance;
[SerializeField] int m_ShadowCascadeCount;
[SerializeField] float m_ShadowCascadeSplit0;
[SerializeField] float m_ShadowCascadeSplit1;
[SerializeField] float m_ShadowCascadeSplit2;
[SerializeField]
float m_ShadowMaxDistance;
[SerializeField]
int m_ShadowCascadeCount;
[SerializeField]
float m_ShadowCascadeSplit0;
[SerializeField]
float m_ShadowCascadeSplit1;
[SerializeField]
float m_ShadowCascadeSplit2;
public float shadowMaxDistance { set { m_ShadowMaxDistance = value; OnValidate(); } get { return m_ShadowMaxDistance; } }
public int shadowCascadeCount { set { m_ShadowCascadeCount = value; OnValidate(); } get { return m_ShadowCascadeCount; } }

// Subsurface scattering
[ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
[SerializeField] Color m_SssProfileStdDev1;
[ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
[SerializeField] Color m_SssProfileStdDev2;
[SerializeField] float m_SssProfileLerpWeight;
[SerializeField] float m_SssBilateralScale;
[SerializeField] [ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
Color m_SssProfileStdDev1;
[SerializeField] [ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
Color m_SssProfileStdDev2;
[SerializeField]
float m_SssProfileLerpWeight;
[SerializeField]
float m_SssBilateralScale;
public Color sssProfileStdDev1 { set { m_SssProfileStdDev1 = value; OnValidate(); } get { return m_SssProfileStdDev1; } }
public Color sssProfileStdDev2 { set { m_SssProfileStdDev2 = value; OnValidate(); } get { return m_SssProfileStdDev2; } }

4
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs


using System;
namespace UnityEngine.Experimental.Rendering
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[Serializable]
public class SubsurfaceScatteringProfile

// A1(v1, v2, w, x) = G1(x, v1) * (1 - w) + G1(r, v2) * w,
// A2(v1, v2, w, x, y) = A1(v1, v2, w, x) * A1(v1, v2, w, y).
// The resulting filter function is a non-Gaussian PDF.
// It is separable by design, but generally not radially symmmetric.
// It is separable by design, but generally not radially symmetric.
// Find the widest Gaussian across 3 color channels.
float maxStdDev1 = Mathf.Max(m_StdDev1.r, m_StdDev1.g, m_StdDev1.b);

16
Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs


return renderContext;
}
static Mesh m_ScreenSpaceTriangle = null;
static Mesh m_FullscreenTriangle = null;
static Mesh GetScreenSpaceTriangle()
static Mesh GetFullscreenTriangle()
if (!m_ScreenSpaceTriangle)
if (!m_FullscreenTriangle)
m_ScreenSpaceTriangle = new Mesh
m_FullscreenTriangle = new Mesh
{
// Note: neither the vertex nor the index data is actually used if the vertex shader computes vertices
// using 'SV_VertexID'. However, there is currently no way to bind NULL vertex or index buffers.

}
return m_ScreenSpaceTriangle;
return m_FullscreenTriangle;
}
// Draws a full screen triangle as a faster alternative to drawing a full-screen quad.

{
SetupMaterialHDCamera(camera, material);
commandBuffer.SetRenderTarget(colorBuffer);
commandBuffer.DrawMesh(GetScreenSpaceTriangle(), Matrix4x4.identity, material, 0, shaderPassID, properties);
commandBuffer.DrawMesh(GetFullscreenTriangle(), Matrix4x4.identity, material, 0, shaderPassID, properties);
}
// Draws a full screen triangle as a faster alternative to drawing a full-screen quad.

{
SetupMaterialHDCamera(camera, material);
commandBuffer.SetRenderTarget(colorBuffer, depthStencilBuffer);
commandBuffer.DrawMesh(GetScreenSpaceTriangle(), Matrix4x4.identity, material, 0, shaderPassID, properties);
commandBuffer.DrawMesh(GetFullscreenTriangle(), Matrix4x4.identity, material, 0, shaderPassID, properties);
}
// Draws a full screen triangle as a faster alternative to drawing a full-screen quad.

{
SetupMaterialHDCamera(camera, material);
commandBuffer.SetRenderTarget(colorBuffers, depthStencilBuffer);
commandBuffer.DrawMesh(GetScreenSpaceTriangle(), Matrix4x4.identity, material, 0, shaderPassID, properties);
commandBuffer.DrawMesh(GetFullscreenTriangle(), Matrix4x4.identity, material, 0, shaderPassID, properties);
}
// Draws a full screen triangle as a faster alternative to drawing a full-screen quad.

9
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


posInput.positionWS += V * depthOffsetVS;
}
// Generates a triangle in homogeneous clip space, s.t.
// v0 = (-1, -1, 1), v1 = (3, -1, 1), v2 = (-1, 3, 1).
float4 GetFullscreenTriangleVertexPosition(uint vertexID)
{
float2 uv = float2((vertexID << 1) & 2, vertexID & 2);
return float4(uv * 2.0 - 1.0, 1.0, 1.0);
}
#endif // UNITY_COMMON_INCLUDED

6
Assets/ScriptableRenderLoop/ShaderLibrary/Hammersley.hlsl


#endif
}
float RadicalInverse_VdC(uint bits)
float VanDerCorputBase2(uint i)
return float(ReverseBits32(bits)) * 2.3283064365386963e-10; // 0x100000000
return float(ReverseBits32(i)) * 2.3283064365386963e-10; // 0x100000000
return float2(float(i) / float(sequenceLength), RadicalInverse_VdC(i));
return float2(float(i) / float(sequenceLength), VanDerCorputBase2(i));
}
static const float2 k_Hammersley2dSeq16[] = {

2
ProjectSettings/GraphicsSettings.asset


m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
m_CustomRenderPipeline: {fileID: 11400000, guid: b9f70be9ae966df448c8d09888d77fd0,
m_CustomRenderPipeline: {fileID: 11400000, guid: e185fecca3c73cd47a09f1092663ef32,
type: 2}
m_TransparencySortMode: 0
m_TransparencySortAxis: {x: 0, y: 0, z: 1}

正在加载...
取消
保存