Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by DaveA · Sep 02, 2011 at 11:39 PM · rendertextureclampaspect-ratiostereoscopic

How to get RenderTexture non-square?

I'm working on a stereo viewing system. I want to render a right and left camera to a right and left RenderTexture, then use 'main camera' to view those two textures side-by-side. That all works fine.

The problem I have is this: I want a final aspect ration of 4x3. Each 'eye' camera (right/left) should produce a 4x3 aspect ratio image. So the planes I render to have that aspect ratio. But the RT's themselves are 'square' (or whatever power of two), and render the left-most portion of each plane correctly, but only up to where width == height (a square). After that, the clamped texture just stretches ugly to make up the last quarter of the width of the image. If I set the texture to Tile, it does that, but what I really need is 'stretch' rather than 'tile'.

How can I do that?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Owen-Reynolds · Sep 03, 2011 at 05:15 PM

Stretch vs. tile is a function of the UV coords. If you take a normal plane, scale it however, the UV corners should still be set to exactly one texture. If somehow, your UV coords are set to 1.5 textures, your options are clamp or tile for the extra 0.5 -- stretch isn't possible. A hack is to set the UV matrix top line to, ummmm, all time 0.6666 (will cut the sideways coords by 2/3s so that 1.5 counts as 1.)

May be helpful, this is from using render textures in XNA, but how different can it be?:

The render texture should be as many pixels large as the "screen" you are drawing to. If you swap in a 600x600 renderTo texture for an 800x600 screen, the rightmost 200 pixels are just falling off. Easier than scaling the texture after it's created, is scaling down the screen as you render it. In the camera's projection matrix you can multiply the top row (x) by width/height (or vise-versa.) That tells the camera to shrink the width as it renders. the 800 pixels across it was going to write to, are now 600 pixels. I think ViewPort Rect (the answer above) is another way to set the Projection matrix.

I think you're going to have some aspect problems even if you solve the edge-clamp issue -- drawing a whole screen on half a screen (with a square texture) won't look right. I'm thinking the solution is to have a renderTo texture the size of half a screen, and then look up how to set the projection matrix to a tall, narrow area, the size of half a screen (this isn't Unity stuff -- plenty of places to look up "if aspect ratio is this, use these #s for projMat.")

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

Answer by sven1994 · Sep 03, 2011 at 09:47 AM

This does not really answer your question, but if i understood you right you could try a different approach. Instead of render textures you can just have two cameras with different viewport rects. Left camera: x=0 y=0 w=0.5 h=1. Right camera: x=0.5 y=0 w=0.5 h=1 for example.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get a camera to render to render texture at a custom aspect ratio. 1 Answer

Renderer Texture on GUITexture 1 Answer

How to keep Render Texture aspect ratio from perspective camera when window is resized? 1 Answer

Graphics.Blit scale 1 Answer

Canvas aspect ratio 1 Answer


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