Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity 5 Standard Shader - different UVs for the primary textures?

Discussion in 'Shaders' started by ivank, Jun 19, 2016.

  1. ivank

    ivank

    Joined:
    Nov 16, 2013
    Posts:
    97
    Hello,
    we would very much appreciate the advice regarding this (our search so far has not been successful):
    Is it somehow possible, using Standard Shader, to achieve that the height/bump or lightnes or AO texture would use different UV set (and possibly tilling) than the main texture map?

    In fact I still do not believe that such feature quite common in probably every 3D modeling package is not built in there right away...(or maybe is and I do not see?)

    Could anybody suggest to poor humble user:) how to modify the Standard Shader (without breaking its optimalization and platform universality) to achieve this?
    Or even just how to apply the needed texture to the second UV channel using just Unityscript, for example in Start() function?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    So quick comment about "features common in every 3D modeling package". Unity isn't a modeling program, it's a real time 3D engine, and as such there are usually concessions that have to be made to accommodate real time performance.

    That being said, using a different UV for textures isn't one of those features that's actually missing. The standard shader is not something intrinsic to the engine, but rather a complex shader written in Unity's shader system. The built in standard shader covers the most common expected use cases, but you can easily write your own setups using the same lighting model using surface shaders.

    I highly recommend reading this:
    http://www.alanzucconi.com/2015/06/10/a-gentle-introduction-to-shaders-in-unity3d/

    Alternatively if you're more comfortable with node based material systems which are becoming common in 3D modeling programs you can get ShaderForge from the asset store.
    https://www.assetstore.unity3d.com/en/#!/content/14147
     
  3. ivank

    ivank

    Joined:
    Nov 16, 2013
    Posts:
    97
    :)
    Sorry for not being clear; agreed, Unity of course is not modeling package.
    It uses, however, the 3D models produced by them; the models can have more than one UV set and most of the modeling packages allow to assign different UV sets to individual textures (height, lightness, etc.) contained in one material.
    Unity claims to support up to four UVs per mesh (?), so to get the above functionality should be possible almost instantly?

    So again: Could anybody suggest any way how to achieve this in the Standard Shader? Even "emergency" Unityscript snippet would be fine for the model I am just working on.

    I apologize for asking this, probably simple question, to this forum where much more intricate issues have been discussed (and solved); within last year or so I managed basic Unity use plus some scripting, now I see shaders will have to be the next step...:)
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    UV0 is used by default for the main textures, and the standard shader has an option to use UV1 for "detail" textures, but UV1 also gets reused for baked lightmap UVs if you use Unity's built in Baked GI. UV2 gets used for real time GI UVs. UV3 is not used and available.

    There's no magic Unityscript to make shaders use separate UVs for different textures beyond what's already supported by the included Standard shader. You must write a new surface shader to do what you want, in which case you can do whatever you want, including using all 4 UV sets and having unique offsets and scales for each texture.
     
  5. Flavio89

    Flavio89

    Joined:
    Jun 6, 2016
    Posts:
    4
    I need to use normal(main) + normal(detail) + baked lightmap
    But lightmap use the UV1
    Is possible to apply detail normal map in UV 3 ?
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
  7. ivank

    ivank

    Joined:
    Nov 16, 2013
    Posts:
    97
    Ok, that's exactly what I was afraid of.
    It means there is no straightforward way to use your own AO or lightmaps created in 3D modeling applications - like to put them simply into their respective slots and select the UV channel (choice of two would be enough) the same way as for detail maps!
    Creating such maps in modeling sw such as 3DS Max etc. is quite common and handy in architect and product visualizations (and Unity claims to promote such non-game applications).
    Is there any chance that this simple - and quite logical - workflow would be enabled?

    As simple example - to use externally created AO map on the "non-static" wall with tiled brick texture is impossible - without getting into complicated scripting which not average user wants/is able to do...
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    As part of the built in Standard shader? No. It's already an explosion of permutations that can account for hundreds of megabytes.

    Surface shaders exist for this reason and are fairly simple to learn. That page I linked to earlier you can learn to write a surface shader in about an hour.