/// <summary> /// Render stero reflections for VR. /// </summary> void RenderSteroReflection(ReflectionData data, Camera cam, OceanCameraSettings settings) { #if UNITY_540_OR_HIGHER && CETO_USE_STEAM_VR if (OceanVR.OpenVRInUse) { Shader.EnableKeyword("CETO_STERO_CAMERA"); if (cam.stereoTargetEye == StereoTargetEyeMask.Both || cam.stereoTargetEye == StereoTargetEyeMask.Left) { Vector3 eyePos; Quaternion eyeRot; Matrix4x4 projection; OceanVR.GetSteamVRLeftEye(cam, out eyePos, out eyeRot, out projection); RenderReflection(data.cam, data.target0, eyePos, eyeRot, projection, settings); } if (cam.stereoTargetEye == StereoTargetEyeMask.Both || cam.stereoTargetEye == StereoTargetEyeMask.Right) { Vector3 eyePos; Quaternion eyeRot; Matrix4x4 projection; OceanVR.GetSteamVRRightEye(cam, out eyePos, out eyeRot, out projection); RenderReflection(data.cam, data.target1, eyePos, eyeRot, projection, settings); } } else { Shader.DisableKeyword("CETO_STERO_CAMERA"); RenderReflection(data.cam, data.target0, cam.transform.position, cam.transform.rotation, cam.projectionMatrix, settings); } #else Shader.DisableKeyword("CETO_STERO_CAMERA"); RenderReflection(data.cam, data.target0, cam.transform.position, cam.transform.rotation, cam.projectionMatrix, settings); #endif }
/// <summary> /// Render stero depth pass for VR. /// The depths need to be rendered twice (once for each eye). /// </summary> void RenderSteroOceanDepth(DepthData data, Camera cam) { #if UNITY_540_OR_HIGHER && CETO_USE_STEAM_VR if (OceanVR.OpenVRInUse) { Shader.EnableKeyword("CETO_STERO_CAMERA"); if (cam.stereoTargetEye == StereoTargetEyeMask.Both || cam.stereoTargetEye == StereoTargetEyeMask.Left) { Vector3 eyePos; Quaternion eyeRot; Matrix4x4 projection; OceanVR.GetSteamVRLeftEye(cam, out eyePos, out eyeRot, out projection); RenderOceanDepth(data, data.target0, eyePos, eyeRot, projection); Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME0, data.target0); } if (cam.stereoTargetEye == StereoTargetEyeMask.Both || cam.stereoTargetEye == StereoTargetEyeMask.Right) { Vector3 eyePos; Quaternion eyeRot; Matrix4x4 projection; OceanVR.GetSteamVRRightEye(cam, out eyePos, out eyeRot, out projection); RenderOceanDepth(data, data.target1, eyePos, eyeRot, projection); Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME1, data.target1); } } else { Shader.DisableKeyword("CETO_STERO_CAMERA"); RenderOceanDepth(data, data.target0, cam.transform.position, cam.transform.rotation, cam.projectionMatrix); Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME0, data.target0); } #else Shader.DisableKeyword("CETO_STERO_CAMERA"); RenderOceanDepth(data, data.target0, cam.transform.position, cam.transform.rotation, cam.projectionMatrix); Shader.SetGlobalTexture(Ocean.OCEAN_DEPTH_TEXTURE_NAME0, data.target0); #endif }
//OYM: 报错 void Awake() { try { //There can only be one ocean in a scene if (Instance != null) { throw new InvalidOperationException("There can only be one ocean instance."); } //OYM: 检测是否有多个实例的 else { Instance = this; } //This is so I dont forget to set these back to false when finished debugging. if (DISABLE_ALL_MULTITHREADING) { LogInfo("Disabled multithreading is on"); } if (DISABLE_FOURIER_MULTITHREADING) { LogInfo("Disabled Fourier multithreading is on"); } if (DISABLE_PROJECTED_GRID_BORDER) { LogInfo("Disabled projection border is on"); } if (DISABLE_PROJECTION_FLIPPING) { LogInfo("Disabled flipping is on"); } if (DISABLE_PROJECT_SCENE_VIEW) { LogInfo("Disabled project scene is on"); } //OYM: 报错 #if CETO_DEBUG_SCHEDULER LogInfo("Debug scheduler is on"); #endif #if UNITY_WEBGL DISABLE_ALL_MULTITHREADING = true; LogInfo("Disabled multithreading for WebGL"); #endif #if CETO_USE_STEAM_VR LogInfo("Ceto using StreamVR enabled"); //OYM: 蛤? #endif OceanVR.Initialize(); WindDirVector = CalculateWindDirVector();//OYM: 计算风力 if (doublePrecisionProjection) { Projection = new Projection3d(this);//OYM: 双精度函数 } else { Projection = new Projection3f(this); } OceanTime = new OceanTime(); //OYM: 获取时间,这个地方是考虑到可以改的地方吗 m_waveOverlayMat = new Material(waveOverlaySdr); //OYM: 创建material OverlayManager = new OverlayManager(m_waveOverlayMat); //OYM: 管理器 m_scheduler = new Scheduler(100, 100, this); //OYM: 线程设置 } catch (Exception e) { LogError(e.ToString()); DisableOcean(); } }