浏览代码

Merge pull request #111 from Unity-Technologies/Fix-Discrenpency-forward-deferred

HDRenderPipeline: Fix discrepencey forward deferred
/main
GitHub 8 年前
当前提交
2c21b8bb
共有 9 个文件被更改,包括 37 次插入42 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs
  2. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs.hlsl
  3. 7
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader
  4. 34
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  5. 3
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.hlsl
  6. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs
  7. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  8. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LayeredLitNormalSampling.hlsl.meta
  9. 9
      Assets/TestScenes/HDTest/HDRenderLoopTest.meta

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs


public enum DebugViewGbuffer
{
Depth = DebugViewVarying.VertexColorAlpha + 1,
BakeDiffuseLighting,
BakeDiffuseLightingWithAlbedoPlusEmissive,
}
}
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/DebugViewMaterial.cs.hlsl


// UnityEngine.Experimental.Rendering.HDPipeline.Attributes.DebugViewGbuffer: static fields
//
#define DEBUGVIEWGBUFFER_DEPTH (10)
#define DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING (11)
#define DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING_WITH_ALBEDO_PLUS_EMISSIVE (11)
#endif

7
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader


float linearDepth = frac(posInput.depthVS * 0.1);
result = linearDepth.xxx;
}
else if (_DebugViewMaterial == DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING)
// Caution: This value is not the same than the builtin data bakeDiffuseLighting. It also include emissive and multiply by the albedo
else if (_DebugViewMaterial == DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING_WITH_ALBEDO_PLUS_EMISSIVE)
result = bakeDiffuseLighting;
// TODO: require a remap
// TODO: we should not gamma correct, but easier to debug for now without correct high range value
result = bakeDiffuseLighting; needLinearToSRGB = true;
}
GetBSDFDataDebug(_DebugViewMaterial, bsdfData, result, needLinearToSRGB);

34
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


// Clear GBuffers
using (new Utilities.ProfilingSample("Clear GBuffer", renderContext))
if (!debugParameters.ShouldUseForwardRenderingOnly())
Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
using (new Utilities.ProfilingSample("Clear GBuffer", renderContext))
{
Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
}
// END TEMP
}
}

Shader.SetGlobalInt("_DebugViewMaterial", (int)debugParameters.debugViewMaterial);
RenderOpaqueRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial");
RenderOpaqueRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial", Utilities.kRendererConfigurationBakedLighting);
}
// Render GBuffer opaque

// Render forward transparent
{
RenderTransparentRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial");
RenderTransparentRenderList(cull, hdCamera.camera, renderContext, "DebugViewMaterial", Utilities.kRendererConfigurationBakedLighting);
}
// Last blit

return ;
}
// Bind material data
m_LitRenderLoop.Bind();
m_lightLoop.RenderDeferredLighting(hdCamera, renderContext, m_CameraColorBuffer);
}

using (new Utilities.ProfilingSample("Forward Pass", renderContext))
{
// Bind material data
m_LitRenderLoop.Bind();
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthBufferRT);
m_lightLoop.RenderForward(camera, renderContext, renderOpaque);

RenderOpaqueRenderList(cullResults, camera, renderContext, "Forward");
RenderOpaqueRenderList(cullResults, camera, renderContext, "Forward", Utilities.kRendererConfigurationBakedLighting);
}
else
{

{
using (new Utilities.ProfilingSample("Forward Only Pass", renderContext))
{
// Bind material data
m_LitRenderLoop.Bind();
RenderOpaqueRenderList(cullResults, camera, renderContext, "ForwardOnlyOpaque");
RenderOpaqueRenderList(cullResults, camera, renderContext, "ForwardOnlyOpaque", Utilities.kRendererConfigurationBakedLighting);
}
}

InitAndClearBuffer(camera, renderContext);
// TODO: Find a correct place to bind these material textures
// We have to bind the material specific global parameters in this mode
m_LitRenderLoop.Bind();
RenderDepthPrepass(cullResults, camera, renderContext);
// Forward opaque with deferred/cluster tile require that we fill the depth buffer

using (new Utilities.ProfilingSample("Build Light list", renderContext))
{
m_lightLoop.PrepareLightsForGPU(m_ShadowSettings, cullResults, camera, ref shadows);
m_lightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthBufferRT); // TODO: Use async compute here to run light culling during shadow
PushGlobalParams(hdCamera, renderContext);
m_lightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthBufferRT); // TODO: Use async compute here to run light culling during shadow
PushGlobalParams(hdCamera, renderContext);
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// must be call after BuildGPULightLists.

3
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Builtin/BuiltinData.hlsl


break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_BAKE_DIFFUSE_LIGHTING:
// TODO: require a remap
result = builtinData.bakeDiffuseLighting;
// TODO: we should not gamma correct, but easier to debug for now without correct high range value
result = builtinData.bakeDiffuseLighting; needLinearToSRGB = true;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVE_COLOR:
// emissiveColor is premultiply by emissive intensity

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs


const int k_LtcLUTMatrixDim = 3; // size of the matrix (3x3)
const int k_LtcLUTResolution = 64;
Material CreateEngineMaterial(string shaderPath)
{
Material mat = new Material(Shader.Find(shaderPath) as Shader);
mat.hideFlags = HideFlags.HideAndDontSave;
return mat;
}
Texture2D CreateLUT(int width, int height, TextureFormat format, Color[] pixels)
{
Texture2D tex = new Texture2D(width, height, format, false /*mipmap*/, true /*linear*/);

public void Build()
{
m_InitPreFGD = CreateEngineMaterial("Hidden/HDRenderPipeline/PreIntegratedFGD");
m_InitPreFGD = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/PreIntegratedFGD");
// TODO: switch to RGBA64 when it becomes available.
m_PreIntegratedFGD = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


ADD_IDX(layerTexCoord.base).uv += offset;
}
float3 ADD_IDX(GetNormalTS)(LayerTexCoord layerTexCoord, float3 detailNormalTS, float detailMask, bool useBias, float bias)
float3 ADD_IDX(GetNormalTS)(FragInputs input, LayerTexCoord layerTexCoord, float3 detailNormalTS, float detailMask, bool useBias, float bias)
{
float3 normalTS;

surfaceData.normalWS = float3(0.0, 0.0, 0.0); // Need to init this so that the compiler leaves us alone.
// TODO: think about using BC5
normalTS = ADD_IDX(GetNormalTS)(layerTexCoord, detailNormalTS, detailMask, false, 0.0f);
normalTS = ADD_IDX(GetNormalTS)(input, layerTexCoord, detailNormalTS, detailMask, false, 0.0f);
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
surfaceData.perceptualSmoothness = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_BaseColorMap), ADD_ZERO_IDX(sampler_BaseColorMap), ADD_IDX(layerTexCoord.base)).a;

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LayeredLitNormalSampling.hlsl.meta


fileFormatVersion: 2
guid: 541d9773d4d9b4c4f92e026284359f50
timeCreated: 1485010820
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/TestScenes/HDTest/HDRenderLoopTest.meta


fileFormatVersion: 2
guid: bb067c1f82e9d8648b8909e905f6607b
folderAsset: yes
timeCreated: 1484331444
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存