Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 LeeJBaxter · Sep 10, 2018 at 09:28 AM · multiple-monitorsblit

How do I blit a Texture to a specified display?

I'm working on something where, for the time being, I'm having to use a Canvas, RawImage and RenderTexture to effectively blit an input Texture to a specific display. The script that drives this looks like the following;

 using UnityEngine;
 using UnityEngine.UI;

 [RequireComponent(typeof(Canvas))]
 [RequireComponent(typeof(RawImage))]
 public sealed class BlittableCanvas : MonoBehaviour
 {
     private Canvas canvasComponent = null;
     private RawImage rawImageComponent = null;
     private RenderTexture renderTexture = null;

     public void Setup(int displayIndex)
     {
         this.rawImageComponent.texture = null;
         if (this.renderTexture != null)
         {
             this.renderTexture.Release();
             this.renderTexture = null;
         }

         Display display = DisplayUtils.GetDisplay(displayIndex, true);
         if (display == null)
         {
             this.canvasComponent.targetDisplay = 0;
             this.rawImageComponent.color = new Color(0.0f, 0.0f, 0.0f, 0.0f);
         }
         else
         {
             this.canvasComponent.targetDisplay = displayIndex;
             this.renderTexture = new RenderTexture(
                 display.renderingWidth, display.renderingHeight, 0, RenderTextureFormat.Default);
             this.rawImageComponent.texture = this.renderTexture;
             this.rawImageComponent.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
         }
     }

     public void Blit(Texture texture, Material material)
     {
         if (this.renderTexture == null) return;
         if (texture == null) return;
         if (material == null) return;

         Graphics.Blit(texture, this.renderTexture, material);
     }

     private void Awake()
     {
         this.canvasComponent = this.GetComponent<Canvas>();
         this.rawImageComponent = this.GetComponent<RawImage>();
     }

     private void OnDestroy()
     {
         this.rawImageComponent.texture = null;
         if (this.renderTexture != null)
         {
             this.renderTexture.Release();
         }
     }
 }

Note that the line "Display display DisplayUtils.GetDisplay(displayIndex, true);" uses a helper method that I wrote that returns the Display with the given index, and "true" activates it if it hasn't been already. So I attach this script to a GameObject containing a Canvas and RawImage, and then call "Setup(displayIndex)" to set it up to output to the specified display. I can then use the "Blit(texture, material)" method in order to blit a texture to the display (fullscreen).


Of course, at the moment I need a GameObject with this script attached (which I have stored as a prefab) for each display in order for this to work. What I ideally want to do is to replace this prefab and script with a simple method as follows;

 public void Blit(Texture texture, int displayIndex, Material material)
 {
     // Implementation?
 }

I want to be able to do this without having to instantiate any prefabs. Does anyone have any ideas on how I could possibly do this? Note that it's mandatory that I can choose the display that I wish to render to (using "displayIndex"), as my system uses multiple displays.

Comment
Add comment · Show 1
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 sergiobd · Jan 16, 2019 at 02:59 AM 0
Share

Did you find a way to do this?

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.

Follow this Question

Answers Answers and Comments

88 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

Related Questions

using multiple monitors / video outputs? 5 Answers

multi-camera on multi-screen 0 Answers

Black capture using Application.CaptureScreenshot with Multidisplay, 0 Answers

Rendering a screen aligned quad with Graphics.blit - not working? 0 Answers

Multiple Blit problem 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