2
\$\begingroup\$

I have an array of vertices with texture coordinates for a UV map in Unity:

newUV.Add(new Vector2 (0, 1)); // FACE 1
newUV.Add(new Vector2 (1, 1));
newUV.Add(new Vector2 (1, 0));
newUV.Add(new Vector2 (0, 0));

newUV.Add(new Vector2 (0, 1)); // FACE 2
newUV.Add(new Vector2 (1, 1));
newUV.Add(new Vector2 (1, 0));
newUV.Add(new Vector2 (0, 0));

mesh.uv = newUV.ToArray();

It textures my mesh just fine.

How could I go around tinting FACE 1 to a darker color? Let's say the texture is just plain green and I wanted to texture only on FACE 1 to be a darker shade of green.

\$\endgroup\$
1
\$\begingroup\$

Let's say the texture is just plain green and I wanted to texture only on FACE 1 to be a darker shade of green.

I think you have 3 possibilities:

  • use a second texture lookup to drive different light intensity on different part of the mesh. Perhaps you want to look at self-illumin shaders built-in in unity. May be that's exactly what you are looking for, if you only want a different light intensity on some area.

Two other way of doing it (probably not suited for your specific case, but useful in more complex scenarios):

  • split the mesh into 2 submesh and assign a different material to each submesh (same texture but different shaders of uniform values) => (draw back: you'll probably have an additional draw call unless the mesh can be static/dynamic batched)

  • encode some additional data into some unused vertex attributes and use that data inside the shader to apply a darker shading (draw back: memory overhead per vertex: if the mesh is you will waste memory for just darkening a potentially small area)

\$\endgroup\$
  • \$\begingroup\$ Thank you for your answer. Yes I am indeed working on implementing lighting on my Voxel world and I think your first proposed solution is the one I'm looking for but I can't figure out exactly what you mean by "use a second texture lookup to drive different light intensity". I understand how Minecraft determines the lighting of a face (a value between 15 and 0 depending on distance from the light source). But I don't understand how I could use the self-illum shader to apply different lighting to different vertices/faces. Are you saying I should apply a second UV map w/ semi transparent texture \$\endgroup\$ – Juicy Feb 24 '14 at 17:05
  • \$\begingroup\$ If I'm using a Self-illumin shader, how can I apply UV coordinates for the illumin? I know the mesh can take two UV maps so I figure to use one UV map for the texture and the second UV map for applying different shades using the illumin texture. But how can I tell unity to use the Illumin and not the Base when applying the second UV map. \$\endgroup\$ – Juicy Feb 25 '14 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.