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 Joker042 · Sep 06, 2013 at 05:37 PM · texturegraphicsprocedural

Creating an outline around the opaque pixels on a plane. Outline should extend outside of plane.

Short question:

Start with a 2 triangle rectangular mesh with an alpha tested texture on it. The mesh's corner UV coordinates will be somewhere inside the texture, not at the extremes. I'd like to draw an outline around only the pixels which are opaque. The outline would extend outside the mesh boundaries when it needs to, so that all of the pixels are bordered. If there is a shader-only solution, that would be brilliant, but I'm willing to create more planes behind the existing ones if necessary.

The view will always be top down, no moving camera, the plane will always be directly facing the camera. This is for mobile processors, so I'd like to keep the draw calls down, but I don't mind if the actual algorithm / setup takes a while as I can crunch in the background.

More information:

The plane mesh is part of a jigsaw puzzle piece. Each piece is made up of many rectangular meshes which were "merged" (placed in the same game object, not merged at the mesh level) to make a randomly shaped piece. The jigsaw puzzle texture will have a transparent background, and I drop any meshes which do not contain an opaque pixel. I need an outline around each piece (which is made up of many meshes), but I'm happy to draw it around each mesh, as this seems more viable. If the texture extends to the edge of one of the meshes, I still need to draw the outline around it.

I hope I've explained that well, please let me know if it's not understandable.

Things I've tried which failed:

  • Simple edge detect on the alpha of the texture. This does not have outlines around the mesh edges which are not at the edge of the image.

  • Scaling the image in many forms. Any time you scale, the pixels toward the top of the image all move upwards, so the leaves on the top of a tree don't have shadows on the underside. Also, obviously, outline width varies with x and y pos.

The way I think it might be possible but I'm not smart enough to do:

  • In the shader, on the first pass, draw the texture pixel with ZWrite On

  • On the second pass, with ZTest Greater, instead of painting one pixel, paint an n x n square, where n is the width of the outline. That's the part I'd like to know about!

Comment
Add comment · Show 2
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 Joker042 · Sep 06, 2013 at 05:28 PM 0
Share

I know there are a lot of other questions out there about outlines, but I think this one is a little different, given the transparency and the UVs inside the texture. I've also considered generating a separate texture atlas and applying each piece's texture to a single plane, which would be possible but annoying.

Thanks for reading!

avatar image Joker042 · Sep 06, 2013 at 05:37 PM 0
Share

Just a thought. If a solution can only draw an outline in world units, not texture pixels, that's also brilliant.

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

15 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

Related Questions

Procedurally combine (merge) two Texture2D 2 Answers

Pixelated Texture Edges on Terrain 0 Answers

Problem with Graphics.DrawTexture 0 Answers

How can I turn off texture filtering on procedurally generated textures? 1 Answer

Purchased procedural texture looks wrong when applied 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