浏览代码

fix formatting

/main
Tim Cooper 8 年前
当前提交
b999f813
共有 8 个文件被更改,包括 97 次插入98 次删除
  1. 4
      Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs
  2. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipeWindow.cs
  3. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  4. 169
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  5. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipelineSetup.cs
  6. 9
      Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs
  7. 4
      Assets/ScriptableRenderLoop/core/RenderPipeline.cs
  8. 2
      Assets/ScriptableRenderLoop/core/Singleton.cs

4
Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs


var instance = ScriptableObject.CreateInstance<BasicRenderLoop>();
UnityEditor.AssetDatabase.CreateAsset(instance, "Assets/BasicRenderLoopTutorial/BasicRenderLoop.asset");
}
#endif
protected override IRenderPipeline InternalCreatePipeline()

public class BasicRenderLoopInstance : RenderPipeline
{
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
{
base.Render(renderContext, cameras);

context.Submit();
}
}
// Setup lighting variables for shader to use

context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// Prepare L2 spherical harmonics values for efficient evaluation in a shader

1
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipeWindow.cs


{
public class HDRenderPipeWindow : EditorWindow
{
[MenuItem("HDRenderPipeline/Configure Overrides")]
static void ConfigureOverrides()
{

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


foreach (Object obj in materials)
{
Material mat = obj as Material;
if(mat.shader.name == "HDRenderLoop/LayeredLit")
if (mat.shader.name == "HDRenderLoop/LayeredLit")
{
LayeredLitGUI.SynchronizeAllLayers(mat);
}

169
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


}
}
}
#endif
private HDRenderPipeline()

public Vector4 screenSize;
public Matrix4x4 viewProjectionMatrix;
public Matrix4x4 invViewProjectionMatrix;
}
}
public class DebugParameters
{
// Material Debugging
public int debugViewMaterial = 0;
public class DebugParameters
{
// Material Debugging
public int debugViewMaterial = 0;
// Rendering debugging
public bool displayOpaqueObjects = true;
public bool displayTransparentObjects = true;
// Rendering debugging
public bool displayOpaqueObjects = true;
public bool displayTransparentObjects = true;
public bool useForwardRenderingOnly = false; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool useDepthPrepass = false;
public bool useDistortion = true;
public bool useForwardRenderingOnly = false; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool useDepthPrepass = false;
public bool useDistortion = true;
// we have to fallback to forward-only rendering when scene view is using wireframe rendering mode --
// as rendering everything in wireframe + deferred do not play well together
public bool ShouldUseForwardRenderingOnly () { return useForwardRenderingOnly || GL.wireframe; }
// we have to fallback to forward-only rendering when scene view is using wireframe rendering mode --
// as rendering everything in wireframe + deferred do not play well together
public bool ShouldUseForwardRenderingOnly()
{
return useForwardRenderingOnly || GL.wireframe;
}
public class GBufferManager
{
public const int MaxGbuffer = 8;
public class GBufferManager
{
public const int MaxGbuffer = 8;
public void SetBufferDescription(int index, string stringId, RenderTextureFormat inFormat, RenderTextureReadWrite inSRGBWrite)
{
IDs[index] = Shader.PropertyToID(stringId);
RTIDs[index] = new RenderTargetIdentifier(IDs[index]);
formats[index] = inFormat;
sRGBWrites[index] = inSRGBWrite;
}
public void SetBufferDescription(int index, string stringId, RenderTextureFormat inFormat, RenderTextureReadWrite inSRGBWrite)
{
IDs[index] = Shader.PropertyToID(stringId);
RTIDs[index] = new RenderTargetIdentifier(IDs[index]);
formats[index] = inFormat;
sRGBWrites[index] = inSRGBWrite;
}
public void InitGBuffers(int width, int height, CommandBuffer cmd)
public void InitGBuffers(int width, int height, CommandBuffer cmd)
{
for (int index = 0; index < gbufferCount; index++)
for (int index = 0; index < gbufferCount; index++)
{
}
}
public RenderTargetIdentifier[] GetGBuffers()
public RenderTargetIdentifier[] GetGBuffers()
{
var colorMRTs = new RenderTargetIdentifier[gbufferCount];
for (int index = 0; index < gbufferCount; index++)
var colorMRTs = new RenderTargetIdentifier[gbufferCount];
for (int index = 0; index < gbufferCount; index++)
{
colorMRTs[index] = RTIDs[index];
}
colorMRTs[index] = RTIDs[index];
}
return colorMRTs;
}
return colorMRTs;
}
/*
/*
public void BindBuffers(Material mat)
{
for (int index = 0; index < gbufferCount; index++)

}
*/
public int gbufferCount { get; set; }
int[] IDs = new int[MaxGbuffer];
RenderTargetIdentifier[] RTIDs = new RenderTargetIdentifier[MaxGbuffer];
RenderTextureFormat[] formats = new RenderTextureFormat[MaxGbuffer];
RenderTextureReadWrite[] sRGBWrites = new RenderTextureReadWrite[MaxGbuffer];
}
public int gbufferCount { get; set; }
int[] IDs = new int[MaxGbuffer];
RenderTargetIdentifier[] RTIDs = new RenderTargetIdentifier[MaxGbuffer];
RenderTextureFormat[] formats = new RenderTextureFormat[MaxGbuffer];
RenderTextureReadWrite[] sRGBWrites = new RenderTextureReadWrite[MaxGbuffer];
}
{
{
private readonly HDRenderPipeline m_Owner;
// TODO: Find a way to automatically create/iterate through deferred material

m_Owner = owner;
m_CameraColorBuffer = Shader.PropertyToID("_CameraColorTexture");
m_CameraDepthBuffer = Shader.PropertyToID("_CameraDepthTexture");
m_CameraDepthBuffer = Shader.PropertyToID("_CameraDepthTexture");
m_CameraColorBufferRT = new RenderTargetIdentifier(m_CameraColorBuffer);
m_CameraDepthBufferRT = new RenderTargetIdentifier(m_CameraDepthBuffer);

m_DistortionBufferRT = new RenderTargetIdentifier(m_DistortionBuffer);
m_LitRenderLoop.Build();
m_lightLoop = new LightLoop(owner);
m_lightLoop.Build(owner.textureSettings);

Shader.SetGlobalInt("_EnvLightSkyEnabled", 1);
}
else
{
{
}
}
var cmd = new CommandBuffer { name = "Push Global Parameters" };
var cmd = new CommandBuffer {name = "Push Global Parameters"};
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
public override void Render(ScriptableRenderContext renderContext, Camera[] cameras)
{

return;
// Set camera constant buffer
// TODO...
// TODO...
CullingParameters cullingParams;
if (!CullResults.GetCullingParameters(camera, out cullingParams))

renderContext.SetupCameraProperties(camera);
HDCamera hdCamera = Utilities.GetHDCamera(camera);
// 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();

ShadowOutput shadows;
using (new Utilities.ProfilingSample("Shadow Pass", renderContext))
{
{
}
}
{
{
m_lightLoop.PrepareLightsForGPU(m_Owner.shadowSettings, cullResults, camera, ref shadows);
m_lightLoop.BuildGPULightLists(camera, renderContext, m_CameraDepthBufferRT); // TODO: Use async compute here to run light culling during shadow
}

// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// must be call after BuildGPULightLists.
// must be call after BuildGPULightLists.
// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
UpdateSkyEnvironment(hdCamera, renderContext);

// bind depth surface for editor grid/gizmo/selection rendering
if (camera.cameraType == CameraType.SceneView)
{
{
var cmd = new CommandBuffer();
cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, m_CameraDepthBufferRT);
renderContext.ExecuteCommandBuffer(cmd);

var settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName))
{
rendererConfiguration = rendererConfiguration,
sorting = { flags = SortFlags.CommonOpaque }
sorting = {flags = SortFlags.CommonOpaque}
};
settings.inputFilter.SetQueuesOpaque();
renderContext.DrawRenderers(settings);

var settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName))
{
rendererConfiguration = rendererConfiguration,
sorting = { flags = SortFlags.CommonTransparent }
sorting = {flags = SortFlags.CommonTransparent}
};
settings.inputFilter.SetQueuesTransparent();
renderContext.DrawRenderers(settings);

{
if (debugParameters.ShouldUseForwardRenderingOnly())
{
return ;
return;
}
using (new Utilities.ProfilingSample("GBuffer Pass", renderContext))

// m_gbufferManager.BindBuffers(m_DebugViewMaterialGBuffer);
// TODO: Bind depth textures
var cmd = new CommandBuffer { name = "GBuffer Debug Pass" };
var cmd = new CommandBuffer {name = "GBuffer Debug Pass"};
cmd.Blit(null, m_CameraColorBufferRT, m_DebugViewMaterialGBuffer, 0);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();

// Last blit
{
var cmd = new CommandBuffer { name = "Blit DebugView Material Debug" };
var cmd = new CommandBuffer {name = "Blit DebugView Material Debug"};
cmd.Blit(m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();

{
if (debugParameters.ShouldUseForwardRenderingOnly())
{
return ;
return;
}
m_lightLoop.RenderDeferredLighting(hdCamera, renderContext, m_CameraColorBuffer);

{
m_SkyManager.RenderSky(hdCamera, m_lightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthBufferRT, renderContext);
}
void RenderForward(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, bool renderOpaque)
{
// TODO: Currently we can't render opaque object forward when deferred is enabled

{
// If opaque velocity have been render during GBuffer no need to render it here
if ((ShaderConfig.s_VelocityInGbuffer == 1) || debugParameters.ShouldUseForwardRenderingOnly())
return ;
return;
var cmd = new CommandBuffer { name = "" };
var cmd = new CommandBuffer {name = ""};
cmd.GetTemporaryRT(m_VelocityBuffer, w, h, 0, FilterMode.Point, Builtin.RenderLoop.GetVelocityBufferFormat(), Builtin.RenderLoop.GetVelocityBufferReadWrite());
cmd.SetRenderTarget(m_VelocityBufferRT, m_CameraDepthBufferRT);
renderContext.ExecuteCommandBuffer(cmd);

void RenderDistortion(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
{
if (!debugParameters.useDistortion)
return ;
return;
using (new Utilities.ProfilingSample("Distortion Pass", renderContext))
{

var cmd = new CommandBuffer { name = "" };
var cmd = new CommandBuffer {name = ""};
cmd.GetTemporaryRT(m_DistortionBuffer, w, h, 0, FilterMode.Point, Builtin.RenderLoop.GetDistortionBufferFormat(), Builtin.RenderLoop.GetDistortionBufferReadWrite());
cmd.SetRenderTarget(m_DistortionBufferRT, m_CameraDepthBufferRT);
cmd.ClearRenderTarget(false, true, Color.black); // TODO: can we avoid this clear for performance ?

if (!localActive)
{
var cmd = new CommandBuffer { name = "" };
var cmd = new CommandBuffer {name = ""};
cmd.Blit(m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();

}
}
// Function to prepare light structure for GPU lighting
void PrepareLightsForGPU(ShadowSettings shadowSettings, CullResults cullResults, Camera camera, ref ShadowOutput shadowOutput)
{

int w = camera.pixelWidth;
int h = camera.pixelHeight;
cmd.GetTemporaryRT(m_CameraColorBuffer, w, h, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
cmd.GetTemporaryRT(m_CameraColorBuffer, w, h, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true); // Enable UAV
{
{
}
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
{
{
}
}
{
{
{
{
}
}
// END TEMP
}
}

4
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipelineSetup.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class HDRenderPipelineSetup : ScriptableObject
{

var instance = ScriptableObject.CreateInstance<HDRenderPipelineSetup>();
UnityEditor.AssetDatabase.CreateAsset(instance, "Assets/HDRenderPipelineSetup.asset");
}
#endif
public ComputeShader buildScreenAABBShader = null;
public ComputeShader buildPerTileLightListShader = null; // FPTL

// For image based lighting
public Shader m_InitPreFGD;
}
}

9
Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs


else
UnityObject.DestroyImmediate(obj);
#else
UnityObject.Destroy(obj);
UnityObject.Destroy(obj);
#endif
obj = null;
}

buffer = null;
}
}
public class ProfilingSample
: IDisposable

}
public void Dispose()
{
{
Dispose(true);
}

if (disposed)
return;
return;
if (disposing)
{

return hdCamera;
}
public static void SetupMaterialHDCamera(HDCamera hdCamera, Material material)
{
material.SetVector("_ScreenSize", hdCamera.screenSize);

4
Assets/ScriptableRenderLoop/core/RenderPipeline.cs


if (disposed)
throw new ObjectDisposedException(string.Format("{0} has been disposed. Do not call Render on disposed RenderLoops.", this));
}
public virtual void Dispose()
{
disposed = true;

2
Assets/ScriptableRenderLoop/core/Singleton.cs


public abstract class Singleton<T> : ScriptableObject where T : ScriptableObject
{
private static T theInstance { get; set; }
protected static T instance
{
get

正在加载...
取消
保存