浏览代码

- HDRenderLoop: Added exposure/tonemap to the new inspector.

- Cleaned the way debug render are done.
/main
Julien Ignace 8 年前
当前提交
581745c8
共有 2 个文件被更改,包括 63 次插入48 次删除
  1. 101
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  2. 10
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoopInspector.cs

101
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


// Material Debugging
public MaterialDebugMode materialDebugMode = MaterialDebugMode.None;
public GBufferDebugMode gBufferDebugMode = GBufferDebugMode.None;
public bool displayMaterialDebugForTransparent = false;
public bool enableTonemap = true;
public float exposure = 0;
}
private DebugParameters m_DebugParameters = new DebugParameters();

}
public const int MaxLights = 32;
public bool enableTonemap = true;
public float exposure = 0;
//[SerializeField]
//ShadowSettings m_ShadowSettings = ShadowSettings.Default;

// END TEMP
}
void RenderOpaqueRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
{
if (!debugParameters.displayOpaqueObjects)
return;
DrawRendererSettings settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName));
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
settings.inputCullingOptions.SetQueuesOpaque();
renderLoop.DrawRenderers(ref settings);
}
void RenderTransparentRenderList(CullResults cull, Camera camera, RenderLoop renderLoop, string passName)
{
if (!debugParameters.displayTransparentObjects)
return;
DrawRendererSettings settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName));
settings.rendererConfiguration = RendererConfiguration.ConfigureOneLightProbePerRenderer | RendererConfiguration.ConfigureReflectionProbesProbePerRenderer;
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
settings.inputCullingOptions.SetQueuesTransparent();
renderLoop.DrawRenderers(ref settings);
}
void RenderGBuffer(CullResults cull, Camera camera, RenderLoop renderLoop)
{
// setup GBuffer for rendering

renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
DrawRendererSettings settings = new DrawRendererSettings(cull, camera, new ShaderPassName("GBuffer"));
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
settings.inputCullingOptions.SetQueuesOpaque();
renderLoop.DrawRenderers(ref settings);
RenderOpaqueRenderList(cull, camera, renderLoop, "GBuffer");
}
void RenderMaterialDebug(CullResults cull, Camera camera, RenderLoop renderLoop)

cmd.name = "Debug Pass";
cmd.GetTemporaryRT(s_CameraColorBuffer, -1, -1, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cmd.GetTemporaryRT(s_CameraDepthBuffer, -1, -1, 24, FilterMode.Point, RenderTextureFormat.Depth);
cmd.name = "Material Debug Pass";
cmd.GetTemporaryRT(s_CameraColorBuffer, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cmd.GetTemporaryRT(s_CameraDepthBuffer, camera.pixelWidth, camera.pixelHeight, 24, FilterMode.Point, RenderTextureFormat.Depth);
cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraColorBuffer), new RenderTargetIdentifier(s_CameraDepthBuffer));
cmd.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));
renderLoop.ExecuteCommandBuffer(cmd);

DrawRendererSettings settings = new DrawRendererSettings(cull, camera, new ShaderPassName("Debug"));
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
settings.inputCullingOptions.SetQueuesOpaque();
renderLoop.DrawRenderers(ref settings);
if(debugParameters.displayMaterialDebugForTransparent)
{
settings.sorting.sortOptions = SortOptions.BackToFront;
settings.inputCullingOptions.SetQueuesTransparent();
renderLoop.DrawRenderers(ref settings);
}
RenderOpaqueRenderList(cull, camera, renderLoop, "Debug");
RenderTransparentRenderList(cull, camera, renderLoop, "Debug");
cmd.name = "FinalPass";
cmd.Blit(s_CameraColorBuffer, BuiltinRenderTextureType.CameraTarget, m_FinalPassMaterial, 0);
cmd.name = "Blit Material Debug";
cmd.Blit(s_CameraColorBuffer, BuiltinRenderTextureType.CameraTarget);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}

// gbufferManager.BindBuffers(m_DeferredMaterial);
// TODO: Bind depth textures
var cmd = new CommandBuffer();
cmd.name = "GBuffer Debug";
cmd.Blit(null, new RenderTargetIdentifier(s_CameraColorBuffer), m_GBufferDebugMaterial, 0);
cmd.name = "GBuffer Debug Pass";
cmd.Blit(null, BuiltinRenderTextureType.CameraTarget, m_GBufferDebugMaterial, 0);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}

renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
DrawRendererSettings settings = new DrawRendererSettings(cullResults, camera, new ShaderPassName("Forward"));
settings.rendererConfiguration = RendererConfiguration.ConfigureOneLightProbePerRenderer | RendererConfiguration.ConfigureReflectionProbesProbePerRenderer;
settings.sorting.sortOptions = SortOptions.SortByMaterialThenMesh;
settings.inputCullingOptions.SetQueuesTransparent();
renderLoop.DrawRenderers(ref settings);
RenderTransparentRenderList(cullResults, camera, renderLoop, "Forward");
}
void FinalPass(RenderLoop renderLoop)

m_FinalPassMaterial.SetVector("_ToneMapCoeffs1", tonemapCoeff1);
m_FinalPassMaterial.SetVector("_ToneMapCoeffs2", tonemapCoeff2);
m_FinalPassMaterial.SetFloat("_EnableToneMap", enableTonemap ? 1.0f : 0.0f);
m_FinalPassMaterial.SetFloat("_Exposure", exposure);
m_FinalPassMaterial.SetFloat("_EnableToneMap", debugParameters.enableTonemap ? 1.0f : 0.0f);
m_FinalPassMaterial.SetFloat("_Exposure", debugParameters.exposure);
CommandBuffer cmd = new CommandBuffer();
cmd.name = "FinalPass";

//UpdateLightConstants(cullResults.culledLights /*, ref shadows */);
if (debugParameters.materialDebugMode == MaterialDebugMode.None)
bool needDebugRendering = debugParameters.materialDebugMode != MaterialDebugMode.None || debugParameters.gBufferDebugMode != GBufferDebugMode.None;
if (!needDebugRendering)
if(debugParameters.displayOpaqueObjects)
RenderGBuffer(cullResults, camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
if(debugParameters.displayTransparentObjects)
RenderForward(cullResults, camera, renderLoop);
if (debugParameters.gBufferDebugMode != GBufferDebugMode.None)
{
RenderGBufferDebug(camera, renderLoop);
}
RenderForward(cullResults, camera, renderLoop);
RenderMaterialDebug(cullResults, camera, renderLoop);
if(debugParameters.materialDebugMode != MaterialDebugMode.None)
{
RenderMaterialDebug(cullResults, camera, renderLoop);
}
else if (debugParameters.gBufferDebugMode != GBufferDebugMode.None)
{
InitAndClearBuffer(camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
RenderGBufferDebug(camera, renderLoop);
}
}
renderLoop.Submit ();

10
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoopInspector.cs


{
public readonly GUIContent debugParameters = new GUIContent("Debug Parameters");
public readonly GUIContent materialDebugMode = new GUIContent("Material Debug Mode", "Display various properties of Materials.");
public readonly GUIContent transparentMaterialDebugMode = new GUIContent("Transparent Material Debug", "Display material debug for transparent objects.");
public readonly GUIContent enableTonemap = new GUIContent("Enable Tonemap");
public readonly GUIContent exposure = new GUIContent("Exposure");
public readonly GUIContent[] materialDebugStrings = { new GUIContent("None"),
new GUIContent("Diffuse Color"),

private static Styles s_Styles = null;
private static Styles styles { get { if (s_Styles == null) s_Styles = new Styles(); return s_Styles; } }
const float kMaxExposure = 32.0f;
public override void OnInspectorGUI()
{
HDRenderLoop renderLoop = target as HDRenderLoop;

debugParameters.gBufferDebugMode = (HDRenderLoop.GBufferDebugMode)EditorGUILayout.IntPopup(styles.gBufferDebugMode, (int)debugParameters.gBufferDebugMode, styles.gBufferDebugStrings, styles.gBufferDebugValues);
debugParameters.materialDebugMode = (HDRenderLoop.MaterialDebugMode)EditorGUILayout.IntPopup(styles.materialDebugMode, (int)debugParameters.materialDebugMode, styles.materialDebugStrings, styles.materialDebugValues);
debugParameters.displayMaterialDebugForTransparent = EditorGUILayout.Toggle(styles.transparentMaterialDebugMode, debugParameters.displayMaterialDebugForTransparent);
EditorGUILayout.Space();
debugParameters.enableTonemap = EditorGUILayout.Toggle(styles.enableTonemap, debugParameters.enableTonemap);
debugParameters.exposure = Mathf.Max(Mathf.Min(EditorGUILayout.FloatField(styles.exposure, debugParameters.exposure), kMaxExposure), -kMaxExposure);
EditorGUILayout.Space();
debugParameters.displayOpaqueObjects = EditorGUILayout.Toggle(styles.displayOpaqueObjects, debugParameters.displayOpaqueObjects);

正在加载...
取消
保存