- Home /
Rendering with GL.Begin to a RenderTexture does not update it continuously (2019.2)
So I am trying to render a trianglestrip to a rendertexture. For this I created a small script that takes a bunch of transforms and a rendertexture and draws a trianglestrip that connects the transforms. For simplicity, I assume the transforms are already in UVspace and use an identity matrix.
public class GLRenderTextureTest : MonoBehaviour {
public List<Transform> targets;
public RenderTexture rt;
private Material UVMaterial;
void Start() {
UVMaterial = new Material(Shader.Find("Unlit/TestShader"));
}
void Update() {
RenderTexture.active = rt;
UVMaterial.SetPass(0);
GL.PushMatrix();
GL.LoadIdentity();
GL.Begin(GL.TRIANGLE_STRIP);
for (int i = 0; i < targets.Count; i++) {
GL.Vertex3(targets[i].position.x, targets[i].position.z, 0);
}
GL.End();
GL.PopMatrix();
RenderTexture.active = null;
}
}
And this is what it looks like in the scene:
But if I then go and move one of the transforms, the rendertexture does not update!
I feel like this should be working. I've already exhausted all solutions the google search results provided, to no avail. So here I am, stuck with a simple task, not knowing how to fix this.
To reproduce:
Create a new 3D project.
Create a new RenderTexture RT, no depth buffer, size 1024x1024
Create a new Material M
Add RenderTexture RT to Material M
Create a new Unlit Shader and name it TestShader
Add a quad to the scene, rotate by 90° x, scale 2, pos in zero
Add Material M to Quad
Add 8 (or any x >=3) spheres to the scene, scale 0,05f, place them inside the quad area
Add a new script called GLRenderTextureTest, copy code from above
Add spheres and rendertexture to the script in inspector
save scene
hit play and move any sphere