protected virtual void OnDestroy() { if (m_rteCamera != null) { m_rteCamera.CommandBufferRefresh -= OnCommandBufferRefresh; m_rteCamera.Destroy(); m_rteCamera = null; } }
protected override void OnDestroy() { base.OnDestroy(); if (m_rteCamera != null) { m_rteCamera.CommandBufferRefresh -= OnCommandBufferRefresh; m_rteCamera.Destroy(); m_rteCamera = null; } }
protected override void Render(Shader shader, string tag, Camera renderCamera) { IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>(); m_rteCamera = graphics.CreateCamera(renderCamera, UnityEngine.Rendering.CameraEvent.AfterForwardAlpha, false, true); for (int i = 0; i < m_renderers.Count; ++i) { Renderer[] renderers = m_renderers[i]; for (int j = 0; j < renderers.Length; ++j) { m_rteCamera.RenderersCache.Add(renderers[j]); } } //Material material = new Material(shader); //m_rteCamera.RenderersCache.MaterialOverride = material; bool invertCulling = GL.invertCulling; GL.invertCulling = true; renderCamera.projectionMatrix *= Matrix4x4.Scale(new Vector3(1, -1, 1)); renderCamera.Render(); GL.invertCulling = invertCulling; //Object.Destroy(material); m_rteCamera.Destroy(); m_renderers.Clear(); }
private void DestroyGraphicsCamera() { IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>(); if (graphics != null) { IRTECamera camera = IOCContainer.Resolve <IRTECamera>(); IOCContainer.UnregisterFallback(camera); camera.Destroy(); } }
protected virtual void OnDisable() { if (m_rteCamera != null) { m_rteCamera.Destroy(); m_rteCamera = null; } if (BtnProjection != null) { BtnProjection.gameObject.SetActive(false); } }
private void OnDestroy() { if (m_window != null) { m_window.IOCContainer.UnregisterFallback <IRTEGraphicsLayer>(this); m_window.CameraResized -= OnCameraResized; } if (m_graphicsCamera != null) { m_graphicsCamera.Destroy(); } if (m_camera != null) { Destroy(m_camera.gameObject); } if (m_renderTextureCamera != null && m_renderTextureCamera.OverlayMaterial != null) { Destroy(m_renderTextureCamera.OverlayMaterial); } }
private static Texture2D Render( Camera camera, Shader shader, Renderer[] renderers, int width = -1, int height = -1) { bool autoSize = width < 0 || height < 0; int _width = autoSize ? (int)camera.pixelRect.width : width; int _height = autoSize ? (int)camera.pixelRect.height : height; GameObject go = new GameObject(); Camera renderCam = go.AddComponent <Camera>(); renderCam.CopyFrom(camera); renderCam.renderingPath = RenderingPath.Forward; renderCam.enabled = false; renderCam.clearFlags = CameraClearFlags.SolidColor; renderCam.backgroundColor = Color.white; renderCam.cullingMask = 0; IRenderPipelineCameraUtility cameraUtility = IOC.Resolve <IRenderPipelineCameraUtility>(); if (cameraUtility != null) { cameraUtility.EnablePostProcessing(renderCam, false); cameraUtility.SetBackgroundColor(renderCam, Color.white); } renderCam.allowHDR = false; renderCam.allowMSAA = false; renderCam.forceIntoRenderTexture = true; float aspect = renderCam.aspect; renderCam.rect = new Rect(Vector2.zero, Vector2.one); renderCam.aspect = aspect; RenderTextureDescriptor descriptor = new RenderTextureDescriptor() { width = _width, height = _height, colorFormat = RenderTextureFormat, autoGenerateMips = false, depthBufferBits = 16, dimension = TextureDimension.Tex2D, enableRandomWrite = false, memoryless = RenderTextureMemoryless.None, sRGB = true, useMipMap = false, volumeDepth = 1, msaaSamples = 1 }; RenderTexture rt = RenderTexture.GetTemporary(descriptor); RenderTexture prev = RenderTexture.active; renderCam.targetTexture = rt; RenderTexture.active = rt; Material replacementMaterial = new Material(shader); IRTEGraphics graphics = IOC.Resolve <IRTEGraphics>(); IRTECamera rteCamera = graphics.CreateCamera(renderCam, CameraEvent.AfterForwardAlpha, false, true); rteCamera.RenderersCache.MaterialOverride = replacementMaterial; rteCamera.Camera.name = "BoxSelectionCamera"; foreach (Renderer renderer in renderers) { Material[] materials = renderer.sharedMaterials; for (int i = 0; i < materials.Length; ++i) { if (materials[i] != null) { rteCamera.RenderersCache.Add(renderer); } } } rteCamera.RefreshCommandBuffer(); if (RenderPipelineInfo.Type != RPType.Standard) { bool invertCulling = GL.invertCulling; GL.invertCulling = true; renderCam.projectionMatrix *= Matrix4x4.Scale(new Vector3(1, -1, 1)); renderCam.Render(); GL.invertCulling = invertCulling; } else { renderCam.Render(); } Texture2D img = new Texture2D(_width, _height, TextureFormat, false, false); img.ReadPixels(new Rect(0, 0, _width, _height), 0, 0); img.Apply(); RenderTexture.active = prev; RenderTexture.ReleaseTemporary(rt); UnityObject.DestroyImmediate(go); UnityObject.Destroy(replacementMaterial); rteCamera.Destroy(); //System.IO.File.WriteAllBytes("Assets/box_selection.png", img.EncodeToPNG()); return(img); }