浏览代码

An attempt at fixing issues.

- Changed to use the standard full-screen triangle drawing function instead of
  one in the post processing utilities.
- Apply _Downsample at some points in the shader. Not it works.
- Small tweaks.
/Branch_Batching2
Keijiro Takahashi 8 年前
当前提交
b9613a40
共有 4 个文件被更改,包括 32 次插入24 次删除
  1. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 44
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AmbientOcclusion.cs
  3. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/Resources/Composition.hlsl
  4. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/Resources/Estimation.hlsl

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


using (new Utilities.ProfilingSample("Build Light list and render shadows", renderContext))
{
// TODO: Everything here (SSAO, Shadow, Build light list, material and light classification can be parallelize with Async compute)
m_SsaoEffect.Render(m_Asset.ssaoSettingsToUse, camera, renderContext, GetDepthTexture(), m_Asset.renderingSettings.useForwardRenderingOnly);
m_SsaoEffect.Render(m_Asset.ssaoSettingsToUse, hdCamera, renderContext, GetDepthTexture(), m_Asset.renderingSettings.useForwardRenderingOnly);
m_LightLoop.PrepareLightsForGPU(m_Asset.shadowSettings, cullResults, camera);
m_LightLoop.RenderShadows(renderContext, cullResults);
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render

44
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/AmbientOcclusion.cs


using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.PostProcessing;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

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 _MainTex = Shader.PropertyToID("_MainTex");
internal static readonly int _AOBuffer = Shader.PropertyToID("_AmbientOcclusionTexture");
internal static readonly int _TempTex1 = Shader.PropertyToID("_TempTex1");
internal static readonly int _TempTex2 = Shader.PropertyToID("_TempTex2");

PropertySheet m_Sheet;
Material m_Material;
readonly RenderTargetIdentifier m_AmbientOcclusionRT;

public void Build(RenderPipelineResources renderPipelinesResources)
{
var material = Utilities.CreateEngineMaterial("Hidden/HDPipeline/ScreenSpace/AmbientOcclusion");
// TODO: Don't we need to also free the material ?
m_Sheet = new PropertySheet(material);
m_Material = Utilities.CreateEngineMaterial("Hidden/HDPipeline/ScreenSpace/AmbientOcclusion");
m_Material.hideFlags = HideFlags.DontSave;
public void Render(ScreenSpaceAmbientOcclusionSettings.Settings settings, Camera camera, ScriptableRenderContext renderContext, RenderTargetIdentifier depthID, bool isForward)
public void Render(ScreenSpaceAmbientOcclusionSettings.Settings settings, HDCamera hdCamera, ScriptableRenderContext renderContext, RenderTargetIdentifier depthID, bool isForward)
{
const RenderTextureFormat kFormat = RenderTextureFormat.ARGB32;
const RenderTextureReadWrite kRWMode = RenderTextureReadWrite.Linear;

return ;
}
var width = camera.pixelWidth;
var height = camera.pixelHeight;
var width = hdCamera.camera.pixelWidth;
var height = hdCamera.camera.pixelHeight;
m_Sheet.properties.SetFloat(Uniforms._Intensity, settings.intensity);
m_Sheet.properties.SetFloat(Uniforms._Radius, settings.radius);
m_Sheet.properties.SetFloat(Uniforms._Downsample, 1.0f / downsize);
m_Sheet.properties.SetFloat(Uniforms._SampleCount, settings.sampleCount);
m_Material.SetFloat(Uniforms._Intensity, settings.intensity);
m_Material.SetFloat(Uniforms._Radius, settings.radius);
m_Material.SetFloat(Uniforms._Downsample, 1.0f / downsize);
m_Material.SetFloat(Uniforms._SampleCount, settings.sampleCount);
// Start building a command buffer.
var cmd = new CommandBuffer { name = "Ambient Occlusion" };

// AO estimation.
cmd.GetTemporaryRT(Uniforms._TempTex1, width / downsize, height / downsize, 0, kFilter, kFormat, kRWMode);
cmd.BlitFullscreenTriangle(depthID, Uniforms._TempTex1, m_Sheet, 0);
cmd.SetGlobalTexture(Uniforms._MainTex, depthID);
Utilities.DrawFullScreen(cmd, m_Material, hdCamera, Uniforms._TempTex1, null, 0);
cmd.BlitFullscreenTriangle(Uniforms._TempTex1, Uniforms._TempTex2, m_Sheet, 1);
cmd.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex1);
Utilities.DrawFullScreen(cmd, m_Material, hdCamera, Uniforms._TempTex2, null, 1);
cmd.BlitFullscreenTriangle(Uniforms._TempTex2, Uniforms._TempTex1, m_Sheet, 2);
cmd.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex2);
Utilities.DrawFullScreen(cmd, m_Material, hdCamera, Uniforms._TempTex1, null, 2);
cmd.BlitFullscreenTriangle(Uniforms._TempTex1, Uniforms._AOBuffer, depthID, m_Sheet, 3);
cmd.SetGlobalTexture(Uniforms._MainTex, Uniforms._TempTex1);
Utilities.DrawFullScreen(cmd, m_Material, hdCamera, Uniforms._AOBuffer, null, 3);
cmd.ReleaseTemporaryRT(Uniforms._TempTex1);
// Setup texture for lighting pass (automagic of unity)

public void Cleanup()
{
if (m_Sheet != null)
m_Sheet.Release();
if (m_Material != null)
{
if (Application.isPlaying)
Object.Destroy(m_Material);
else
Object.DestroyImmediate(m_Material);
}
}
}
}

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/Resources/Composition.hlsl


ao += GetPackedAO(p4) * w4;
ao /= w0 + w1 + w2 + w3 + w4;
return half4(ao, 0, 0, 0);
return half4(1 - ao, 0, 0, 0);
}
#endif // UNITY_HDRENDERPIPELINE_AMBIENTOCCLUSION_COMPOSITION

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/Resources/Estimation.hlsl


half4 Frag(Varyings input) : SV_Target
{
// input.positionCS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw / _Downsample);
FETCH_GBUFFER(gbuffer, _GBufferTexture, posInput.unPositionSS);
FETCH_GBUFFER(gbuffer, _GBufferTexture, posInput.unPositionSS / _Downsample);
DECODE_FROM_GBUFFER(gbuffer, 0xFFFFFFFF, bsdfData, unused);
// Parameters used in coordinate conversion

// View space normal and depth
half3 norm_o = SampleNormal(bsdfData);
float depth_o = SampleDepth(posInput.unPositionSS);
float depth_o = SampleDepth(posInput.unPositionSS / _Downsample);
// Reconstruct the view-space position.
float3 vpos_o = ReconstructViewPos(uv, depth_o, p11_22, p13_31);

}
// TODO: Check with Keijiro but ao is inverted here...
ao = 1.0 - ao;
//ao = 1.0 - ao;
// Apply intensity normalization/amplifier/contrast.
ao = pow(max(0, ao * _Radius * _Intensity / _SampleCount), kContrast);

正在加载...
取消
保存