浏览代码

renderpass API mostly working although forward is inverted in Z for some reason

/main
Filip Iliescu 7 年前
当前提交
f7e8412b
共有 4 个文件被更改,包括 14 次插入26 次删除
  1. 16
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/OnTileDeferredRenderPipeline.cs
  2. 16
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/Shaders/Internal-DeferredShading.shader
  3. 4
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/Shaders/LightingTemplate.hlsl
  4. 4
      Assets/ScriptableRenderPipeline/MobileRenderPipeline/Shaders/UnityStandardCore.cginc

16
Assets/ScriptableRenderPipeline/MobileRenderPipeline/OnTileDeferredRenderPipeline.cs


// cannot read depth buffer directly in shader on iOS
private RenderPassAttachment s_GBufferRedF32;
// When rendering the game view, we need an extra blit because
// we're not rendering to a fullscreen resolution
private static int _sceneViewBlitId;
private static int _sceneViewDepthId;
private static Material _blitDepthMaterial;

s_GBufferNormal = new RenderPassAttachment(RenderTextureFormat.ARGB2101010);
s_GBufferEmission = new RenderPassAttachment(RenderTextureFormat.ARGBHalf);
s_GBufferZ = new RenderPassAttachment(RenderTextureFormat.Depth);
s_CameraTarget = new RenderPassAttachment(RenderTextureFormat.ARGB32);
s_CameraTarget = s_GBufferAlbedo;
s_Depth = new RenderPassAttachment(RenderTextureFormat.Depth);
s_GBufferEmission.Clear(new Color(0.0f, 0.0f, 0.0f, 0.0f), 1.0f, 0);

m_BlitMaterial = new Material (finalPassShader) { hideFlags = HideFlags.HideAndDontSave };
_blitDepthMaterial = new Material(Shader.Find("Hidden/BlitCopyWithDepth"));
_blitDepthMaterial = new Material(Shader.Find("Hidden/BlitCopyWithDepth")) { hideFlags = HideFlags.HideAndDontSave };
_sceneViewBlitId = Shader.PropertyToID("_TempCameraRT");
_sceneViewDepthId = Shader.PropertyToID("_TempCameraDepth");

{
using (RenderPass rp = new RenderPass (loop, camera.pixelWidth, camera.pixelHeight, 1, SystemInfo.supportsReadOnlyDepth ?
new[] { s_GBufferAlbedo, s_GBufferSpecRough, s_GBufferNormal, s_GBufferEmission } :
new[] { s_GBufferAlbedo, s_GBufferSpecRough, s_GBufferNormal, s_GBufferEmission, s_GBufferRedF32 }, s_GBufferZ)) {
new[] { s_GBufferAlbedo, s_GBufferSpecRough, s_GBufferNormal, s_GBufferEmission, s_GBufferRedF32 }, s_Depth)) {
// GBuffer pass
using (new RenderPass.SubPass (rp, SystemInfo.supportsReadOnlyDepth ?

loop.ExecuteCommandBuffer (cmd);
// render opaque objects using Deferred pass
var settings = new DrawRendererSettings (cullResults, camera, new ShaderPassName ("Gbuffer Pass")) {
var settings = new DrawRendererSettings (cullResults, camera, new ShaderPassName ("Deferred")) {
sorting = { flags = SortFlags.CommonOpaque },
rendererConfiguration = RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe
};

}
//Lighting Pass
using (new RenderPass.SubPass(rp, new[] { s_GBufferEmission }, new[] { s_GBufferAlbedo, s_GBufferSpecRough, s_GBufferNormal, s_GBufferEmission, SystemInfo.supportsReadOnlyDepth ? s_Depth : s_GBufferRedF32 }, true))
using (new RenderPass.SubPass(rp, new[] { s_GBufferEmission }, SystemInfo.supportsReadOnlyDepth ?
new[] { s_GBufferAlbedo, s_GBufferSpecRough, s_GBufferNormal, s_GBufferEmission, s_Depth } :
new[] { s_GBufferAlbedo, s_GBufferSpecRough, s_GBufferNormal, s_GBufferEmission, s_GBufferRedF32 }, true))
{
using (var cmd = new CommandBuffer { name = "Deferred Lighting and Reflections Pass"} )
{

16
Assets/ScriptableRenderPipeline/MobileRenderPipeline/Shaders/Internal-DeferredShading.shader


#include "LightingTemplate.hlsl"
#ifdef UNITY_FRAMEBUFFER_FETCH_AVAILABLE
void frag (unity_v2f_deferred i,
in half4 outGBuffer0 : SV_Target0,
in half4 outGBuffer1 : SV_Target1,
in half4 outGBuffer2 : SV_Target2,
out half4 outEmission : SV_Target3,
in float outLinearDepth : SV_Target4)
#else
#endif
#ifdef UNITY_FRAMEBUFFER_FETCH_AVAILABLE
outEmission = CalculateLight(i, outGBuffer0, outGBuffer1, outGBuffer2, outLinearDepth);
#else
return CalculateLight(i);
#endif
return CalculateLight(i);
}
ENDCG

4
Assets/ScriptableRenderPipeline/MobileRenderPipeline/Shaders/LightingTemplate.hlsl


UNITY_DECLARE_FRAMEBUFFER_INPUT_HALF(0);
UNITY_DECLARE_FRAMEBUFFER_INPUT_HALF(1);
UNITY_DECLARE_FRAMEBUFFER_INPUT_HALF(2);
UNITY_DECLARE_FRAMEBUFFER_INPUT_FLOAT(3);
UNITY_DECLARE_FRAMEBUFFER_INPUT_HALF(3);
UNITY_DECLARE_FRAMEBUFFER_INPUT_FLOAT(4);
// from LightDefinitions.cs.hlsl

UnityLight light;
UNITY_INITIALIZE_OUTPUT(UnityLight, light);
float depth = UNITY_READ_FRAMEBUFFER_INPUT(3, i.pos);
float depth = UNITY_READ_FRAMEBUFFER_INPUT(4, i.pos);
OnChipDeferredCalculateLightParams (i, wpos, uv, light.dir, atten, fadeDist, colorCookie, depth);
#if defined (POINT_COOKIE) || defined (DIRECTIONAL_COOKIE) || defined (SPOT)

4
Assets/ScriptableRenderPipeline/MobileRenderPipeline/Shaders/UnityStandardCore.cginc


out half4 outGBuffer2 : SV_Target2,
out half4 outEmission : SV_Target3 // RT3: emission (rgb), --unused-- (a)
#if (UNITY_ALLOWED_MRT_COUNT > 4)
#if defined(UNITY_FRAMEBUFFER_FETCH_AVAILABLE)
#if defined(UNITY_SUPPORT_DEPTH_FETCH)
,out float outDepth : SV_Target4 // RT4: zData (F32)
#elif defined(SHADOWS_SHADOWMASK)
,out half4 outShadowMask : SV_Target4 // RT4: shadowmask (rgba)

// Baked direct lighting occlusion if any
#if (UNITY_ALLOWED_MRT_COUNT > 4)
#if defined(UNITY_FRAMEBUFFER_FETCH_AVAILABLE)
#if defined(UNITY_SUPPORT_DEPTH_FETCH)
outDepth = i.pos.z;
#elif defined(SHADOWS_SHADOWMASK)
outShadowMask = UnityGetRawBakedOcclusions(i.ambientOrLightmapUV.xy, IN_WORLDPOS(i));

正在加载...
取消
保存