浏览代码

SSAO: Stop using "Resources" directory

- Stopped using "Resources" directory and added the SSAO shader to
  HDRenderPipelineResources instead.
- Changed some file names.
/RenderPassXR_Sandbox
sebastienlagarde 8 年前
当前提交
f67f629a
共有 15 个文件被更改,包括 258 次插入20 次删除
  1. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs
  2. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset
  3. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset.meta
  4. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs
  5. 10
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AOEstimator.hlsl
  6. 99
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/NoiseFilter.hlsl
  7. 148
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.shader
  8. 9
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/Resources.meta
  9. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs.meta
  10. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs
  11. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.shader.meta
  12. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/NoiseFilter.hlsl.meta
  13. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AOEstimator.hlsl.meta
  14. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AOEstimator.hlsl

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs


public ScreenSpaceAmbientOcclusionEffect()
{}
public void Build(RenderPipelineResources renderPipelinesResources)
public void Build(RenderPipelineResources renderPipelineResources)
m_Material = Utilities.CreateEngineMaterial("Hidden/HDPipeline/ScreenSpace/AmbientOcclusion");
m_Material = Utilities.CreateEngineMaterial(renderPipelineResources.screenSpaceAmbientOcclusionShader);
m_Material.hideFlags = HideFlags.DontSave;
}

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset


m_EditorClassIdentifier:
debugDisplayLatlongShader: {fileID: 4800000, guid: c1d1d149a043a5349ba367da6c2051ba,
type: 3}
debugDisplayShadowMapShader: {fileID: 4800000, guid: ee25e539f5594f44085e0a9000c15d9b,
type: 3}
debugViewMaterialGBufferShader: {fileID: 4800000, guid: 439949ea1bfa91b4ba0d04269fcde33d,
type: 3}
debugViewTilesShader: {fileID: 4800000, guid: c7c2bd17b06ceb4468e14081aaf1b96f,

deferredShader: {fileID: 4800000, guid: 00dd221e34a6ab349a1196b0f2fab693, type: 3}
screenSpaceAmbientOcclusionShader: {fileID: 4800000, guid: cf0db7f5267ad944dbf4326b7102c9ca,
type: 3}
clearDispatchIndirectShader: {fileID: 7200000, guid: fc1f553acb80a6446a32d33e403d0656,
type: 3}
buildDispatchIndirectShader: {fileID: 7200000, guid: 4eb1b418be7044c40bb5200496c50f14,

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset.meta


fileFormatVersion: 2
guid: 42086e81f4f0c724f96f7f09cc995354
timeCreated: 1496162188
timeCreated: 1497258182
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs


instance.debugFullScreenShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugFullScreen.Shader");
instance.deferredShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Deferred.Shader");
instance.screenSpaceAmbientOcclusionShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.Shader");
instance.clearDispatchIndirectShader = UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/cleardispatchindirect.compute");
instance.buildDispatchIndirectShader = UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>("Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/builddispatchindirect.compute");

// Lighting resources
public Shader deferredShader;
public Shader screenSpaceAmbientOcclusionShader;
// Lighting tile pass resources
public ComputeShader clearDispatchIndirectShader;

10
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AOEstimator.hlsl


#ifndef UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_ESTIMATION
#define UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_ESTIMATION
#include "CommonAmbientOcclusion.hlsl"
#ifndef UNITY_HDRENDERPIPELINE_SSAO_AOESTIMATOR
#define UNITY_HDRENDERPIPELINE_SSAO_AOESTIMATOR
half _Intensity;
float _Radius;

}
// Distance-based AO estimator based on Morgan 2011 http://goo.gl/2iz3P
half4 Frag(Varyings input) : SV_Target
half4 FragAO(Varyings input) : SV_Target
{
PositionInputs posInput = GetPositionInput(input.positionCS.xy / _Downsample, _ScreenSize.zw);

return PackAONormal(ao, norm_o);
}
#endif // UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_ESTIMATION
#endif // UNITY_HDRENDERPIPELINE_SSAO_AOESTIMATOR

99
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/NoiseFilter.hlsl


#ifndef UNITY_HDRENDERPIPELINE_SSAO_NOISEFILTER
#define UNITY_HDRENDERPIPELINE_SSAO_NOISEFILTER
half _Downsample;
TEXTURE2D(_MainTex);
SAMPLER2D(sampler_MainTex);
float4 _MainTex_TexelSize;
half4 FragSeparableFilter(Varyings input) : SV_Target
{
// input.positionCS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
float2 uv = posInput.positionSS;
#if defined(SSAO_NOISEFILTER_HORIZONTAL)
// Horizontal pass: Always use 2 texels interval to match to
// the dither pattern.
float2 delta = float2(_MainTex_TexelSize.x * 2.0, 0.0);
#else // SSAO_NOISEFILTER_VERTICAL
// Vertical pass: Apply _Downsample to match to the dither
// pattern in the original occlusion buffer.
float2 delta = float2(0.0, _MainTex_TexelSize.y / _Downsample * 2.0);
#endif
// 5-tap Gaussian with linear sampling.
half4 p0 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv);
half4 p1a = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv - delta * 1.3846153846);
half4 p1b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + delta * 1.3846153846);
half4 p2a = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv - delta * 3.2307692308);
half4 p2b = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + delta * 3.2307692308);
#if defined(SSAO_NOISEFILTER_CENTERNORMAL)
half3 n0 = SampleNormal(posInput.unPositionSS);
#else
half3 n0 = GetPackedNormal(p0);
#endif
// Geometry-aware weighting.
half w0 = 0.2270270270;
half w1a = CompareNormal(n0, GetPackedNormal(p1a)) * 0.3162162162;
half w1b = CompareNormal(n0, GetPackedNormal(p1b)) * 0.3162162162;
half w2a = CompareNormal(n0, GetPackedNormal(p2a)) * 0.0702702703;
half w2b = CompareNormal(n0, GetPackedNormal(p2b)) * 0.0702702703;
half s;
s = GetPackedAO(p0) * w0;
s += GetPackedAO(p1a) * w1a;
s += GetPackedAO(p1b) * w1b;
s += GetPackedAO(p2a) * w2a;
s += GetPackedAO(p2b) * w2b;
s /= w0 + w1a + w1b + w2a + w2b;
return PackAONormal(s, n0);
}
half4 FragFinalFilter(Varyings input) : SV_Target0
{
// input.positionCS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
float2 uv = posInput.positionSS;
float2 delta = _MainTex_TexelSize.xy / _Downsample; // TODO: is it correct, we have already bilateral upsample here ?
// 5-tap box blur filter.
half4 p0 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv);
half4 p1 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + float2(-delta.x, -delta.y));
half4 p2 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + float2(+delta.x, -delta.y));
half4 p3 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + float2(-delta.x, +delta.y));
half4 p4 = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv + float2(+delta.x, +delta.y));
half3 n0 = GetPackedNormal(p0);
// Geometry-aware weighting.
half w0 = 1.0;
half w1 = CompareNormal(n0, GetPackedNormal(p1));
half w2 = CompareNormal(n0, GetPackedNormal(p2));
half w3 = CompareNormal(n0, GetPackedNormal(p3));
half w4 = CompareNormal(n0, GetPackedNormal(p4));
half ao;
ao = GetPackedAO(p0) * w0;
ao += GetPackedAO(p1) * w1;
ao += GetPackedAO(p2) * w2;
ao += GetPackedAO(p3) * w3;
ao += GetPackedAO(p4) * w4;
ao /= w0 + w1 + w2 + w3 + w4;
// Note: When we ImageLoad outside of texture size, the value returned by Load is 0.
// We use this property to have a neutral value for AO that doesn't consume a sampler and work also with compute shader (i.e use ImageLoad)
// We store inverse AO so neutral is black. So either we sample inside or outside the texture it return 0 in case of neutral
return half4(ao, 0, 0, 0); // <= we don't invert ao here but when we sample the texture for reasons explain above
}
#endif // UNITY_HDRENDERPIPELINE_SSAO_NOISEFILTER

148
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.shader


Shader "Hidden/HDPipeline/Lighting/ScreenSpaceAmbientOcclusion"
{
HLSLINCLUDE
#include "../../../ShaderLibrary/Common.hlsl"
#include "../../ShaderConfig.cs.hlsl"
#include "../../ShaderVariables.hlsl"
#define UNITY_MATERIAL_LIT // Needs to be defined before including Material.hlsl
#include "../../Material/Material.hlsl"
DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
// The constant below determines the contrast of occlusion. This allows
// users to control over/under occlusion. At the moment, this is not exposed
// to the editor because it's rarely useful.
static const float kContrast = 0.6;
// The constant below controls the geometry-awareness of the bilateral
// filter. The higher value, the more sensitive it is.
static const float kGeometryCoeff = 0.8;
// The constants below are used in the AO estimator. Beta is mainly used
// for suppressing self-shadowing noise, and Epsilon is used to prevent
// calculation underflow. See the paper (Morgan 2011 http://goo.gl/2iz3P)
// for further details of these constants.
static const float kBeta = 0.002;
// A small value used for avoiding self-occlusion.
static const float kEpsilon = 1e-6;
// Interleaved gradient function from Jimenez 2014 http://goo.gl/eomGso
float GradientNoise(float2 uv)
{
uv = floor(uv * _ScreenParams.xy);
float f = dot(float2(0.06711056, 0.00583715), uv);
return frac(52.9829189 * frac(f));
}
// Check if the depth value is valid.
bool CheckDepth(float rawDepth)
{
#if defined(UNITY_REVERSED_Z)
return rawDepth > 0.00001;
#else
return rawDepth < 0.99999;
#endif
}
// AO/normal packed format conversion
half4 PackAONormal(half ao, half3 n)
{
return half4(ao, n * 0.5 + 0.5);
}
half GetPackedAO(half4 p)
{
return p.x;
}
half3 GetPackedNormal(half4 p)
{
return p.yzw * 2.0 - 1.0;
}
half3 SampleNormal(uint2 unPositionSS)
{
float3 unused;
BSDFData bsdfData;
FETCH_GBUFFER(gbuffer, _GBufferTexture, unPositionSS);
DECODE_FROM_GBUFFER(gbuffer, 0xFFFFFFFF, bsdfData, unused);
return mul((float3x3)unity_WorldToCamera, bsdfData.normalWS);
}
// Normal vector comparer (for geometry-aware weighting)
half CompareNormal(half3 d1, half3 d2)
{
return smoothstep(kGeometryCoeff, 1.0, dot(d1, d2));
}
// Default vertex shader
struct Attributes
{
uint vertexID : SV_VertexID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
return output;
}
ENDHLSL
SubShader
{
Cull Off ZWrite Off ZTest Always
// 0: Ambient occlusion estimation
Pass
{
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragAO
#include "AOEstimator.hlsl"
ENDHLSL
}
// 1: Denoising (horizontal pass)
Pass
{
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragSeparableFilter
#define SSAO_NOISEFILTER_HORIZONTAL
#define SSAO_NOISEFILTER_CENTERNORMAL
#include "NoiseFilter.hlsl"
ENDHLSL
}
// 2: Denoising (vertical pass)
Pass
{
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragSeparableFilter
#define SSAO_NOISEFILTER_VERTICAL
#include "NoiseFilter.hlsl"
ENDHLSL
}
// 3: Final filtering
Pass
{
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragFinalFilter
#include "NoiseFilter.hlsl"
ENDHLSL
}
}
}

9
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/Resources.meta


fileFormatVersion: 2
guid: db071dd34a7fcd9409bfdbedc8296e3b
folderAsset: yes
timeCreated: 1494887925
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AmbientOcclusion.cs.meta → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs.meta

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AmbientOcclusion.cs → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/Resources/AmbientOcclusion.shader.meta → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.shader.meta

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/Resources/Denoising.hlsl.meta → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/NoiseFilter.hlsl.meta

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/Resources/Estimation.hlsl.meta → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AOEstimator.hlsl.meta

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/Resources/Estimation.hlsl → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AOEstimator.hlsl

正在加载...
取消
保存