Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ShaderGraph] Optimized the Camera's direction node. #2485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sienaiwun
Copy link
Contributor

Purpose of this PR:
Optimized the Camera's direction node. Camera direction can be gotten directly from the UNITY_MATRIX_V matrix. Two matrix operations can be saved compared to the previous version.

Testing status:
Tested with the sample URP and HDRP projects. Both work well.

@sienaiwun sienaiwun requested a review from a team as a code owner November 2, 2020 02:48
@sienaiwun sienaiwun marked this pull request as draft November 3, 2020 09:57
@sienaiwun sienaiwun marked this pull request as ready for review November 3, 2020 09:58
@sienaiwun
Copy link
Contributor Author

I was wondering why the Labeler/label action fails, and how can I resolve it?

@marctem marctem requested review from alindmanUnity and a user November 9, 2020 17:32
Copy link
Contributor

@cdxntchou cdxntchou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks correct at first glance.

@LandonTownsendUnity -- just double check that it is actually returning the same value as previously.

@cdxntchou cdxntchou requested a review from a team November 9, 2020 23:01
@DennisDeRykeUnity
Copy link
Contributor

@thomas-zeng
Per documentation, the Shader Graph Camera node’s Direction method returns the camera’s forward vector direction.

  1. This would be the same vector for both XR and non-XR cases, wouldn’t it?
  2. For XR, do you suspect situations where the matrix math changed by this PR might result in a different answer than the current code?

@LandonTownsendUnity
If you have any existing test shaders which use the Camera node, could you share those with me? If not then I'll try to cobble one together myself for some sanity tests on Quest (or Quest Link).

@ghost
Copy link

ghost commented Nov 10, 2020

Today I'm going to make a test shader to test this PR vs the original algorithm. If there is even a slight change this shader should detect it.

cdxntchou pushed a commit that referenced this pull request Nov 10, 2020
@ghost
Copy link

ghost commented Nov 10, 2020

CameraDirParityCheck.zip
This shader should appear as white or another very bright color if there is any disparity between the original equation for the camera direction and the one suggested by this PR. @DennisDeRykeUnity Try using this in XR scenarios in both HDRP and URP to see if it every shows up as anything besides solid black. I confirmed it works normally for both perspective and orthographic in both HDRP and URP but it's worth double checking in XR.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me but wait for XR QA. Linked shader in comments that should help with testing.

@thomas-zeng
Copy link
Contributor

Hey @DennisDeRykeUnity

  1. This would be the same vector for both XR and non-XR cases, wouldn’t it?
    -- In XR, forward vector is per eye. So they could potentially be different.
  2. For XR, do you suspect situations where the matrix math changed by this PR might result in a different answer than the current code?
    -- We should verify in XR, camera direction node behaves the same before/after this change.

PR changes looks good to me.

@DennisDeRykeUnity
Copy link
Contributor

My apologies for the delays. I was busy with other tasks and vacation. I intend to perform XR testing this week.

@alindmanUnity
Copy link
Contributor

@DennisDeRykeUnity were you able to preform XR testing on this PR?

@DennisDeRykeUnity
Copy link
Contributor

@alindmanUnity No. I'll test it briefly tomorrow on URP and HDRP with CameraDirParityCheck shader. I'll test perspective camera only since orthographic is not applicable for XR.

@DennisDeRykeUnity
Copy link
Contributor

First I tried testing this with the SRP packages from the PR 2485 dev branch (sienaiwun:sgcameradirection cd4bc9e) but this resulted in compiler errors with several recent versions of Unity. So I obtained the SRP packages from Graphics master ce3633b and implemented one-line code change from PR 2485 locally in this file:
com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/CameraNode.cs

Next I started with the default empty 3D scene, added some cubes and capsules, and assigned them all a new material that uses Landon's Camera Direction Parity Check shader. Using the configurations below, if I do not apply head tracking (the camera remains stationary) then all the objects are black as expected.

  • Unity 2021.2.0a1 (trunk 31233d44259e)
  • URP (Graphics master ce3633b + one-line code change from PR 2485)
  • Simple test scene with Landon's CameraDirParityCheck shader applied
  • Quest Link
  • Multi Pass Stereo and Single Pass Instancing
  • Playmode

If head tracking is enabled, then the objects blink between an assortment of solid colors due to even subtle movements of the camera. However, without XR enabled I can rotate the camera in the Editor in Play mode and see similar color blinking, so I suspect the shader only returns black if the camera rotation is the default zero values (0, 0, 0). @LandonTownsendUnity Am I correct that your shader is only expected to return black when no rotation has been applied to the camera?

@DennisDeRykeUnity DennisDeRykeUnity self-requested a review December 24, 2020 03:09
Copy link
Contributor

@DennisDeRykeUnity DennisDeRykeUnity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Landon realized that the constant float input for his shader's Multiply node was excessive. Setting it to 10000 aleviates the color blinking, and objects are all black as expected even with XR head tracking enabled using these configurations:

  • Unity 2021.2.0a1 (trunk 31233d44259e)
  • URP and HDRP (Graphics master ce3633b + one-line code change from PR 2485)
  • Simple test scene with Landon's CameraDirParityCheck shader applied
  • Quest Link
  • Multi Pass Stereo and Single Pass Instancing
  • Standalone player

Also I saw no anomalies using these configurations:

  • Unity 2021.2.0a1 (trunk 31233d44259e)
  • URP and HDRP (Graphics master ce3633b + one-line code change from PR 2485)
  • URP and HDRP* Template scenes
  • Quest Link
  • Single Pass Instancing
  • Play mode
  • For this PR I used the old "workshop" HDRP scene since I am familiar with it.

I approve this PR on behalf of Unity XR QA.

@sienaiwun
Copy link
Contributor Author

Hi guys, is this issue still open?

@esmelusina esmelusina removed the request for review from alindmanUnity February 1, 2022 00:44
@esmelusina
Copy link
Contributor

I went ahead and removed Alex from the PR. Please go ahead with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants