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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by karlnp · Nov 11, 2012 at 03:37 AM · graphicsoptimizationrendertextureadvice

Compositing a cursor over a rendertexture - GL pipeline problems?

Basically I'm trying to recreate the interactive surfaces in Doom3 using RenderTextures. So far I raycast every frame to see what the player is pointing at, and if it's using a RenderTexture, I get the camera, target texture, and texture coordinates of where on the texture the player is pointing.

The camera-find algorithm is brute force, but there will only ever be a few active cameras in a given Scene, so while alternatives are welcome this won't be too bad of a performance hit.

What I want to do next is display a HTML-esque hand cursor at the specified texture coordinates as a precursor to making and using a simple UI, but it's not working. What am I doing wrong?

Note: This attempt incorporates solutions from other unityAnswers, available [here],[1] [here],[2] [here],[3] and here.

 using UnityEngine;
 using System.Collections;
        
 public class mouseScript : MonoBehaviour {
     public Camera lastrendTexCam;
     public GameObject lastSightedObj;
     public GameObject testObj;
     public Texture2D cursorTexture; 
     string lastScreen = null;
     Ray tempray = new Ray();
     RaycastHit temphit;
     RenderTexture rendTex;
     private int i;
     float wperc;
     float hperc;
     
     // Use this for initialization
     void Start () {
         lastrendTexCam = new Camera();
         lastSightedObj = new GameObject();
         testObj = new GameObject();
         temphit = new RaycastHit();
         rendTex = new RenderTexture(1,1,0);
         i = 0;
         wperc = 0.0f;
         hperc = 0.0f;
         cursorTexture = new Texture2D(128,128);
         cursorTexture = (Texture2D)Resources.Load("UI/hand");
     }
     
     // Update is called once per frame
     void Update () {
         
         tempray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(tempray, out temphit)){
             print ("Raycasted " + temphit.transform.name);
         }
         if(i == 0 || temphit.transform.CompareTag("Interactive")){
                 testObj = temphit.transform.gameObject;
                 i++;
                 isCamera();
         }
     }
     
     bool isCamera(){
         rendTex = (RenderTexture) testObj.renderer.material.mainTexture;
         Camera[] cameras = FindObjectsOfType(typeof(Camera)) as Camera[];
         foreach(Camera c in cameras){
             if (c.targetTexture == rendTex){
                 lastrendTexCam = c;
                 lastSightedObj = temphit.transform.gameObject;
                 lastScreen = lastSightedObj.name;
                 var pixelUV = temphit.textureCoord;
                 wperc = (pixelUV.x * rendTex.width);
                 hperc = (pixelUV.y * rendTex.height);
                 print (cursorTexture);
                 drawCursor ();
                 return true;
             }    
         }
         print ("Didn't find the RenderTexture target.");
         return false;
     }
     
     void drawCursor(){
         RenderTexture.active = lastrendTexCam.targetTexture;
         print (RenderTexture.active);
         GL.PushMatrix();
         GL.LoadPixelMatrix (0, 2048, 2048, 0);
           Graphics.DrawTexture (new Rect (wperc, hperc, cursorTexture.width, cursorTexture.height), cursorTexture);
           GL.PopMatrix ();                    
           RenderTexture.active = null;
     }
     
     
         
 }


[1]: http://answers.unity3d.com/questions/13512/how-do-you-programmatically-retrieve-the-rendering.html

[2]: http://answers.unity3d.com/questions/16139/when-does-rendertextureactive-myrt-work.html

[3]: http://answers.unity3d.com/questions/23523/pass-clicks-through-camera.html

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 vvander · Nov 01, 2015 at 06:58 PM 0
Share

Did you find any avenues for success with this? I need something like this for a project I'm working on, but rather than displaying an HT$$anonymous$$L cursor I'm ok with using the system cursor as long as it can translate coordinates effectively for a raycast selection through the secondary camera(s).

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

10 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

Related Questions

Multiple Cars not working 1 Answer

When making a large scene/map/level, is graphic/quality compromise inevitable? 2 Answers

Best way to convert particles and sprites in a single sprite at runTime 1 Answer

Split a big level mesh in Unity 2 Answers

Help! how to convert input.GetAxis to Accelerometer 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