- Home /
Question by
bkogawi · Jul 22, 2019 at 09:39 AM ·
cameratexturerendertexturerender
Capture RenderTexture pixels multiple times in one frame?
I have a script that moves a camera around many times in one frame. I need to capture 1x1 pixel color of the camera each time I move it to another predetermined point.
I am currently using a rendertexture and assumed I could pull out a single pixel from there to get what I wanted, but it seems to output the same color over and over even when the camera is looking elsewhere (dark grey).
Here is roughly what I am attempting; where have I gone wrong? Thanks!;
public RenderTexture vertexColorOutput;
public Camera vertexCamera;
[...]
public void THEFUNCTION()
{
Texture2D output;
for (int i = 0; i < NUMBER; i++)
{
output = new Texture2D(1, 1);
vertexCamera.transform.position = positions[i];
vertexCamera.transform.rotation = rotations[i];
RenderTexture.active = vertexColorOutput;
vertexCamera.Render();
output.ReadPixels(new Rect(0, 0, 1, 1), 0, 0);
output.Apply();
newColors[i] = output.GetPixel(0, 0);
}
___________ = newColors; //Why are newColors all "33 33 33 255"?
}
Comment
Have you made sure to assign the target texture on the camera?
Best Answer
Answer by bkogawi · Jul 23, 2019 at 06:16 PM
Assigning texture based on the following page's example code seemed to fix the problem.