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 /
avatar image
1
Question by Friedemann_A · May 11, 2017 at 02:17 PM · shader3dshaderstextures

Make triplanar mapped textures stay in place?

Hi everybody!

My goal is to really quickly texture objects that have been created by slapping multiple primitives together (really tight time constraints on this project).

In order to avoid UVs, I'd like to texture them using a triplanar mapping approach, based on worldspace-coordinates of the objects. This way, no matter how I stretch the primitives, the seamless textures always stay un-stretched. So far that works and looks like this:

alt text

However, the objects will move during runtime, and since I'm using worldspace coordinates for the triplanar mapping, the textures don't move with the objects, like in this GIF:

GIF

Anybody got any ideas on how I could make the textures move with the objects? Like some way to bake them onto the models when the scene is loaded? (I can't just use objectspace-coordinates for the mapping, since that will result in stretching of the textures)

Thanks in advance!

triplanar-01.jpg (148.5 kB)
Comment
Add comment · Show 1
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 · May 11, 2017 at 04:04 PM 0
Share

Textures mapped using worldspace coordinates, by definition, remain fixed to positions in the world. If your object moves through the world, it will inherit the texture of the position it moves into. If you want to map your texture onto your object without relying on UV-wrapping, you might want to try object-space coordinates ins$$anonymous$$d.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · May 11, 2017 at 03:37 PM

You would have to do the triplanar mapping in the vertex shader to get that effect... otherwise you'll be writing the model to the GPU every frame which will kill performance.

Look into the shader language cG. Then import the Old diffuse shader (much easier to modify than the new standard one) and apply your algorithm to the vertex shader so it calculates the texture coords dynamically. The pixel shader should work without modification.

Comment
Add comment · Show 5 · 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 Friedemann_A · May 11, 2017 at 03:57 PM 0
Share

Thanks for your reply! I'm doing the calculations for the triplanar mapping in vertex shader (written in cG). However, using the objectspace coordinates of vertices as texture-coordinates results in the texture being stretched. Using worldspace coordinates of vertices results in the texture not moving with the object, as seen in the GIF in my original post.

avatar image FortisVenaliter Friedemann_A · May 11, 2017 at 07:47 PM 2
Share

Ah, I thought you were shooting for the opposite effect. In that case, I would set it up to generate the Texture coords on the CPU in the editor. Add an editor script that can change the UVs, run it in the editor, then use a regular shader. That way, once the objects are scaled properly, you can apply the texture coordinates properly, but they'll stay static in the game.

avatar image Glurth FortisVenaliter · May 11, 2017 at 11:03 PM 1
Share

I agree with the "bake" method: Create your model in the scene, at position 0,0,0. Then modify it's uv's with your mapping algorithim ONCE, then save the mesh asset which now statically contains the appropriate UVs. You could also perform that entire process during initialization (slower loading but less dev steps).

Show more comments
avatar image calpolican · Feb 12, 2021 at 01:52 AM 0
Share

Hey sorry to necro this post, but can you share more info on how to move th UVs so that they adapt to the world position in order to "bake" the result. How do I know what position should I move each UV to?

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I edit Material Textures without creating a new Shader?,How to edit Material Texture 1 Answer

Mesh shader to outline colour changes 1 Answer

Outlining simple objects without artifacts 0 Answers

Possible for a shader to have two decal slots? 2 Answers

Shader Overlay Texture 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