x


How can I get or set textures on a material other than the main texture? (eg, the bump map)

I can't figure what is the name of this component, so I'll try to describe it somehow.

When selecting a mesh in the inspector, there are 2 textures displayed. One texture is accessible trough

Texture2D tex = renderer.material.GetTexture("_MainTex") as Texture2D; 

How can I accesses the other texture?

Thanks.

more ▼

asked Nov 19 '10 at 09:14 AM

Samuel gravatar image

Samuel
28 4 5 9

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Different shaders which have multiple textures will have an internal variable name for each texture. As you've shown, the common name for the main diffuse texture is "_MainTex", and some other names used in some of Unity's built in shaders are:

  • "_BumpMap" (the normal map in bumpmapped shaders)
  • "_Cube" (the reflection cubemap in reflective shaders)
  • "_DecalTex" (for the decal shader)
  • "_Detail" (for a shader which allows detail maps)
  • "_ParallaxMap" (for parallax mapped shaders)

You can also access the "_MainTex" more conveniently by using the .mainTexture property of the Material class like this:

Texture2D tex = renderer.material.mainTexture;
more ▼

answered Nov 19 '10 at 12:06 PM

duck gravatar image

duck ♦♦
41k 92 148 415

Excellent explanation, Thanks a lot!

Nov 19 '10 at 12:10 PM Samuel

is there a list of this somewhere we can view / can I access the Illumin map?

Jul 12 '11 at 07:25 AM vivalarosa

@mehowe7: What shader do you use? Not every shader has every texture variable. The variable names in this answer are common names, but noone stops a shader-author to use something completely different.

btw. don't post question as answers to other questions!!!

If you have further questions on this topic, ask your own question. But first think about it. What's your concrete question. What information is necessary to understand your question. Ask one question at a time and phrase it as clearly as possible. Include all "relevant" code, don't post the whole script

Jan 03 '12 at 03:49 PM Bunny83
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2197
x1655
x813
x152
x45

asked: Nov 19 '10 at 09:14 AM

Seen: 2826 times

Last Updated: Jan 03 '12 at 03:49 PM