Evgenii Golubev 8 年前
当前提交
538bf3b2
共有 20 个文件被更改,包括 52 次插入54 次删除
  1. 4
      Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs
  2. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugDisplayShadowMap.shader
  3. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewMaterialGBuffer.shader
  4. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewTiles.shader
  5. 13
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  6. 18
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  7. 3
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/Resources/Deferred.shader
  8. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/LightingConvexHullUtils.hlsl
  9. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute
  10. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  11. 3
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  12. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl
  13. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl
  14. 2
      Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs
  15. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl
  16. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/API/Metal.hlsl
  17. 2
      Assets/ScriptableRenderLoop/ShaderLibrary/API/PSSL.hlsl
  18. 9
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  19. 7
      Assets/ScriptableRenderLoop/fptl/FptlLighting.cs
  20. 2
      Assets/ScriptableRenderLoop/fptl/LightingConvexHullUtils.hlsl

4
Assets/BasicRenderLoopTutorial/BasicRenderLoop.cs


var settings = new DrawRendererSettings(cull, camera, new ShaderPassName("BasicPass"));
settings.sorting.flags = SortFlags.CommonOpaque;
settings.inputFilter.SetQueuesOpaque();
context.DrawRenderers(settings);
context.DrawRenderers(ref settings);
// Draw skybox
context.DrawSkybox(camera);

settings.inputFilter.SetQueuesTransparent();
context.DrawRenderers(settings);
context.DrawRenderers(ref settings);
context.Submit();
}

26
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugDisplayShadowMap.shader


Varyings Vert(Attributes input)
{
float4 positions[] =
{
float4(-1.0, -1.0, 0.0f, 1.0),
float4( 1.0, -1.0, 0.0f, 1.0),
float4( 1.0, 1.0, 0.0f, 1.0),
float4( 1.0, 1.0, 0.0f, 1.0),
float4(-1.0, 1.0, 0.0f, 1.0),
float4(-1.0, -1.0, 0.0f, 1.0)
};
float2 texcoords[] =
{
float2(0.0, 1.0),
float2(1.0, 1.0),
float2(1.0, 0.0),
float2(1.0, 0.0),
float2(0.0, 0.0),
float2(0.0, 1.0),
};
output.positionCS = positions[input.vertexID];
output.texcoord = texcoords[input.vertexID] * _TextureScaleBias.xy + _TextureScaleBias.zw;
output.positionCS = GetFullscreenTriangleVertexPosition(input.vertexID);
output.texcoord = GetFullscreenTriangleTexcoord(input.vertexID) * _TextureScaleBias.xy + _TextureScaleBias.zw;
return output;
}

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


DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
int _DebugViewMaterial;

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Debug/Resources/DebugViewTiles.shader


// variable declaration
//-------------------------------------------------------------------------------------
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
uint _ViewTilesFlags;

13
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


method.Invoke(asset, new object[0]);
}
private void DebuggingUI(HDRenderPipeline renderContext)
private void DebuggingUI(HDRenderPipeline renderContext, HDRenderPipelineInstance renderpipelineInstance)
{
EditorGUILayout.LabelField(styles.debugging);

DebugParametersUI(renderContext);
EditorGUILayout.Space();
ShadowDebugParametersUI(renderContext);
ShadowDebugParametersUI(renderContext, renderpipelineInstance);
EditorGUI.indentLevel--;
}

}
}
private void ShadowDebugParametersUI(HDRenderPipeline renderContext)
private void ShadowDebugParametersUI(HDRenderPipeline renderContext, HDRenderPipelineInstance renderpipelineInstance)
{
m_ShowDebugShadow.boolValue = EditorGUILayout.Foldout(m_ShowDebugShadow.boolValue, styles.shadowDebugParameters);
if (!m_ShowDebugShadow.boolValue)

{
if ((ShadowDebugMode)m_DebugShadowVisualizationMode.intValue == ShadowDebugMode.VisualizeShadowMap)
{
EditorGUILayout.IntSlider(m_DebugShadowVisualizeShadowIndex, 0, 5/*renderContext.GetCurrentShadowCount() - 1*/, styles.shadowDebugVisualizeShadowIndex);
EditorGUILayout.IntSlider(m_DebugShadowVisualizeShadowIndex, 0, renderpipelineInstance.GetCurrentShadowCount() - 1, styles.shadowDebugVisualizeShadowIndex);
}
}
EditorGUI.indentLevel--;

public override void OnInspectorGUI()
{
var renderContext = target as HDRenderPipeline;
HDRenderPipelineInstance renderpipelineInstance = UnityEngine.Experimental.Rendering.RenderPipelineManager.currentPipeline as HDRenderPipelineInstance;
if (!renderContext)
if (!renderContext || renderpipelineInstance == null)
DebuggingUI(renderContext);
DebuggingUI(renderContext, renderpipelineInstance);
SkySettingsUI(renderContext);
SssSettingsUI(renderContext);
ShadowParametersUI(renderContext);

18
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


Shader.SetGlobalInt("_EnvLightSkyEnabled", 1);
}
else
{
{
}
}
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)
{

sorting = { flags = SortFlags.CommonOpaque }
};
settings.inputFilter.SetQueuesOpaque();
renderContext.DrawRenderers(settings);
renderContext.DrawRenderers(ref settings);
}
void RenderTransparentRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderContext, string passName, RendererConfiguration rendererConfiguration = 0)

sorting = { flags = SortFlags.CommonTransparent }
};
settings.inputFilter.SetQueuesTransparent();
renderContext.DrawRenderers(settings);
renderContext.DrawRenderers(ref settings);
}
void RenderDepthPrepass(CullResults cull, Camera camera, ScriptableRenderContext renderContext)

propertyBlock.SetVector("_TextureScaleBias", texcoordScaleBias);
debugCB.SetViewport(new Rect(x, y, overlaySize, overlaySize));
debugCB.DrawProcedural(Matrix4x4.identity, m_DebugDisplayShadowMap, 0, MeshTopology.Triangles, 6, 1, propertyBlock);
debugCB.DrawProcedural(Matrix4x4.identity, m_DebugDisplayShadowMap, 0, MeshTopology.Triangles, 3, 1, propertyBlock);
NextOverlayCoord(ref x, ref y, overlaySize, camera.pixelWidth);
}

propertyBlock.SetVector("_TextureScaleBias", new Vector4(1.0f, 1.0f, 0.0f, 0.0f));
debugCB.SetViewport(new Rect(x, y, overlaySize, overlaySize));
debugCB.DrawProcedural(Matrix4x4.identity, m_DebugDisplayShadowMap, 0, MeshTopology.Triangles, 6, 1, propertyBlock);
debugCB.DrawProcedural(Matrix4x4.identity, m_DebugDisplayShadowMap, 0, MeshTopology.Triangles, 3, 1, propertyBlock);
NextOverlayCoord(ref x, ref y, overlaySize, camera.pixelWidth);
}

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


ZWrite Off
ZTest Always
Blend [_SrcBlend] [_DstBlend], One Zero
Cull Off
HLSLPROGRAM
#pragma target 4.5

DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
struct Attributes

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/LightingConvexHullUtils.hlsl


#if 1
float3 maxZdir = float3(-sphCen.z*sphCen.x, -sphCen.z*sphCen.y, sphCen.x*sphCen.x + sphCen.y*sphCen.y); // cross(sphCen,cross(Zaxis,sphCen))
float len = length(maxZdir);
float scalarProj = len>0.0001 ? (maxZdir.z/len) : len; // since len>=(maxZdir.z/len) we can use len as an approximate value when len<=epsilon
float scalarProj = len>0.0001 ? (maxZdir.z/len) : len; // if len<=0.0001 then either |sphCen|<sphRadius or sphCen is very closely aligned with Z axis in which case little to no additional offs needed.
float offs = scalarProj*sphRadiusIn;
#else
float offs = sphRadiusIn; // more false positives due to larger radius but works too

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Lighting/TilePass/Resources/shadeopaque.compute


DECLARE_GBUFFER_TEXTURE(_GBufferTexture);
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
SAMPLER2D(sampler_CameraDepthTexture);
#ifdef OUTPUT_SPLIT_LIGHTING

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


var cmd = new CommandBuffer() { name = "" };
// generate screen-space AABBs (used for both fptl and clustered).
if (m_lightCount != 0)
{
temp.SetRow(0, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
temp.SetRow(1, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));

3
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader


Pass Keep
}
Cull Off
ZTest Always
ZWrite Off
Blend One [_DstBlend]

float4 _FilterKernels[N_PROFILES][N_SAMPLES + 1]; // RGB = weights, A = radial distance
float4x4 _InvProjMatrix;
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
TEXTURE2D(_GBufferTexture2);
TEXTURE2D(_IrradianceSource);

2
Assets/ScriptableRenderLoop/HDRenderPipeline/ShaderVariables.hlsl


CBUFFER_END
// TODO: Change code here so probe volume use only one transform instead of all this parameters!
TEXTURE3D(unity_ProbeVolumeSH);
TEXTURE3D_FLOAT(unity_ProbeVolumeSH);
SAMPLER3D(samplerunity_ProbeVolumeSH);
CBUFFER_START(UnityProbeVolume)

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl


SAMPLER2D(sampler_CameraDepthTexture);
#define SRL_BilinearSampler sampler_CameraDepthTexture // Used for all textures
TEXTURE2D(_CameraDepthTexture);
TEXTURE2D_FLOAT(_CameraDepthTexture);
TEXTURE2D(_OcclusionTexture);
float HenyeyGreensteinPhase(float g, float cosTheta) {

2
Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs


commandBuffer.Dispose();
// Render
loop.DrawShadows(settings);
loop.DrawShadows(ref settings);
}
}
}

2
Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl


#define TEXTURE2D_HALF TEXTURE2D
#define TEXTURE2D_FLOAT TEXTURE2D
#define TEXTURE3D_HALF TEXTURE3D
#define TEXTURE3D_FLOAT TEXTURE3D
#define SAMPLER2D_HALF SAMPLER2D
#define SAMPLER2D_FLOAT SAMPLER2D

2
Assets/ScriptableRenderLoop/ShaderLibrary/API/Metal.hlsl


#define TEXTURE2D_HALF TEXTURE2D
#define TEXTURE2D_FLOAT TEXTURE2D
#define TEXTURE3D_HALF TEXTURE3D
#define TEXTURE3D_FLOAT TEXTURE3D
#define SAMPLER2D_HALF SAMPLER2D
#define SAMPLER2D_FLOAT SAMPLER2D

2
Assets/ScriptableRenderLoop/ShaderLibrary/API/PSSL.hlsl


#define TEXTURE2D_HALF TEXTURE2D
#define TEXTURE2D_FLOAT TEXTURE2D
#define TEXTURE3D_HALF TEXTURE3D
#define TEXTURE3D_FLOAT TEXTURE3D
#define SAMPLER2D_HALF SAMPLER2D
#define SAMPLER2D_FLOAT SAMPLER2D

9
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


// Generates a triangle in homogeneous clip space, s.t.
// v0 = (-1, -1, 1), v1 = (3, -1, 1), v2 = (-1, 3, 1).
float2 GetFullscreenTriangleTexcoord(uint vertexID)
{
#if UNITY_UV_STARTS_AT_TOP
return float2((vertexID << 1) & 2, 1.0 - (vertexID & 2));
#else
return float2((vertexID << 1) & 2, vertexID & 2);
#endif
}
float4 GetFullscreenTriangleVertexPosition(uint vertexID)
{
float2 uv = float2((vertexID << 1) & 2, vertexID & 2);

7
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs


//@TODO: need to get light probes + LPPV too?
settings.inputFilter.SetQueuesOpaque();
settings.rendererConfiguration = RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe;
loop.DrawRenderers(settings);
loop.DrawRenderers(ref settings);
}
void RenderForward(CullResults cull, Camera camera, ScriptableRenderContext loop, bool opaquesOnly)

if (opaquesOnly) settings.inputFilter.SetQueuesOpaque();
else settings.inputFilter.SetQueuesTransparent();
loop.DrawRenderers(settings);
loop.DrawRenderers(ref settings);
}
static void DepthOnlyForForwardOpaques(CullResults cull, Camera camera, ScriptableRenderContext loop)

sorting = { flags = SortFlags.CommonOpaque }
};
settings.inputFilter.SetQueuesOpaque();
loop.DrawRenderers(settings);
loop.DrawRenderers(ref settings);
}
bool usingFptl

var cmd = new CommandBuffer() { name = "Build light list" };
// generate screen-space AABBs (used for both fptl and clustered).
if (numLights != 0)
{
var proj = CameraProjection(camera);
var temp = new Matrix4x4();

2
Assets/ScriptableRenderLoop/fptl/LightingConvexHullUtils.hlsl


#if 1
float3 maxZdir = float3(-sphCen.z*sphCen.x, -sphCen.z*sphCen.y, sphCen.x*sphCen.x + sphCen.y*sphCen.y); // cross(sphCen,cross(Zaxis,sphCen))
float len = length(maxZdir);
float scalarProj = len>0.0001 ? (maxZdir.z/len) : len; // since len>=(maxZdir.z/len) we can use len as an approximate value when len<=epsilon
float scalarProj = len>0.0001 ? (maxZdir.z/len) : len; // if len<=0.0001 then either |sphCen|<sphRadius or sphCen is very closely aligned with Z axis in which case little to no additional offs needed.
float offs = scalarProj*sphRadiusIn;
#else
float offs = sphRadiusIn; // more false positives due to larger radius but works too

正在加载...
取消
保存