/// <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 the reflections. /// </summary> void RenderReflectionFor(Camera cam, Camera reflectCamera, OceanCameraSettings settings) { //UpdateSkyBox(cam, reflectCamera); Vector3 eulerA = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-eulerA.x, eulerA.y, eulerA.z); reflectCamera.transform.position = cam.transform.position; float level = m_ocean.level; Vector3 pos = new Vector3(0, level, 0); Vector3 normal = Vector3.up; float d = -Vector3.Dot(normal, pos) - clipPlaneOffset; Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d); Matrix4x4 reflection = Matrix4x4.zero; reflection = CalculateReflectionMatrix(reflection, reflectionPlane); Vector3 oldPos = cam.transform.position; Vector3 newpos = reflection.MultiplyPoint(oldPos); reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection; Vector4 clipPlane = CameraSpacePlane(reflectCamera, pos, normal, 1.0f); Matrix4x4 projection = cam.projectionMatrix; projection = CalculateObliqueMatrix(projection, clipPlane); reflectCamera.projectionMatrix = projection; reflectCamera.transform.position = newpos; Vector3 euler = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z); reflectCamera.cullingMask = GetReflectionLayermask(settings); reflectCamera.cullingMask = OceanUtility.HideLayer(reflectCamera.cullingMask, Ocean.OCEAN_LAYER); int oldPixelLightCount = QualitySettings.pixelLightCount; if (!pixelLightsInReflection) { QualitySettings.pixelLightCount = 0; } bool oldCulling = GL.invertCulling; GL.invertCulling = !oldCulling; reflectCamera.Render(); QualitySettings.pixelLightCount = oldPixelLightCount; GL.invertCulling = oldCulling; }
private void RenderReflectionFor(Camera cam, Camera reflectCamera, OceanCameraSettings settings) { Vector3 eulerAngles = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-eulerAngles.x, eulerAngles.y, eulerAngles.z); reflectCamera.transform.position = cam.transform.position; float level = this.m_ocean.level; Vector3 vector = new Vector3(0f, level, 0f); Vector3 up = Vector3.up; float w = -Vector3.Dot(up, vector) - this.clipPlaneOffset; Vector4 plane = new Vector4(up.x, up.y, up.z, w); Matrix4x4 matrix4x = Matrix4x4.zero; matrix4x = this.CalculateReflectionMatrix(matrix4x, plane); Vector3 position = cam.transform.position; Vector3 position2 = matrix4x.MultiplyPoint(position); reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * matrix4x; Vector4 clipPlane = this.CameraSpacePlane(reflectCamera, vector, up, 1f); Matrix4x4 matrix4x2 = cam.projectionMatrix; matrix4x2 = this.CalculateObliqueMatrix(matrix4x2, clipPlane); reflectCamera.projectionMatrix = matrix4x2; reflectCamera.transform.position = position2; Vector3 eulerAngles2 = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-eulerAngles2.x, eulerAngles2.y, eulerAngles2.z); reflectCamera.cullingMask = this.GetReflectionLayermask(settings); reflectCamera.cullingMask = OceanUtility.HideLayer(reflectCamera.cullingMask, Ocean.OCEAN_LAYER); int pixelLightCount = QualitySettings.pixelLightCount; if (!this.pixelLightsInReflection) { QualitySettings.pixelLightCount = 0; } bool invertCulling = GL.invertCulling; GL.invertCulling = !invertCulling; if (ForestVR.Enabled) { } reflectCamera.Render(); QualitySettings.pixelLightCount = pixelLightCount; GL.invertCulling = invertCulling; }
/// <summary> /// Gets if this camera should render the reflections. /// </summary> bool GetDisableReflections(OceanCameraSettings settings) { return (settings != null) ? settings.disableReflections : false; }
private REFLECTION_RESOLUTION GetReflectionResolution(OceanCameraSettings settings) { return (!(settings != null)) ? this.reflectionResolution : settings.reflectionResolution; }
/// <summary> /// Render the reflections. /// </summary> void RenderReflection(Camera reflectionCam, RenderTexture target, Vector3 position, Quaternion rotation, Matrix4x4 projection, OceanCameraSettings settings) { // Copy camera position/rotation/projection data into the reflectionCamera reflectionCam.ResetWorldToCameraMatrix(); reflectionCam.transform.position = position; reflectionCam.transform.rotation = rotation; reflectionCam.projectionMatrix = projection; reflectionCam.targetTexture = target; float level = m_ocean.level; // find out the reflection plane: position and normal in world space Vector3 pos = new Vector3(0, level, 0); Vector3 normal = Vector3.up; // Reflect camera around reflection plane Vector4 worldSpaceClipPlane = Plane(pos, normal); reflectionCam.worldToCameraMatrix *= CalculateReflectionMatrix(worldSpaceClipPlane); // Setup oblique projection matrix so that near plane is our reflection // plane. This way we clip everything behind it for free. Vector4 cameraSpaceClipPlane = CameraSpacePlane(reflectionCam, pos, normal); reflectionCam.projectionMatrix = reflectionCam.CalculateObliqueMatrix(cameraSpaceClipPlane); reflectionCam.cullingMask = GetReflectionLayermask(settings); reflectionCam.cullingMask = OceanUtility.HideLayer(reflectionCam.cullingMask, Ocean.OCEAN_LAYER); bool oldCulling = GL.invertCulling; GL.invertCulling = !oldCulling; NotifyOnEvent.Disable = true; reflectionCam.Render(); NotifyOnEvent.Disable = false; GL.invertCulling = oldCulling; reflectionCam.targetTexture = null; }
private bool GetDisableUnderwater(OceanCameraSettings settings) { return(settings != null && settings.disableUnderwater); }
/// <summary> /// Gets if this camera should render the reflections. /// </summary> bool GetDisableReflections(OceanCameraSettings settings) { return((settings != null) ? settings.disableReflections : false); }
/// <summary> /// Gets the reflection layer mask from the camera settings /// if provided else use the default mask /// </summary> LayerMask GetReflectionLayermask(OceanCameraSettings settings) { return (settings != null) ? settings.reflectionMask : reflectionMask; }
private REFLECTION_RESOLUTION GetReflectionResolution(OceanCameraSettings settings) { return((!(settings != null)) ? this.reflectionResolution : settings.reflectionResolution); }
/// <summary> /// Gets if this camera should render the reflections. /// </summary> bool GetDisableUnderwater(OceanCameraSettings settings) { return (settings != null) ? settings.disableUnderwater : false; }
private LayerMask GetReflectionLayermask(OceanCameraSettings settings) { return (!(settings != null)) ? this.reflectionMask : settings.reflectionMask; }
private LayerMask GetReflectionLayermask(OceanCameraSettings settings) { return((!(settings != null)) ? this.reflectionMask : settings.reflectionMask); }
private bool GetDisableReflections(OceanCameraSettings settings) { return settings != null && settings.disableReflections; }
private void CreateRenderTarget(ReflectionData data, string camName, int width, int height, bool isHdr, OceanCameraSettings settings) { int num = this.ResolutionToNumber(this.GetReflectionResolution(settings)); width /= num; height /= num; if (data.tex != null && data.tex.width == width && data.tex.height == height) { data.tex.anisoLevel = this.ansio; return; } if (data.tex != null) { RTUtility.ReleaseAndDestroy(data.tex); } RenderTextureFormat format; if ((isHdr || QualitySettings.activeColorSpace == ColorSpace.Linear) && SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf)) { format = RenderTextureFormat.ARGBHalf; } else { format = RenderTextureFormat.ARGB32; } data.tex = new RenderTexture(width, height, 0, format, RenderTextureReadWrite.Default); data.tex.filterMode = FilterMode.Bilinear; data.tex.wrapMode = TextureWrapMode.Clamp; data.tex.useMipMap = false; data.tex.anisoLevel = this.ansio; data.tex.hideFlags = HideFlags.HideAndDontSave; data.tex.name = "Ceto Reflection Texture: " + camName; if (data.cam != null) { if (data.cam.targetTexture != null) { RTUtility.ReleaseAndDestroy(data.cam.targetTexture); } data.cam.targetTexture = new RenderTexture(width, height, 16, format, RenderTextureReadWrite.Default); data.cam.targetTexture.filterMode = FilterMode.Bilinear; data.cam.targetTexture.wrapMode = TextureWrapMode.Clamp; data.cam.targetTexture.useMipMap = false; data.cam.targetTexture.anisoLevel = 0; data.cam.targetTexture.hideFlags = HideFlags.HideAndDontSave; data.cam.targetTexture.name = "Ceto Reflection Render Target: " + camName; } }
private bool GetDisableAllOverlays(OceanCameraSettings settings) { return(settings != null && settings.disableAllOverlays); }
/// <summary> /// Render the reflections. /// </summary> void RenderReflectionFor(Camera cam, Camera reflectCamera, OceanCameraSettings settings) { //UpdateSkyBox(cam, reflectCamera); Vector3 eulerA = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-eulerA.x, eulerA.y, eulerA.z); reflectCamera.transform.position = cam.transform.position; float level = m_ocean.level; Vector3 pos = new Vector3(0,level,0); Vector3 normal = Vector3.up; float d = -Vector3.Dot(normal, pos) - clipPlaneOffset; Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d); Matrix4x4 reflection = Matrix4x4.zero; reflection = CalculateReflectionMatrix(reflection, reflectionPlane); Vector3 oldPos = cam.transform.position; Vector3 newpos = reflection.MultiplyPoint(oldPos); reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection; Vector4 clipPlane = CameraSpacePlane(reflectCamera, pos, normal, 1.0f); Matrix4x4 projection = cam.projectionMatrix; projection = CalculateObliqueMatrix(projection, clipPlane); reflectCamera.projectionMatrix = projection; reflectCamera.transform.position = newpos; Vector3 euler = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z); reflectCamera.cullingMask = GetReflectionLayermask(settings); reflectCamera.cullingMask = OceanUtility.HideLayer(reflectCamera.cullingMask, Ocean.OCEAN_LAYER); int oldPixelLightCount = QualitySettings.pixelLightCount; if (!pixelLightsInReflection) QualitySettings.pixelLightCount = 0; bool oldCulling = GL.invertCulling; GL.invertCulling = !oldCulling; reflectCamera.Render(); QualitySettings.pixelLightCount = oldPixelLightCount; GL.invertCulling = oldCulling; }
/// <summary> /// Gets the reflection resolution from the camera settings /// if provided else use the default resolution /// </summary> REFLECTION_RESOLUTION GetReflectionResolution(OceanCameraSettings settings) { return (settings != null) ? settings.reflectionResolution : reflectionResolution; }
private bool GetDisableReflections(OceanCameraSettings settings) { return(settings != null && settings.disableReflections); }
private void RenderReflectionFor(Camera cam, Camera reflectCamera, OceanCameraSettings settings) { Vector3 eulerAngles = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-eulerAngles.x, eulerAngles.y, eulerAngles.z); reflectCamera.transform.position = cam.transform.position; float level = this.m_ocean.level; Vector3 vector = new Vector3(0f, level, 0f); Vector3 up = Vector3.up; float w = -Vector3.Dot(up, vector) - this.clipPlaneOffset; Vector4 plane = new Vector4(up.x, up.y, up.z, w); Matrix4x4 matrix4x = Matrix4x4.zero; matrix4x = this.CalculateReflectionMatrix(matrix4x, plane); Vector3 position = cam.transform.position; Vector3 position2 = matrix4x.MultiplyPoint(position); reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * matrix4x; Vector4 clipPlane = this.CameraSpacePlane(reflectCamera, vector, up, 1f); Matrix4x4 matrix4x2 = cam.projectionMatrix; matrix4x2 = this.CalculateObliqueMatrix(matrix4x2, clipPlane); reflectCamera.projectionMatrix = matrix4x2; reflectCamera.transform.position = position2; Vector3 eulerAngles2 = cam.transform.eulerAngles; reflectCamera.transform.eulerAngles = new Vector3(-eulerAngles2.x, eulerAngles2.y, eulerAngles2.z); reflectCamera.cullingMask = this.GetReflectionLayermask(settings); reflectCamera.cullingMask = OceanUtility.HideLayer(reflectCamera.cullingMask, Ocean.OCEAN_LAYER); int pixelLightCount = QualitySettings.pixelLightCount; if (!this.pixelLightsInReflection) { QualitySettings.pixelLightCount = 0; } bool invertCulling = GL.invertCulling; GL.invertCulling = !invertCulling; reflectCamera.Render(); QualitySettings.pixelLightCount = pixelLightCount; GL.invertCulling = invertCulling; }
/// <summary> /// Gets the reflection layer mask from the camera settings /// if provided else use the default mask /// </summary> LayerMask GetOceanDepthsLayermask(OceanCameraSettings settings) { return (settings != null) ? settings.oceanDepthsMask : oceanDepthsMask; }
/// <summary> /// Create the render targets for the reflection camera and the reflection texture. /// </summary> void CreateRenderTarget(ReflectionData data, string camName, int width, int height, bool isHdr, OceanCameraSettings settings) { int scale = ResolutionToNumber(GetReflectionResolution(settings)); width /= scale; height /= scale; //If the texture has been created and settings have not changed //just update the ansio settings and return. if (data.tex != null && data.tex.width == width && data.tex.height == height) { data.tex.anisoLevel = ansio; return; } //Settings have changed or textures not created. if (data.tex != null) { RTUtility.ReleaseAndDestroy(data.tex); } RenderTextureFormat format; if (isHdr || QualitySettings.activeColorSpace == ColorSpace.Linear) { format = RenderTextureFormat.ARGBHalf; } else { format = RenderTextureFormat.ARGB32; } //This is the actual texture that will be sampled from for the reflections data.tex = new RenderTexture(width, height, 0, format, RenderTextureReadWrite.Default); data.tex.filterMode = FilterMode.Bilinear; data.tex.wrapMode = TextureWrapMode.Clamp; data.tex.useMipMap = false; data.tex.anisoLevel = ansio; data.tex.hideFlags = HideFlags.HideAndDontSave; data.tex.name = "Ceto Reflection Texture: " + camName; //This is the camera that will render the reflections. //Maybe null if a custom reflection method is being used. if (data.cam != null) { if (data.cam.targetTexture != null) { RTUtility.ReleaseAndDestroy(data.cam.targetTexture); } data.cam.targetTexture = new RenderTexture(width, height, 16, format, RenderTextureReadWrite.Default); data.cam.targetTexture.filterMode = FilterMode.Bilinear; data.cam.targetTexture.wrapMode = TextureWrapMode.Clamp; //data.cam.targetTexture.useMipMap = false; data.cam.targetTexture.anisoLevel = 0; data.cam.targetTexture.hideFlags = HideFlags.HideAndDontSave; data.cam.targetTexture.name = "Ceto Reflection Render Target: " + camName; } }
/// <summary> /// Gets the reflection layer mask from the camera settings /// if provided else use the default mask /// </summary> LayerMask GetReflectionLayermask(OceanCameraSettings settings) { return((settings != null) ? settings.reflectionMask : reflectionMask); }
/// <summary> /// Gets the reflection layer mask from the camera settings /// if provided else use the default mask /// </summary> LayerMask GetOceanDepthsLayermask(OceanCameraSettings settings) { return((settings != null) ? settings.oceanDepthsMask : oceanDepthsMask); }
/// <summary> /// Gets the reflection resolution from the camera settings /// if provided else use the default resolution /// </summary> REFLECTION_RESOLUTION GetReflectionResolution(OceanCameraSettings settings) { return((settings != null) ? settings.reflectionResolution : reflectionResolution); }
/// <summary> /// Gets if this camera should render the reflections. /// </summary> bool GetDisableUnderwater(OceanCameraSettings settings) { return((settings != null) ? settings.disableUnderwater : false); }
/// <summary> /// Create the render targets for the reflection camera and the reflection texture. /// </summary> void CreateRenderTarget(ReflectionData data, int width, int height, bool isHdr, bool stero, OceanCameraSettings settings) { int scale = ResolutionToNumber(GetReflectionResolution(settings)); width /= scale; height /= scale; //If the texture has been created and settings have not changed return if (data.target0 != null && data.target0.width == width && data.target0.height == height) { return; } RenderTextureFormat format; if ((isHdr || QualitySettings.activeColorSpace == ColorSpace.Linear) && SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf)) { format = RenderTextureFormat.ARGBHalf; } else { format = RenderTextureFormat.ARGB32; } data.DestroyTargets(); data.target0 = new RenderTexture(width, height, 16, format, RenderTextureReadWrite.Default); data.target0.filterMode = FilterMode.Bilinear; data.target0.wrapMode = TextureWrapMode.Clamp; data.target0.useMipMap = false; data.target0.anisoLevel = 0; data.target0.hideFlags = HideFlags.HideAndDontSave; data.target0.name = "Ceto Reflection Render Target0"; if (stero) { data.target1 = new RenderTexture(width, height, 16, format, RenderTextureReadWrite.Default); data.target1.filterMode = FilterMode.Bilinear; data.target1.wrapMode = TextureWrapMode.Clamp; data.target1.useMipMap = false; data.target1.anisoLevel = 0; data.target1.hideFlags = HideFlags.HideAndDontSave; data.target1.name = "Ceto Reflection Render Target1"; } }
/// <summary> /// Gets if this camera should render the reflections. /// </summary> bool GetDisableAllOverlays(OceanCameraSettings settings) { return (settings != null) ? settings.disableAllOverlays : false; }
private LayerMask GetOceanDepthsLayermask(OceanCameraSettings settings) { return((!(settings != null)) ? this.oceanDepthsMask : settings.oceanDepthsMask); }
/// <summary> /// Gets if this camera should render the reflections. /// </summary> bool GetDisableAllOverlays(OceanCameraSettings settings) { return((settings != null) ? settings.disableAllOverlays : false); }
/// <summary> /// Create the render targets for the reflection camera and the reflection texture. /// </summary> void CreateRenderTarget(ReflectionData data, string camName, int width, int height, bool isHdr, OceanCameraSettings settings) { int scale = ResolutionToNumber(GetReflectionResolution(settings)); width /= scale; height /= scale; //If the texture has been created and settings have not changed //just update the ansio settings and return. if (data.tex != null && data.tex.width == width && data.tex.height == height) { data.tex.anisoLevel = ansio; return; } //Settings have changed or textures not created. if (data.tex != null) RTUtility.ReleaseAndDestroy(data.tex); RenderTextureFormat format; if (isHdr || QualitySettings.activeColorSpace == ColorSpace.Linear) format = RenderTextureFormat.ARGBHalf; else format = RenderTextureFormat.ARGB32; //This is the actual texture that will be sampled from for the reflections data.tex = new RenderTexture(width, height, 0, format, RenderTextureReadWrite.Default); data.tex.filterMode = FilterMode.Bilinear; data.tex.wrapMode = TextureWrapMode.Clamp; data.tex.useMipMap = false; data.tex.anisoLevel = ansio; data.tex.hideFlags = HideFlags.HideAndDontSave; data.tex.name = "Ceto Reflection Texture: " + camName; //This is the camera that will render the reflections. //Maybe null if a custom reflection method is being used. if (data.cam != null) { if (data.cam.targetTexture != null) RTUtility.ReleaseAndDestroy(data.cam.targetTexture); data.cam.targetTexture = new RenderTexture(width, height, 16, format, RenderTextureReadWrite.Default); data.cam.targetTexture.filterMode = FilterMode.Bilinear; data.cam.targetTexture.wrapMode = TextureWrapMode.Clamp; data.cam.targetTexture.useMipMap = false; data.cam.targetTexture.anisoLevel = 0; data.cam.targetTexture.hideFlags = HideFlags.HideAndDontSave; data.cam.targetTexture.name = "Ceto Reflection Render Target: " + camName; } }