Seems simple enough: The goal is to draw a grid of tiles to a texture.
float cellSize = 32f;
RenderTexture renderTexture = new RenderTexture(512, 512, 0);
//RenderTexture.GetTemporary(width, height); //tried both, just in case.
RenderTexture.active = renderTexture;
//for each cell, blah blah
{
Rect r = new Rect(x * cellSize, y * cellSize, cellSize, cellSize);
Graphics.DrawTexture(r, tileTexture);
}
When I look at the resulting raw render texture in the editor, that code isn’t doing anything the documentation says. The documentation says it will draw in screen space, which, to my understanding is, (0,0) top left, with 1 unit = 1 pixel of texture space.
EDIT: That’s what it says screen space is, for this function, in the documentation, top left. Yes, I know generally things are bottom left. I wish they were consistent…
Instead, it covers the entire surface with seemingly one GIGANTIC version of my tiny tile image. In fact, it goes beyond the edges, as if it was rendering at above 100% width and height of the render texture. That isn’t right.
Alright, so I simplify it down to one cell. And take a guess maybe it’s texture space instead of screen space:
Rect r = new Rect(0f, 0f, 0.5f, 0.5f);
According to the wiki, that should start drawing at the top left, and attempt to draw a half pixel wide, half pixel tall tile (or essentially nothing). Nope. It draws it at the TOP RIGHT, half of the render texture’s width and height, kinda like texture space, as I was guessing. And… flipped/rotated? What?
Maybe the documentation is wrong, and it is not in screen space?
Rect r = new Rect(0f, 0f, 0.75f, 0.75f);
I kid you not, resulting texture.
THE SAME RESULT AS THE PREVIOUS TEST! Top right, half width, half height of the render texture.
In fact, no matter what size I enter, it will be half the render texture width/height. Now I have no clue what’s going on.
This simple problem is ruining my day. I have definitely been staring at this too long.