浏览代码

HDRenderPipeline: Revert a small change about DebugViewMaterialGBuffer.shader

- the clean of  DebugViewMaterialGBuffer was not necessary
/Branch_batcher
Sebastien Lagarde 8 年前
当前提交
4ec50247
共有 7 个文件被更改,包括 134 次插入91 次删除
  1. 18
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 51
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Resources/Deferred.shader
  3. 28
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  4. 3
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassResources.cs
  5. 12
      Assets/ScriptableRenderPipeline/ShaderLibrary/Wind.hlsl
  6. 104
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader
  7. 9
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader.meta

18
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


Shader.SetGlobalInt("_DebugDisplayMode", (int)debugDisplaySettings.debugDisplayMode);
Shader.SetGlobalInt("_DebugViewMaterial", (int)debugDisplaySettings.materialDebugSettings.debugViewMaterial);
Shader.SetGlobalVector("_DebugLightingAlbedo", debugAlbedo);
Shader.SetGlobalVector("_DebugLightingSmoothness", debugSmoothness);
Shader.SetGlobalVector("_DebugLightingSmoothness", debugSmoothness);
}
public void UpdateCommonSettings()

readonly Material m_FilterAndCombineSubsurfaceScattering;
private Material m_DebugDisplayShadowMap;
private Material m_DebugViewMaterialGBuffer;
private Material m_DebugDisplayLatlong;
// Various buffer

void InitializeDebugMaterials()
{
m_DebugDisplayShadowMap = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DebugDisplayShadowMap");
m_DebugViewMaterialGBuffer = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DebugViewMaterialGBuffer");
m_DebugDisplayLatlong = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/DebugDisplayLatlong");
}

m_LitRenderLoop.Cleanup();
Utilities.Destroy(m_DebugDisplayShadowMap);
Utilities.Destroy(m_DebugViewMaterialGBuffer);
Utilities.Destroy(m_DebugDisplayLatlong);
m_SkyManager.Cleanup();

// Render GBuffer opaque
if (!m_Owner.renderingSettings.ShouldUseForwardRenderingOnly())
{
RenderTargetIdentifier[] colorRTs = { m_CameraColorBufferRT, m_CameraSubsurfaceBufferRT };
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, debugDisplaySettings, colorRTs, m_CameraDepthStencilBufferRT, new RenderTargetIdentifier(GetDepthTexture()), false);
Utilities.SetupMaterialHDCamera(hdCamera, m_DebugViewMaterialGBuffer);
// m_gbufferManager.BindBuffers(m_DebugViewMaterialGBuffer);
// TODO: Bind depth textures
var cmd = new CommandBuffer { name = "DebugViewMaterialGBuffer" };
cmd.Blit(null, m_CameraColorBufferRT, m_DebugViewMaterialGBuffer, 0);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// Render forward transparent

if (m_LightLoop != null)
m_LightLoop.RenderForward(camera, renderContext, renderOpaque);
if (renderOpaque)
{
RenderOpaqueRenderList(cullResults, camera, renderContext, passName, Utilities.kRendererConfigurationBakedLighting);

51
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Resources/Deferred.shader


outputs.combinedLighting = float4(diffuseLighting + specularLighting, 1.0);
#endif
#ifdef DEBUG_DISPLAY
if (_DebugDisplayMode == DEBUGDISPLAYMODE_VIEW_MATERIAL)
{
// Init to not expected value
float3 result = float3(-666.0, 0.0, 0.0);
bool needLinearToSRGB = false;
if (_DebugViewMaterial == DEBUGVIEWGBUFFER_DEPTH)
{
float linearDepth = frac(posInput.depthVS * 0.1);
result = linearDepth.xxx;
}
// 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)
{
// 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);
float4 value;
// If we haven't touch result, we don't blend it. This allow to have the GBuffer debug pass working with the regular forward debug pass.
// The forward debug pass will write its value and then the deferred will overwrite only touched texels.
if (result.x == -666.0)
{
value = float4(0.0, 0.0, 0.0, 0.0);
}
else
{
// TEMP!
// For now, the final blit in the backbuffer performs an sRGB write
// So in the meantime we apply the inverse transform to linear data to compensate.
if (!needLinearToSRGB)
result = SRGBToLinear(max(0, result));
value = float4(result, 1.0);
}
// Note: When DEBUG_DISPLAY is on for DEBUGDISPLAYMODE_VIEW_MATERIAL there is no OUTPUT_SPLIT_LIGHTING
#ifdef OUTPUT_SPLIT_LIGHTING
outputs.specularLighting = value;
outputs.diffuseLighting = float4(0.0, 0.0, 0.0, 0.0);
#else
outputs.combinedLighting = value;
#endif
}
#endif // DEBUG_DISPLAY
return outputs;
}

28
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


Material m_DeferredIndirectMaterialSRT = null;
Material m_DeferredIndirectMaterialMRT = null;
Material m_DeferredAllMaterialSRT = null;
Material m_DeferredViewMaterial = null; // Only use for DisplayDebug view material
Material m_DeferredAllMaterialMRT = null;
Material m_DebugViewTilesMaterial = null;

m_DeferredAllMaterialSRT.SetInt("_SrcBlend", (int)BlendMode.One);
m_DeferredAllMaterialSRT.SetInt("_DstBlend", (int)BlendMode.Zero);
m_DeferredViewMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
Utilities.SelectKeyword(m_DeferredViewMaterial, tileKeywords, 2);
m_DeferredViewMaterial.EnableKeyword("LIGHTLOOP_TILE_PASS");
m_DeferredViewMaterial.DisableKeyword("OUTPUT_SPLIT_LIGHTING");
m_DeferredViewMaterial.EnableKeyword("DEBUG_DISPLAY");
m_DeferredViewMaterial.SetInt("_StencilRef", 0);
m_DeferredViewMaterial.SetInt("_StencilCmp", 4 /* LEqual */);
m_DeferredViewMaterial.SetInt("_SrcBlend", (int)BlendMode.SrcAlpha);
m_DeferredViewMaterial.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha);
m_DeferredAllMaterialMRT = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Deferred");
Utilities.SelectKeyword(m_DeferredAllMaterialMRT, tileKeywords, 2);
m_DeferredAllMaterialMRT.EnableKeyword("LIGHTLOOP_TILE_PASS");

Utilities.Destroy(m_DeferredIndirectMaterialSRT);
Utilities.Destroy(m_DeferredIndirectMaterialMRT);
Utilities.Destroy(m_DeferredAllMaterialSRT);
Utilities.Destroy(m_DeferredViewMaterial);
Utilities.Destroy(m_DeferredAllMaterialMRT);
Utilities.Destroy(m_DebugViewTilesMaterial);

SetupDebugDisplayMode(debugDisplaySettings.IsDebugDisplayEnable());
// If we visualize material properties we do only one pass with a specific blend mode
if (debugDisplaySettings.debugDisplayMode == DebugDisplayMode.ViewMaterial)
{
Utilities.SelectKeyword(m_DeferredViewMaterial, "USE_CLUSTERED_LIGHTLIST", "USE_FPTL_LIGHTLIST", bUseClusteredForDeferred); // Not used, but setup it to avoid corruption just in case
Utilities.DrawFullScreen(cmd, m_DeferredViewMaterial, hdCamera, colorBuffers, depthStencilBuffer);
SetGlobalPropertyRedirect(null, 0, null);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
return;
}
if (!m_PassSettings.enableTileAndCluster)
{
PushGlobalParams(camera, renderContext, null, 0);

}
// Pass global parameters to compute shader
// TODO: get rid of this by making global parameters visible to compute shaders
// TODO: get rid of this by making global parameters visible to compute shaders
PushGlobalParams(camera, renderContext, shadeOpaqueShader, kernel);
// TODO: Update value like in ApplyDebugDisplaySettings() call. Sadly it is high likely that this will not be keep in sync. we really need to get rid of this by making global parameters visible to compute shaders

3
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePassResources.cs


public ComputeShader buildPerVoxelLightListShader = null; // clustered
public ComputeShader clearDispatchIndirectShader = null;
public ComputeShader shadeOpaqueShader = null;
// For image based lighting
public Shader m_InitPreFGD;
}
}

12
Assets/ScriptableRenderPipeline/ShaderLibrary/Wind.hlsl


float AttenuateTrunk(float x, float s)
{
float r = (x / s);
return pow(r,1/s);
return PositivePow(r,1/s);
}

gust = pow(gust, 2) * WIND_SETTINGS_GustScale;
}
float3 trunkNoise =
float3 trunkNoise =
(normalizedDir * WIND_SETTINGS_WorldDirectionAndSpeed.w)
+ (gust * normalizedDir * WIND_SETTINGS_GustSpeed)
(normalizedDir * WIND_SETTINGS_WorldDirectionAndSpeed.w)
+ (gust * normalizedDir * WIND_SETTINGS_GustSpeed)
+ (trunk * WIND_SETTINGS_Turbulence)
) * drag;

void ApplyWind( inout float3 worldPos,
void ApplyWind( inout float3 worldPos,
inout float3 worldNormal,
float3 rootWP,
float stiffness,

float3 rotAxis = cross(float3(0, 1, 0), wind.Direction);
worldPos = Rotate(rootWP, worldPos, rotAxis, (wind.Strength) * 0.001 * att);
float3 shiverDirection = normalize(lerp(worldNormal, normalize(wind.Direction + wind.ShiverDirection), shiverDirectionality));
worldPos += wind.ShiverStrength * shiverDirection * shiverMask;
}

104
Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader


Shader "Hidden/HDRenderPipeline/DebugViewMaterialGBuffer"
{
SubShader
{
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha // We will lerp only the values that are valid
HLSLPROGRAM
#pragma target 4.5
#pragma only_renderers d3d11 ps4 metal // TEMP: until we go further in dev
#pragma vertex Vert
#pragma fragment Frag
#include "../../../ShaderLibrary/Common.hlsl"
#include "../../../ShaderLibrary/Color.hlsl"
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_LIT
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "../../ShaderConfig.cs.hlsl"
#include "../../ShaderVariables.hlsl"
#define DEBUG_DISPLAY
#include "../../Debug/DebugDisplay.hlsl"
#include "../../Material/Material.hlsl"
DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
struct Attributes
{
float3 positionOS : POSITION;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
};
Varyings Vert(Attributes input)
{
// TODO: implement SV_vertexID full screen quad
Varyings output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionCS = TransformWorldToHClip(positionWS);
return output;
}
float4 Frag(Varyings input) : SV_Target
{
// input.positionCS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionCS.xy, _ScreenSize.zw);
float depth = LOAD_TEXTURE2D(_MainDepthTexture, posInput.unPositionSS).x;
UpdatePositionInput(depth, _InvViewProjMatrix, _ViewProjMatrix, posInput);
FETCH_GBUFFER(gbuffer, _GBufferTexture, posInput.unPositionSS);
BSDFData bsdfData;
float3 bakeDiffuseLighting;
DECODE_FROM_GBUFFER(gbuffer, 0xFFFFFFFF, bsdfData, bakeDiffuseLighting);
// Init to not expected value
float3 result = float3(-666.0, 0.0, 0.0);
bool needLinearToSRGB = false;
if (_DebugViewMaterial == DEBUGVIEWGBUFFER_DEPTH)
{
float linearDepth = frac(posInput.depthVS * 0.1);
result = linearDepth.xxx;
}
// 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)
{
// 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);
// f we haven't touch result, we don't blend it. This allow to have the GBuffer debug pass working with the regular forward debug pass.
// The forward debug pass will write its value and then the deferred will overwrite only touched texels.
if (result.x == -666.0)
{
return float4(0.0, 0.0, 0.0, 0.0);
}
else
{
// TEMP!
// For now, the final blit in the backbuffer performs an sRGB write
// So in the meantime we apply the inverse transform to linear data to compensate.
if (!needLinearToSRGB)
result = SRGBToLinear(max(0, result));
return float4(result, 1.0);
}
}
ENDHLSL
}
}
Fallback Off
}

9
Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader.meta


fileFormatVersion: 2
guid: 439949ea1bfa91b4ba0d04269fcde33d
timeCreated: 1492803708
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存