当前位置: 首页>>代码示例>>C#>>正文


C# RenderTexture.DiscardContents方法代码示例

本文整理汇总了C#中UnityEngine.RenderTexture.DiscardContents方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTexture.DiscardContents方法的具体用法?C# RenderTexture.DiscardContents怎么用?C# RenderTexture.DiscardContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.RenderTexture的用法示例。


在下文中一共展示了RenderTexture.DiscardContents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Blur

        // 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);
        }
开发者ID:haejoon,项目名称:realdedicated-unitylibrary,代码行数:34,代码来源:HeightDepthOfField.cs

示例2: CreateNewRenderTexture

        private RenderTexture CreateNewRenderTexture(int width, int height)
        {
            RenderTexture renderTexture = new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32);
            renderTexture.filterMode = FilterMode.Point;
            renderTexture.DiscardContents();

            return renderTexture;
        }
开发者ID:Cthutu,项目名称:tojam,代码行数:8,代码来源:PixelCamera2DEditor.cs

示例3: Initialize

    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);
    }
开发者ID:JerethChampagne,项目名称:ArenaLegends,代码行数:17,代码来源:DistortionMobile.cs

示例4: Initialize

 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;
 }
开发者ID:naskew100,项目名称:Fired-Up,代码行数:19,代码来源:DistortionMobile.cs

示例5: OnRenderImage

        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
//.........这里部分代码省略.........
开发者ID:haejoon,项目名称:realdedicated-unitylibrary,代码行数:101,代码来源:HeightDepthOfField.cs

示例6: renderToTexture

        /// <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:
//.........这里部分代码省略.........
开发者ID:icedown,项目名称:VesselViewer,代码行数:101,代码来源:VesselViewer.cs

示例7: ReturnTexture

 private static void ReturnTexture(RenderTexture texture)
 {
     texture.DiscardContents();
     texturePool.Add(texture);
 }
开发者ID:mmandel,项目名称:8Nights2,代码行数:5,代码来源:RenderedFrame.cs

示例8: InitializeRT

    /// <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);
    }
开发者ID:SoulfulSolutions,项目名称:The_Last_Ranger,代码行数:25,代码来源:MDynamicRT.cs

示例9: DoDeinterlace

 private void DoDeinterlace(RenderTexture source, RenderTexture target)
 {
     target.DiscardContents();
     RenderTexture prev = RenderTexture.active;
     Graphics.Blit(source, target, _deinterlaceMaterial);
     RenderTexture.active = prev;
 }
开发者ID:vovo5558,项目名称:NewScopePlus,代码行数:7,代码来源:AVProLiveCameraFormatConverter.cs

示例10: Sample

 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);
 }
开发者ID:slb1988,项目名称:StrangeIoCLearning,代码行数:18,代码来源:FullScreenEffects.cs

示例11: DiscardContents

	public static void DiscardContents( RenderTexture rtex )
	{
	#if !( UNITY_WP8 || UNITY_WP8_1 || UNITY_WSA ) // why?..
		rtex.DiscardContents();
	#endif
	}
开发者ID:mirrorfishmedia,项目名称:GGJ2016,代码行数:6,代码来源:AmplifyMotionBase.cs

示例12: Update

    // 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
    }
开发者ID:OSW-team,项目名称:Project-4,代码行数:55,代码来源:ReflectionCamera.cs

示例13: RenderAmbientLight

        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();
        }
开发者ID:Elendow,项目名称:GGJ2016,代码行数:73,代码来源:LightingSystem.cs

示例14: OnRenderImage

        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);
        }
开发者ID:Elendow,项目名称:GGJ2016,代码行数:22,代码来源:LightingSystem.cs

示例15: FourTapCone

		// 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();
		}
开发者ID:mvokal,项目名称:IWScriptingTest,代码行数:7,代码来源:HighlightingBase.cs


注:本文中的UnityEngine.RenderTexture.DiscardContents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。