浏览代码

Move handling of camera-relative rendering from GeometryUtils()

/main
Evgenii Golubev 7 年前
当前提交
3a7560c2
共有 2 个文件被更改,包括 10 次插入11 次删除
  1. 14
      ScriptableRenderPipeline/Core/CoreRP/GeometryUtils.cs
  2. 7
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs

14
ScriptableRenderPipeline/Core/CoreRP/GeometryUtils.cs


using System;
using System;
namespace UnityEngine.Experimental.Rendering
{

public static class GeometryUtils
{
// Returns 'true' if the OBB intersects (or is inside) the frustum, 'false' otherwise.
// 'cameraRelativeOffset' can be used to intersect a world-space OBB with a camera-relative frustum.
public static bool Overlap(OrientedBBox obb, Vector3 cameraRelativeOffset,
Frustum frustum, int numPlanes, int numCorners)
public static bool Overlap(OrientedBBox obb, Frustum frustum, int numPlanes, int numCorners)
Vector3 center = obb.center + cameraRelativeOffset;
// Test the OBB against frustum planes. Frustum planes have inward-facing.
// Test the OBB against frustum planes. Frustum planes are inward-facing.
// The OBB is outside if it's entirely behind one of the frustum planes.
// See "Real-Time Rendering", 3rd Edition, 16.10.2.
for (int i = 0; overlap && i < numPlanes; i++)

+ obb.extentZ * Mathf.Abs(Vector3.Dot(n, obb.forward));
// Negative distance -> center behind the plane (outside).
float centerToPlaneDist = Vector3.Dot(n, center) + d;
float centerToPlaneDist = Vector3.Dot(n, obb.center) + d;
// outside = maxHalfDiagProj < -centerToPlaneDist
// outside = maxHalfDiagProj + centerToPlaneDist < 0

// Merge 2 loops. Continue as long as all points are outside either plane.
for (int j = 0; j < numCorners; j++)
{
float proj = Vector3.Dot(plane.normal, frustum.corners[j] - center);
float proj = Vector3.Dot(plane.normal, frustum.corners[j] - obb.center);
outsidePos = outsidePos && ( proj > plane.distance);
outsideNeg = outsideNeg && (-proj > plane.distance);
}

7
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs


if (ShaderConfig.s_CameraRelativeRendering != 0)
{
camOffset = -camPosition; // Camera-relative
camOffset = camPosition; // Camera-relative
}
m_VisibleVolumeBounds.Clear();

// TODO: cache these?
var obb = OrientedBBox.Create(volume.transform);
// Handle camera-relative rendering.
obb.center -= camOffset;
if (GeometryUtils.Overlap(obb, camOffset, camera.frustum, 6, 8))
if (GeometryUtils.Overlap(obb, camera.frustum, 6, 8))
{
// TODO: cache these?
var properties = volume.parameters.GetProperties();

正在加载...
取消
保存