Created
April 24, 2019 08:59
-
-
Save unitycoder/c96da82bc31d6780ca238a70ae89e862 to your computer and use it in GitHub Desktop.
Render To Texture Without Camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://forum.unity.com/threads/render-to-texture-without-a-camera.235053/#post-4464151 | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class RenderToTextureWithoutCamera : MonoBehaviour | |
{ | |
public Material material; | |
public RenderTexture rt; | |
public int Pass = 0; | |
void Blit(RenderTexture destination, Material mat, int pass) | |
{ | |
RenderTexture.active = destination; | |
GL.PushMatrix(); | |
GL.LoadOrtho(); | |
GL.invertCulling = true; | |
mat.SetPass(pass); | |
GL.Begin(GL.QUADS); | |
GL.MultiTexCoord2(0, 0.0f, 0.0f); | |
GL.Vertex3(0.0f, 0.0f, 0.0f); | |
GL.MultiTexCoord2(0, 1.0f, 0.0f); | |
GL.Vertex3(1.0f, 0.0f, 0.0f); | |
GL.MultiTexCoord2(0, 1.0f, 1.0f); | |
GL.Vertex3(1.0f, 1.0f, 0.0f); | |
GL.MultiTexCoord2(0, 0.0f, 1.0f); | |
GL.Vertex3(0.0f, 1.0f, 0.0f); | |
GL.End(); | |
GL.invertCulling = false; | |
GL.PopMatrix(); | |
} | |
void Start() | |
{ | |
Pass = material.passCount - 1; | |
} | |
void Update() | |
{ | |
Blit(rt, material,Pass); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment