DiscardContents() публичный Метод

Discards the contents of the RenderTexture.

public DiscardContents ( ) : void
Результат void
        // flat blur
        void Blur(RenderTexture from  ,RenderTexture  to , int iterations  , int blurPass, float spread  )
        {
            RenderTexture tmp  = RenderTexture.GetTemporary (to.width, to.height, 0);

            if (iterations < 2) {
                dofBlurMaterial.SetVector ("offsets", new Vector4 (0.0f, spread * oneOverBaseSize, 0.0f, 0.0f));
                tmp.DiscardContents ();
                Graphics.Blit (from, tmp, dofBlurMaterial, blurPass);

                dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize,  0.0f, 0.0f, 0.0f));
                to.DiscardContents ();
                Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
            }
            else {
                dofBlurMaterial.SetVector ("offsets", new Vector4 (0.0f, spread * oneOverBaseSize, 0.0f, 0.0f));
                tmp.DiscardContents ();
                Graphics.Blit (from, tmp, dofBlurMaterial, blurPass);

                dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize,  0.0f, 0.0f, 0.0f));
                to.DiscardContents ();
                Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);

                dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize,  spread * oneOverBaseSize, 0.0f, 0.0f));
                tmp.DiscardContents ();
                Graphics.Blit (to, tmp, dofBlurMaterial, blurPass);

                dofBlurMaterial.SetVector ("offsets", new Vector4 (spread / widthOverHeight * oneOverBaseSize,  -spread * oneOverBaseSize, 0.0f, 0.0f));
                to.DiscardContents ();
                Graphics.Blit (tmp, to, dofBlurMaterial, blurPass);
            }

            RenderTexture.ReleaseTemporary (tmp);
        }
	static int DiscardContents(IntPtr L)
	{
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("UnityEngine.RenderTexture.Register");
#endif
		try
		{
			int count = LuaDLL.lua_gettop(L);

			if (count == 1)
			{
				UnityEngine.RenderTexture obj = (UnityEngine.RenderTexture)ToLua.CheckObject<UnityEngine.RenderTexture>(L, 1);
				obj.DiscardContents();
				return 0;
			}
			else if (count == 3)
			{
				UnityEngine.RenderTexture obj = (UnityEngine.RenderTexture)ToLua.CheckObject<UnityEngine.RenderTexture>(L, 1);
				bool arg0 = LuaDLL.luaL_checkboolean(L, 2);
				bool arg1 = LuaDLL.luaL_checkboolean(L, 3);
				obj.DiscardContents(arg0, arg1);
				return 0;
			}
			else
			{
				return LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.RenderTexture.DiscardContents");
			}
		}
		catch (Exception e)
		{
			return LuaDLL.toluaL_exception(L, e);
		}
	}
Пример #3
0
    static int DiscardContents(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                UnityEngine.RenderTexture obj = (UnityEngine.RenderTexture)ToLua.CheckObject <UnityEngine.RenderTexture>(L, 1);
                obj.DiscardContents();
                return(0);
            }
            else if (count == 3)
            {
                UnityEngine.RenderTexture obj = (UnityEngine.RenderTexture)ToLua.CheckObject <UnityEngine.RenderTexture>(L, 1);
                bool arg0 = LuaDLL.luaL_checkboolean(L, 2);
                bool arg1 = LuaDLL.luaL_checkboolean(L, 3);
                obj.DiscardContents(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.RenderTexture.DiscardContents"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #4
0
 static int QPYX_DiscardContents_YXQP(IntPtr L_YXQP)
 {
     try
     {
         int QPYX_count_YXQP = LuaDLL.lua_gettop(L_YXQP);
         if (QPYX_count_YXQP == 1)
         {
             UnityEngine.RenderTexture QPYX_obj_YXQP = (UnityEngine.RenderTexture)ToLua.CheckObject <UnityEngine.RenderTexture>(L_YXQP, 1);
             QPYX_obj_YXQP.DiscardContents();
             return(0);
         }
         else if (QPYX_count_YXQP == 3)
         {
             UnityEngine.RenderTexture QPYX_obj_YXQP = (UnityEngine.RenderTexture)ToLua.CheckObject <UnityEngine.RenderTexture>(L_YXQP, 1);
             bool QPYX_arg0_YXQP = LuaDLL.luaL_checkboolean(L_YXQP, 2);
             bool QPYX_arg1_YXQP = LuaDLL.luaL_checkboolean(L_YXQP, 3);
             QPYX_obj_YXQP.DiscardContents(QPYX_arg0_YXQP, QPYX_arg1_YXQP);
             return(0);
         }
         else
         {
             return(LuaDLL.luaL_throw(L_YXQP, "invalid arguments to method: UnityEngine.RenderTexture.DiscardContents"));
         }
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
    static int DiscardContents(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.RenderTexture)))
            {
                UnityEngine.RenderTexture obj = (UnityEngine.RenderTexture)ToLua.ToObject(L, 1);
                obj.DiscardContents();
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.RenderTexture), typeof(bool), typeof(bool)))
            {
                UnityEngine.RenderTexture obj = (UnityEngine.RenderTexture)ToLua.ToObject(L, 1);
                bool arg0 = LuaDLL.lua_toboolean(L, 2);
                bool arg1 = LuaDLL.lua_toboolean(L, 3);
                obj.DiscardContents(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.RenderTexture.DiscardContents"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Пример #6
0
 static public int DiscardContents(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 1)
         {
             UnityEngine.RenderTexture self = (UnityEngine.RenderTexture)checkSelf(l);
             self.DiscardContents();
             return(0);
         }
         else if (argc == 3)
         {
             UnityEngine.RenderTexture self = (UnityEngine.RenderTexture)checkSelf(l);
             System.Boolean            a1;
             checkType(l, 2, out a1);
             System.Boolean a2;
             checkType(l, 3, out a2);
             self.DiscardContents(a1, a2);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Пример #7
0
 static public int DiscardContents(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (argc == 1)
         {
             UnityEngine.RenderTexture self = (UnityEngine.RenderTexture)checkSelf(l);
             self.DiscardContents();
             pushValue(l, true);
             return(1);
         }
         else if (argc == 3)
         {
             UnityEngine.RenderTexture self = (UnityEngine.RenderTexture)checkSelf(l);
             System.Boolean            a1;
             checkType(l, 2, out a1);
             System.Boolean a2;
             checkType(l, 3, out a2);
             self.DiscardContents(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function DiscardContents to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #8
0
        private RenderTexture CreateNewRenderTexture(int width, int height)
        {
            RenderTexture renderTexture = new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32);
            renderTexture.filterMode = FilterMode.Point;
            renderTexture.DiscardContents();

            return renderTexture;
        }
 static public int DiscardContents(IntPtr l)
 {
     try {
         UnityEngine.RenderTexture self = (UnityEngine.RenderTexture)checkSelf(l);
         self.DiscardContents();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        /////////////////////////////////////////////////////////////////////////////////
        public void PostRender()
        {
            // Render UI to the active camera
            RenderEvent(PostRenderId + _rendererId);

#if !UNITY_4_1 && !UNITY_4_2
            if (IsRenderToTexture)
            {
                _texture.DiscardContents(false, true);
            }
#endif
        }
Пример #11
0
 static public int DiscardContents__Boolean__Boolean(IntPtr l)
 {
     try {
         UnityEngine.RenderTexture self = (UnityEngine.RenderTexture)checkSelf(l);
         System.Boolean            a1;
         checkType(l, 2, out a1);
         System.Boolean a2;
         checkType(l, 3, out a2);
         self.DiscardContents(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    private void Initialize()
    {
        //Screen.SetResolution(1980, 1024, true);
        var goCamera = new GameObject("RenderTextureCamera");
        var cameraInstance = goCamera.AddComponent<Camera>();
        var cam = Camera.main;
        cameraInstance.CopyFrom(cam);
        cameraInstance.depth++;
        cameraInstance.cullingMask = CullingMask;
        goCamera.transform.parent = cam.transform;
        renderTexture = new RenderTexture((int)(Screen.width * Scale), (int)(Screen.height * Scale), 32, RenderTextureFormat);
        renderTexture.DiscardContents();
        renderTexture.filterMode = FilterMode.Point;
        cameraInstance.targetTexture = renderTexture;

        Shader.SetGlobalTexture("_GrabTextureMobile", renderTexture);
    }
Пример #13
0
 private void Initialize()
 {
     goCamera = new GameObject("RenderTextureCamera");
     cameraInstance = goCamera.AddComponent<Camera>();
     var cam = Camera.main;
     cameraInstance.CopyFrom(cam);
     cameraInstance.depth++;
     cameraInstance.cullingMask = CullingMask;
     cameraInstance.renderingPath = RenderingPath;
     goCamera.transform.parent = cam.transform;
     renderTexture = new RenderTexture(Mathf.RoundToInt(Screen.width * TextureScale), Mathf.RoundToInt(Screen.height * TextureScale), 16, RenderTextureFormat);
     renderTexture.DiscardContents();
     renderTexture.filterMode = FilterMode;
     cameraInstance.targetTexture = renderTexture;
     instanceCameraTransform = cameraInstance.transform;
     oldPosition = instanceCameraTransform.position;
     Shader.SetGlobalTexture("_GrabTextureMobile", renderTexture);
     isInitialized = true;
 }
Пример #14
0
    private void Awake()
    {
        m_Camera = gameObject.GetComponent <Camera>();

        m_DepthMaterial   = new Material(Shader.Find("Hidden/Depth"));
        m_InteracMaterial = new Material(Shader.Find("Hidden/Interact"));
        m_FoamMaterial    = new Material(Shader.Find("Hidden/Foam"));

        m_DepthTexture = new RenderTexture(1024, 1024, 24);
        m_DepthTexture.DiscardContents(true, true);
        m_InterectTexture = new RenderTexture(1024, 1024, 24);
        m_InterectTexture.DiscardContents(true, true);
        m_FoamTexture = new RenderTexture(1024, 1024, 16);
        m_FoamTexture.DiscardContents(true, true);
        m_FoamPreTexture = new RenderTexture(1024, 1024, 24);
        m_FoamPreTexture.DiscardContents(true, true);

        m_Camera.targetTexture = m_FoamTexture;
    }
Пример #15
0
    // Use this for initialization
    private void Update()
    {
        Vector3 pos = transform.position;
        Vector3 normal = transform.up;
        float d = -Vector3.Dot(normal, pos) - m_ClipPlaneOffset;
        Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);

        Matrix4x4 reflection = Matrix4x4.zero;
        CalculateReflectionMatrix(ref reflection, reflectionPlane);
        Vector3 oldpos = currentCamera.transform.position;
        Vector3 newpos = reflection.MultiplyPoint(oldpos);

        if (go==null) {
            renderTexture = new RenderTexture((int) (Screen.width * TextureScale), (int) (Screen.height * TextureScale), 16, RenderTextureFormat);
            renderTexture.DiscardContents();
            go = new GameObject("Water Refl Camera");
            reflectionCamera = go.AddComponent<Camera>();
            reflectionCamera.depth = currentCamera.depth - 1;
            reflectionCamera.renderingPath = RenderingPath;
            reflectionCamera.depthTextureMode = DepthTextureMode.None;
            go.transform.position = transform.position;
            go.transform.rotation = transform.rotation;
            reflectionCamera.cullingMask = CullingMask;
            reflectionCamera.targetTexture = renderTexture;
            reflectionCamera.hdr = HDR;
            reflectionCamera.useOcclusionCulling = OcclusionCulling;
            Shader.SetGlobalTexture("_ReflectionTex", renderTexture);
            instanceCameraTransform = reflectionCamera.transform;
        }
        reflectionCamera.worldToCameraMatrix = currentCamera.worldToCameraMatrix * reflection;
        Vector4 clipPlane = CameraSpacePlane(reflectionCamera, pos, normal, 1.0f);
        #if UNITY_4_3 || UNITY_4_5
        reflectionCamera.projectionMatrix = CalculateObliqueMatrix(reflectionCamera.projectionMatrix, clipPlane);
        #else
        reflectionCamera.projectionMatrix = currentCamera.CalculateObliqueMatrix(clipPlane);
        #endif

        #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        GL.SetRevertBackfacing(true);
        #else
        GL.invertCulling = true;
        #endif
        go.transform.position = newpos;
        Vector3 euler = currentCamera.transform.eulerAngles;
        go.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);

        UpdateCameraPosition();

        #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
        GL.SetRevertBackfacing(false);
        #else
        GL.invertCulling = false;
        #endif
    }
Пример #16
0
		// Performs one blur iteration
		protected void FourTapCone(RenderTexture src, RenderTexture dst, int iteration)
		{
			float off = blurMinSpread + iteration * blurSpread;
			blurMaterial.SetFloat(ShaderPropertyID._OffsetScale, off);
			Graphics.Blit(src, dst, blurMaterial);
			src.DiscardContents();
		}
Пример #17
0
		// Performs one blur iteration
		protected void FourTapCone(RenderTexture src, RenderTexture dst, float off)
		{
			blurMaterial.SetFloat(ShaderPropertyID._Scale, off);
			Graphics.Blit(src, dst, blurMaterial);
			src.DiscardContents();
		}
Пример #18
0
        private void OnRenderImage(RenderTexture src, RenderTexture dest)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying || Util.IsSceneViewFocused)
            {
                Shader.SetGlobalTexture("_ObstacleTex", Texture2D.whiteTexture);
                if (dest != null)
                    dest.DiscardContents();
                Graphics.Blit(src, dest);
                return;
            }
#endif
            Update2DTK();
            UpdateCamera();
            RenderObstacles();
            SetupShaders();
            RenderNormalBuffer();
            RenderLightSources();
            RenderLightSourcesBlur();
            RenderAmbientLight();
            RenderLightOverlay(src, dest);
        }
        void OnRenderImage(RenderTexture source  , RenderTexture destination )
        {
            #if UNITY_EDITOR
            FindShaders ();
            CheckSupport ();
            CreateMaterials ();
            #endif

            widthOverHeight = (1.0f * source.width) / (1.0f * source.height);
            oneOverBaseSize = 1.0f / 512.0f;

            cameraNear = camera.nearClipPlane;
               cameraFar = camera.farClipPlane;
            cameraFov = camera.fieldOfView;
            cameraAspect = camera.aspect;

            Matrix4x4 frustumCorners   = Matrix4x4.identity;
            Vector4 vec  ;
            Vector3 corner  ;
            float fovWHalf   = cameraFov * 0.5f;
            Vector3 toRight   = camera.transform.right * cameraNear * Mathf.Tan (fovWHalf * Mathf.Deg2Rad) * cameraAspect;
            Vector3 toTop  = camera.transform.up * cameraNear * Mathf.Tan (fovWHalf * Mathf.Deg2Rad);
            Vector3 topLeft  = (camera.transform.forward * cameraNear - toRight + toTop);
            float cameraScaleFactor = topLeft.magnitude * cameraFar/cameraNear;

            topLeft.Normalize();
            topLeft *= cameraScaleFactor;

            Vector3 topRight  = (camera.transform.forward * cameraNear + toRight + toTop);
            topRight.Normalize();
            topRight *= cameraScaleFactor;

            Vector3 bottomRight   = (camera.transform.forward * cameraNear + toRight - toTop);
            bottomRight.Normalize();
            bottomRight *= cameraScaleFactor;

            Vector3 bottomLeft = (camera.transform.forward * cameraNear - toRight - toTop);
            bottomLeft.Normalize();
            bottomLeft *= cameraScaleFactor;

            frustumCorners.SetRow (0, topLeft);
            frustumCorners.SetRow (1, topRight);
            frustumCorners.SetRow (2, bottomRight);
            frustumCorners.SetRow (3, bottomLeft);

            dofMaterial.SetMatrix ("_FrustumCornersWS", frustumCorners);
            dofMaterial.SetVector ("_CameraWS", camera.transform.position);

            Transform t ;
            if (!objectFocus)
                t = camera.transform;
            else
                t = objectFocus.transform;

            dofMaterial.SetVector ("_ObjectFocusParameter", new Vector4 (
                        t.position.y - 0.25f, t.localScale.y * 1.0f / smoothness, 1.0f, objectFocus ? objectFocus.collider.bounds.extents.y * 0.75f : 0.55f));

            dofMaterial.SetFloat ("_ForegroundBlurExtrude", foregroundBlurExtrude);
            dofMaterial.SetVector ("_InvRenderTargetSize", new Vector4 ((float)(1.0f / (1.0f * source.width)), (float)(1.0f / (1.0 * source.height)), 0.0f, 0.0f));

            int divider   = 1;
            if (resolution == DofResolution.Medium)
                divider = 2;
            else if (resolution >= DofResolution.Medium)
                divider = 3;

            RenderTexture hrTex   = RenderTexture.GetTemporary (source.width, source.height, 0);
            RenderTexture mediumTexture = RenderTexture.GetTemporary (source.width / divider, source.height / divider, 0);
            RenderTexture mediumTexture2  = RenderTexture.GetTemporary (source.width / divider, source.height / divider, 0);
            RenderTexture lowTexture  = RenderTexture.GetTemporary (source.width / (divider * 2), source.height / (divider * 2), 0);

            source.filterMode = FilterMode.Bilinear;
            hrTex.filterMode = FilterMode.Bilinear;
            lowTexture.filterMode = FilterMode.Bilinear;
            mediumTexture.filterMode = FilterMode.Bilinear;
            mediumTexture2.filterMode = FilterMode.Bilinear;

            // background (coc -> alpha channel)
               	        CustomGraphicsBlit (null, source, dofMaterial, 3);

               	        // better downsample (should actually be weighted for higher quality)
               	        mediumTexture2.DiscardContents();
               	        Graphics.Blit (source, mediumTexture2, dofMaterial, 6);

            Blur (mediumTexture2, mediumTexture, 1, 0, maxBlurSpread * 0.75f);
            Blur (mediumTexture, lowTexture, 2, 0, maxBlurSpread);

            // some final calculations can be performed in low resolution
            dofBlurMaterial.SetTexture ("_TapLow", lowTexture);
            dofBlurMaterial.SetTexture ("_TapMedium", mediumTexture);
            Graphics.Blit (null, mediumTexture2, dofBlurMaterial, 2);

            dofMaterial.SetTexture ("_TapLowBackground", mediumTexture2);
            dofMaterial.SetTexture ("_TapMedium", mediumTexture); // only needed for debugging

            // apply background defocus
            hrTex.DiscardContents();
            Graphics.Blit (source, hrTex, dofMaterial, visualize ? 2 : 0);

            // foreground handling
            CustomGraphicsBlit (hrTex, source, dofMaterial, 5);

            // better downsample and blur (shouldn't be weighted)
            Graphics.Blit (source, mediumTexture2, dofMaterial, 6);
            Blur (mediumTexture2, mediumTexture, 1, 1, maxBlurSpread * 0.75f);
            Blur (mediumTexture, lowTexture, 2, 1, maxBlurSpread);

            // some final calculations can be performed in low resolution
            dofBlurMaterial.SetTexture ("_TapLow", lowTexture);
            dofBlurMaterial.SetTexture ("_TapMedium", mediumTexture);
            Graphics.Blit (null, mediumTexture2, dofBlurMaterial, 2);

            if (destination != null)
                destination.DiscardContents ();

            dofMaterial.SetTexture ("_TapLowForeground", mediumTexture2);
            dofMaterial.SetTexture ("_TapMedium", mediumTexture); // only needed for debugging
            Graphics.Blit (source, destination, dofMaterial, visualize ? 1 : 4);

            RenderTexture.ReleaseTemporary (hrTex);
            RenderTexture.ReleaseTemporary (mediumTexture);
            RenderTexture.ReleaseTemporary (mediumTexture2);
            RenderTexture.ReleaseTemporary (lowTexture);
        }
 private void Sample(RenderTexture source, RenderTexture dest, float off, Material mat)
 {
     if ((Object) dest != (Object) null)
       dest.DiscardContents();
     RenderTexture renderTexture = source;
     RenderTexture dest1 = dest;
     Material mat1 = mat;
     Vector2[] vector2Array = new Vector2[4];
     int index1 = 0;
     vector2Array[index1] = new Vector2(-off, -off);
     int index2 = 1;
     vector2Array[index2] = new Vector2(-off, off);
     int index3 = 2;
     vector2Array[index3] = new Vector2(off, off);
     int index4 = 3;
     vector2Array[index4] = new Vector2(off, -off);
     Graphics.BlitMultiTap((Texture) renderTexture, dest1, mat1, vector2Array);
 }
Пример #21
0
	public static void DiscardContents( RenderTexture rtex )
	{
	#if !( UNITY_WP8 || UNITY_WP8_1 || UNITY_WSA ) // why?..
		rtex.DiscardContents();
	#endif
	}
Пример #22
0
        /// <summary>
        /// render the vessel diagram to a texture.
        /// </summary>
        /// <param name="renderTexture">Texture to render to.</param>
        void renderToTexture(RenderTexture renderTexture)
        {
            //render not when invisible, grasshopper.
            if (basicSettings.screenVisible)
            {

                //switch rendering to the texture
                RenderTexture backupRenderTexture = RenderTexture.active;
                if (!renderTexture.IsCreated())
                    renderTexture.Create();
                renderTexture.DiscardContents();
                RenderTexture.active = renderTexture;

                //setup viewport and such
                GL.PushMatrix();
                GL.LoadPixelMatrix(0, renderTexture.width, 0, renderTexture.height);
                GL.Viewport(new Rect(0, 0, renderTexture.width, renderTexture.height));

                //clear the texture
                GL.Clear(true, true, Color.black);
                
                //set up the screen position and scaling matrix
                Matrix4x4 matrix = Matrix4x4.TRS(new Vector3(basicSettings.scrOffX, basicSettings.scrOffY, 0), Quaternion.identity, new Vector3(basicSettings.scaleFact, basicSettings.scaleFact, 1));
                //dunno what this does, but I trust in the stolen codes
                lineMaterial.SetPass(0);
              
                while (partQueue.Count > 0)
                {
                    Part next = partQueue.Dequeue();
                    if (next != null)
                    {
                        renderPart(next, matrix, true);
                    }
                }
                GL.Clear(true, false, Color.black);
                if (partQueue.Count == 0)
                {
                    if (!FlightGlobals.ActiveVessel.isEVA)
                    {
                        partQueue.Enqueue(FlightGlobals.ActiveVessel.rootPart);
                    }
                }
                //lineMaterial.SetPass(1);
                //turn on wireframe, since triangles would get filled othershipwise
                GL.wireframe = true;
                //now render each part (assumes root part is in the queue)
                while (partQueue.Count > 0)
                {
                    Part next = partQueue.Dequeue();
                    if (next != null)
                    {
                        renderPart(next, matrix, false);
                    }
                }
                //now render engine exhaust indicators
                if (customMode == null)
                {
                    if (basicSettings.displayEngines)
                    {
                        renderEngineThrusts(matrix);
                    }
                }
                else
                {
                    switch (customMode.MinimodesOverride)
                    {
                        case (int)CustomModeSettings.OVERRIDE_TYPES.AS_BASIC:
                            if (basicSettings.displayEngines)
                            {
                                renderEngineThrusts(matrix);    
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.STATIC:
                            if (customMode.staticSettings.displayEngines)
                            {
                                renderEngineThrusts(matrix);    
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.FUNCTION:
                            if (customMode.displayEnginesDelegate(customMode))
                            {
                                renderEngineThrusts(matrix); 
                            } break;
                    }
                }
                //now render the bounding boxes (so theyre on top)
                if (customMode == null)
                {
                    if (basicSettings.colorModeBox != (int)ViewerConstants.COLORMODE.HIDE)
                    {
                        renderRects(matrix);
                    }
                }
                else
                {
                    switch (customMode.ColorModeOverride)
                    {
                        case (int)CustomModeSettings.OVERRIDE_TYPES.AS_BASIC:
                            if (basicSettings.colorModeBox != (int)ViewerConstants.COLORMODE.HIDE)
                            {
                                renderRects(matrix);
                            }break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.STATIC:
                            if (customMode.staticSettings.colorModeBox != (int)ViewerConstants.COLORMODE.HIDE)
                            {
                                renderRects(matrix);
                            }break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.FUNCTION:
                            renderRects(matrix);
                            break;
                    }
                }
                
                //now render center of mass
                if (customMode == null)
                {
                    if (basicSettings.displayCOM) 
                    {
                        renderCOM(matrix);
                    }
                }
                else
                {
                    switch (customMode.MinimodesOverride)
                    {
                        case (int)CustomModeSettings.OVERRIDE_TYPES.AS_BASIC:
                            if (basicSettings.displayCOM) 
                            {
                                renderCOM(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.STATIC:
                            if (customMode.staticSettings.displayCOM)
                            {
                                renderCOM(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.FUNCTION:
                            if (customMode.displayCOMDelegate(customMode))
                            {
                                renderCOM(matrix);
                            } break;
                    }
                }
                //first, render the ground
                if (customMode == null)
                {
                    if (basicSettings.displayGround != (int)ViewerConstants.GROUND_DISPMODE.OFF)
                    {
                        renderGround(matrix);
                    }
                }
                else
                {
                    switch (customMode.MinimodesOverride)
                    {
                        case (int)CustomModeSettings.OVERRIDE_TYPES.AS_BASIC:
                            if (basicSettings.displayGround != (int)ViewerConstants.GROUND_DISPMODE.OFF)
                            {
                                renderGround(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.STATIC:
                            if (customMode.staticSettings.displayGround != (int)ViewerConstants.GROUND_DISPMODE.OFF)
                            {
                                renderGround(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.FUNCTION:
                            if (customMode.displayGroundDelegate(customMode) != (int)ViewerConstants.GROUND_DISPMODE.OFF)
                            {
                                renderGround(matrix);
                            } break;
                    }
                }
                //first, render the ground
                if (customMode == null)
                {
                    if (basicSettings.displayAxes)
                    {
                        renderAxes(matrix);
                    }
                }
                else
                {
                    switch (customMode.MinimodesOverride)
                    {
                        case (int)CustomModeSettings.OVERRIDE_TYPES.AS_BASIC:
                            if (basicSettings.displayAxes)
                            {
                                renderAxes(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.STATIC:
                            if (customMode.staticSettings.displayAxes)
                            {
                                renderAxes(matrix);
                            } break;
                        case (int)CustomModeSettings.OVERRIDE_TYPES.FUNCTION:
                            if (customMode.displayAxesDelegate(customMode))
                            {
                                renderAxes(matrix);
                            } break;
                    }
                }
                
                /*if (settings.displayCOP)
                {
                    renderCOP(matrix);
                }*/
                //then set the max stages (for the stage coloring)
                stagesLastTime = stagesThisTimeMax;
                //undo stuff
                GL.wireframe = false;
                GL.PopMatrix();
                RenderTexture.active = backupRenderTexture;
            }
        }
Пример #23
0
    /// <summary>
    /// The recommended way to initialize the Dynamic RT Camera
    /// </summary>
    /// <param name="rtWidth"></param>
    /// <param name="rtHeight"></param>
    public void InitializeRT(int rtWidth, int rtHeight)
    {
        _rt = new RenderTexture(rtWidth, rtHeight, colorDepth);

        _rt.useMipMap = false;
        _rt.name = "Dynamically created RT by AB Minimap";

        _rt.antiAliasing = antiAliasing;
        _rt.filterMode = filterMode;
        _hasBeenInitialized = true;

        _rt.DiscardContents();
        _rt.Create();

        GetComponent<Camera>().targetTexture = _rt;
        GetComponent<Camera>().ResetAspect();

        if (rtChangedHandler != null)
            rtChangedHandler(_rt);
    }
Пример #24
0
        private void RenderAmbientLight()
        {
            if (!EnableAmbientLight || AmbientLightComputeMaterial == null)
                return;

            Profiler.BeginSample("LightingSystem.OnRenderImage Ambient Light");

            ConfigLightCamera(true);

            if (_ambientTexture == null)
            {
                _ambientTexture =
                    new RenderTexture(_extendedLightTextureSize.x, _extendedLightTextureSize.y, 0, _texFormat);
            }
            if (_prevAmbientTexture == null)
            {
                _prevAmbientTexture =
                    new RenderTexture(_extendedLightTextureSize.x, _extendedLightTextureSize.y, 0, _texFormat);
            }
            if (_ambientEmissionTexture == null)
            {
                _ambientEmissionTexture =
                    new RenderTexture(_extendedLightTextureSize.x, _extendedLightTextureSize.y, 0, _texFormat);
            }

            if (EnableAmbientLight)
            {
                var oldBackgroundColor = LightCamera.backgroundColor;
                LightCamera.targetTexture = _ambientEmissionTexture;
                LightCamera.cullingMask = 1 << AmbientLightLayer;
                LightCamera.backgroundColor = new Color(0, 0, 0, 0);
                LightCamera.Render();
                LightCamera.targetTexture = null;
                LightCamera.cullingMask = 0;
                LightCamera.backgroundColor = oldBackgroundColor;
            }

            for (int i = 0; i < _aditionalAmbientLightCycles + 1; i++)
            {
                var tmp = _prevAmbientTexture;
                _prevAmbientTexture = _ambientTexture;
                _ambientTexture = tmp;

                var texSize = new Vector2(_ambientTexture.width, _ambientTexture.height);
                var posShift = ((Vector2) (_currPos - _oldPos)/LightPixelSize).Div(texSize);
                _oldPos = _currPos;

                AmbientLightComputeMaterial.SetTexture("_LightSourcesTex", _ambientEmissionTexture);
                AmbientLightComputeMaterial.SetTexture("_MainTex", _prevAmbientTexture);
                AmbientLightComputeMaterial.SetVector("_Shift", posShift);

                _ambientTexture.DiscardContents();
                Graphics.Blit(null, _ambientTexture, AmbientLightComputeMaterial);

                if (BlurAmbientLight && AmbientLightBlurMaterial != null)
                {
                    Profiler.BeginSample("LightingSystem.OnRenderImage Bluring Ambient Light");

                    _prevAmbientTexture.DiscardContents();
                    AmbientLightBlurMaterial.mainTexture = _ambientTexture;
                    Graphics.Blit(null, _prevAmbientTexture, AmbientLightBlurMaterial);

                    var tmpblur = _prevAmbientTexture;
                    _prevAmbientTexture = _ambientTexture;
                    _ambientTexture = tmpblur;

                    Profiler.EndSample();
                }
            }

            _aditionalAmbientLightCycles = 0;
            Profiler.EndSample();
        }
    private bool DoFormatConversion(RenderTexture target)
    {
        if (_buffers == null || _buffers.Count == 0)
            return false;

        target.DiscardContents();

        if (!_requiresTextureCrop)
        {
            RenderTexture prev = RenderTexture.active;
            Graphics.Blit(_buffers[0]._texture, target, _conversionMaterial, 0);
            RenderTexture.active = prev;
        }
        else
        {
            RenderTexture prev = RenderTexture.active;
            RenderTexture.active = target;
            _conversionMaterial.SetPass(0);

            GL.PushMatrix();
            GL.LoadOrtho();
            DrawQuad();
            GL.PopMatrix();

            RenderTexture.active = prev;
        }

        return true;
    }
 private void DoDeinterlace(RenderTexture source, RenderTexture target)
 {
     target.DiscardContents();
     RenderTexture prev = RenderTexture.active;
     Graphics.Blit(source, target, _deinterlaceMaterial);
     RenderTexture.active = prev;
 }
Пример #27
0
 private static void ReturnTexture(RenderTexture texture)
 {
     texture.DiscardContents();
     texturePool.Add(texture);
 }
Пример #28
0
 public static void DiscardContents(RenderTexture rtex)
 {
     rtex.DiscardContents();
 }