Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by mfcas · Mar 22, 2011 at 08:38 PM · shaderspritegraphicscullingspritemanager2

Culling part of a sprite in Sprite Manager 2

Hello, I have no idea how to solve the following problem:

I need to cut off a part of a sprite, so the first half is rendered properly, and the second is not rendered at all (totally translucent). I thought I'd have to do a shader for that but I couldn't really write anything that made sense. I need to adjust how much/what part of a sprite is cut off on the go. By "what part" I mean that I need to be able to not only cut off (for example) right half of the sprite, but also the bottom and along any axis (not really simultaneously).

If you know how to solve this problem (even partially), please post an answer! Many thanks!

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
1
Best Answer

Answer by Brady · Apr 28, 2011 at 07:50 PM

There are two ways to do this:

To cut off just one side of a sprite, use one of the Truncate* methods. For example, TruncateRight(0.5f) will truncate the right side of the sprite so that half of it is still showing. TruncateBottom(0.25f) will only leave the top 25% showing (cuts off the bottom).

These methods only cut off one side at a time, however. To cut off multiple sides, use a clipping rect. To do that, decide the rectangular area, in world space, you want to confine the sprite to, and outside of which, the sprite will get cut off. Think of this sort of like framing the sprite.

Create a Rect that describes this rectangular area, we'll assume you call this "clip2D". Then, do this:

Rect3D clip3D = new Rect(clip2D);

Now you can apply the clipping to your sprite:

mySprite.ClippingRect = clip3D;

That's all there is to it.

Comment
Add comment · Show 1 · 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 mfcas · Apr 29, 2011 at 08:11 AM 0
Share

Thanks, I tested both methods and they work really well. It doesn't completely solve the problem, but certainly is much faster and more elegant than the solution I came up with.

I needed this for 2D portals (those from "Portal"). I know that I could settle for depth tricks, but I wanted two sides of the portal to be available to go through, so for example, two object can use each side of one portal simultaneously.

I wrote a shader that cuts off a part of a texture in a material along any axis. I managed to use it and get any rotated sprite work with a portal at any angle, though it's a mess.

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

No one has followed this question yet.

Related Questions

How to resize shader area? 0 Answers

Shader - Hide self overlapping mesh 1 Answer

Pixel snap for material made with Unlit Shader Graph? 1 Answer

double-sided plane with texture? 4 Answers

UI masking in a jet fighter HUD 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