Keijiro Takahashi
8 年前
当前提交
2a5a3d5c
共有 27 个文件被更改,包括 715 次插入 和 0 次删除
-
5Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
-
9Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion.meta
-
18Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/AOSettings.asset
-
9Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/AOSettings.asset.meta
-
9Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Editor.meta
-
56Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Editor/AmbientOcclusionSettingsEditor.cs
-
12Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Editor/AmbientOcclusionSettingsEditor.cs.meta
-
9Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Runtime.meta
-
89Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Runtime/AmbientOcclusionContext.cs
-
12Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Runtime/AmbientOcclusionContext.cs.meta
-
26Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Runtime/AmbientOcclusionSettings.cs
-
13Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Runtime/AmbientOcclusionSettings.cs.meta
-
9Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Shaders.meta
-
51Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Shaders/AmbientOcclusion.shader
-
9Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Shaders/AmbientOcclusion.shader.meta
-
153Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Shaders/Common.hlsl
-
9Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Shaders/Common.hlsl.meta
-
54Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Shaders/Composition.hlsl
-
9Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Shaders/Composition.hlsl.meta
-
61Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Shaders/Denoising.hlsl
-
9Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Shaders/Denoising.hlsl.meta
-
75Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Shaders/Estimation.hlsl
-
9Assets/ScriptableRenderPipeline/HDRenderPipeline/AmbientOcclusion/Shaders/Estimation.hlsl.meta
|
|||
fileFormatVersion: 2 |
|||
guid: dfbd1e12822bf6f4695aedb562176965 |
|||
folderAsset: yes |
|||
timeCreated: 1494634490 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 3b6f679b62de9f94bbdc6a8acce5e110, type: 3} |
|||
m_Name: AOSettings |
|||
m_EditorClassIdentifier: |
|||
intensity: 1 |
|||
radius: 0.5 |
|||
sampleCount: 8 |
|||
downsampling: 1 |
|||
m_aoShader: {fileID: 4800000, guid: cf0db7f5267ad944dbf4326b7102c9ca, type: 3} |
|
|||
fileFormatVersion: 2 |
|||
guid: fcc5323b0ecc350428972c61f4780b54 |
|||
timeCreated: 1494891906 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
mainObjectFileID: 11400000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 45a54c87809570549a059aaddf8ad804 |
|||
folderAsset: yes |
|||
timeCreated: 1494636845 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEditor; |
|||
using System.IO; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[CustomEditor(typeof(AmbientOcclusionSettings))] |
|||
class AmbientOcclusionSettingsEditor : Editor |
|||
{ |
|||
SerializedProperty m_intensity; |
|||
SerializedProperty m_radius; |
|||
SerializedProperty m_sampleCount; |
|||
SerializedProperty m_downsampling; |
|||
|
|||
void OnEnable() |
|||
{ |
|||
m_intensity = serializedObject.FindProperty("intensity"); |
|||
m_radius = serializedObject.FindProperty("radius"); |
|||
m_sampleCount = serializedObject.FindProperty("sampleCount"); |
|||
m_downsampling = serializedObject.FindProperty("downsampling"); |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
serializedObject.Update(); |
|||
|
|||
EditorGUILayout.PropertyField(m_intensity); |
|||
EditorGUILayout.PropertyField(m_radius); |
|||
EditorGUILayout.PropertyField(m_sampleCount); |
|||
EditorGUILayout.PropertyField(m_downsampling); |
|||
|
|||
serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
|
|||
[MenuItem("Assets/Create/Ambient Occlusion Settings")] |
|||
static void CreateSettings() |
|||
{ |
|||
var path = AssetDatabase.GetAssetPath(Selection.activeObject); |
|||
|
|||
if (string.IsNullOrEmpty(path)) |
|||
{ |
|||
path = "Assets"; |
|||
} |
|||
else if (Path.GetExtension(path) != "") |
|||
{ |
|||
path = path.Replace(Path.GetFileName(path), ""); |
|||
} |
|||
|
|||
var assetPath = AssetDatabase.GenerateUniqueAssetPath(path + "/AOSettings.asset"); |
|||
|
|||
var asset = CreateInstance<AmbientOcclusionSettings>(); |
|||
UnityEditor.AssetDatabase.CreateAsset(asset, assetPath); |
|||
UnityEditor.AssetDatabase.SaveAssets(); |
|||
UnityEditor.AssetDatabase.Refresh(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 28eb7eee2bd8891479835c00645b055c |
|||
timeCreated: 1494636845 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 917ee6833fe78f84db1d1694a9971a55 |
|||
folderAsset: yes |
|||
timeCreated: 1494887935 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.PostProcessing; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public sealed class AmbientOcclusionContext |
|||
{ |
|||
static class Uniforms |
|||
{ |
|||
internal static readonly int _Intensity = Shader.PropertyToID("_Intensity"); |
|||
internal static readonly int _Radius = Shader.PropertyToID("_Radius"); |
|||
internal static readonly int _Downsample = Shader.PropertyToID("_Downsample"); |
|||
internal static readonly int _SampleCount = Shader.PropertyToID("_SampleCount"); |
|||
internal static readonly int _TempTex1 = Shader.PropertyToID("_TempTex1"); |
|||
internal static readonly int _TempTex2 = Shader.PropertyToID("_TempTex2"); |
|||
internal static readonly int _CameraDepthTexture = Shader.PropertyToID("_CameraDepthTexture"); |
|||
internal static readonly int _CameraGBufferTexture1 = Shader.PropertyToID("_CameraGBufferTexture1"); |
|||
} |
|||
|
|||
AmbientOcclusionSettings m_Settings; |
|||
RenderTargetIdentifier[] m_GBufferIDs; |
|||
RenderTargetIdentifier[] m_MRT = { 0, 0 }; |
|||
PropertySheet m_Sheet; |
|||
|
|||
public AmbientOcclusionContext(AmbientOcclusionSettings settings, RenderTargetIdentifier[] gbufferIDs) |
|||
{ |
|||
m_Settings = settings; |
|||
m_GBufferIDs = gbufferIDs; |
|||
} |
|||
|
|||
public void Render(Camera camera, ScriptableRenderContext renderContext, RenderTargetIdentifier depthID) |
|||
{ |
|||
if (m_Sheet == null) |
|||
{ |
|||
var material = new Material(m_Settings.aoShader) { hideFlags = HideFlags.DontSave }; |
|||
m_Sheet = new PropertySheet(material); |
|||
} |
|||
|
|||
const RenderTextureFormat kFormat = RenderTextureFormat.ARGB32; |
|||
const RenderTextureReadWrite kRWMode = RenderTextureReadWrite.Linear; |
|||
const FilterMode kFilter = FilterMode.Bilinear; |
|||
|
|||
var width = camera.pixelWidth; |
|||
var height = camera.pixelHeight; |
|||
var downsize = m_Settings.downsampling ? 2 : 1; |
|||
|
|||
// Provide the settings via uniforms.
|
|||
m_Sheet.properties.SetFloat(Uniforms._Intensity, m_Settings.intensity); |
|||
m_Sheet.properties.SetFloat(Uniforms._Radius, m_Settings.radius); |
|||
m_Sheet.properties.SetFloat(Uniforms._Downsample, 1.0f / downsize); |
|||
m_Sheet.properties.SetFloat(Uniforms._SampleCount, m_Settings.sampleCount); |
|||
|
|||
// Start building a command buffer.
|
|||
var cmd = new CommandBuffer { name = "Ambient Occlusion" }; |
|||
cmd.SetGlobalTexture(Uniforms._CameraDepthTexture, depthID); |
|||
cmd.SetGlobalTexture(Uniforms._CameraGBufferTexture1, m_GBufferIDs[1]); |
|||
|
|||
// AO estimation.
|
|||
cmd.GetTemporaryRT(Uniforms._TempTex1, width / downsize, height / downsize, 0, kFilter, kFormat, kRWMode); |
|||
cmd.BlitFullscreenTriangle(depthID, Uniforms._TempTex1, m_Sheet, 0); |
|||
|
|||
// Denoising (horizontal pass).
|
|||
cmd.GetTemporaryRT(Uniforms._TempTex2, width, height, 0, kFilter, kFormat, kRWMode); |
|||
cmd.BlitFullscreenTriangle(Uniforms._TempTex1, Uniforms._TempTex2, m_Sheet, 1); |
|||
cmd.ReleaseTemporaryRT(Uniforms._TempTex1); |
|||
|
|||
// Denoising (vertical pass).
|
|||
cmd.GetTemporaryRT(Uniforms._TempTex1, width, height, 0, kFilter, kFormat, kRWMode); |
|||
cmd.BlitFullscreenTriangle(Uniforms._TempTex2, Uniforms._TempTex1, m_Sheet, 2); |
|||
cmd.ReleaseTemporaryRT(Uniforms._TempTex2); |
|||
|
|||
// Composite into the emission buffer.
|
|||
m_MRT[0] = m_GBufferIDs[0]; |
|||
m_MRT[1] = m_GBufferIDs[3]; |
|||
cmd.BlitFullscreenTriangle(Uniforms._TempTex1, m_MRT, depthID, m_Sheet, 3); |
|||
cmd.ReleaseTemporaryRT(Uniforms._TempTex1); |
|||
|
|||
// Register the command buffer and release it.
|
|||
renderContext.ExecuteCommandBuffer(cmd); |
|||
cmd.Dispose(); |
|||
} |
|||
|
|||
public void Cleanup() |
|||
{ |
|||
m_Sheet.Release(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d8a84f4cdff7d6e4c9864e0e606c1692 |
|||
timeCreated: 1494889441 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public sealed class AmbientOcclusionSettings : ScriptableObject |
|||
{ |
|||
[Range(0, 2)] |
|||
public float intensity = 1.0f; |
|||
|
|||
public float radius = 0.5f; |
|||
|
|||
[Range(1, 32)] |
|||
public int sampleCount = 8; |
|||
|
|||
public bool downsampling = true; |
|||
|
|||
// SSAO shader: hidden in inspector.
|
|||
[SerializeField] |
|||
Shader m_aoShader; |
|||
|
|||
public Shader aoShader |
|||
{ |
|||
get { return m_aoShader; } |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3b6f679b62de9f94bbdc6a8acce5e110 |
|||
timeCreated: 1494886884 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: |
|||
- m_aoShader: {fileID: 4800000, guid: cf0db7f5267ad944dbf4326b7102c9ca, type: 3} |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: db071dd34a7fcd9409bfdbedc8296e3b |
|||
folderAsset: yes |
|||
timeCreated: 1494887925 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Hidden/PostProcessing/AmbientOcclusion" |
|||
{ |
|||
SubShader |
|||
{ |
|||
Cull Off ZWrite Off ZTest Always |
|||
|
|||
// 0: Ambient occlusion estimation |
|||
Pass |
|||
{ |
|||
HLSLPROGRAM |
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
#include "Estimation.hlsl" |
|||
ENDHLSL |
|||
} |
|||
|
|||
// 1: Denoising (horizontal pass) |
|||
Pass |
|||
{ |
|||
HLSLPROGRAM |
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
#define AO_DENOISE_HORIZONTAL |
|||
#define AO_DENOISE_CENTER_NORMAL |
|||
#include "Denoising.hlsl" |
|||
ENDHLSL |
|||
} |
|||
|
|||
// 2: Denoising (vertical pass) |
|||
Pass |
|||
{ |
|||
HLSLPROGRAM |
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
#define AO_DENOISE_VERTICAL |
|||
#include "Denoising.hlsl" |
|||
ENDHLSL |
|||
} |
|||
|
|||
// 3: Composition |
|||
Pass |
|||
{ |
|||
Blend Zero OneMinusSrcColor, Zero OneMinusSrcAlpha |
|||
HLSLPROGRAM |
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
#include "Composition.hlsl" |
|||
ENDHLSL |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cf0db7f5267ad944dbf4326b7102c9ca |
|||
timeCreated: 1494633359 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_COMMON |
|||
#define UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_COMMON |
|||
|
|||
#include "../../../ShaderLibrary/Common.hlsl" |
|||
#include "../../../ShaderLibrary/Packing.hlsl" |
|||
|
|||
// Uniforms given from the camera. |
|||
float4x4 unity_WorldToCamera; |
|||
float4x4 unity_CameraProjection; |
|||
float4 _ZBufferParams; |
|||
float4 _ScreenParams; |
|||
|
|||
// GBuffer RT1 (10:10:8/2:2) |
|||
// Normal (RG), PerceptualRoughness (B), MaterialID (A). |
|||
TEXTURE2D(_CameraGBufferTexture1); |
|||
SAMPLER2D(sampler_CameraGBufferTexture1); |
|||
|
|||
TEXTURE2D(_CameraDepthTexture); |
|||
SAMPLER2D(sampler_CameraDepthTexture); |
|||
|
|||
// 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; |
|||
|
|||
float2 SinCos(float theta) |
|||
{ |
|||
float sn, cs; |
|||
sincos(theta, sn, cs); |
|||
return float2(sn, cs); |
|||
} |
|||
|
|||
// Pseudo random number generator with 2D coordinates |
|||
float UVRandom(float u, float v) |
|||
{ |
|||
float f = dot(float2(12.9898, 78.233), float2(u, v)); |
|||
return frac(43758.5453 * sin(f)); |
|||
} |
|||
|
|||
// 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)); |
|||
} |
|||
|
|||
// Boundary check for depth sampler |
|||
// (returns a very large value if it lies out of bounds) |
|||
float CheckBounds(float2 uv, float d) |
|||
{ |
|||
float ob = any(uv < 0) + any(uv > 1); |
|||
#if defined(UNITY_REVERSED_Z) |
|||
ob += (d <= 0.00001); |
|||
#else |
|||
ob += (d >= 0.99999); |
|||
#endif |
|||
return ob * 1e8; |
|||
} |
|||
|
|||
// 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; |
|||
} |
|||
|
|||
// Depth/normal sampling |
|||
float SampleDepth(float2 uv) |
|||
{ |
|||
float z = SAMPLE_TEXTURE2D(_CameraDepthTexture, sampler_CameraDepthTexture, uv).x; |
|||
return LinearEyeDepth(z, _ZBufferParams) + CheckBounds(uv, z); |
|||
} |
|||
|
|||
half3 SampleNormal(float2 uv) |
|||
{ |
|||
float4 packed = SAMPLE_TEXTURE2D(_CameraGBufferTexture1, sampler_CameraGBufferTexture1, uv); |
|||
|
|||
float roughness; |
|||
uint index; |
|||
UnpackFloatInt10bit(packed.z, 4.0, roughness, index); |
|||
|
|||
float3 norm; |
|||
#ifdef USE_NORMAL_TETRAHEDRON_ENCODING |
|||
norm = UnpackNormalTetraEncode(packed.xy * 2.0 - 1.0, index); |
|||
#else |
|||
packed.xy *= float2((index & 1) ? 1.0 : -1.0, (index & 2) ? 1.0 : -1.0); |
|||
norm = UnpackNormalOctEncode(packed.xy); |
|||
#endif |
|||
|
|||
return mul((float3x3)unity_WorldToCamera, norm); |
|||
} |
|||
|
|||
// Normal vector comparer (for geometry-aware weighting) |
|||
half CompareNormal(half3 d1, half3 d2) |
|||
{ |
|||
return smoothstep(kGeometryCoeff, 1.0, dot(d1, d2)); |
|||
} |
|||
|
|||
// Reconstruct view-space position from UV and depth. |
|||
// p11_22 = (unity_CameraProjection._11, unity_CameraProjection._22) |
|||
// p13_31 = (unity_CameraProjection._13, unity_CameraProjection._23) |
|||
float3 ReconstructViewPos(float2 uv, float depth, float2 p11_22, float2 p13_31) |
|||
{ |
|||
return float3((uv * 2.0 - 1.0 - p13_31) / p11_22 * depth, depth); |
|||
} |
|||
|
|||
// Default vertex shader |
|||
struct Attributes |
|||
{ |
|||
float3 vertex : POSITION; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float4 vertex : SV_POSITION; |
|||
float2 texcoord : TEXCOORD0; |
|||
}; |
|||
|
|||
Varyings Vert(Attributes input) |
|||
{ |
|||
Varyings output; |
|||
output.vertex = float4(input.vertex.xy, 0.0, 1.0); |
|||
output.texcoord = (input.vertex.xy + 1.0) * 0.5; |
|||
#if UNITY_UV_STARTS_AT_TOP |
|||
output.texcoord.y = 1.0 - output.texcoord.y; |
|||
#endif |
|||
return output; |
|||
} |
|||
|
|||
#endif // UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_COMMON |
|
|||
fileFormatVersion: 2 |
|||
guid: 45b0ccffd1246974298356d4ee0c9124 |
|||
timeCreated: 1495063770 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_COMPOSITION |
|||
#define UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_COMPOSITION |
|||
|
|||
#include "Common.hlsl" |
|||
|
|||
half _Downsample; |
|||
|
|||
TEXTURE2D(_MainTex); |
|||
SAMPLER2D(sampler_MainTex); |
|||
float4 _MainTex_TexelSize; |
|||
|
|||
struct CompositionOutput |
|||
{ |
|||
half4 gbuffer0 : SV_Target0; |
|||
half4 gbuffer3 : SV_Target1; |
|||
}; |
|||
|
|||
CompositionOutput Frag(Varyings input) |
|||
{ |
|||
float2 delta = _MainTex_TexelSize.xy / _Downsample; |
|||
|
|||
float2 uv = input.texcoord; |
|||
|
|||
// 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; |
|||
|
|||
CompositionOutput output; |
|||
output.gbuffer0 = half4(0.0, 0.0, 0.0, ao); |
|||
output.gbuffer3 = half4((half3)ao, 0.0); |
|||
return output; |
|||
} |
|||
|
|||
#endif // UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_COMPOSITION |
|
|||
fileFormatVersion: 2 |
|||
guid: 0b56dfc1b10fc274ba63531d4d3c2e45 |
|||
timeCreated: 1495072012 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_DENOISING |
|||
#define UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_DENOISING |
|||
|
|||
#include "Common.hlsl" |
|||
|
|||
half _Downsample; |
|||
|
|||
TEXTURE2D(_MainTex); |
|||
SAMPLER2D(sampler_MainTex); |
|||
float4 _MainTex_TexelSize; |
|||
|
|||
half4 Frag(Varyings input) : SV_Target |
|||
{ |
|||
#if defined(AO_DENOISE_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 // AO_DENOISE_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 |
|||
|
|||
float2 uv = input.texcoord; |
|||
|
|||
// 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(AO_DENOISE_CENTER_NORMAL) |
|||
half3 n0 = SampleNormal(uv); |
|||
#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); |
|||
} |
|||
|
|||
#endif // UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_DENOISING |
|
|||
fileFormatVersion: 2 |
|||
guid: 6c9740fd91eea8448b63651a36de99d6 |
|||
timeCreated: 1495081785 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#ifndef UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_ESTIMATION |
|||
#define UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_ESTIMATION |
|||
|
|||
#include "Common.hlsl" |
|||
|
|||
half _Intensity; |
|||
float _Radius; |
|||
half _Downsample; |
|||
int _SampleCount; |
|||
|
|||
// Sample point picker |
|||
float3 PickSamplePoint(float2 uv, float index) |
|||
{ |
|||
// Uniformaly distributed points on a unit sphere http://goo.gl/X2F1Ho |
|||
float gn = GradientNoise(uv * _Downsample); |
|||
// FIXEME: This was added to avoid a NVIDIA driver issue. |
|||
// vvvvvvvvvvvv |
|||
float u = frac(UVRandom(0.0, index + uv.x * 1e-10) + gn) * 2.0 - 1.0; |
|||
float theta = (UVRandom(1.0, index + uv.x * 1e-10) + gn) * TWO_PI; |
|||
float3 v = float3(SinCos(theta).yx * sqrt(1.0 - u * u), u); |
|||
// Make them distributed between [0, _Radius] |
|||
float l = sqrt((index + 1.0) / _SampleCount) * _Radius; |
|||
return v * l; |
|||
} |
|||
|
|||
// Distance-based AO estimator based on Morgan 2011 http://goo.gl/2iz3P |
|||
half4 Frag(Varyings input) : SV_Target |
|||
{ |
|||
float2 uv = input.texcoord; |
|||
|
|||
// Parameters used in coordinate conversion |
|||
float3x3 proj = (float3x3)unity_CameraProjection; |
|||
float2 p11_22 = float2(unity_CameraProjection._11, unity_CameraProjection._22); |
|||
float2 p13_31 = float2(unity_CameraProjection._13, unity_CameraProjection._23); |
|||
|
|||
// View space normal and depth |
|||
half3 norm_o = SampleNormal(uv); |
|||
float depth_o = SampleDepth(uv); |
|||
|
|||
// Reconstruct the view-space position. |
|||
float3 vpos_o = ReconstructViewPos(uv, depth_o, p11_22, p13_31); |
|||
|
|||
float ao = 0.0; |
|||
|
|||
for (int s = 0; s < _SampleCount; s++) |
|||
{ |
|||
// Sample point |
|||
float3 v_s1 = PickSamplePoint(uv, s); |
|||
v_s1 = faceforward(v_s1, -norm_o, v_s1); |
|||
float3 vpos_s1 = vpos_o + v_s1; |
|||
|
|||
// Reproject the sample point |
|||
float3 spos_s1 = mul(proj, vpos_s1); |
|||
float2 uv_s1_01 = (spos_s1.xy / vpos_s1.z + 1.0) * 0.5; |
|||
|
|||
// Depth at the sample point |
|||
float depth_s1 = SampleDepth(uv_s1_01); |
|||
|
|||
// Relative position of the sample point |
|||
float3 vpos_s2 = ReconstructViewPos(uv_s1_01, depth_s1, p11_22, p13_31); |
|||
float3 v_s2 = vpos_s2 - vpos_o; |
|||
|
|||
// Estimate the obscurance value |
|||
float a1 = max(dot(v_s2, norm_o) - kBeta * depth_o, 0.0); |
|||
float a2 = dot(v_s2, v_s2) + kEpsilon; |
|||
ao += a1 / a2; |
|||
} |
|||
|
|||
// Apply intensity normalization/amplifier/contrast. |
|||
ao = pow(max(0, ao * _Radius * _Intensity / _SampleCount), kContrast); |
|||
|
|||
return PackAONormal(ao, norm_o); |
|||
} |
|||
|
|||
#endif // UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_ESTIMATION |
|
|||
fileFormatVersion: 2 |
|||
guid: b09fe107b0c1e7840a6251e037b7ba7f |
|||
timeCreated: 1494982781 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue