• 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 Caithelin · Mar 29, 2014 at 08:05 AM · rendertextureout of bounds

Height of RenderTexture only 357 pixels

Hello Unity folks,

I'm trying to render a camera (reference stored in this.camera (GameObject)) to a RenderTexture (only in the Editor, so however, it works in my free version of Unity). The problem is, that renderTexture.height has the exact value of 1024 but texture.ReadPixels can only fetch a height of 357 pixels (LogError: Trying to read pixel out of bounds). I replaced the renderTexture.height for the Rect for the ReadPixels() call with some random value between 0 and 1025 and figured out, that the max height is 357. Below that cap all values work as expected. The other thing is, that I can fetch horizontal pixels without a limit (replacing renderTexture.width with 4096 for example) and theres no error.

Does anyone have the same problem or can you figure out what's going wrong here? I've tried to find the error the whole week but without any results.

Thank you for your answers.

Ps: Sorry for bad english.


Here's the relevant part of my code:

             int width = 1024;
             int height = width;
 
             RenderTexture renderTexture = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
 
             this.camera.camera.targetTexture = renderTexture;
             this.camera.camera.aspect = 1;
             this.camera.camera.Render();
 
             RenderTexture.active = renderTexture;
 
             Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false);
 
             texture.ReadPixels(new Rect(0.0f, 0.0f, renderTexture.width, renderTexture.height), 0, 0);
             texture.Apply();
 
             RenderTexture.active = null;
 
             return texture;
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 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 avatar image avatar image avatar image

Related Questions

How do you programmatically retrieve the rendering camera from its render texture? 2 Answers

what does Camera.targetTexture do? 1 Answer

Window Computer Lock causes a problem 1 Answer

Rendering screenshot using multiple cameras and one rendertexture 0 Answers

OnInspectorGUI Custom Drawing? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges