x


Shader Texture Change

Hi, guys.

I'm making some pinball game and I have a doubt about some textures.

On the pinball table I have some objects that work as labels like "POWER", arrows and other lights. All objects have some shader and are using the same Texture Map, an image that contains all textures of all objects on the table (this was provided by my 3D modeler).

I need to change the texture of some objects when player hit some table areas. Some objects, not all objects. Is there any way to do this using a general texture map like I'm using or I need to create specified textures for each object?

Thanks!

more ▼

asked Dec 27, 2010 at 04:10 PM

mausalamon gravatar image

mausalamon
11 4 4 9

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

3 answers: sort voted first

You can use general texture maps for that. Just create a script that changes the texture whenever the instance gets hit, or whenerver you want to change the apperance. I have made a script that works quite similar. It changes textures when you hit a button.

var happyTex : Texture; var sadTex : Texture;

function OnEnable(){ renderer.material.mainTexture = happyTex; }

function Update () { if (Input.GetKeyDown (KeyCode.U)) { if (renderer.material.mainTexture == happyTex) { renderer.material.mainTexture = sadTex; } else if (renderer.material.mainTexture == sadTex) { renderer.material.mainTexture = happyTex; } } }

more ▼

answered Jan 07, 2011 at 02:27 PM

Graineik gravatar image

Graineik
11 6 4 4

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

Thank you! This sample code help me!

more ▼

answered Jan 07, 2011 at 03:49 PM

mausalamon gravatar image

mausalamon
11 4 4 9

This does not belong in an answer, and this technique isn't code-based. It's based on modeling and texturing.

Jan 07, 2011 at 04:18 PM Jessy
(comments are locked)
10|3000 characters needed characters left

The term that you want, when saying "general texture map", is atlas.

You can do this any way you like. My recommendation is to copy the UVs, from UV1, move them to UV2. Then, you can transform them as you like, but it would probably make the most sense to work with them in the islands they came in, because the modeler presumably did a good job unwrapping already. Then, when the appearances need to change, change the materials, and use custom shaders that utilize UV2 instead of UV1.

You could always just keep the same UVs, and map a new atlas to them, but if you've got an entire machine, and you're only going to make an atlas for a subset of that machine, UV1 probably isn't going to make good use of texture space - there would probably be a lot of empty area.

more ▼

answered Jan 07, 2011 at 02:58 PM

Jessy gravatar image

Jessy
18.4k 208 178 293

(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:

x3602
x3096
x912
x304
x16

asked: Dec 27, 2010 at 04:10 PM

Seen: 4255 times

Last Updated: Dec 27, 2010 at 04:10 PM