• 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 Monko · Jun 08, 2013 at 06:05 PM · texturemeshuvuv mapping

Apply texture to a mesh on all 3 sides

I am working on a marching cubes terrain, and I need to apply a texture to it. The problem is, I don't know how to apply the texture so the mesh looks "normal" from any angle. Right now, Ive been doing this:

 uvs = new Vector2[mesh.vertices.length];
 for (var i=0; i < uvs.Length; i+=1) {
 uvs[i] = Vector2(mesh.vertices[i].x,mesh.vertices[i].z);
 }
 mesh.uv = uvs;

This code works, but the mesh doesn't draw right when a part of the mesh is completely straight up. That is because my code only applys the texture onto the x and z plane. I've been looking online for solutions, and couldn't find any source code. But I have learned that there is a way to apply texture on all 3 of the xyz planes, and simply blend the result together. Unfortunately, I have no idea how to do this.

If anyone out there knows how to apply a texture onto a mesh, please let me know. ( I know it will involve UVs and normals)

After doing further research, ive learned that what im trying to do is called triplanar texturing.

Comment
Add comment · Show 5
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 DaveA · Jun 08, 2013 at 06:47 PM 0
Share

I would recommend getting some/all of the existing voxel add-ons from the Asset Store and see how they did it. VoxelForm is my favorite.

avatar image Monko · Jun 08, 2013 at 10:00 PM 0
Share

I don't have the money to buy any voxel add-ons, and im pretty sure someone out there knows how to do this. Does anyone have any sample code, or a website that explains how to apply a texture onto a mesh from all 3 sides.

avatar image Monko · Jun 10, 2013 at 11:53 PM 0
Share

O$$anonymous$$, after doing further thinking, I think I figured out how to do something simaler to triplanar textureing. First off, I create a 3 UVs for all 3 sides by doing this:

 uvsx = new Vector2[mesh.vertices.length];
 for (var i=0; i < uvsx.Length; i+=1) {
 uvsx[i] = Vector2(mesh.vertices[i].y,mesh.vertices[i].z);
 }
 uvsy = new Vector2[mesh.vertices.length];
 for (var i=0; i < uvsy.Length; i+=1) {
 uvsy[i] = Vector2(mesh.vertices[i].z,mesh.vertices[i].x);
 }
 uvsz = new Vector2[mesh.vertices.length];
 for (var i=0; i < uvsz.Length; i+=1) {
 uvsz[i] = Vector2(mesh.vertices[i].x,mesh.vertices[i].y);
 }

All I need to do now is blend them together as one. Unfortunately, I don't know how. So does anyone know how to blend these 3 UV together?

avatar image Benproductions1 · Jun 11, 2013 at 10:34 AM 0
Share

How about looking at some open source voxel engines and seeing how they did it?

avatar image Monko · Jun 12, 2013 at 01:46 PM 0
Share

O$$anonymous$$, I have looked all over the internet, and I have found a few shaders. But I have no idea what I would use a shader for. Also, when I transfer them into my game, they always give parsing error's that I don't know how to fix because I usually work with java script. Does anyone now how to finish up the code I posted above, or at least show me a website with a working triplanar texturing code?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Monko · Jun 14, 2013 at 06:30 PM

Anyone able to help?

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

Answer by DavidWilliams · Jul 01, 2013 at 08:23 AM

You do indeed want to use triplanar texturing. Have a look at these resources:

  • Generating Complex Procedural Terrains Using the GPU (Section 1.5)

  • Volumetric Representation of Virtual Environments (Section 3.5.1)

Note that you are on the right track, but you don't want to 'combine the UVs'. Instead you sample the texture three times (once with each set of UVs) and then combine the results. You will need some good shader programming skills to do this - I don't believe you can just use C#/JavaScript.

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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

17 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

Related Questions

Split a mesh while using same UVs and texture position. 0 Answers

Assigning UV Map to model at runtime 0 Answers

UV Mapping for 2D Meshes with 3 Vertices Only 1 Answer

2 Textures on a single mesh 1 Answer

Procedural Mesh UVs Edge Case? 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