• 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
Question by CHPedersen · Sep 18, 2012 at 10:50 AM · rendertextureaspect ratiovectrosity

Vectrosity: SetCamera(), aspect, resolution and rendertextures

Hi all! (and Eric, perhaps, particularly? ;) )

I'm trying to draw some basic lines and points with Vectrosity. Its default settings work fine. One issue is that I need them drawn on top of GUI controls drawn using UnityGUI. These are always drawn last, with no way to change it, so to get around that, I'd like to render the Vectrosity lines into a RenderTexture, and then just display that in a call to GUI.DrawTexture.

My problem with this approach is that the rendertexture has a resolution and aspect ratio which are radically different from the screen's. I need the rendertexture's resolution to be 600x40, resulting in an aspect ratio of 600/40 = 15. The methods which set the camera with which Vectrosity renders its linemeshes do not pick up neither the aspect ratio nor the rendertarget of the camera I'm passing to it. I'm doing this:

 RenderTexture PowerLinesRT = new RenderTexture(600, 40, 0, RenderTextureFormat.ARGB32); // No depth buffer needed. Will only contain 2D lines
 PowerLinesRT.Create();
 camera.aspect = 600 / 40; // = 15
 camera.targetTexture = PowerLinesRT;
 VectorLine.SetCamera(camera); // Creates a camera for the vectorlines, but does not pick up the custom aspect ratio or the rendertarget
 
 // I expect these endpoints to define a horizontal line from one end of the rendertexture to the other, 10 pixels from the top
 Vector2 feedthroughStart = new Vector2(0, PowerLinesRT.height - 10);
 Vector2 feedthroughStop = new Vector2(PowerLinesRT.width-1, PowerLinesRT.height - 10);
 
 // PowerLineOffColor and PowerLineOff are colors and materials set in the editor, they work as expected
 FeedthroughLine = new VectorLine("Feedthrough", new Vector2[] { feedthroughStart, feedthroughStop }, PowerLineOffColor, PowerLineOff, 20);
 FeedthroughLine.Draw();

I tried to further customize the camera by picking up the reference returned by SetCamera, i.e. I can do this:

 Camera vectrosityCam = VectorLine.SetCamera(camera); // Creates a camera for the vectorlines, but does not pick up the custom aspect ratio or the rendertarget
 vectrosityCam.aspect = 600 / 40; // = 15
 vectrosityCam.targetTexture = PowerLinesRT; // Manually set the vectrosity camera's rendertarget instead

This gives the vectrosity camera the desired aspect ratio and rendertarget. But it does not pick up the rendertexture's resolution. The coordinates given to VectorLine's constructor afterwards still look like they generate a mesh relative to the Screen's resolution, and not the rendertexture's. This is a problem. I'd really like to be able to give it coordinates relative to the rendertexture's resolution. Is there a way to make it understand that? Or am I doing something really silly here?

Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Eric5h5 · Sep 18, 2012 at 10:04 PM

The bad news is, it's not quite that simple. The good news is, it so happens that Vectrosity 2.1 has a SetCameraRendertexture function, which makes the vector camera use a rendertexture, like this:

 VectorLine.SetCameraRendertexture (myRenderTexture);

Then you can use

 VectorLine.SetCameraRendertexture (null);

to make it stop rendering to a rendertexture. The other bad news is, Vectrosity 2.1 isn't out yet. The other good news is, it will be out Real Soon Now (after I update the docs).

Comment
CHPedersen

People who like this

1 Show 2 · 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 CHPedersen · Sep 19, 2012 at 07:55 AM 0
Share

Hey Eric,

Thanks for getting back to me. In a way I'm relieved it wasn't quite that simple. I was worried I was doing something silly and not understanding how to use it correctly. :)

The feature you describe for 2.1 looks really neat! I'm looking forward to the update. I spent some time yesterday messing around with 2.0 and eventually settled on a hacky solution I'll use temporarily until you release Vectrosity 2.1. I'll simply transform the coordinates given to the VectorLine constructor from the screen's coordinate system to the rendertexture's by adding or subtracting some multiple of the ratio between their respective aspect ratios. (The "aspect ratio-ratio", as it were. Confusing, much?) Then pass those coordinates to VectorLine instead. That is, to put a point at x = 0 in the RT, I'm actually giving it a negative x coordinate that makes it move the point way off-screen, to a place where the wide rendertexture's left side ends up. It works ok, it just makes the code look a little unintuitive.

avatar image Eric5h5 · Sep 21, 2012 at 04:49 AM 0
Share

...And Vectrosity 2.1 is out.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Depth of Field and Render Textures 1 Answer

Need Help Getting RenderTexture & Graphics.Blit Working: Boosting Mobile Performance 0 Answers

Reading RenderTexture with glReadPixels has weird alpha blending 0 Answers

What does "RenderTexture: Resolving NULL surfaces." means? How to solve it. 0 Answers

Steam VR Render object to only one eye 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