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
1
Question by RoopeKT · Jul 08, 2020 at 05:31 PM · render texturerescale

How to manually resize render texture without recreating it?

I want to resize my render texture every frame, so always recreating it isn't great idea. I'm trying to create portals, and don't want them to render in full resolution, when I'm far from them.

I tried to first enable dynamic scaling, and then just change RenderTexture.width (and height), but I'm still getting errors like: "Setting width of already created render texture is not supported!".

I know about ScalableBufferManager, but I don't see way to manually resize render texture with it.

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 Namey5 · Jul 09, 2020 at 05:52 AM 0
Share

For dynamic resolution, internally Unity doesn't actually change the resolution of the render target each frame. Ins$$anonymous$$d, the render target remains at full resolution the entire time, but only small portions of it are actually rendered to. I haven't worked with dynamic resolution myself, but unfortunately it looks like you have to scale all RTs by the same factor globally (you can't resize on a per-RT basis).

avatar image RoopeKT · Jul 09, 2020 at 07:49 AM 0
Share

I guess I could use ScalableBuffer$$anonymous$$anager by not marking render textures as dynamically scalable by default, and by enabling it for one at a time, but it would be dirty. I'm wondering what ScalableBuffer$$anonymous$$anager actually does, and if could do it myself.

avatar image Namey5 RoopeKT · Jul 09, 2020 at 11:49 PM 0
Share

$$anonymous$$y guess is that it would be something similar to SetViewport;

https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.SetViewport.html

By setting a viewport, rendering only happens within the provided Rect. If you wanted to do this with a camera, you could set its rect or pixelRect;

https://docs.unity3d.com/ScriptReference/Camera-rect.html
https://docs.unity3d.com/ScriptReference/Camera-pixelRect.html

avatar image RoopeKT Namey5 · Jul 10, 2020 at 08:02 PM 0
Share

I haven't used command buffers, and can't get them to work, and camera's view port rectangle doesn't work with render textures. I'm probably going to end up using ScalableBuffer$$anonymous$$anager.

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Quelfth · Oct 28, 2020 at 05:29 PM

I believe that dynamic scaling works automatically. You don't need to change the size, because with dynamic scaling enabled, Unity should automatically resize the render texture if your frame rate drops. Or, if you want to control the scale manually, you can use ScalableBufferManager.ResizeBuffers(width, height) to set the scale of all render textures with the dynamically scalable flag set.

However, it seems to me that this only allows you to change the scales of all render textures simultaneously, and if you have multiple portals, it would seem inappropriate to scale all of them at the same time.

I don't believe that it is possible to change the scale of a render texture dynamically, but I'm not sure that creating render textures every frame is as expensive as you think it is. Additionally, you don't actually need to create them every frame, since you only need to create a new one when the size you want it to be is different from the size it is.

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
3

Answer by Mandoz · Oct 28, 2020 at 07:11 AM

I'm not sure whether is a right way. Anyway it woked for me.

rtex.Release(); rtex.width = 1024; rtex.height = 720; rtex.Create();

Comment
Add comment · Show 1 · 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 RoopeKT · Oct 28, 2020 at 02:56 PM 0
Share

Thanks, but this does recreate the texture (rtex.Create()), which makes it way to slow for optimization.

avatar image
0

Answer by studentutu · Jun 04, 2021 at 08:12 AM

@Mandoz @RoopeKT Just resize the actual render texture width/height = it will not allocate any more than it needs and will preserve all the references. See the Manual. It says - it is not like Texture - width/height are mutable properties! And also, you don't need to manually call .Create() if you already have a render texture created (either before or inside Unity Editor); it is best to create 1 texture ahead of time and set your target properties inside the editor. You will be able to see/preview everything

Comment
Add comment · Show 1 · 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 RoopeKT · Jun 04, 2021 at 03:19 PM 0
Share

Trying to change width/height after the render texture has been created with .Create() will cause an error: "Setting width of already created render texture is not supported!". Render texture must be created before used, and I was looking for a way to resize a texture already in use.

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

133 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 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 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 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 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 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 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

Perspective Correction with Render Texture 0 Answers

Making Portal-Like Objects 2 Answers

UV Mapping - FBX meshes wont accept textures 0 Answers

RenderTexture.Create failed RenderTexture.GenerateMips failed 1 Answer

Android/IOS GUI Rescale 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