Evgenii Golubev
8 年前
当前提交
65c98c8d
共有 9 个文件被更改,包括 170 次插入 和 103 次删除
-
8Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader
-
4Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/ComputeGgxIblSampleData.compute
-
93Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs
-
4Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/ComputeGgxIblSampleData.compute.meta
-
134Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/RuntimeFilterIBL.cs
-
12Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/RuntimeFilterIBL.cs.meta
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/PrecomputeIblGgxData.compute.meta
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/ComputeGgxIblSampleData.compute
|
|||
fileFormatVersion: 2 |
|||
guid: 764a24bb47ef5ba4781d9ae82ca07445 |
|||
timeCreated: 1484572881 |
|||
licenseType: Pro |
|||
ComputeShaderImporter: |
|||
currentAPIMask: 4 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
using System; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class IBLFilterGGX |
|||
{ |
|||
RenderTexture m_GgxIblSampleData = null; |
|||
const int k_GgxIblMaxSampleCount = 89; // Width
|
|||
const int k_GgxIblMipCountMinusOne = 6; // Height (UNITY_SPECCUBE_LOD_STEPS)
|
|||
|
|||
ComputeShader m_ComputeGgxIblSampleDataCS = null; |
|||
int m_ComputeIblGgxSampleDataKernel = -1; |
|||
|
|||
ComputeShader m_BuildProbabilityTablesCS = null; |
|||
int m_ConditionalDensitiesKernel = -1; |
|||
int m_MarginalRowDensitiesKernel = -1; |
|||
|
|||
Material m_GgxConvolveMaterial = null; // Convolves a cubemap with GGX
|
|||
|
|||
public bool IsInitialized() |
|||
{ |
|||
return m_GgxIblSampleData != null; |
|||
} |
|||
|
|||
public void Initialize(ScriptableRenderContext context) |
|||
{ |
|||
if (!m_ComputeGgxIblSampleDataCS) |
|||
{ |
|||
m_ComputeGgxIblSampleDataCS = Resources.Load<ComputeShader>("ComputeGgxIblSampleData"); |
|||
m_ComputeIblGgxSampleDataKernel = m_ComputeGgxIblSampleDataCS.FindKernel("ComputeGgxIblSampleData"); |
|||
} |
|||
|
|||
if (!m_BuildProbabilityTablesCS) |
|||
{ |
|||
m_BuildProbabilityTablesCS = Resources.Load<ComputeShader>("BuildProbabilityTables"); |
|||
m_ConditionalDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeConditionalDensities"); |
|||
m_MarginalRowDensitiesKernel = m_BuildProbabilityTablesCS.FindKernel("ComputeMarginalRowDensities"); |
|||
} |
|||
|
|||
if (!m_GgxConvolveMaterial) |
|||
{ |
|||
m_GgxConvolveMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/GGXConvolve"); |
|||
} |
|||
|
|||
if (!m_GgxIblSampleData) |
|||
{ |
|||
m_GgxIblSampleData = new RenderTexture(k_GgxIblMaxSampleCount, k_GgxIblMipCountMinusOne, 1, RenderTextureFormat.ARGBFloat); |
|||
m_GgxIblSampleData.dimension = TextureDimension.Tex2D; |
|||
m_GgxIblSampleData.useMipMap = false; |
|||
m_GgxIblSampleData.autoGenerateMips = false; |
|||
m_GgxIblSampleData.enableRandomWrite = true; |
|||
m_GgxIblSampleData.filterMode = FilterMode.Point; |
|||
m_GgxIblSampleData.Create(); |
|||
|
|||
m_ComputeGgxIblSampleDataCS.SetTexture(m_ComputeIblGgxSampleDataKernel, "output", m_GgxIblSampleData); |
|||
|
|||
var cmd = new CommandBuffer() { name = "Compute GGX IBL Sample Data" }; |
|||
cmd.DispatchCompute(m_ComputeGgxIblSampleDataCS, m_ComputeIblGgxSampleDataKernel, 1, 1, 1); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Dispose(); |
|||
} |
|||
} |
|||
|
|||
void FilterCubemapGgxCommon(ScriptableRenderContext context, int mipCount, |
|||
Texture source, RenderTexture target, |
|||
Mesh[] cubemapFaceMesh) |
|||
{ |
|||
// Solid angle associated with a texel of the cubemap.
|
|||
float invOmegaP = (6.0f * source.width * source.width) / (4.0f * Mathf.PI); |
|||
|
|||
m_GgxConvolveMaterial.SetTexture("_MainTex", source); |
|||
m_GgxConvolveMaterial.SetTexture("_GgxIblSamples", m_GgxIblSampleData); |
|||
m_GgxConvolveMaterial.SetFloat("_LastLevel", mipCount - 1); |
|||
m_GgxConvolveMaterial.SetFloat("_InvOmegaP", invOmegaP); |
|||
|
|||
for (int mip = 1; mip < ((int)EnvConstants.SpecCubeLodStep + 1); ++mip) |
|||
{ |
|||
MaterialPropertyBlock props = new MaterialPropertyBlock(); |
|||
props.SetFloat("_Level", mip); |
|||
|
|||
for (int face = 0; face < 6; ++face) |
|||
{ |
|||
Utilities.SetRenderTarget(context, target, ClearFlag.ClearNone, mip, (CubemapFace)face); |
|||
|
|||
var cmd = new CommandBuffer { name = "" }; |
|||
cmd.DrawMesh(cubemapFaceMesh[face], Matrix4x4.identity, m_GgxConvolveMaterial, 0, 0, props); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Filters MIP map levels (other than 0) with GGX using BRDF importance sampling.
|
|||
public void FilterCubemapGgx(ScriptableRenderContext context, int mipCount, |
|||
Texture source, RenderTexture target, |
|||
Mesh[] cubemapFaceMesh) |
|||
{ |
|||
m_GgxConvolveMaterial.DisableKeyword("USE_MIS"); |
|||
|
|||
FilterCubemapGgxCommon(context, mipCount, source, target, cubemapFaceMesh); |
|||
} |
|||
|
|||
// Filters MIP map levels (other than 0) with GGX using multiple importance sampling.
|
|||
public void FilterCubemapGgxMis(ScriptableRenderContext context, int mipCount, |
|||
Texture source, RenderTexture target, |
|||
RenderTexture conditionalCdf, RenderTexture marginalRowCdf, |
|||
Mesh[] cubemapFaceMesh) |
|||
{ |
|||
// Bind the input cubemap.
|
|||
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "envMap", source); |
|||
|
|||
// Bind the outputs.
|
|||
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "conditionalDensities", conditionalCdf); |
|||
m_BuildProbabilityTablesCS.SetTexture(m_ConditionalDensitiesKernel, "marginalRowDensities", marginalRowCdf); |
|||
m_BuildProbabilityTablesCS.SetTexture(m_MarginalRowDensitiesKernel, "marginalRowDensities", marginalRowCdf); |
|||
|
|||
int numRows = conditionalCdf.height; |
|||
|
|||
var cmd = new CommandBuffer() { name = "Build Probability Tables" }; |
|||
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_ConditionalDensitiesKernel, numRows, 1, 1); |
|||
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_MarginalRowDensitiesKernel, 1, 1, 1); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Dispose(); |
|||
|
|||
m_GgxConvolveMaterial.EnableKeyword("USE_MIS"); |
|||
m_GgxConvolveMaterial.SetTexture("_ConditionalDensities", conditionalCdf); |
|||
m_GgxConvolveMaterial.SetTexture("_MarginalRowDensities", marginalRowCdf); |
|||
|
|||
FilterCubemapGgxCommon(context, mipCount, source, target, cubemapFaceMesh); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 827056f7b26e8a64883735043af76431 |
|||
timeCreated: 1484572874 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: d1d990f8fa3bd5040b4ceb3aaa64fa07 |
|||
timeCreated: 1484498071 |
|||
licenseType: Pro |
|||
ComputeShaderImporter: |
|||
currentAPIMask: 4 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue