Graphics.DrawTexture ScreenRect isn't in screen space as documented.

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);

Resulting texture.

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.

The idea of a Render Texture is to be able to modify the texture and have it update in real-time. This functionality is for things like mini-maps, or split screen. If you are not intending to have this texture update in real-time I would consider simply using a Texture2D.

Otherwise:
What it seems you are wanting to do is create a material with the texture tiled on it. To do this you simply need to create a new material, drag the texture on to it in the editor and set the material’s tiling variables. This material can then be added to an object to give you the desired tiling texture.

Graphics.DrawTexture() is attempting to draw the passed in texture to the output window in screen space(0-1). I’m not sure why exactly your images are the same but I would suggest looking into defaults when code changes show no visual difference.

If it wasn’t evident by the three different subjects above; I will bluntly state that I have no idea what exactly you are wanting. For future reference, the best thing you can do is state exactly what you are wanting as an end result. Otherwise, you end up with an argument about screen space and no real answers.