Guest User

Untitled

a guest
Apr 27th, 2022
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. step 1: find the vertex shader of your shader (I will be using SCSS as an example)
  2.  
  3. in SCSS the vertex shader is on line 6 in SCSS_Forward.cginc
  4.  
  5. this is what it looks like
  6.  
  7. VertexOutput vert(appdata_full v) {
  8. VertexOutput o = (VertexOutput)0;
  9.  
  10. UNITY_SETUP_INSTANCE_ID(v);
  11. UNITY_INITIALIZE_OUTPUT(VertexOutput, o);
  12. UNITY_TRANSFER_INSTANCE_ID(v, o);
  13. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  14. ...
  15. }
  16.  
  17.  
  18.  
  19.  
  20.  
  21. Step 2: paste the functions I included at the bottom before the vertex shader (so in front of the VertexOutput vert(...))
  22.  
  23.  
  24.  
  25.  
  26. Step 3:
  27. now if we wanted something to only display in VR we modify that to this.
  28.  
  29. VertexOutput vert(appdata_full v) {
  30. VertexOutput o = (VertexOutput)0;
  31.  
  32. if(!isVR()){
  33. return o;
  34. }
  35.  
  36. UNITY_SETUP_INSTANCE_ID(v);
  37. UNITY_INITIALIZE_OUTPUT(VertexOutput, o);
  38. UNITY_TRANSFER_INSTANCE_ID(v, o);
  39. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  40. ...
  41. }
  42.  
  43. this will make the gpu discard all triangles if it's not in vr
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. //this needs to match your camera_res_height in the config.json file
  54. #define VRC_CONFIG_CAMERA_RESOLUTION 2160
  55.  
  56. bool isVR()
  57. {
  58. // USING_STEREO_MATRICES
  59. #if UNITY_SINGLE_PASS_STEREO
  60. return true;
  61. #else
  62. return false;
  63. #endif
  64. }
  65.  
  66. //UNITY_MATRIX_P._13 < 0 left eye, UNITY_MATRIX_P._13 > 0 right eye & UNITY_MATRIX_P._13 == 0 not vr
  67. bool isLeftEye()
  68. {
  69. return UNITY_MATRIX_P._13 < 0;
  70. }
  71.  
  72. bool isRightEye()
  73. {
  74. return UNITY_MATRIX_P._13 > 0;
  75. }
  76.  
  77. bool isNotVr()
  78. {
  79. return UNITY_MATRIX_P._13 == 0;
  80. }
  81.  
  82. bool isOrtho()
  83. {
  84. return unity_OrthoParams.w == 1 || UNITY_MATRIX_P[3][3] == 1;
  85. }
  86.  
  87. float verticalFOV()
  88. {
  89. return 2.0 * atan(1.0 / unity_CameraProjection._m11) * 180.0 / UNITY_PI;
  90. }
  91.  
  92. // this checks if the shader is being rendered by a reflection probe
  93. // I don't know how check for box projection if that's even possible
  94. bool isReflectionProbe()
  95. {
  96. return UNITY_MATRIX_P[0][0] == 1 && unity_CameraProjection._m11 == 1;
  97. }
  98.  
  99. bool isVRHandCamera()
  100. {
  101. return !isVR() && abs(UNITY_MATRIX_V[0].y) > 0.0000005;
  102. }
  103.  
  104. bool isDesktop()
  105. {
  106. return !isVR() && abs(UNITY_MATRIX_V[0].y) < 0.0000005;
  107. }
  108.  
  109. bool isVRHandCameraPreview()
  110. {
  111. return isVRHandCamera() && _ScreenParams.y == 720;
  112. }
  113.  
  114. bool isVRHandCameraPicture()
  115. {
  116. return isVRHandCamera() && _ScreenParams.y == VRC_CONFIG_CAMERA_RESOLUTION;
  117. }
  118.  
  119. bool isVRHandCameraPictureAnyResolution()
  120. {
  121. if (_ScreenParams.y == 1080 || _ScreenParams.y == 2160 || _ScreenParams.y == 1440 || _ScreenParams.y == 720)
  122. {
  123. return isVRHandCamera();
  124. }
  125. return false;
  126. }
  127.  
  128. bool isPanorama()
  129. {
  130. // Crude method
  131. // FOV=90=camproj=[1][1]
  132. return unity_CameraProjection[1][1] == 1 && _ScreenParams.x == 1075 && _ScreenParams.y == 1025;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment