浏览代码

HDRenderLoop: Commit second draft, need testing

/main
Sebastien Lagarde 8 年前
当前提交
0e900c4e
共有 10 个文件被更改,包括 624 次插入900 次删除
  1. 17
      Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
  2. 262
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  3. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightDefinition.cs
  4. 145
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightLoop.cs
  5. 998
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs
  6. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.hlsl
  7. 3
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.shader
  8. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightLoop.cs.meta
  9. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.cs.meta
  10. 71
      Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.cs

17
Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs


public readonly GUIContent tileLightLoopSettings = new GUIContent("Tile Light Loop settings");
public readonly string[] tileLightLoopDebugTileFlagStrings = new string[] { "Direct Light", "Reflection Light", "Area Light"};
public readonly GUIContent directIndirectSinglePass = new GUIContent("Enable direct and indirect lighting in single pass", "Toggle");
public readonly GUIContent splitLightEvaluation = new GUIContent("Enable direct and indirect lighting in single pass", "Toggle");
public readonly GUIContent disableTileAndCluster = new GUIContent("Disable Tile/clustered", "Toggle");
public readonly GUIContent textureSettings = new GUIContent("texture Settings");

EditorGUILayout.Space();
if (renderLoop.tilePassLightLoop != null)
// TODO: we should call a virtual method or something similar to setup the UI, inspector should not know about it
TilePass tilePass = renderLoop.lightLoop as TilePass;
if (tilePass != null)
renderLoop.tilePassLightLoop.debugViewTilesFlags = EditorGUILayout.MaskField("DebugView Tiles", renderLoop.tilePassLightLoop.debugViewTilesFlags, styles.tileLightLoopDebugTileFlagStrings);
renderLoop.tilePassLightLoop.enableDirectIndirectSinglePass = EditorGUILayout.Toggle(styles.directIndirectSinglePass, renderLoop.tilePassLightLoop.enableDirectIndirectSinglePass);
renderLoop.tilePassLightLoop.enableBigTilePrepass = EditorGUILayout.Toggle(styles.bigTilePrepass, renderLoop.tilePassLightLoop.enableBigTilePrepass);
renderLoop.tilePassLightLoop.enableClustered = EditorGUILayout.Toggle(styles.clustered, renderLoop.tilePassLightLoop.enableClustered);
tilePass.debugViewTilesFlags = EditorGUILayout.MaskField("DebugView Tiles", tilePass.debugViewTilesFlags, styles.tileLightLoopDebugTileFlagStrings);
tilePass.enableSplitLightEvaluation = EditorGUILayout.Toggle(styles.directSplitLightEvaluation, tilePass.enableSplitLightEvaluation);
tilePass.enableBigTilePrepass = EditorGUILayout.Toggle(styles.bigTilePrepass, tilePass.enableBigTilePrepass);
tilePass.enableClustered = EditorGUILayout.Toggle(styles.clustered, tilePass.enableClustered);
tilePass.disableTileAndCluster = EditorGUILayout.Toggle(styles.disableTileAndCluster, tilePass.disableTileAndCluster);
if (EditorGUI.EndChangeCheck())
{

262
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


int m_WidthOnRecord;
int m_HeightOnRecord;
enum LightLoopType
// This must be allocate outside of Rebuild() else the option in the class can't be set in the inspector (as it will in this case recreate the class with default value)
LightLoop m_lightLoop = new TilePass();
public LightLoop lightLoop
SinglePass = 0,
TilePass = 1
};
// This must be init externally else The value can't be set in the inspector... (as it will recreate the class with default value)
LightLoop m_lightLoop = new SinglePass();
get { return m_lightLoop; }
}
// TODO: Find a way to automatically create/iterate through deferred material
// TODO TO CHECK: SebL I move allocation from Rebuild() to here, but there was a comment "// Our object can be garbage collected, so need to be allocate here", it is still true ?

// "SendMessage cannot be called during Awake, CheckConsistency, or OnValidate UnityEngine.Experimental.ScriptableRenderLoop.HDRenderLoop:OnValidate()"
// Workaround is to declare this dirty flag and call REbuild in Render()
m_Dirty = true;
}
public void ChangeLoop(LightLoopType type)
{
m_lightLoop.Cleanup();
switch (type)
{
case LightLoopType.SinglePass:
m_lightLoop = new SinglePass();
break;
case LightLoopType.TilePass:
m_lightLoop = new TilePass();
break;
}
m_lightLoop.Rebuild();
}
public override void Rebuild()

m_DistortionBufferRT = new RenderTargetIdentifier(m_DistortionBuffer);
m_LitRenderLoop.Rebuild();
// Init various light loop
m_lightLoop.Rebuild();
m_lightLoop.Rebuild(m_TextureSettings);
m_Dirty = false;
}

{
using (new Utilities.ProfilingSample("InitAndClearBuffer", renderLoop))
{
// We clear only the depth buffer, no need to clear the various color buffer as we overwrite them.
// Clear depth/stencil and init buffers
// We clear only the depth buffer, no need to clear the various color buffer as we overwrite them.
// Clear depth/stencil and init buffers
cmd.name = "";
cmd.name = "";
// Init buffer
// With scriptable render loop we must allocate ourself depth and color buffer (We must be independent of backbuffer for now, hope to fix that later).

// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.
// Clear HDR target
using (new Utilities.ProfilingSample("Clear HDR target", renderLoop))
using (new Utilities.ProfilingSample("Clear HDR target", renderLoop))
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
using (new Utilities.ProfilingSample("Clear GBuffer", renderLoop))
using (new Utilities.ProfilingSample("Clear GBuffer", renderLoop))
Utilities.SetRenderTarget(renderLoop, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
Utilities.SetRenderTarget(renderLoop, m_gbufferManager.GetGBuffers(), m_CameraDepthBufferRT, ClearFlag.ClearColor, Color.black);
}
// END TEMP

if (debugParameters.useDepthPrepass)
return;
using (new Utilities.ProfilingSample("Depth Prepass", renderLoop))
using (new Utilities.ProfilingSample("Forward opaque depth", renderLoop))
// or use the new MAterial.SetPassEnable ?
Utilities.SetRenderTarget(renderLoop, m_CameraDepthBufferRT);
RenderOpaqueRenderList(cull, camera, renderLoop, "DepthOnly");
}

m_SkyRenderer.RenderSky(camera, m_SkyParameters, m_CameraColorBufferRT, m_CameraDepthBufferRT, renderLoop);
}
void RenderForward(CullResults cullResults, Camera camera, RenderLoop renderLoop)
void RenderForward(CullResults cullResults, Camera camera, RenderLoop renderLoop, bool renderOpaque)
{
using (new Utilities.ProfilingSample("Forward Pass", renderLoop))
{

Utilities.SetRenderTarget(renderLoop, m_CameraColorBufferRT, m_CameraDepthBufferRT);
m_lightLoop.RenderForward(camera, renderLoop, renderOpaque);
if (debugParameters.useForwardRenderingOnly)
{

}
for (int lightIndex = 0, numLights = cullResults.visibleLights.Length; lightIndex < numLights; ++lightIndex)
{
var light = cullResults.visibleLights[lightIndex];
// We only process light with additional data
var additionalData = light.light.GetComponent<AdditionalLightData>();
if (additionalData == null)
{
Debug.LogWarning("Light entity detected without additional data, will not be taken into account " + light.light.name);
continue;
}
// Note: LightType.Area is offline only, use for baking, no need to test it
var lightData = new LightData();
// Test whether we should treat this punctual light as an area light.
// It's a temporary hack until the proper UI support is added.
if (additionalData.archetype != LightArchetype.Punctual)
{
// Early out if we reach the maximum
if (lightList.areaLights.Count >= k_MaxAreaLightsOnSCreen)
continue;
if (additionalData.archetype == LightArchetype.Rectangle)
{
lightData.lightType = GPULightType.Rectangle;
}
else
{
lightData.lightType = GPULightType.Line;
}
}
else
{
if (lightList.punctualLights.Count >= k_MaxPunctualLightsOnSCreen)
continue;
switch (light.lightType)
{
case LightType.Directional: lightData.lightType = GPULightType.Directional; break;
case LightType.Spot: lightData.lightType = GPULightType.Spot; break;
case LightType.Point: lightData.lightType = GPULightType.Point; break;
}
}
lightData.positionWS = light.light.transform.position;
lightData.invSqrAttenuationRadius = 1.0f / (light.range * light.range);
lightData.color = new Vector3(lightColorR, lightColorG, lightColorB);
lightData.forward = light.light.transform.forward; // Note: Light direction is oriented backward (-Z)
lightData.up = light.light.transform.up;
lightData.right = light.light.transform.right;
if (lightData.lightType == GPULightType.Spot)
{
var spotAngle = light.spotAngle;
var innerConePercent = additionalData.GetInnerSpotPercent01();
var cosSpotOuterHalfAngle = Mathf.Clamp(Mathf.Cos(spotAngle * 0.5f * Mathf.Deg2Rad), 0.0f, 1.0f);
var sinSpotOuterHalfAngle = Mathf.Sqrt(1.0f - cosSpotOuterHalfAngle * cosSpotOuterHalfAngle);
var cosSpotInnerHalfAngle = Mathf.Clamp(Mathf.Cos(spotAngle * 0.5f * innerConePercent * Mathf.Deg2Rad), 0.0f, 1.0f); // inner cone
var val = Mathf.Max(0.001f, (cosSpotInnerHalfAngle - cosSpotOuterHalfAngle));
lightData.angleScale = 1.0f / val;
lightData.angleOffset = -cosSpotOuterHalfAngle * lightData.angleScale;
// TODO: find a proper place to store the cotangent.
lightData.size.x = cosSpotOuterHalfAngle / sinSpotOuterHalfAngle;
}
else
{
// 1.0f, 2.0f are neutral value allowing GetAngleAnttenuation in shader code to return 1.0
lightData.angleScale = 1.0f;
lightData.angleOffset = 2.0f;
}
lightData.diffuseScale = additionalData.affectDiffuse ? 1.0f : 0.0f;
lightData.specularScale = additionalData.affectSpecular ? 1.0f : 0.0f;
lightData.shadowDimmer = additionalData.shadowDimmer;
lightData.IESIndex = -1;
lightData.cookieIndex = -1;
lightData.shadowIndex = -1;
if (light.light.cookie != null)
{
// TODO: add texture atlas support for cookie textures.
switch (light.lightType)
{
case LightType.Spot:
lightData.cookieIndex = m_CookieTexArray.FetchSlice(light.light.cookie);
break;
case LightType.Point:
lightData.cookieIndex = m_CubeCookieTexArray.FetchSlice(light.light.cookie);
break;
}
}
// Setup shadow data arrays
bool hasShadows = light.light.shadows != LightShadows.None && shadowOutput.GetShadowSliceCountLightIndex(lightIndex) != 0;
bool hasNotReachMaxLimit = lightList.punctualShadows.Count + (lightData.lightType == GPULightType.Point ? 6 : 1) <= k_MaxShadowOnScreen;
if (hasShadows && hasNotReachMaxLimit) // Note < MaxShadows should be check at shadowOutput creation
{
// When we have a point light, we assumed that there is 6 consecutive PunctualShadowData
lightData.shadowIndex = lightList.punctualShadows.Count;
for (int sliceIndex = 0; sliceIndex < shadowOutput.GetShadowSliceCountLightIndex(lightIndex); ++sliceIndex)
{
PunctualShadowData punctualShadowData = new PunctualShadowData();
int shadowSliceIndex = shadowOutput.GetShadowSliceIndex(lightIndex, sliceIndex);
punctualShadowData.worldToShadow = shadowOutput.shadowSlices[shadowSliceIndex].shadowTransform.transpose; // Transpose for hlsl reading ?
punctualShadowData.lightType = lightData.lightType;
punctualShadowData.bias = light.light.shadowBias;
lightList.punctualShadows.Add(punctualShadowData);
}
}
if (additionalData.archetype == LightArchetype.Punctual)
{
lightList.punctualLights.Add(lightData);
}
else
{
lightData.twoSided = additionalData.isDoubleSided;
lightData.size = new Vector2(additionalData.areaLightLength,
additionalData.areaLightWidth);
// Area and line lights are both currently stored as area lights on the GPU.
lightList.areaLights.Add(lightData);
}
}
for (int probeIndex = 0, numProbes = cullResults.visibleReflectionProbes.Length; probeIndex < numProbes; probeIndex++)
{
var probe = cullResults.visibleReflectionProbes[probeIndex];
// If probe have not been rendered discard
if (probe.texture == null)
continue;
if (lightList.envLights.Count >= k_MaxEnvLightsOnSCreen)
continue;
var envLightData = new EnvLightData();
// CAUTION: localToWorld is the transform for the widget of the reflection probe. i.e the world position of the point use to do the cubemap capture (mean it include the local offset)
envLightData.positionWS = probe.localToWorld.GetColumn(3);
envLightData.envShapeType = EnvShapeType.None;
// TODO: Support sphere in the interface
if (probe.boxProjection != 0)
{
envLightData.envShapeType = EnvShapeType.Box;
}
// remove scale from the matrix (Scale in this matrix is use to scale the widget)
envLightData.right = probe.localToWorld.GetColumn(0);
envLightData.right.Normalize();
envLightData.up = probe.localToWorld.GetColumn(1);
envLightData.up.Normalize();
envLightData.forward = probe.localToWorld.GetColumn(2);
envLightData.forward.Normalize();
// Artists prefer to have blend distance inside the volume!
// So we let the current UI but we assume blendDistance is an inside factor instead
// Blend distance can't be larger than the max radius
// probe.bounds.extents is BoxSize / 2
float maxBlendDist = Mathf.Min(probe.bounds.extents.x, Mathf.Min(probe.bounds.extents.y, probe.bounds.extents.z));
float blendDistance = Mathf.Min(maxBlendDist, probe.blendDistance);
envLightData.innerDistance = probe.bounds.extents - new Vector3(blendDistance, blendDistance, blendDistance);
envLightData.envIndex = m_CubeReflTexArray.FetchSlice(probe.texture);
envLightData.offsetLS = probe.center; // center is misnamed, it is the offset (in local space) from center of the bounding box to the cubemap capture point
envLightData.blendDistance = blendDistance;
lightList.envLights.Add(envLightData);
}
m_lightLoop.PrepareLightsForGPU(cullResults, camera);
m_lightLoop.PrepareLightsForGPU(cullResults, camera, ref shadowOutput);
}
void Resize(Camera camera)

}
}
public void PushGlobalParams(Camera camera, RenderLoop renderLoop, HDRenderLoop.LightList lightList)
public void PushGlobalParams(Camera camera, RenderLoop renderLoop)
{
if (m_SkyRenderer.IsSkyValid(m_SkyParameters))
{

Shader.SetGlobalInt("_EnvLightSkyEnabled", 0);
}
m_lightLoop.PushGlobalParams(camera, renderLoop, lightList);
m_lightLoop.PushGlobalParams(camera, renderLoop);
}
public override void Render(Camera[] cameras, RenderLoop renderLoop)

RenderDepthPrepass(cullResults, camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
// For tile lighting with forward opaque
// Forward opaque with deferred tile require that we fill the depth buffer
// correctly to build the light list.
// TODO: avoid double lighting by tagging stencil or gbuffer that we must not lit.
// TODO: ask Morten why this pass is not before GBuffer ? Will make more sense and avoid
// to do gbuffer pass on unseen mesh.
// TODO: how do we select only the object that must be render forward ?
// this is all object with gbuffer pass disabled ?
//RenderForwardOpaqueDepth(cullResults, camera, renderLoop);
if (debugParameters.debugViewMaterial != 0)

}
RenderDeferredLighting(camera, renderLoop);
RenderForward(cullResults, camera, renderLoop, true);
RenderForward(cullResults, camera, renderLoop); // Note: We want to render forward opaque before RenderSky, then RenderTransparent - can only do that once we have material.SetPass feature...
RenderForward(cullResults, camera, renderLoop, false);
RenderForwardUnlit(cullResults, camera, renderLoop);
RenderVelocity(cullResults, camera, renderLoop); // Note we may have to render velocity earlier if we do temporalAO, temporal volumetric etc... Mean we will not take into account forward opaque in case of deferred rendering ?

2
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightDefinition.cs


[GenerateHLSL]
public struct DirectionalLightData
{
public Vector3 direction;
public Vector3 forward;
public float diffuseScale;
public Vector3 up;

145
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightLoop.cs


{
public class LightLoop
{
public virtual string GetKeyword()
{
return "";
}
// TODO: We should rather put the texture settings in LightLoop, but how do we serialize it ?
public virtual void Rebuild(TextureSettings textureSettings) {}
public virtual void Rebuild()
{
m_lightList = new LightList();
public virtual void Cleanup() {}
s_DirectionalLights = new ComputeBuffer(HDRenderLoop.k_MaxDirectionalLightsOnSCreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(DirectionalLightData)));
s_DirectionalShadowList = new ComputeBuffer(HDRenderLoop.k_MaxCascadeCount, System.Runtime.InteropServices.Marshal.SizeOf(typeof(DirectionalShadowData)));
s_PunctualLightList = new ComputeBuffer(HDRenderLoop.k_MaxPunctualLightsOnSCreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightData)));
s_AreaLightList = new ComputeBuffer(HDRenderLoop.k_MaxAreaLightsOnSCreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightData)));
s_EnvLightList = new ComputeBuffer(HDRenderLoop.k_MaxEnvLightsOnSCreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData)));
s_PunctualShadowList = new ComputeBuffer(HDRenderLoop.k_MaxShadowOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(PunctualShadowData)));
public virtual bool NeedResize() { return false; }
m_CookieTexArray = new TextureCache2D();
m_CookieTexArray.AllocTextureArray(8, m_TextureSettings.spotCookieSize, m_TextureSettings.spotCookieSize, TextureFormat.RGBA32, true);
m_CubeCookieTexArray = new TextureCacheCubemap();
m_CubeCookieTexArray.AllocTextureArray(4, m_TextureSettings.pointCookieSize, TextureFormat.RGBA32, true);
m_CubeReflTexArray = new TextureCacheCubemap();
m_CubeReflTexArray.AllocTextureArray(32, m_TextureSettings.reflectionCubemapSize, TextureFormat.BC6H, true);
}
public virtual void AllocResolutionDependentBuffers(int width, int height) { }
public virtual void Cleanup()
{
Utilities.SafeRelease(s_DirectionalLights);
Utilities.SafeRelease(s_DirectionalShadowList);
Utilities.SafeRelease(s_PunctualLightList);
Utilities.SafeRelease(s_AreaLightList);
Utilities.SafeRelease(s_EnvLightList);
Utilities.SafeRelease(s_PunctualShadowList);
public virtual void ReleaseResolutionDependentBuffers() {}
if (m_CubeReflTexArray != null)
{
m_CubeReflTexArray.Release();
m_CubeReflTexArray = null;
}
if (m_CookieTexArray != null)
{
m_CookieTexArray.Release();
m_CookieTexArray = null;
}
if (m_CubeCookieTexArray != null)
{
m_CubeCookieTexArray.Release();
m_CubeCookieTexArray = null;
}
}
public virtual void NewFrame() {}
virtual void NewFrame()
{
m_CookieTexArray.NewFrame();
m_CubeCookieTexArray.NewFrame();
m_CubeReflTexArray.NewFrame();
}
public virtual void PrepareLightsForGPU(CullResults cullResults, Camera camera, ref ShadowOutput shadowOutput) { }
// TODO: this should not be aprt of the interface but for now make something working
public virtual void BuildGPULightLists(Camera camera, RenderLoop loop, RenderTargetIdentifier cameraDepthBufferRT) { }
public virtual void PushGlobalParams(Camera camera, RenderLoop loop) {}
public ShadowData GetShadowData(VisibleLight light, AdditionalLightData additionalData, int lightIndex, ref ShadowOutput shadowOutput)
{
bool hasDirectionalShadows = light.light.shadows != LightShadows.None && shadowOutput.GetShadowSliceCountLightIndex(lightIndex) != 0;
public virtual void RenderDeferredLighting(Camera camera, RenderLoop renderLoop, RenderTargetIdentifier cameraColorBufferRT) {}
if (hasDirectionalShadows)
{
for (int sliceIndex = 0; sliceIndex < shadowOutput.GetShadowSliceCountLightIndex(lightIndex); ++sliceIndex)
{
ShadowData shadowData = new ShadowData();
int shadowSliceIndex = shadowOutput.GetShadowSliceIndex(lightIndex, sliceIndex);
shadowData.worldToShadow = shadowOutput.shadowSlices[shadowSliceIndex].shadowTransform.transpose; // Transpose for hlsl reading ?
shadowData.lightType = lightData.lightType;
shadowData.bias = light.light.shadowBias;
m_lightList.directionalShadows.Add(shadowData);
}
}
}
public DirectionalLightData GetDirectionalLightData(VisibleLight light, AdditionalLightData additionalData)
{
Debug.Assert(light.lightType == LightType.Directional);
var directionalLightData = new DirectionalLightData();
// Light direction for directional and is opposite to the forward direction
directionalLightData.direction = -light.light.transform.forward;
// up and right are use for cookie
directionalLightData.up = light.light.transform.up;
directionalLightData.right = light.light.transform.right;
directionalLightData.positionWS = light.light.transform.position;
directionalLightData.color = GetLightColor(light);
directionalLightData.diffuseScale = additionalData.affectDiffuse ? 1.0f : 0.0f;
directionalLightData.specularScale = additionalData.affectSpecular ? 1.0f : 0.0f;
directionalLightData.invScaleX = 1.0f / light.light.transform.localScale.x;
directionalLightData.invScaleY = 1.0f / light.light.transform.localScale.y;
directionalLightData.cosAngle = 0.0f;
directionalLightData.sinAngle = 0.0f;
directionalLightData.shadowIndex = -1;
directionalLightData.cookieIndex = -1;
if (light.light.cookie != null)
{
directionalLightData.tileCookie = (light.light.cookie.wrapMode == TextureWrapMode.Repeat);
directionalLightData.cookieIndex = m_CookieTexArray.FetchSlice(light.light.cookie);
}
directionalLightData.shadowIndex = 0;
}
public virtual void PrepareLightsForGPU(CullResults cullResults, Camera camera) { }
public virtual void PushGlobalParams(Camera camera, RenderLoop loop)
{
Shader.SetGlobalTexture("_CookieTextures", m_CookieTexArray.GetTexCache());
Shader.SetGlobalTexture("_CookieCubeTextures", m_CubeCookieTexArray.GetTexCache());
Shader.SetGlobalTexture("_EnvTextures", m_CubeReflTexArray.GetTexCache());
s_DirectionalLights.SetData(m_lightList.directionalLights.ToArray());
s_DirectionalShadowList.SetData(m_lightList.directionalShadows.ToArray());
s_PunctualLightList.SetData(m_lightList.punctualLights.ToArray());
s_AreaLightList.SetData(m_lightList.areaLights.ToArray());
s_EnvLightList.SetData(m_lightList.envLights.ToArray());
s_PunctualShadowList.SetData(m_lightList.punctualShadows.ToArray());
Shader.SetGlobalBuffer("_DirectionalLightList", s_DirectionalLights);
Shader.SetGlobalInt("_DirectionalLightCount", m_lightList.directionalLights.Count);
Shader.SetGlobalBuffer("_DirectionalShadowList", s_DirectionalShadowList);
Shader.SetGlobalBuffer("_PunctualLightList", s_PunctualLightList);
Shader.SetGlobalInt("_PunctualLightCount", m_lightList.punctualLights.Count);
Shader.SetGlobalBuffer("_AreaLightList", s_AreaLightList);
Shader.SetGlobalInt("_AreaLightCount", m_lightList.areaLights.Count);
Shader.SetGlobalBuffer("_PunctualShadowList", s_PunctualShadowList);
Shader.SetGlobalBuffer("_EnvLightList", s_EnvLightList);
Shader.SetGlobalInt("_EnvLightCount", m_lightList.envLights.Count);
Shader.SetGlobalVectorArray("_DirShadowSplitSpheres", m_lightList.directionalShadowSplitSphereSqr);
}
public virtual void RenderDeferredLighting(Camera camera, RenderLoop renderLoop, RenderTargetIdentifier cameraColorBufferRT) {}
public virtual void RenderForward(Camera camera, RenderLoop renderLoop, bool renderOpaque) {}
}
}

998
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/TilePass/TilePass.cs
文件差异内容过多而无法显示
查看文件

2
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.hlsl


out float3 diffuseLighting,
out float3 specularLighting)
{
float3 L = lightData.direction;
float3 L = -lightData.forward; // Lights are pointing backward in Unity
float illuminance = saturate(dot(bsdfData.normalWS, L));
diffuseLighting = float3(0.0, 0.0, 0.0);

3
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.shader


#define SHADERPASS SHADERPASS_FORWARD
// TEMP until pragma work in include
// #include "../../Lighting/Forward.hlsl"
// LIGHTLOOP_TILE_PASS
#pragma multi_compile LIGHTLOOP_SINGLE_PASS
#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS
//#pragma multi_compile SHADOWFILTERING_FIXED_SIZE_PCF
#include "../../Lighting/Lighting.hlsl"

12
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/LightLoop.cs.meta


fileFormatVersion: 2
guid: 1669ef5a164969c4c90cd3509b01123d
timeCreated: 1481066258
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.cs.meta


fileFormatVersion: 2
guid: cb651810696af0d4789441b1f469aa2f
timeCreated: 1477266406
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

71
Assets/ScriptableRenderLoop/HDRenderLoop/Lighting/SinglePass/SinglePass.cs


using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using System;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
public class SinglePass : LightLoop
{
string GetKeyword()
{
return "LIGHTLOOP_SINGLE_PASS";
}
public const int k_MaxDirectionalLightsOnSCreen = 3;
public const int k_MaxPunctualLightsOnSCreen = 512;
public const int k_MaxAreaLightsOnSCreen = 128;
public const int k_MaxEnvLightsOnSCreen = 64;
public const int k_MaxShadowOnScreen = 16;
public const int k_MaxCascadeCount = 4; //Should be not less than m_Settings.directionalLightCascadeCount;
Material m_DeferredMaterial = null;
public override void Rebuild()
{
base.Rebuild();
m_DeferredMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderLoop/Deferred");
m_DeferredMaterial.EnableKeyword(GetKeyword());
}
public override void Cleanup()
{
base.Cleanup();
Utilities.Destroy(m_DeferredMaterial);
}
public override void PrepareLightsForGPU(CullResults cullResults, Camera camera)
{
}
public override void PushGlobalParams(Camera camera, RenderLoop loop)
{
base.PushGlobalParams();
}
public override void RenderDeferredLighting(Camera camera, RenderLoop renderLoop, RenderTargetIdentifier cameraColorBufferRT)
{
var invViewProj = Utilities.GetViewProjectionMatrix(camera).inverse;
m_DeferredMaterial.SetMatrix("_InvViewProjMatrix", invViewProj);
var screenSize = Utilities.ComputeScreenSize(camera);
m_DeferredMaterial.SetVector("_ScreenSize", screenSize);
m_DeferredMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
m_DeferredMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
// m_gbufferManager.BindBuffers(m_DeferredMaterial);
// TODO: Bind depth textures
using (new Utilities.ProfilingSample("SinglePass - Deferred Lighting Pass", renderLoop))
{
var cmd = new CommandBuffer { name = "" };
cmd.Blit(null, cameraColorBufferRT, m_DeferredMaterial, 0);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
}
}
正在加载...
取消
保存