/// <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> /// 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 }
private void CreateReflectionCameraFor(Camera cam, ReflectionData data) { if (data.cam == null) { GameObject gameObject = new GameObject("Ceto Reflection Camera: " + cam.name); gameObject.hideFlags = HideFlags.HideAndDontSave; DisableFog disableFog = gameObject.AddComponent <DisableFog>(); disableFog.enabled = !this.fogInReflection; data.cam = gameObject.AddComponent <Camera>(); data.cam.depthTextureMode = DepthTextureMode.None; data.cam.renderingPath = RenderingPath.Forward; data.cam.enabled = false; data.cam.hdr = cam.hdr; data.cam.targetTexture = null; data.cam.useOcclusionCulling = false; } data.cam.fieldOfView = cam.fieldOfView; data.cam.nearClipPlane = cam.nearClipPlane; data.cam.farClipPlane = cam.farClipPlane; data.cam.orthographic = cam.orthographic; data.cam.aspect = cam.aspect; data.cam.orthographicSize = cam.orthographicSize; data.cam.rect = new Rect(0f, 0f, 1f, 1f); data.cam.backgroundColor = this.m_ocean.defaultSkyColor; data.cam.clearFlags = ((!this.skyboxInReflection) ? CameraClearFlags.Color : CameraClearFlags.Skybox); if (this.copyCullDistances) { data.cam.layerCullDistances = cam.layerCullDistances; data.cam.layerCullSpherical = true; } }
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; } }
/// <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> /// Create the reflection camera for this camera. /// </summary> void CreateReflectionCameraFor(Camera cam, ReflectionData data) { if (data.cam == null) { GameObject go = new GameObject("Ceto Reflection Camera: " + cam.name); go.AddComponent <IgnoreOceanEvents>(); go.hideFlags = HideFlags.HideAndDontSave; DisableFog disableFog = go.AddComponent <DisableFog>(); disableFog.enabled = !fogInReflection; data.cam = go.AddComponent <Camera>(); //data.cam.CopyFrom(cam); //This will cause a recursive culling error in Unity >= 5.4 data.cam.depthTextureMode = DepthTextureMode.None; data.cam.renderingPath = RenderingPath.Forward; data.cam.enabled = false; data.cam.allowHDR = cam.allowHDR; data.cam.targetTexture = null; } data.cam.fieldOfView = cam.fieldOfView; data.cam.nearClipPlane = cam.nearClipPlane; data.cam.farClipPlane = cam.farClipPlane; data.cam.orthographic = cam.orthographic; data.cam.aspect = cam.aspect; data.cam.orthographicSize = cam.orthographicSize; data.cam.rect = new Rect(0, 0, 1, 1); data.cam.backgroundColor = m_ocean.defaultSkyColor; data.cam.clearFlags = (skyboxInReflection) ? CameraClearFlags.Skybox : CameraClearFlags.SolidColor; //Copy the cull distances used by the camera. //Since the reflection camera uses a oblique projection matrix //the layer culling must be spherical or the cull wont match //that used by the camera. There will still be some mismatch //between the reflection culling and camera culling if the //camera does not use spherical culling. if (copyCullDistances) { data.cam.layerCullDistances = cam.layerCullDistances; data.cam.layerCullSpherical = true; } }
private void CreateReflectionCameraFor(Camera cam, ReflectionData data) { if (data.cam == null) { GameObject gameObject = new GameObject("Ceto Reflection Camera: " + cam.name); gameObject.hideFlags = HideFlags.HideAndDontSave; DisableFog disableFog = gameObject.AddComponent<DisableFog>(); disableFog.enabled = !this.fogInReflection; data.cam = gameObject.AddComponent<Camera>(); data.cam.depthTextureMode = DepthTextureMode.None; data.cam.renderingPath = RenderingPath.Forward; data.cam.enabled = false; data.cam.hdr = cam.hdr; data.cam.targetTexture = null; data.cam.useOcclusionCulling = false; } data.cam.fieldOfView = cam.fieldOfView; data.cam.nearClipPlane = cam.nearClipPlane; data.cam.farClipPlane = cam.farClipPlane; data.cam.orthographic = cam.orthographic; data.cam.aspect = cam.aspect; data.cam.orthographicSize = cam.orthographicSize; data.cam.rect = new Rect(0f, 0f, 1f, 1f); data.cam.backgroundColor = this.m_ocean.defaultSkyColor; data.cam.clearFlags = ((!this.skyboxInReflection) ? CameraClearFlags.Color : CameraClearFlags.Skybox); if (this.copyCullDistances) { data.cam.layerCullDistances = cam.layerCullDistances; data.cam.layerCullSpherical = true; } }
/// <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> /// Create the reflection camera for this camera. /// </summary> void CreateReflectionCameraFor(Camera cam, ReflectionData data) { if (data.cam == null) { GameObject go = new GameObject("Ceto Reflection Camera: " + cam.name); go.AddComponent<IgnoreOceanEvents>(); go.hideFlags = HideFlags.HideAndDontSave; DisableFog disableFog = go.AddComponent<DisableFog>(); disableFog.enabled = !fogInReflection; data.cam = go.AddComponent<Camera>(); //data.cam.CopyFrom(cam); //This will cause a recursive culling error in Unity >= 5.4 data.cam.depthTextureMode = DepthTextureMode.None; data.cam.renderingPath = RenderingPath.Forward; data.cam.enabled = false; data.cam.hdr = cam.hdr; data.cam.targetTexture = null; } data.cam.fieldOfView = cam.fieldOfView; data.cam.nearClipPlane = cam.nearClipPlane; data.cam.farClipPlane = cam.farClipPlane; data.cam.orthographic = cam.orthographic; data.cam.aspect = cam.aspect; data.cam.orthographicSize = cam.orthographicSize; data.cam.rect = new Rect(0, 0, 1, 1); data.cam.backgroundColor = m_ocean.defaultSkyColor; data.cam.clearFlags = (skyboxInReflection) ? CameraClearFlags.Skybox : CameraClearFlags.SolidColor; //Copy the cull distances used by the camera. //Since the reflection camera uses a oblique projection matrix //the layer culling must be spherical or the cull wont match //that used by the camera. There will still be some mismatch //between the reflection culling and camera culling if the //camera does not use spherical culling. if (copyCullDistances) { data.cam.layerCullDistances = cam.layerCullDistances; data.cam.layerCullSpherical = true; } }