• 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 Luca Belluccini · Mar 23, 2014 at 11:09 PM · collisionraycastdecalreview

Decal using generated mesh

Hello, I am writing a script to drop decals on walls. More in detail, I first started with:

  • Use a Raycast

  • Get the point and normal (if collided)

  • Generate the 4 corners vertices, given a decal size

  • Test the wall against those vertices using 4 Raycasts

  • If all Raycasts are successfull, use their points to draw a quad and apply a texture over it (add some offset to avoid z-fighting)

  • Assign this new mesh to an empty prefab (with some extra stuff inside)

The problems with that solution are mainly:

  • the fact you will not drop decals if the "available area" on the wall is smaller than the size of the decal one

  • the decals can overlap

I started to tweak this solution, not only testing the 4 corners but trying to use 2 arrays of Raycasts (one for Upper-Left to Upper-Right and one to Lower-Left to Lower-Right). In this way, I can detect with a quantifiable but potentially small error which is the available area on the wall and resize my decal accordingly.

alt text

This is the result of the second approach. This can be further optimized checking the size of the resulting quad and use another texture for "smaller" horizontal sections, to avoid severe texture deformation.

Finally, to avoid decals to be overlapping, I could test twice the Raycasts: once against the wall layer and once to the decals layer. If I am hitting the decal, I consider this point as invalid and continue testing.

To do that, I managed to reuse the same mesh used for the texture, but assigned to the empty object's MeshCollider.

alt text

It works, but sometimes I get some overlapping decal... Maybe 2 arrays of Raycasts are not enough... I should move to a spiral-like pattern or vertical scanning.

What do you think about this solution? Anyone faced a similar problem? Is there a way to avoid multiple Raycast tests?

I saw this blog post about projecting decals using volumes... But in my opinion my problem is a little different.

cattura.png (243.1 kB)
cattura3.png (346.7 kB)
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Custom Collision Detection 4 Answers

Collision Detection If Raycast Source Is inside A Collider? 4 Answers

Optimization of bullet hit calculation per frame 1 Answer

Raycast Mouse Click On Specific Objects Only 0 Answers

Help with a field of sight 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