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 FatWednesday · Dec 06, 2012 at 06:50 PM · screenrendertexturefullscreenquad

RenderTextures and FullScreen Quads

Hey all,

Trying to write a small script that when attached to a camera will allow me to control the size of the rendered screen (so that I can render to a smaller texture, then scale that up to the screen size for performance).

EDIT: The new code bellow currently renders the camera, and uses the OnRenderImage() to draw it to a fullscreen quad (through to another render texture). Both output image files display expected results, the scene as it should be, and an inverted colour version.

 using UnityEngine;
 using System.Collections;
 
 public class RenderBufferControl : BaseObject
 {
     private Material mat;
     private RenderTexture rTex;
     private Camera _cam;
 
     protected override void CustomAwake () 
     {
         _cam = GetComponent<Camera>();
 
         mat = new Material (
             "Shader \"Hidden/Invert\" {" +
             "SubShader {" +
             "    Pass {" +
             "        ZTest Always Cull Off ZWrite Off" +
             "        SetTexture [_RenderTex] { combine one-texture }" +
             "    }" +
             "}" +
             "}"
         );
 
         rTex = new RenderTexture(1024, 1024, 24);
 
         _cam.targetTexture = rTex;
     }
 
     void OnRenderImage (RenderTexture source, RenderTexture dest) 
     {
         RenderTexture.active = dest;
         source.SetGlobalShaderProperty ("_RenderTex");
 
         DrawFullScreenQuad(mat);
 
         // Output source and destination to images to confirm their contents.
         Util.SaveImage(source, "Source.png");
         Util.SaveImage(dest, "Dest.png");
     }
 
     public static void DrawFullScreenQuad(Material material)
     {
         GL.PushMatrix();
         GL.LoadOrtho();
         
         int i = 0;
         while (i < material.passCount)
         {
             material.SetPass(i);
             GL.Begin(GL.QUADS);
             GL.Color(Color.white);
             GL.TexCoord2(0, 0);
             GL.Vertex3(0, 0, 0.1f);
 
             GL.TexCoord2(1, 0);
             GL.Vertex3(1, 0, 0.1f);
 
             GL.TexCoord2(1, 1);
             GL.Vertex3(1, 1, 0.1f);
 
             GL.TexCoord2(0, 1);
             GL.Vertex3(0, 1, 0.1f);
             GL.End();
             ++i;
         }
 
         GL.PopMatrix();
     }
 }


The only issue now is that I need to be drawing the fullscreen quad to the actual screen, not just to another render texture. I'm not entirely sure how to do this, could anyone suggest a way of achieving this?

EDIT: Currently I've managed to get it working by setting the source render texture in OnRenderImage() as the texture for a material on a plane set in front of an orthographic camera that is rendered after the main camera. this seems to work, but I'd still like to know if this is the best way to do it, or if there are any other methods to use.

Comment
Add comment · Show 2
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 Dave-Carlile · Dec 06, 2012 at 07:05 PM 0
Share

You haven't actually stated what the problem is.

avatar image FatWednesday · Dec 07, 2012 at 12:38 AM 0
Share

Woops nnot sure how I missed that one, i've added it to the post.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Dec 06, 2012 at 11:07 PM

Ummm ... maybe try a 2nd quad with flipped verts (it says culling is off, but it always sneaks some in)? And put Z as an Inspector var to check other vals? (final Z should be negative? But not sure what LoadOrtho is doing.)

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 FatWednesday · Dec 07, 2012 at 10:34 AM 0
Share

Tried reversing the vert order, still no dice :(. I also just checked that the render texture was getting the screen by saving it to an image, and besides a slightly warped perspective and dimmer lighting that usual it seems to be rendering the camera view just fine.

avatar image
0

Answer by DuFFOwNz · Nov 09, 2016 at 05:46 AM

Maybe Graphics.Blit is what you're looking for. You can draw a fullscreen quad on the game view by setting the dest RenderTexture to null like:

 Graphics.Blit(aTexture, null as RenderTexture, material);


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

12 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

Related Questions

Easy way to render a texture, pixel perfectly, with a shader, and get the result? 0 Answers

RenderTexture to capture an area bigger than Screen on IOS 0 Answers

behavior of Screen object differs in Unity 3 1 Answer

Just installed Unity, cannot see menu bar 1 Answer

Toggle full screen double click issue 2 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