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
0
Question by cabot696 · Jun 27, 2011 at 07:29 AM · textureproceduraldungeonseamless

How to map texture across multiple objects?

Hi, I'm in the middle of creating a procedural dungeon that is built out of cubic template models. How do I apply a giant texture that spreads across multiple meshes (multiple models) and that tiles seamlessly (assuming the texture is tiled)? I'm trying to achieve a realistic look and this isn't possible if each tile has the same, small texture.

Would I have to write my own shader using CG or is this possible without resorting to that?

Thanks, Lucas.

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 cabot696 · Jun 29, 2011 at 01:51 AM 0
Share

I've been working on this for the last few hours without much luck. I don't think it's possible to import multiple objects into one uv-map in Blender so I've been trying to write a custom cg script to map the world position on the object ins$$anonymous$$d. So far I've been partly successful where I've been able to map one side of the dungeon, but the rest aren't working correctly. It looks like this: http://i.imgur.com/DjzLL.jpg

It seems that the shader is taking one side and just stretching it on the z-axis across the world ins$$anonymous$$d of mapping each side in 3d. Here's the shader: http://pastebin.com/70vNCEQk

What can I change to fix the problem?

Thanks for the help.

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by raminsh · Jun 27, 2011 at 07:40 AM

Hello actually i have done exact same thing for a big block of city, a jungle, a cave... However i didn't make a shader. What i did was simply inside belender or maya, and put all the uv set in one layout and then applied one single material that had that texture and ofcourse they were all multiple objects. The cave or the road was used in a procedural case. You just have to setup the uvs properly. I hope that helps.

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 cabot696 · Jun 27, 2011 at 03:09 PM 0
Share

I'm sorry, I'm a bit confused. Would you please elaborate? The objects I want to map are all different shapes that connect together, so their uv layout will look different because they are different shapes. What do you mean by putting them in one layout then?

Also, doing this, how does Unity know to map only a small part of the texture to each object and how does it know how to apply the offset of the texture correctly?

avatar image
0

Answer by Borgo · Jun 27, 2011 at 03:16 PM

No need to write your own shader, just make your meshes to share the same UV name in your 3D model application. e.g.: We have a room with 3 meshes: floor, walls and ceiling. We want to bake a Lightmap in the 3D software and use in these 3 meshes. You can make 3 UVs with same name like "lm_uv". This UV will be shared with the meshes.

Comment
Add comment · Show 4 · 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 cabot696 · Jun 27, 2011 at 03:55 PM 0
Share

I'm using Blender. Do all the objects have to be in the same .blend file or does it not matter? And the 5 objects I'm using all have the same uv map name of "UVTex" but when I import the models into Unity, they are renamed to "(nameofobject)-$$anonymous$$". What am I doing wrong? Thanks.

avatar image raminsh · Jun 27, 2011 at 04:03 PM 0
Share

borgo in right. if you are using blender, I recommend have all the objects in one scene and make them share the same material with that specific texture you have in $$anonymous$$d. however when you export them, all you need to do is export them seperately. I usually make sure that there are only one uvset for the objects because sometimes in gets messed up when imported to the engine.

avatar image cabot696 · Jun 27, 2011 at 04:51 PM 0
Share

I apologize, I can't seem to figure this out. All my objects are in one .blend file which are assigned to the same material. How do I then set up the UV maps correctly? (They just have to be the same name?) Would somebody be so kind as to give me a step-by-step tutorial in Blender?

avatar image raminsh · Jun 27, 2011 at 05:40 PM 0
Share

okay I certainly do not $$anonymous$$d but the problem is I don't know how to layout the uv maps in blender, I use max and maya. but this probably would help you : http://wiki.blender.org/index.php/Doc:$$anonymous$$anual/Textures/UV/Editing_the_Layout have in $$anonymous$$d that you need to select all the objects before entering the uveditor so you can see all the related uvs and lay them out together.

avatar image
0

Answer by Owen-Reynolds · Jun 29, 2011 at 04:40 AM

Your shader is doing a front projection. Switch to xz for a top projection. Your shader:

 void surf (Input IN, inout SurfaceOutput o) {
   float3 worlduv = IN.worldPos;
   o.Albedo = tex2D (_MainTex, worlduv);
 }

The texture lookup (last line) uses a float2. Since your worlduv is a float3, it just slices off the last part and uses worlduv.xy for the lookup, which is a front projection.

For a top down, change the last line to:

 tex2D (_MainTex, worlduv.xz); // FYI, yz is a side projection

Of course, that will map the floor just fine, but smear over the sides of walls. [EDIT] If your objects will always have flat sides facing at 0,90,180,270 degrees, you could guess a front/side/top projection using the normal (code has been tested):

 struct Input {
 float2 uv_MainTex; // unused
 float3 worldNormal;
 float3 worldPos;
 };

 void surf (Input IN, inout SurfaceOutput o) {
   // Guess correct planar map from normal. 0.5 is an arbitrary cutoff
   float2 UV;
   // NOTE: assuming no bottom-facing, otherwise use abs()
   if(IN.worldNormal.y>0.5) UV = IN.worldPos.xz; // top
   else if(abs(IN.worldNormal.x)>0.5) UV = IN.worldPos.yz; // side
   else UV = IN.worldPos.xy; // front

   // 0.1 is an arbitrary x10 texture size scale 
   half4 c = tex2D (_MainTex, UV*0.1);
   o.Albedo = c.rgb;
   o.Alpha = c.a;
 }

The edges all have bad seems, but there's no way around that.

Comment
Add comment · Show 2 · 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 cabot696 · Jun 29, 2011 at 06:25 PM 0
Share

Ah I see. Is there anyway to texture using a front projection without touching the top projection at all, so that I can use o.Albedo += tex2D (_$$anonymous$$ainTex, worlduv.xy) to add them both together? If not, could I use another method within the same shader? It will be hard to use separate shaders because that requires me to use separate models for each plane which would greatly complicate things.

avatar image Owen-Reynolds · Jul 01, 2011 at 12:27 AM 0
Share

You could make several prefabs with the same plane, rotated however, and different shaders. Otherwise, I added to my post how to do a "guess correct projection" shader.

avatar image
0

Answer by Wesww · Jul 27, 2011 at 04:15 AM

Hey cabot, what did you end up using in the end?

Also, did you ever get Owen Reynolds world based uv shader to work?

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Procedural Texturing on Multiple Terrain Mesh 1 Answer

Seamless 3D tiles 1 Answer

Do I need to split my mesh up to properly UV texture it? 1 Answer

Assigning UV Map to model at runtime 0 Answers

Procedural Random Walk Dungeon Generator? 2 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