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 WILEz1975 · May 10, 2015 at 10:21 PM · shader programmingprojectors

Find angle face under mouse pointer.

Hello, I state that I am a c# programmer, but bad shaders programmer :)

I have a projector component and I need to find the angle projected texture to exclude the projecting on vertical faces.

My projector is under the mouse pointer and when is over an horizontal faces is ok.

Ok

I would like to prevent the projector "work" also on vertical faces to avoid this bad effect.

alt text

If possible I would do it in the shader code to avoid the vertical projected image even if the cursor is located on the corners of an horizontal face and a part "goes out" on vertical face.

In c# i find this solution:

if (Physics.Raycast(MouseRay,out hitInfo)){

if(hitInfo.normal.y>0) draw...

else

not draw...

....

But only it works on curved surfaces and not, for example, on the face cubes.

How can I do?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Rodolphito · May 11, 2015 at 09:19 AM

I would recommend having the cancel texture on a plane mesh, and have a script cast a vertical ray downwards every time the mouse moves and position the mesh there, probably with a small offset to prevent z fighting. The benefit of doing it this way is that the symbol is not cut, it is rendered entirely.

So, use a unity plane primitive with your texture and mouse tracking script, and then have it cast a downwards vertical ray to find the correct altitude to render the mesh.

Comment
Add comment · Show 4 · 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 WILEz1975 · May 11, 2015 at 09:33 PM 0
Share

Thanks for the answer but I would like to have the texture projected even on strong angles. The problem is only in the vertical faces.

alt text

I would like to get something like this:

 if (angle> 85) not draw

and possibly by pixels :)

3.jpg (162.6 kB)
avatar image Rodolphito · May 11, 2015 at 10:55 PM 0
Share

How about separating the object into 2 objects, in different layers (or with tags) which is a layer of projectable things and another layer of unprojectable things. This would be useless if you have dynamic objects that you want to be able to project on based on angle though. It is also a kind of time consu$$anonymous$$g method.

Alternatively you can render the sprite in screenspace, sampling the normal of the place under your mouse and using it to align the sprite, but that is not really what you asked for.

avatar image WILEz1975 · May 14, 2015 at 03:17 AM 0
Share

alt text

Solved, and per-pixel :)

With this simple code:

  if(input.norm.y<=0)
             textureColor=float4(0.0, 0.0, 0.0, 0.0);
solved.jpg (72.7 kB)
avatar image matchstickct WILEz1975 · Nov 16, 2015 at 03:48 PM 0
Share

Hi there. I am having the same issue outlined here.

Would you be able to maybe show how you implemented your solution? i.e. maybe the whole shader code or a description.

$$anonymous$$any thanks

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

21 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

Related Questions

Grid Projector only for up-facing normals 1 Answer

How does the unity projector work ? 1 Answer

Shader Problem 0 Answers

Shader float value weirdness 1 Answer

Found undocumented ZTest mode, unity_GUIZTestMode for Shader. What kind of ZTest mode this is? 3 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