Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DrZoop · Nov 01, 2013 at 11:38 PM · rendertexturerender texturedrawtexturegraphics.drawtexture

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.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Nov 01, 2013 at 11:43 PM 0
Share

draw in screen space, which, to my understanding is, (0,0) top left

Screen space starts at (0,0) in the bottom left. GUI space starts at (0,0) in the top left. Doesn't solve your issue.

avatar image DrZoop · Nov 01, 2013 at 11:48 PM 0
Share

Documentation calls it screenRect, but then says top left: http://docs.unity3d.com/Documentation/ScriptReference/Graphics.DrawTexture.html . I was just using their terms. Yes, I know generally things are bottom left. Thanks for the clarification though, as I am sure that'd confuse others who are reading.

avatar image DrZoop · Nov 04, 2013 at 07:29 PM 0
Share

So, I have deduced that it will do it correctly some frames, and other frames do it incorrectly. Particularly the first frame it will always be incorrect, but after that most frames will be correct. Any ideas?

avatar image DrZoop · Nov 06, 2013 at 02:55 AM 0
Share

It is LITERALLY screen space. Not texture space. You must scale all desired drawing coordinates as if they were rendered onto the screen. Very... strange... I imagine there is some way to change the matrix used (I tried GL. functions, no luck), to put it into texture space, but I ins$$anonymous$$d simply calculated the conversion from screen space to texture space by hand. In this one application, I am okay with this solution, but I'd prefer an "official" answer to this question some day.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by standingguy · Mar 17, 2014 at 08:36 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Save RenderTarget (Color Format: Depth) into a png as a heightmap 0 Answers

What Can we do if device doesnot support render Textures 0 Answers

Graphics.DrawTexture with multiple camera on mobile device not working 0 Answers

In Unity 2D how can I make a shader aware of the Z coordinate (depth) of the object it is about to draw over? 1 Answer

Binding EGLImage to RenderTexture (or setting NativeTexturePtr) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges