-
Notifications
You must be signed in to change notification settings - Fork 817
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Port] [2022.3] Fix HDRP sky rendering when Camera Relative Rendering…
… is disabled This PR fixes HDRP sky rendering when Camera Relative Rendering is disabled. `ComputePixelCoordToWorldSpaceViewDirectionMatrix()` in `HDCamera.cs` contains: ``` ... if (useGenericMatrix) { var viewSpaceRasterTransform = new Matrix4x4( new Vector4(2.0f * resolution.z, 0.0f, 0.0f, -1.0f), new Vector4(0.0f, -2.0f * resolution.w, 0.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 0.0f), new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); var transformT = viewConstants.invViewProjMatrix.transpose * Matrix4x4.Scale(new Vector3(-1.0f, -1.0f, -1.0f)); return viewSpaceRasterTransform * transformT; } ... ``` Here the view matrix that was used to build `viewConstants.invViewProjMatrix` has translation component if Camera Relative Rendering is disabled when it shouldn't.  Scene View  Game View, bugged  Game View, fixed
- Loading branch information
1 parent
a59444a
commit 9d4a304
Showing
3 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Packages/com.unity.render-pipelines.high-definition/Tests/Editor/HDCameraTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using NUnit.Framework; | ||
using UnityEngine.Experimental.Rendering; | ||
|
||
namespace UnityEngine.Rendering.HighDefinition.Tests | ||
{ | ||
class HDCameraTests | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
if (GraphicsSettings.currentRenderPipeline is not HDRenderPipelineAsset) | ||
Assert.Ignore("This is an HDRP Tests, and the current pipeline is not HDRP."); | ||
} | ||
|
||
[Test] | ||
public void TestCameraRelativeRendering() | ||
{ | ||
GameObject cameraGameObject = new GameObject("Camera"); | ||
var camera = cameraGameObject.AddComponent<Camera>(); | ||
var hdCamera = new HDCamera(camera); | ||
|
||
var positionSettings = new CameraPositionSettings(); | ||
positionSettings.position = new Vector3(100.0f, 300.0f, 500.0f); | ||
positionSettings.rotation = Quaternion.Euler(62.34f, 185.53f, 323.563f); | ||
|
||
var resolution = new Vector4(1920.0f, 1080.0f, 1.0f / 1920.0f, 1.0f / 1080.0f); | ||
float aspect = resolution.x * resolution.w; | ||
|
||
camera.worldToCameraMatrix = positionSettings.ComputeWorldToCameraMatrix(); | ||
camera.projectionMatrix = Matrix4x4.Perspective(75.0f, aspect, 0.1f, 1000.0f); | ||
|
||
var view = camera.worldToCameraMatrix; | ||
var proj = camera.projectionMatrix; | ||
|
||
// Minimal setup for ComputePixelCoordToWorldSpaceViewDirectionMatrix(). | ||
var viewConstants = new HDCamera.ViewConstants(); | ||
viewConstants.viewMatrix = view; | ||
viewConstants.projMatrix = proj; | ||
viewConstants.invViewProjMatrix = (proj * view).inverse; | ||
|
||
// hdCamera.xr must be initialized for ComputePixelCoordToWorldSpaceViewDirectionMatrix(). | ||
var hdrp = HDRenderPipeline.currentPipeline; | ||
hdCamera.Update(hdCamera.frameSettings, hdrp, XRSystem.emptyPass, allocateHistoryBuffers: false); | ||
|
||
var matrix0 = hdCamera.ComputePixelCoordToWorldSpaceViewDirectionMatrix(viewConstants, resolution, aspect, 0); | ||
var matrix1 = hdCamera.ComputePixelCoordToWorldSpaceViewDirectionMatrix(viewConstants, resolution, aspect, 1); | ||
|
||
// These matrices convert a clip space position to a world space view direction, | ||
// therefore should be same regardless of Camera Relative Rendering. | ||
Assert.AreEqual(matrix0, matrix1, $"{matrix0} != {matrix1}"); | ||
|
||
CoreUtils.Destroy(cameraGameObject); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Packages/com.unity.render-pipelines.high-definition/Tests/Editor/HDCameraTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.