sebastienlagarde 8 年前
当前提交
272c1ccf
共有 5 个文件被更改,包括 40 次插入40 次删除
  1. 6
      Assets/Editor/Tests/RenderloopTests/CullResultsTest.cs
  2. 12
      Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.cs
  3. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  4. 24
      Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs
  5. 26
      Assets/ScriptableRenderLoop/fptl/FptlLighting.cs

6
Assets/Editor/Tests/RenderloopTests/CullResultsTest.cs


using UnityEngine;
using UnityEngine;
using UnityEditor;
using UnityEngine.Rendering;
using System.Collections.Generic;

{
void InspectCullResults(Camera camera, CullResults cullResults, RenderLoop renderLoop)
{
VisibleReflectionProbe[] probes = cullResults.culledReflectionProbes;
VisibleReflectionProbe[] probes = cullResults.visibleReflectionProbes;
Assert.AreEqual(1, probes.Length, "Incorrect reflection probe count");

ActiveLight[] lights = cullResults.culledLights;
VisibleLight[] lights = cullResults.visibleLights;
Assert.AreEqual(3, lights.Length, "Incorrect light count");
LightType[] expectedTypes = new LightType[] { LightType.Directional, LightType.Spot, LightType.Point };

12
Assets/ScriptableRenderLoop/ForwardRenderLoop/ForwardRenderLoop.cs


using UnityEngine;
using UnityEngine;
using System.Collections;
using UnityEngine.Rendering;
using System.Collections.Generic;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------
void UpdateLightConstants(ActiveLight[] activeLights, ref ShadowOutput shadow)
void UpdateLightConstants(VisibleLight[] visibleLights, ref ShadowOutput shadow)
{
int nNumLightsIncludingTooMany = 0;

Matrix4x4[] g_matWorldToShadow = new Matrix4x4[ MAX_LIGHTS * MAX_SHADOWMAP_PER_LIGHTS ];
Vector4[] g_vDirShadowSplitSpheres = new Vector4[ MAX_DIRECTIONAL_SPLIT ];
for ( int nLight = 0; nLight < activeLights.Length; nLight++ )
for ( int nLight = 0; nLight < visibleLights.Length; nLight++ )
{
nNumLightsIncludingTooMany++;

ActiveLight light = activeLights [nLight];
VisibleLight light = visibleLights[nLight];
LightType lightType = light.lightType;
Vector3 position = light.light.transform.position;
Vector3 lightDir = light.light.transform.forward.normalized;

renderLoop.SetupCameraProperties (camera);
UpdateLightConstants(cullResults.culledLights, ref shadows);
UpdateLightConstants(cullResults.visibleLights, ref shadows);
DrawRendererSettings settings = new DrawRendererSettings (cullResults, camera, new ShaderPassName("ForwardBase"));
settings.rendererConfiguration = RendererConfiguration.ConfigureOneLightProbePerRenderer | RendererConfiguration.ConfigureReflectionProbesProbePerRenderer;

}
#endif
}
}
}

12
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


//---------------------------------------------------------------------------------------------------------------------------------------------------
void UpdatePunctualLights(ActiveLight[] activeLights)
void UpdatePunctualLights(VisibleLight[] visibleLights)
for (int lightIndex = 0; lightIndex < Math.Min(activeLights.Length, MaxLights); lightIndex++)
for (int lightIndex = 0; lightIndex < Math.Min(visibleLights.Length, MaxLights); lightIndex++)
ActiveLight light = activeLights[lightIndex];
VisibleLight light = visibleLights[lightIndex];
if (light.lightType == LightType.Spot || light.lightType == LightType.Point || light.lightType == LightType.Directional)
{
PunctualLightData l = new PunctualLightData();

renderLoop.SetupCameraProperties (camera);
//UpdateLightConstants(cullResults.culledLights /*, ref shadows */);
//UpdateLightConstants(cullResults.visibleLights /*, ref shadows */);
UpdatePunctualLights(cullResults.culledLights);
UpdateReflectionProbes(cullResults.culledReflectionProbes);
UpdatePunctualLights (cullResults.visibleLights);
UpdateReflectionProbes(cullResults.visibleReflectionProbes);
InitAndClearBuffer(camera, renderLoop);

24
Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs


using UnityEngine;
using UnityEngine;
using System.Collections;
using UnityEngine.Rendering;
using UnityEngine.Profiling;

public int lightIndex;
}
int CalculateNumShadowSplits(int index, ActiveLight[] lights)
int CalculateNumShadowSplits(int index, VisibleLight[] lights)
{
LightType lightType = lights [index].lightType;
if (lightType == LightType.Spot)

return 6;
}
static public void ClearPackedShadows(ActiveLight[] lights, out ShadowOutput packedShadows)
static public void ClearPackedShadows(VisibleLight[] lights, out ShadowOutput packedShadows)
{
packedShadows.directionalShadowSplitSphereSqr = null;
packedShadows.shadowSlices = null;

//---------------------------------------------------------------------------------------------------------------------------------------------------
bool AutoPackLightsIntoShadowTexture(List<InputShadowLightData> shadowLights, ActiveLight[] lights, out ShadowOutput packedShadows)
bool AutoPackLightsIntoShadowTexture(List<InputShadowLightData> shadowLights, VisibleLight[] lights, out ShadowOutput packedShadows)
{
Dictionary<int, InputShadowLightData> activeShadowLights = new Dictionary<int, InputShadowLightData>();
List<int> shadowIndices = new List<int>();

static List<InputShadowLightData> GetInputShadowLightData(CullResults cullResults)
{
var shadowCasters = new List<InputShadowLightData> ();
ActiveLight[] lights = cullResults.culledLights;
VisibleLight[] lights = cullResults.visibleLights;
int directionalLightCount = 0;
for (int i = 0; i < lights.Length; i++)
{

{
if (!m_Settings.enabled)
{
ClearPackedShadows(cullResults.culledLights, out packedShadows);
ClearPackedShadows(cullResults.visibleLights, out packedShadows);
if ( !AutoPackLightsIntoShadowTexture(GetInputShadowLightData(cullResults), cullResults.culledLights, out packedShadows) )
if ( !AutoPackLightsIntoShadowTexture(GetInputShadowLightData(cullResults), cullResults.visibleLights, out packedShadows) )
{
// No shadowing lights found, so skip all rendering
return;

loop.ExecuteCommandBuffer (setRenderTargetCommandBuffer);
setRenderTargetCommandBuffer.Dispose ();
ActiveLight[] activeLights = cullResults.culledLights;
VisibleLight[] visibleLights = cullResults.visibleLights;
var shadowSlices = packedShadows.shadowSlices;
// Render each light's shadow buffer into a subrect of the shared depth texture

Matrix4x4 proj;
Matrix4x4 view;
LightType lightType = activeLights[lightIndex].lightType;
Vector3 lightDirection = activeLights[lightIndex].light.transform.forward;
var shadowNearClip = activeLights[lightIndex].light.shadowNearPlane;
LightType lightType = visibleLights[lightIndex].lightType;
Vector3 lightDirection = visibleLights[lightIndex].light.transform.forward;
var shadowNearClip = visibleLights[lightIndex].light.shadowNearPlane;
int shadowSliceIndex = packedShadows.GetShadowSliceIndex (lightIndex, 0);

loop.DrawShadows(ref settings);
}
}
}
}

26
Assets/ScriptableRenderLoop/fptl/FptlLighting.cs


using UnityEngine;
using UnityEngine;
using UnityEngine.Rendering;
using System;
using System.Collections;

cmd.SetComputeFloatParams(shadercs, name, data);
}
int UpdateDirectionalLights(Camera camera, ActiveLight[] activeLights)
int UpdateDirectionalLights(Camera camera, VisibleLight[] visibleLights)
for (int nLight = 0; nLight < activeLights.Length; nLight++)
for (int nLight = 0; nLight < visibleLights.Length; nLight++)
ActiveLight light = activeLights[nLight];
VisibleLight light = visibleLights[nLight];
if (light.lightType == LightType.Directional)
{
Debug.Assert(dirLightCount < gMaxNumDirLights, "Too many directional lights.");

return dirLightCount;
}
void UpdateShadowConstants(ActiveLight[] activeLights, ref ShadowOutput shadow)
void UpdateShadowConstants(VisibleLight[] visibleLights, ref ShadowOutput shadow)
{
int nNumLightsIncludingTooMany = 0;

Vector4[] g_vLightFalloffParams = new Vector4[MAX_LIGHTS];
for (int nLight = 0; nLight < activeLights.Length; nLight++)
for (int nLight = 0; nLight < visibleLights.Length; nLight++)
ActiveLight light = activeLights[nLight];
VisibleLight light = visibleLights[nLight];
LightType lightType = light.lightType;
Vector3 position = light.light.transform.position;
Vector3 lightDir = light.light.transform.forward.normalized;

int GenerateSourceLightBuffers(Camera camera, CullResults inputs)
{
VisibleReflectionProbe[] probes = inputs.culledReflectionProbes;
VisibleReflectionProbe[] probes = inputs.visibleReflectionProbes;
int numLights = inputs.culledLights.Length;
int numLights = inputs.visibleLights.Length;
int numProbes = probes.Length;
int numVolumes = numLights + numProbes;

int i = 0;
uint shadowLightIndex = 0;
foreach (var cl in inputs.culledLights)
foreach (var cl in inputs.visibleLights)
{
float range = cl.range;

renderLoop.SetupCameraProperties(camera);
UpdateLightConstants(cullResults.culledLights, ref shadows);
UpdateLightConstants(cullResults.visibleLights, ref shadows);
DrawRendererSettings settings = new DrawRendererSettings(cullResults, camera, new ShaderPassName("ForwardBase"));
settings.rendererConfiguration = RendererConfiguration.ConfigureOneLightProbePerRenderer | RendererConfiguration.ConfigureReflectionProbesProbePerRenderer;

//m_DeferredReflectionMaterial.SetInt("_DstBlend", camera.hdr ? (int)BlendMode.One : (int)BlendMode.Zero);
loop.SetupCameraProperties(camera);
UpdateShadowConstants(cullResults.culledLights, ref shadows);
UpdateShadowConstants(cullResults.visibleLights, ref shadows);
RenderGBuffer(cullResults, camera, loop);

loop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
int numDirLights = UpdateDirectionalLights(camera, cullResults.culledLights);
int numDirLights = UpdateDirectionalLights(camera, cullResults.visibleLights);
// Push all global params
PushGlobalParams(camera, loop, camera.cameraToWorldMatrix, projscr, invProjscr, numDirLights);

正在加载...
取消
保存