Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- step 1: find the vertex shader of your shader (I will be using SCSS as an example)
- in SCSS the vertex shader is on line 6 in SCSS_Forward.cginc
- this is what it looks like
- VertexOutput vert(appdata_full v) {
- VertexOutput o = (VertexOutput)0;
- UNITY_SETUP_INSTANCE_ID(v);
- UNITY_INITIALIZE_OUTPUT(VertexOutput, o);
- UNITY_TRANSFER_INSTANCE_ID(v, o);
- UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
- ...
- }
- Step 2: paste the functions I included at the bottom before the vertex shader (so in front of the VertexOutput vert(...))
- Step 3:
- now if we wanted something to only display in VR we modify that to this.
- VertexOutput vert(appdata_full v) {
- VertexOutput o = (VertexOutput)0;
- if(!isVR()){
- return o;
- }
- UNITY_SETUP_INSTANCE_ID(v);
- UNITY_INITIALIZE_OUTPUT(VertexOutput, o);
- UNITY_TRANSFER_INSTANCE_ID(v, o);
- UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
- ...
- }
- this will make the gpu discard all triangles if it's not in vr
- //this needs to match your camera_res_height in the config.json file
- #define VRC_CONFIG_CAMERA_RESOLUTION 2160
- bool isVR()
- {
- // USING_STEREO_MATRICES
- #if UNITY_SINGLE_PASS_STEREO
- return true;
- #else
- return false;
- #endif
- }
- //UNITY_MATRIX_P._13 < 0 left eye, UNITY_MATRIX_P._13 > 0 right eye & UNITY_MATRIX_P._13 == 0 not vr
- bool isLeftEye()
- {
- return UNITY_MATRIX_P._13 < 0;
- }
- bool isRightEye()
- {
- return UNITY_MATRIX_P._13 > 0;
- }
- bool isNotVr()
- {
- return UNITY_MATRIX_P._13 == 0;
- }
- bool isOrtho()
- {
- return unity_OrthoParams.w == 1 || UNITY_MATRIX_P[3][3] == 1;
- }
- float verticalFOV()
- {
- return 2.0 * atan(1.0 / unity_CameraProjection._m11) * 180.0 / UNITY_PI;
- }
- // this checks if the shader is being rendered by a reflection probe
- // I don't know how check for box projection if that's even possible
- bool isReflectionProbe()
- {
- return UNITY_MATRIX_P[0][0] == 1 && unity_CameraProjection._m11 == 1;
- }
- bool isVRHandCamera()
- {
- return !isVR() && abs(UNITY_MATRIX_V[0].y) > 0.0000005;
- }
- bool isDesktop()
- {
- return !isVR() && abs(UNITY_MATRIX_V[0].y) < 0.0000005;
- }
- bool isVRHandCameraPreview()
- {
- return isVRHandCamera() && _ScreenParams.y == 720;
- }
- bool isVRHandCameraPicture()
- {
- return isVRHandCamera() && _ScreenParams.y == VRC_CONFIG_CAMERA_RESOLUTION;
- }
- bool isVRHandCameraPictureAnyResolution()
- {
- if (_ScreenParams.y == 1080 || _ScreenParams.y == 2160 || _ScreenParams.y == 1440 || _ScreenParams.y == 720)
- {
- return isVRHandCamera();
- }
- return false;
- }
- bool isPanorama()
- {
- // Crude method
- // FOV=90=camproj=[1][1]
- return unity_CameraProjection[1][1] == 1 && _ScreenParams.x == 1075 && _ScreenParams.y == 1025;
- }
Advertisement
Add Comment
Please, Sign In to add comment