当前提交
b03bf46b
共有 11 个文件被更改,包括 311 次插入 和 126 次删除
-
11Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs
-
2Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/GGXConvolve.shader
-
65Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs
-
9Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
-
14Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
-
106Assets/ScriptableRenderLoop/ShaderLibrary/ImageBasedLighting.hlsl
-
49Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/ComputeGgxIblSampleData.compute
-
9Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/Resources/ComputeGgxIblSampleData.compute.meta
-
134Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/RuntimeFilterIBL.cs
-
12Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/RuntimeFilterIBL.cs.meta
|
|||
// Precomputes data for IntegrateLD(). See that function for a detailed description. |
|||
|
|||
#include "Common.hlsl" |
|||
#include "ImageBasedLighting.hlsl" |
|||
|
|||
#define MAX_IBL_SAMPLE_CNT 89 |
|||
|
|||
RWTexture2D<float4> output; // [MAX_SAMPLE_CNT x UNITY_SPECCUBE_LOD_STEPS] |
|||
|
|||
#pragma kernel ComputeGgxIblSampleData |
|||
|
|||
[numthreads(MAX_IBL_SAMPLE_CNT, UNITY_SPECCUBE_LOD_STEPS, 1)] |
|||
void ComputeGgxIblSampleData(uint3 groupThreadId : SV_GroupThreadID) |
|||
{ |
|||
uint sampleIndex = groupThreadId.x; |
|||
uint mipLevel = groupThreadId.y + 1; |
|||
uint sampleCount = GetIBLRuntimeFilterSampleCount(mipLevel); |
|||
|
|||
if (sampleIndex >= sampleCount) |
|||
{ |
|||
output[groupThreadId.xy] = float4(0, 0, 0, 0); |
|||
return; |
|||
} |
|||
|
|||
float perceptualRoughness = MipmapLevelToPerceptualRoughness(mipLevel); |
|||
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness); |
|||
|
|||
float bias = 0.5 * roughness; |
|||
|
|||
float2 u = Fibonacci2d(sampleIndex, sampleCount); |
|||
u.x = lerp(u.x, 0, bias); |
|||
|
|||
float3 localL; |
|||
float NdotL, NdotH, VdotH; |
|||
|
|||
SampleGGXDir(u, float3(0, 0, 1), k_identity3x3, roughness, localL, NdotL, NdotH, VdotH, true); |
|||
|
|||
if (NdotL <= 0) |
|||
{ |
|||
// We are not supposed to generate wasteful samples. |
|||
output[groupThreadId.xy] = float4(0, 0, 0, 0); |
|||
return; |
|||
} |
|||
|
|||
float pdf = D_GGX(NdotH, roughness) * 0.25; |
|||
float omegaS = rcp(sampleCount * pdf); |
|||
|
|||
output[groupThreadId.xy] = float4(localL, omegaS); |
|||
} |
|
|||
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: |
撰写
预览
正在加载...
取消
保存
Reference in new issue