Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by darkhog · Apr 24, 2016 at 05:12 PM · performanceraycastingmouseclickretrooverdraw

Either a cool effect or good performance. How do I eat cake and have cake?

I'm doing pixelated 3D using this tutorial: http://www.gamasutra.com/blogs/AhmetKamilKeles/20160421/271027/Creating_perfectly_pixelated_games_with_Unity_2D_or_3D.php

Unfortunately in part of my game clicking on objects is required (which is implemented using OnMouseUpAsButton()).

So if I render on game camera everything to render texture and on "actual" camera (that is child of game camera and has as a child quad rendertexture is displayed on so cameras are aligned perfectly) I only render quad texture is displayed on, using Culling Mask, everything is shown just fine (as game camera's culling mask is set to everything but the layer display quad is on).

But then I can't click things. Alignment is not an issue (as cameras are always aligned perfectly), neither is display quad blocking casts (as it is on IgnoreRaycast layer).

There's solution to this: Enable rendering everything on both cameras. Now I can click everything, but because game has effectively to render level two times, one of which is unnecessary (as it is quickly covered by display quad), performance suffers greatly as a result.

How can I do it so I can get good performance AND be able to click things?

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 tanoshimi · Apr 24, 2016 at 05:19 PM 0
Share

I'm not quite sure why you need the second camera or the quad. Can't this simply be applied as an image effect and blitted to the screen of the main camera?

avatar image darkhog tanoshimi · Apr 24, 2016 at 05:55 PM 0
Share

Unfortunately no, as I need GUI to be unpixelated or either it won't be playable. Render texture+separate cam is easiest solution to do pixelation, just read gamasutra tutorial I've linked.

avatar image tanoshimi darkhog · Apr 24, 2016 at 05:59 PM 0
Share

So put the GUI on a separate camera then if you don't want that pixelated - that's got to be a much more efficient solution than rendering the whole scene twice...

avatar image Gord10 · Apr 24, 2016 at 06:02 PM 0
Share

Hi, I'm the owner of the article.

I don't know an easy workaround, unfortunately. If I were you, I'd try writing my own system ins$$anonymous$$d of On$$anonymous$$ouseUpAsButton event. I'd modify the value of a boolean with mouse button getting pressed down and up. If mouse is up, I'd raycast according to the player camera's position and the ray corresponds to the mouse position (see Camera.ScreenPointToRay).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Gord10 · Apr 24, 2016 at 06:13 PM

Hi, I am the writer of the article. Hmm, I hadn't thought of it before.

I don't know an easy solution, unfortunately, but if I were you I would write my own code instead of OnMouseUpAsButton() event. I'd check whether the mouse is up and then raycast on the player camera by myself.

Comment
Add comment · 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 darkhog · Apr 25, 2016 at 03:55 PM 0
Share

Hm, seems like it is a step in the right direction, but still not enough. You see, player can unlock mouse from the screen so simple cast from camera's position (i.e. center of the screen) won't do.

For example, there are two buttons. Button A is in the center of the screen, while button B is a little to the left. Player unlock mouse to not loose view of nearby enemy patrolling the area while clicking button B (which is correct solution to the puzzle). Ins$$anonymous$$d cast is done from the camera's center and game thinks user clicked button A which initiates trap and the player dies.

Another thing On$$anonymous$$ouseUpAsButton does is checking whether mouse started pressed on the object in question. This way, when you click, say, skybox, and then drag mouse cursor over the object and then let go of a button, the game doesn't accidentally fire up code related to mouse click for that object.

I'm sure there's a way to solve both of those issues, but I don't know it.

avatar image Gord10 darkhog · Apr 26, 2016 at 02:12 PM 0
Share

If you use camera.ScreenPointToRay(Input.mousePosition), I think you get the ray that the mouse is on. If player clicks B, B's ray is created.

For the second problem, you can do another raycast at the moment mouse is down. You store the object clicked on. When mouse is up, you do another raycast and then compare the two objects. (Also don't forget to check if the objects are null, in which no clicking should be executed)

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

61 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

Related Questions

UI performance. FPS drops. Overdraw. 0 Answers

Raycast can not detect collider 1 Answer

Ray-casting Problem 0 Answers

Raycast positioning problem 1 Answer

RayCast Rotation 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