浏览代码

Return correct light count from GenerateSourceLightBuffers

The only functional change is fixing the light count calculation in GenerateSourceLightBuffers.  It actually returns the end index for the probe portion of the light list, not the count of probes.  This doesn't lead to any real bugs because the entries copied into the light data buffers are zero'd out because C# is nice to you.  This would likely manifest in bugs in C/C++.

There are also a lot of readability changes made to GenerateSourceLightBuffers.
/fptl_cleanup
Robert Srinivasiah 8 年前
当前提交
f5f9f47b
共有 1 个文件被更改,包括 40 次插入34 次删除
  1. 74
      Assets/ScriptableRenderPipeline/fptl/FptlLighting.cs

74
Assets/ScriptableRenderPipeline/fptl/FptlLighting.cs


int GenerateSourceLightBuffers(Camera camera, CullResults inputs)
{
var probes = inputs.visibleReflectionProbes;
//ReflectionProbe[] probes = Object.FindObjectsOfType<ReflectionProbe>();
var lights = inputs.visibleLights;
var numModels = (int)LightDefinitions.NR_LIGHT_MODELS;
var numVolTypes = (int)LightDefinitions.MAX_TYPES;

// first pass. Figure out how much we have of each and establish offsets
foreach (var cl in inputs.visibleLights)
// Figure out how much we have of each lights/probes and establish offsets
foreach (var cl in lights)
var volType = cl.lightType == LightType.Spot ? LightDefinitions.SPOT_LIGHT : (cl.lightType == LightType.Point ? LightDefinitions.SPHERE_LIGHT : -1);
if (volType >= 0) ++numEntries[LightDefinitions.DIRECT_LIGHT, volType];
var volType = -1;
if (cl.lightType == LightType.Spot)
volType = LightDefinitions.SPOT_LIGHT;
else if (cl.lightType == LightType.Point)
volType = LightDefinitions.SPHERE_LIGHT;
if (volType >= 0)
++numEntries[LightDefinitions.DIRECT_LIGHT, volType];
var volType = LightDefinitions.BOX_LIGHT; // always a box for now
if (rl.texture != null) ++numEntries[LightDefinitions.REFLECTION_LIGHT, volType];
// always a box for now
var volType = LightDefinitions.BOX_LIGHT;
if (rl.texture != null)
++numEntries[LightDefinitions.REFLECTION_LIGHT, volType];
offsets[0, 0] = 0;
offsets[m, 0] = m == 0 ? 0 : (numEntries[m - 1, numVolTypes - 1] + offsets[m - 1, numVolTypes - 1]);
for (var v = 1; v < numVolTypes; v++) offsets[m, v] = numEntries[m, v - 1] + offsets[m, v - 1];
if (m > 0)
offsets[m, 0] = offsets[m - 1, numVolTypes - 1] + numEntries[m - 1, numVolTypes - 1];
for (var v = 1; v < numVolTypes; v++)
offsets[m, v] = offsets[m, v - 1] + numEntries[m, v - 1];
var numLights = inputs.visibleLights.Length;
var numLights = lights.Length;
foreach (var cl in inputs.visibleLights)
foreach (var cl in lights)
{
var range = cl.range;

var bHasCookie = cl.light.cookie != null;
var bHasShadow = cl.light.shadows != LightShadows.None;
light.flags |= (bHasCookie ? LightDefinitions.HAS_COOKIE_TEXTURE : 0);
light.flags |= (bHasShadow ? LightDefinitions.HAS_SHADOW : 0);
// square spots always have cookie
if (!isCircularSpot) // square spots always have cookie
if (bHasCookie)
Vector3 lightDir = lightToWorld.GetColumn(2); // Z axis in world space
var vz = lightDir; // Z axis in world space
Vector3 vz = lightToWorld.GetColumn(2); // Z axis in world space
var lightDir = vz;
// transform to camera space (becomes a left hand coordinate frame in Unity since Determinant(worldToView)<0)
vx = worldToView.MultiplyVector(vx);

var cota = si > 0.0f ? (cs / si) : FltMax;
//const float cotasa = l.GetCotanHalfSpotAngle();
bound.center = worldToView.MultiplyPoint(lightPos + ((0.5f * range) * lightDir)); // use mid point of the spot as the center of the bounding volume for building screen-space AABB for tiled lighting.
bound.center = worldToView.MultiplyPoint(lightPos + ((0.5f * range) * lightDir)); // use mid point of the spot as the center of the bounding volume for building screen-space AABB for tiled lighting.
light.lightAxisX = vx;
light.lightAxisY = vy;
light.lightAxisZ = vz;
// scale axis to match box or base of pyramid
bound.boxAxisX = (fS * range) * vx;

bound.radius = altDist > (0.5f * range) ? altDist : (0.5f * range); // will always pick fAltDist
bound.scaleXY = squeeze ? new Vector2(0.01f, 0.01f) : new Vector2(1.0f, 1.0f);
// fill up ldata
light.lightAxisX = vx;
light.lightAxisY = vy;
light.lightAxisZ = vz;
light.lightType = (uint)LightDefinitions.SPOT_LIGHT;
light.lightPos = worldToView.MultiplyPoint(lightPos);
light.radiusSq = range * range;

light.flags |= (bHasCookie ? LightDefinitions.HAS_COOKIE_TEXTURE : 0);
light.flags |= (bHasShadow ? LightDefinitions.HAS_SHADOW : 0);
int i = LightDefinitions.DIRECT_LIGHT, j = LightDefinitions.SPOT_LIGHT;
idxOut = numEntries2nd[i, j] + offsets[i, j]; ++numEntries2nd[i, j];

light.lightAxisX = vx;
light.lightAxisY = vy;
light.lightAxisZ = vz;
light.flags |= (bHasCookie ? LightDefinitions.HAS_COOKIE_TEXTURE : 0);
light.flags |= (bHasShadow ? LightDefinitions.HAS_SHADOW : 0);
int i = LightDefinitions.DIRECT_LIGHT, j = LightDefinitions.SPHERE_LIGHT;
idxOut = numEntries2nd[i, j] + offsets[i, j]; ++numEntries2nd[i, j];

// implicit in CalculateHDRDecodeValues() --> float ints = rl.intensity;
var boxProj = (rl.boxProjection != 0);
var decodeVals = rl.hdr;
//Vector4 decodeVals = rl.CalculateHDRDecodeValues();
// C is reflection volume center in world space (NOT same as cube map capture point)
var e = bnds.extents; // 0.5f * Vector3.Max(-boxSizes[p], boxSizes[p]);

lgtData.sliceIndex = m_CubeReflTexArray.FetchSlice(cubemap);
var delta = combinedExtent - e;
lgtData.boxInvRange.Set(1.0f / delta.x, 1.0f / delta.y, 1.0f / delta.z);
lgtData.boxInvRange.Set(1.0f / blendDistance, 1.0f / blendDistance, 1.0f / blendDistance);
bndData.center = Cw;
bndData.boxAxisX = combinedExtent.x * vx;

lightData[idxOut] = lgtData;
}
var numProbesOut = offsets[LightDefinitions.REFLECTION_LIGHT, numVolTypes - 1] + numEntries[LightDefinitions.REFLECTION_LIGHT, numVolTypes - 1];
var probesStartIndex = offsets[LightDefinitions.REFLECTION_LIGHT, 0];
var probesEndIndex = offsets[LightDefinitions.REFLECTION_LIGHT, numVolTypes - 1] + numEntries[LightDefinitions.REFLECTION_LIGHT, numVolTypes - 1];
var numProbesOut = probesEndIndex - probesStartIndex;
for (var m = 0; m < numModels; m++)
{
for (var v = 0; v < numVolTypes; v++)

正在加载...
取消
保存