MarkRestoreExpected() public method

Indicate that there's a RenderTexture restore operation expected.

public MarkRestoreExpected ( ) : void
return void
示例#1
0
文件: Paint.cs 项目: DeanLu/SnowBall
    void PaintTexture(RenderTexture _canvas, Material _brush, float _size, float _posX, float _posY)
    {
        Debug.Log (string.Format("_size = {0}, _posX = {1}, _posY = {2}",_size,_posX,_posY));

        float halfSize = _size / 2F;

        _canvas.MarkRestoreExpected ();
        Graphics.SetRenderTarget(_canvas);

        GL.PushMatrix();

        _brush.SetPass (0);

        GL.LoadOrtho();

        GL.Begin(GL.QUADS);

        GL.TexCoord(new Vector3(0, 0, 0));
        GL.Vertex3(_posX - halfSize, _posY - halfSize, 0);

        GL.TexCoord(new Vector3(0, 1, 0));
        GL.Vertex3(_posX - halfSize, _posY + halfSize, 0);

        GL.TexCoord(new Vector3(1, 1, 0));
        GL.Vertex3(_posX + halfSize, _posY + halfSize, 0);

        GL.TexCoord(new Vector3(1, 0, 0));
        GL.Vertex3(_posX + halfSize, _posY - halfSize, 0);

        GL.End();

        GL.PopMatrix();

        Graphics.SetRenderTarget(null);
    }
示例#2
0
文件: Paint.cs 项目: DeanLu/SnowBall
    void Clear(RenderTexture _canvas, Material _brush)
    {
        _canvas.MarkRestoreExpected ();
        Graphics.SetRenderTarget(_canvas);

        GL.Clear(false, true, Color.clear);

        Graphics.SetRenderTarget(null);
    }
示例#3
0
 static public int MarkRestoreExpected(IntPtr l)
 {
     try {
         UnityEngine.RenderTexture self = (UnityEngine.RenderTexture)checkSelf(l);
         self.MarkRestoreExpected();
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int MarkRestoreExpected(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.RenderTexture obj = (UnityEngine.RenderTexture)ToLua.CheckObject <UnityEngine.RenderTexture>(L, 1);
         obj.MarkRestoreExpected();
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
	static int MarkRestoreExpected(IntPtr L)
	{
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("UnityEngine.RenderTexture.MarkRestoreExpected");
#endif
		try
		{
			ToLua.CheckArgsCount(L, 1);
			UnityEngine.RenderTexture obj = (UnityEngine.RenderTexture)ToLua.CheckObject<UnityEngine.RenderTexture>(L, 1);
			obj.MarkRestoreExpected();
			return 0;
		}
		catch (Exception e)
		{
			return LuaDLL.toluaL_exception(L, e);
		}
	}
        private void WriteCoc ( RenderTexture fromTo, bool fgDilate) {
            dofHdrMaterial.SetTexture("_FgOverlap", null);

            if (nearBlur && fgDilate) {

                int rtW = fromTo.width/2;
                int rtH = fromTo.height/2;

                // capture fg coc
                RenderTexture temp2 = RenderTexture.GetTemporary (rtW, rtH, 0, fromTo.format);
                Graphics.Blit (fromTo, temp2, dofHdrMaterial, 4);

                // special blur
                float fgAdjustment = internalBlurWidth * foregroundOverlap;

                dofHdrMaterial.SetVector ("_Offsets", new Vector4 (0.0f, fgAdjustment , 0.0f, fgAdjustment));
                RenderTexture temp1 = RenderTexture.GetTemporary (rtW, rtH, 0, fromTo.format);
                Graphics.Blit (temp2, temp1, dofHdrMaterial, 2);
                RenderTexture.ReleaseTemporary(temp2);

                dofHdrMaterial.SetVector ("_Offsets", new Vector4 (fgAdjustment, 0.0f, 0.0f, fgAdjustment));
                temp2 = RenderTexture.GetTemporary (rtW, rtH, 0, fromTo.format);
                Graphics.Blit (temp1, temp2, dofHdrMaterial, 2);
                RenderTexture.ReleaseTemporary(temp1);

                // "merge up" with background COC
                dofHdrMaterial.SetTexture("_FgOverlap", temp2);
                fromTo.MarkRestoreExpected(); // only touching alpha channel, RT restore expected
                Graphics.Blit (fromTo, fromTo, dofHdrMaterial,  13);
                RenderTexture.ReleaseTemporary(temp2);
            }
            else {
                // capture full coc in alpha channel (fromTo is not read, but bound to detect screen flip)
				fromTo.MarkRestoreExpected(); // only touching alpha channel, RT restore expected
                Graphics.Blit (fromTo, fromTo, dofHdrMaterial,  0);
            }
        }
示例#7
0
	private void Vignette (float amount, RenderTexture from, RenderTexture to)
	{
		if (lensFlareVignetteMask)
		{
			screenBlend.SetTexture ("_ColorBuffer", lensFlareVignetteMask);
			to.MarkRestoreExpected(); // using blending, RT restore expected
			Graphics.Blit (from == to ? null : from, to, screenBlend, from == to ? 7 : 3);
		}
		else if (from != to)
		{
			Graphics.SetRenderTarget (to);
			GL.Clear(false, true, Color.black); // clear destination to avoid RT restore
			Graphics.Blit (from, to);
		}
	}
示例#8
0
	private void BlendFlares (RenderTexture from, RenderTexture to)
	{
		lensFlareMaterial.SetVector ("colorA", new Vector4 (flareColorA.r, flareColorA.g, flareColorA.b, flareColorA.a) * lensflareIntensity);
		lensFlareMaterial.SetVector ("colorB", new Vector4 (flareColorB.r, flareColorB.g, flareColorB.b, flareColorB.a) * lensflareIntensity);
		lensFlareMaterial.SetVector ("colorC", new Vector4 (flareColorC.r, flareColorC.g, flareColorC.b, flareColorC.a) * lensflareIntensity);
		lensFlareMaterial.SetVector ("colorD", new Vector4 (flareColorD.r, flareColorD.g, flareColorD.b, flareColorD.a) * lensflareIntensity);
		to.MarkRestoreExpected(); // additive blending, RT restore expected
		Graphics.Blit (from, to, lensFlareMaterial);
	}
示例#9
0
	private void AddTo (float intensity_, RenderTexture from, RenderTexture to)
	{
		screenBlend.SetFloat ("_Intensity", intensity_);
		to.MarkRestoreExpected(); // additive blending, RT restore expected
		Graphics.Blit (from, to, screenBlend, 9);
	}
示例#10
0
		/// <summary>
		/// Render highlighting to the highlightingBuffer using frameBuffer.depthBuffer.
		/// </summary>
		/// <param name="frameBuffer">Frame buffer RenderTexture, depthBuffer of which will be used to occlude highlighting.</param>
		public void RenderHighlighting(RenderTexture frameBuffer)
		{
			// Release highlightingBuffer if it wasn't released already
			if (highlightingBuffer != null)
			{
				RenderTexture.ReleaseTemporary(highlightingBuffer);
				highlightingBuffer = null;
			}

			if (!isSupported || !enabled || !go.activeInHierarchy) { return; }

			int aa = QualitySettings.antiAliasing;
			if (aa == 0) { aa = 1; }

			bool depthAvailable = true;
			// Check if frameBuffer.depthBuffer is not available, contains garbage (when MSAA is enabled) or doesn't have stencil bits (when depth is 16 or 0)
			if (frameBuffer == null || frameBuffer.depth < 24) { depthAvailable = false; }

			// Reset aa value to 1 in case mainCam is in DeferredLighting Rendering Path
			if (refCam.actualRenderingPath == RenderingPath.DeferredLighting) { aa = 1; }
			// In case MSAA is enabled in forward/vertex lit rendeirng paths - depth buffer contains garbage
			else if (aa > 1) { depthAvailable = false; }

			// Check if framebuffer depth data availability has changed
			if (isDepthAvailable != depthAvailable)
			{
				isDepthAvailable = depthAvailable;
				// Update ZWrite value for all highlighting shaders correspondingly (isDepthAvailable ? ZWrite Off : ZWrite On)
				Highlighter.SetZWrite(isDepthAvailable ? 0f : 1f);
				if (isDepthAvailable)
				{
					Debug.LogWarning("HighlightingSystem : Framebuffer depth data is available back again and will be used to occlude highlighting. Highlighting occluders disabled.");
				}
				else
				{
					Debug.LogWarning("HighlightingSystem : Framebuffer depth data is not available and can't be used to occlude highlighting. Highlighting occluders enabled.");
				}
			}

			// Set global depth offset properties for highlighting shaders to the values which has this HighlightingBase component
			Highlighter.SetOffsetFactor(offsetFactor);
			Highlighter.SetOffsetUnits(offsetUnits);

			// Set this component as currently active HighlightingBase before enabling Highlighters
			current = this;

			// Turn on highlighting shaders on all highlighter components
			int count = 0;
			for (int i = 0; i < highlighters.Count; i++)
			{
				if (highlighters[i].Highlight()) { count++; }
			}

			// Do nothing in case no Highlighters is currently visible
			if (count == 0)
			{
				current = null;
				return;
			}

			// If frameBuffer.depthBuffer is not available
			int w = Screen.width;
			int h = Screen.height;
			int depth = 24;			// because stencil will be rendered to the highlightingBuffer.depthBuffer

			// If frameBuffer.depthBuffer is available
			if (isDepthAvailable)
			{
				w = frameBuffer.width;
				h = frameBuffer.height;
				depth = 0;			// because stencil will be rendered to frameBuffer.depthBuffer
			}

			// Setup highlightingBuffer RenderTexture
			highlightingBuffer = RenderTexture.GetTemporary(w, h, depth, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, aa);
			if (!highlightingBuffer.IsCreated())
			{
				highlightingBuffer.filterMode = FilterMode.Point;
				highlightingBuffer.useMipMap = false;
				highlightingBuffer.wrapMode = TextureWrapMode.Clamp;
			}

			// Clear highlightingBuffer colorBuffer and clear depthBuffer only in case frameBuffer depth data is not available
			RenderTexture.active = highlightingBuffer;
			GL.Clear((isDepthAvailable ? false : true), true, Color.clear);

			// Use depth data from frameBuffer in case it is available. Use highlightingBuffer.depthBuffer otherwise
			RenderBuffer depthBuffer = isDepthAvailable ? frameBuffer.depthBuffer : highlightingBuffer.depthBuffer;
			
			if (!shaderCameraGO)
			{
				shaderCameraGO = new GameObject("HighlightingCamera");
				shaderCameraGO.hideFlags = HideFlags.HideAndDontSave;
				shaderCamera = shaderCameraGO.AddComponent<Camera>();
				shaderCamera.enabled = false;
			}
			
			shaderCamera.CopyFrom(refCam);
			//shaderCamera.projectionMatrix = mainCam.projectionMatrix;		// Uncomment this line if you have problems using Highlighting System with custom projection matrix on your camera
			shaderCamera.cullingMask = layerMask;
			shaderCamera.rect = new Rect(0f, 0f, 1f, 1f);
			shaderCamera.renderingPath = RenderingPath.Forward;
			shaderCamera.depthTextureMode = DepthTextureMode.None;
			shaderCamera.hdr = false;
			shaderCamera.useOcclusionCulling = false;
			shaderCamera.backgroundColor = new Color(0, 0, 0, 0);
			shaderCamera.clearFlags = CameraClearFlags.Nothing;
			shaderCamera.SetTargetBuffers(highlightingBuffer.colorBuffer, depthBuffer);

			// Get rid of "Tiled GPU Perf warning" if we're not in debug mode
			#if !DEBUG_ENABLED
			frameBuffer.MarkRestoreExpected();
			#endif
			shaderCamera.Render();

			// Extinguish all highlighters
			for (int i = 0; i < highlighters.Count; i++)
			{
				highlighters[i].Extinguish();
			}

			// Highlighting buffer rendering finished. Reset currently active HighlightingBase
			current = null;

			// Create two buffers for blurring the image
			int width = highlightingBuffer.width / _downsampleFactor;
			int height = highlightingBuffer.height / _downsampleFactor;
			RenderTexture buffer = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1);
			RenderTexture buffer2 = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1);
			if (!buffer.IsCreated())
			{
				buffer.useMipMap = false;
				buffer.wrapMode = TextureWrapMode.Clamp;
			}
			if (!buffer2.IsCreated())
			{
				buffer2.useMipMap = false;
				buffer2.wrapMode = TextureWrapMode.Clamp;
			}
			
			// Copy highlighting buffer to the smaller texture
			Graphics.Blit(highlightingBuffer, buffer, blitMaterial);
			
			// Blur the small texture
			bool oddEven = true;
			for (int i = 0; i < iterations; i++)
			{
				if (oddEven) { FourTapCone(buffer, buffer2, i); }
				else { FourTapCone(buffer2, buffer, i); }
				oddEven = !oddEven;
			}
			
			// Upscale blurred texture and cut stencil from it
			Graphics.SetRenderTarget(highlightingBuffer.colorBuffer, depthBuffer);
			cutMaterial.SetTexture(ShaderPropertyID._MainTex, oddEven ? buffer : buffer2);
			DoubleBlit(cutMaterial, 0, cutMaterial, 1);

			// Cleanup
			RenderTexture.ReleaseTemporary(buffer);
			RenderTexture.ReleaseTemporary(buffer2);
		}
示例#11
0
 private void WriteCoc(RenderTexture fromTo, bool fgDilate)
 {
     this.dofHdrMaterial.SetTexture("_FgOverlap", null);
     if (this.nearBlur && fgDilate)
     {
         int width = fromTo.width / 2;
         int height = fromTo.height / 2;
         RenderTexture temporary = RenderTexture.GetTemporary(width, height, 0, fromTo.format);
         Graphics.Blit(fromTo, temporary, this.dofHdrMaterial, 4);
         float num = this.internalBlurWidth * this.foregroundOverlap;
         this.dofHdrMaterial.SetVector("_Offsets", new Vector4(0f, num, 0f, num));
         RenderTexture temporary2 = RenderTexture.GetTemporary(width, height, 0, fromTo.format);
         Graphics.Blit(temporary, temporary2, this.dofHdrMaterial, 2);
         RenderTexture.ReleaseTemporary(temporary);
         this.dofHdrMaterial.SetVector("_Offsets", new Vector4(num, 0f, 0f, num));
         temporary = RenderTexture.GetTemporary(width, height, 0, fromTo.format);
         Graphics.Blit(temporary2, temporary, this.dofHdrMaterial, 2);
         RenderTexture.ReleaseTemporary(temporary2);
         this.dofHdrMaterial.SetTexture("_FgOverlap", temporary);
         fromTo.MarkRestoreExpected();
         Graphics.Blit(fromTo, fromTo, this.dofHdrMaterial, 13);
         RenderTexture.ReleaseTemporary(temporary);
     }
     else
     {
         fromTo.MarkRestoreExpected();
         Graphics.Blit(fromTo, fromTo, this.dofHdrMaterial, 0);
     }
 }
示例#12
0
	private void CreateHelperTextures()
	{
		const int size = 32;
		const int maxSize = size - 1;
		int width = size * size;
		int height = size;

		ReleaseTextures();

		blendCacheLut = new RenderTexture( width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear ) { hideFlags = HideFlags.HideAndDontSave };
		blendCacheLut.name = "BlendCacheLut";
		blendCacheLut.wrapMode = TextureWrapMode.Clamp;
		blendCacheLut.useMipMap = false;
		blendCacheLut.anisoLevel = 0;
		blendCacheLut.Create();

		midBlendLUT = new RenderTexture( width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear ) { hideFlags = HideFlags.HideAndDontSave };
		midBlendLUT.name = "MidBlendLut";
		midBlendLUT.wrapMode = TextureWrapMode.Clamp;
		midBlendLUT.useMipMap = false;
		midBlendLUT.anisoLevel = 0;
		midBlendLUT.Create();
	#if UNITY_4
		midBlendLUT.MarkRestoreExpected();
	#endif

		normalLut = new Texture2D( width, height, TextureFormat.RGB24, false, true ) { hideFlags = HideFlags.HideAndDontSave };
		normalLut.name = "NormalLut";
		normalLut.hideFlags = HideFlags.DontSave;
		normalLut.anisoLevel = 1;
		normalLut.filterMode = FilterMode.Bilinear;
		Color32[] colors = new Color32[ width * height ];
		for ( int z = 0; z < size; z++ )
		{
			int zoffset = z * size;
			for ( int y = 0; y < size; y++ )
			{
				int yoffset = zoffset + y * width;
				for ( int x = 0; x < size; x++ )
				{
					float fr = x / ( float ) maxSize;
					float fg = y / ( float ) maxSize;
					float fb = z / ( float ) maxSize;
					byte br = ( byte ) ( fr * 255 );
					byte bg = ( byte ) ( fg * 255 );
					byte bb = ( byte ) ( fb * 255 );
					colors[ yoffset + x ] = new Color32( br, bg, bb, 255 );
				}
			}
		}
		normalLut.SetPixels32( colors );
		normalLut.Apply();
	}
	private void CreateHelperTextures()
	{
		ReleaseTextures();

		blendCacheLut = new RenderTexture( LutWidth, LutHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear ) { hideFlags = HideFlags.HideAndDontSave };
		blendCacheLut.name = "BlendCacheLut";
		blendCacheLut.wrapMode = TextureWrapMode.Clamp;
		blendCacheLut.useMipMap = false;
		blendCacheLut.anisoLevel = 0;
		blendCacheLut.Create();

		midBlendLUT = new RenderTexture( LutWidth, LutHeight, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear ) { hideFlags = HideFlags.HideAndDontSave };
		midBlendLUT.name = "MidBlendLut";
		midBlendLUT.wrapMode = TextureWrapMode.Clamp;
		midBlendLUT.useMipMap = false;
		midBlendLUT.anisoLevel = 0;
		midBlendLUT.Create();
	#if UNITY_4
		midBlendLUT.MarkRestoreExpected();
	#endif

		CreateDefaultLut();
	}
示例#14
0
    void UpdateRTT()
    {
        RenderCam = gameObject.GetComponent<Camera> ();
        Buffer = new RenderTexture (horizontalResolution, verticalResolution, 16);
        Buffer.generateMips = false;
        Buffer.filterMode = FilterMode.Point;
        //Buffer.antiAliasing = BufferAA;
        Buffer.name = "Pixel Buffer!";
        RenderCam.targetTexture = Buffer;
        if (BufferAA > 1) {
            AABuffer = new RenderTexture(Mathf.CeilToInt(horizontalResolution*AAMulti),Mathf.CeilToInt(verticalResolution*AAMulti),16);

            AABuffer.filterMode = FilterMode.Bilinear;
            AABuffer.generateMips = false;
            AABuffer.antiAliasing = 1;// BufferAA;

            Buffer.name = "AA Pixel Buffer!";
            RenderCam.targetTexture = AABuffer;
            Buffer.MarkRestoreExpected ();

        }
        if (pixelScale == 5)
            OutlinePixelScaling = 2f;
        if (pixelScale == 4)
            OutlinePixelScaling = 1.666f;
        if (pixelScale == 3)
            OutlinePixelScaling = 1.25f;
        if (pixelScale == 2)
            OutlinePixelScaling = .9f;
        if (pixelScale == 1)
            OutlinePixelScaling = .5f;
        if (Application.platform == RuntimePlatform.OSXWebPlayer || Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.WebGLPlayer) {
            OutlinePixelScaling *= -.05f;
        }
        //OutlinePixelScaling *= 1.5f;
        if (!enableOutlines)
            OutlinePixelScaling = 0;
        if(BufferAA == 1)
            OutlinePixelScaling *= 1.1f;
        Shader.SetGlobalFloat("_DitherScale", 24f/2*(768f/Screen.height)*pixelScale  );
        if (!isOrthographic) {
            Shader.SetGlobalFloat ("_OutlineWidth", (shaderOutlineWidth / 2f) * (768f / Screen.height));
        }
        if(isOrthographic)
        {

            Shader.SetGlobalFloat ("_OutlineWidth", (shaderOutlineWidth / 2f)* (768f/Screen.height) * (Camera.main.orthographicSize/90)*OutlinePixelScaling );
            Shader.SetGlobalVector("_DitherScale", new Vector4(Screen.width/256f/pixelScale, Screen.height/256f/pixelScale,0,0) );
            //Debug.Log (Screen.width/256f);
        }
        #if UNITY_EDITOR
        if(!Application.isPlaying && isOrthographic)
            Shader.SetGlobalFloat ("_OutlineWidth", (shaderOutlineWidth * 2f )* (768f/Screen.height));
        #endif

        if(BufferMat)
            BufferMat.mainTexture = Buffer;
        OldAA = BufferAA;
        OldSize = new Vector2 (horizontalResolution,verticalResolution);
        OldOutlines = enableOutlines;
    }