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 youngapprentice · Nov 12, 2012 at 11:53 PM · texturematerial

Add a texture onto a material

What I'm doing here is spawning asteroids.

A script will pick a random model, and a random material (diffuse texture and it's respective bump map), and assign it to the asteroid. This gives me a lot of variety!

My only question is this:

Each model has its own respective Ambient Occlusion map. (It's just a shadow map). I'd like to layer this on top of the diffuse material I am using through scripting, because just a random rock texture looks kind of sad haha

If I could multiply it, that would be ideal, but I don't mind doing an alphaOver (I can convert the shadow map to a transparent png).

Thanks!- YA

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Seth-Bergman · Nov 14, 2012 at 09:40 PM

You're in luck!

http://answers.unity3d.com/questions/248758/custom-shader-to-add-bruises-to-character.html

This is what you want, it's a shader someone very kindly helped me out with, to overlay a "bruises" diffuse w/alpha over a character's base diffuse map..

Be sure to thumbs-up the answer in the link!

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 tmdchi · Nov 13, 2012 at 12:34 AM

To make it happen I think you should have a unique material for each combination of texture+lightmap, which would be not much efficient if you have a lot of them.

The only way I know of having one material in many objects, having each object its own lightmap, is baking the lightmap from inside Unity. But I guess it's not a viable option for you.

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 tmdchi · Nov 13, 2012 at 12:38 AM 0
Share

Of course you can always duplicate the geometry, scale it up a bit, and assign a particles-multiply shader to it with your ambient occlusion as texture. But results may be irregular.

avatar image youngapprentice · Nov 13, 2012 at 12:47 AM 0
Share

Both of those are possible... What about a custom shader? I know that there is a legacy shader that accepts lightmaps, but I don't want the model to be immune to lighting. Anyone have a custom shader they can pull out of their butt?

avatar image tmdchi · Nov 13, 2012 at 10:26 AM 0
Share

A custom shader would still require a texture for the lightmap, so probably you'll be again stuck to one material per object. Unless there's a way to change the reference to the texture, based on the object. $$anonymous$$aybe you're able to configure the material inside the function OnWillRenderObject() ? Just a thought.

avatar image youngapprentice · Nov 13, 2012 at 12:04 PM 0
Share

All right thank you for your help. It's not that big of a deal I guess. I'm just a fan of making an efficient game. Thanks for your help -YA

avatar image
0

Answer by spiceboy9994 · Nov 14, 2012 at 08:56 PM

How about having a class with the list of possible textures and bumpmaps and then randomize from them?. Not sure about how the oclusion maps work, but here's a small example. You just have to be sure that Main Textures at position [n], has its matching Bump Map at position [n]:

 using UnityEngine;
 
 public class MaterialManager: MonoBehaviour
 {
     public Texture[] PossibleTextures;
     public Texture[] PossibleBumpMaps;
 
     void SpawnAsteroid()
     {
         int RandomIndex = Random.Range(0, PossibleTextures.Length);
         renderer.material.SetTexture("_MainTex") = PossibleTextures[RandomIndex];  
         renderer.material.SetTexture("_BumpMap") = PossibleBumpMaps[RandomIndex];
     }
 }

Hope this 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 youngapprentice · Nov 14, 2012 at 09:33 PM 1
Share

Thank you, my friend! $$anonymous$$y problem here is, invariably, the Ambient Occlusion maps. They are layered onto whatever Diffuse texture I have and add Ambient Occlusion to the model, giving it a much more realistic look and feel. So although your solution is good for anyone that wants to randomize textures, it doesn't quite fit the glove in this situation. Thank you for your contribution though! This is sure to help out anyone that might stumble upon this thread.

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

12 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

Related Questions

How can I swap an object's texture when I click? 2 Answers

Material/Texture on the Inside of a Sphere 5 Answers

CRT/LCD screen shader (for materials) 4 Answers

How to set a texture in an image effect material? 1 Answer

Cutout Material is not showing texture transparency? 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