浏览代码

Fix culling of box projector lights

/RenderPassXR_Sandbox
Evgenii Golubev 7 年前
当前提交
b4eccac0
共有 1 个文件被更改,包括 26 次插入37 次删除
  1. 63
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs

63
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


lightData.up = light.light.transform.up;
lightData.right = light.light.transform.right;
if (additionalLightData.archetype != LightArchetype.Punctual)
{
lightData.size = new Vector2(additionalLightData.lightLength, additionalLightData.lightWidth);
}
lightData.up *= 2 / additionalLightData.lightWidth;
lightData.up *= 2 / additionalLightData.lightWidth;
}
if (lightData.lightType == GPULightType.Spot)

{
lightData.shadowIndex = shadowIdx;
}
if (additionalLightData.archetype != LightArchetype.Punctual)
{
lightData.size = new Vector2(additionalLightData.lightLength, additionalLightData.lightWidth);
}
m_lightList.lights.Add(lightData);

var range = light.range;
var lightToWorld = light.localToWorld;
Vector3 lightPos = lightData.positionWS;
Matrix4x4 lightToView = worldToView * lightToWorld;
Vector3 xAxisVS = lightToView.GetColumn(0);
Vector3 yAxisVS = lightToView.GetColumn(1);
Vector3 zAxisVS = lightToView.GetColumn(2);
// Fill bounds
var bound = new SFiniteLightBound();

{
Vector3 lightDir = lightToWorld.GetColumn(2);
// represents a left hand coordinate system in world space
Vector3 vx = lightToWorld.GetColumn(0); // X axis in world space
Vector3 vy = lightToWorld.GetColumn(1); // Y axis in world space
Vector3 vz = lightDir; // Z axis in world space
// transform to camera space (becomes a left hand coordinate frame in Unity since Determinant(worldToView)<0)
vx = worldToView.MultiplyVector(vx);
vy = worldToView.MultiplyVector(vy);
vz = worldToView.MultiplyVector(vz);
// represents a left hand coordinate system in world space since det(worldToView)<0
Vector3 vx = xAxisVS;
Vector3 vy = yAxisVS;
Vector3 vz = zAxisVS;
const float pi = 3.1415926535897932384626433832795f;
const float degToRad = (float)(pi / 180.0);

bound.radius = range;
// represents a left hand coordinate system in world space since det(worldToView)<0
var lightToView = worldToView * lightToWorld;
Vector3 vx = lightToView.GetColumn(0);
Vector3 vy = lightToView.GetColumn(1);
Vector3 vz = lightToView.GetColumn(2);
Vector3 vx = xAxisVS;
Vector3 vy = yAxisVS;
Vector3 vz = zAxisVS;
// fill up ldata
lightVolumeData.lightAxisX = vx;

else if (gpuLightType == GPULightType.Rectangle)
{
Vector3 centerVS = worldToView.MultiplyPoint(lightData.positionWS);
Vector3 xAxisVS = worldToView.MultiplyVector(lightData.right);
Vector3 yAxisVS = worldToView.MultiplyVector(lightData.up);
Vector3 zAxisVS = worldToView.MultiplyVector(lightData.forward);
dimensions.z *= 0.5f;
centerVS += zAxisVS * radius * 0.5f;

else if (gpuLightType == GPULightType.Line)
{
Vector3 centerVS = worldToView.MultiplyPoint(lightData.positionWS);
Vector3 xAxisVS = worldToView.MultiplyVector(lightData.right);
Vector3 yAxisVS = worldToView.MultiplyVector(lightData.up);
Vector3 zAxisVS = worldToView.MultiplyVector(lightData.forward);
float radius = 1.0f / Mathf.Sqrt(lightData.invSqrAttenuationRadius);
Vector3 dimensions = new Vector3(lightData.size.x * 0.5f + radius, radius, radius);

else if (gpuLightType == GPULightType.ProjectorBox)
{
Vector3 posVS = worldToView.MultiplyPoint(lightData.positionWS);
Vector3 xAxisVS = worldToView.MultiplyVector(lightData.right.normalized); // Undo scaling
Vector3 yAxisVS = worldToView.MultiplyVector(lightData.up.normalized); // Undo scaling
Vector3 zAxisVS = worldToView.MultiplyVector(lightData.forward);
Vector3 boxDims = new Vector3(lightData.size.x, lightData.size.y, 1000000.0f);
Vector3 boxDims = new Vector3(lightData.size.x, lightData.size.y, 100000);
bound.boxAxisX = halfDims.x * xAxisVS; // Should this be halved or not?
bound.boxAxisY = halfDims.y * yAxisVS; // Should this be halved or not?
bound.boxAxisZ = halfDims.z * zAxisVS; // Should this be halved or not?
bound.radius = halfDims.magnitude; // Radius of a circumscribed sphere?
bound.boxAxisX = halfDims.x * xAxisVS;
bound.boxAxisY = halfDims.y * yAxisVS;
bound.boxAxisZ = halfDims.z * zAxisVS;
bound.radius = halfDims.magnitude;
lightVolumeData.lightPos = posVS; // Is this the center of the volume?
lightVolumeData.lightPos = posVS;
lightVolumeData.boxInnerDist = halfDims; // No idea what this is. Document your code
lightVolumeData.boxInvRange.Set(1.0f / halfDims.x, 1.0f / halfDims.y, 1.0f / halfDims.z); // No idea what this is. Document your code
lightVolumeData.boxInnerDist = halfDims;
lightVolumeData.boxInvRange.Set(1.0f / halfDims.x, 1.0f / halfDims.y, 1.0f / halfDims.z);
lightVolumeData.featureFlags = (uint)LightFeatureFlags.Punctual;
}
else

正在加载...
取消
保存