浏览代码

Implement the full screen triangle shader

/main
Evgenii Golubev 8 年前
当前提交
020f5c12
共有 3 个文件被更改,包括 27 次插入9 次删除
  1. 16
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader
  2. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  3. 18
      Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs

16
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader


#include "Common.hlsl"
// Note: We have fix as guidelines that we have only one deferred material (with control of GBuffer enabled). Mean a users that add a new
// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem),
// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem),
float3 positionOS : POSITION;
uint vertexId : SV_VertexID;
};
struct Varyings

Varyings Vert(Attributes input)
{
// TODO: implement SV_vertexID full screen quad
// Lights are draw as one fullscreen quad
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionCS = TransformWorldToHClip(positionWS);
// Generate a triangle in homogeneous clip space, s.t.
// v0 = (-1, -1, 1), v1 = (3, -1, 1), v2 = (-1, 3, 1).
output.positionCS = float4(float(input.vertexId % 2) * 4.0 - 1.0,
float(input.vertexId / 2) * 4.0 - 1.0, 1.0, 1.0);
return output;
}

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs


m_SingleDeferredMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m_SingleDeferredMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
cmd.Blit(null, cameraColorBufferRT, m_SingleDeferredMaterial, 0);
Utilities.DrawFullscreen(renderContext, m_SingleDeferredMaterial, cameraColorBufferRT, 0);
}
else
{

18
Assets/ScriptableRenderLoop/HDRenderPipeline/Utilities.cs


cmd.Dispose();
}
static Mesh m_ScreenSpaceTriangle = new Mesh
{
// Note: the vertex data is not actually used if the vertex shader computes vertices using 'SV_VertexID'.
// However, there is currently no way to bind a NULL vertex buffer.
vertices = new [] { new Vector3(-1, -1, 1), new Vector3(3, -1, 1), new Vector3(-1, 3, 1) },
triangles = new [] { 0, 1, 2 }
};
// Draws a full screen triangle as a faster alternative to drawing a full-screen quad.
public static void DrawFullscreen(ScriptableRenderContext context, Material material, RenderTargetIdentifier colorBuffer, int shaderPassID = 0)
{
var cmd = new CommandBuffer() { name = material.GetPassName(shaderPassID) };
cmd.SetRenderTarget(colorBuffer);
cmd.DrawMesh(m_ScreenSpaceTriangle, Matrix4x4.identity, material, 0, shaderPassID);
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// Miscellanous
public static Material CreateEngineMaterial(string shaderPath)
{

正在加载...
取消
保存