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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Unity 5] UV coordinates

Discussion in 'Shaders' started by Phantomx, Mar 16, 2015.

  1. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    Hey,
    so in unity 5 there's supposed to be 2 more mesh uv coordinates. I made a shader to access those coordinates and multiplty a color on UV1 by a detail texture on UV3 (UV2 is still for lightmaps I guess)

    the result is all good when no lightmap is baked, but as soon as the lightmap bakes the detail UV changes and no longer represents what it was before...

    The Shader:
    Code (CSharp):
    1. Shader "Custom/2UV" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.      
    5.         _MainTex ("Palette", 2D) = "white" {}
    6.         _DetailTex ("DetailTexture", 2D) = "white" {}
    7.      
    8.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    9.         _Metallic ("Metallic", Range(0,1)) = 0.0
    10.     }
    11.     SubShader {
    12.         Tags { "RenderType"="Opaque" }
    13.         LOD 200
    14.      
    15.         CGPROGRAM
    16.         #pragma surface surf Standard fullforwardshadows
    17.         #pragma target 3.0
    18.  
    19.         sampler2D _MainTex;
    20.         sampler2D _DetailTex;
    21.  
    22.         struct Input {
    23.             float2 uv_MainTex;
    24.             float2 uv3_DetailTex;
    25.         };
    26.  
    27.         half _Glossiness;
    28.         half _Metallic;
    29.         fixed4 _Color;
    30.  
    31.         void surf (Input IN, inout SurfaceOutputStandard o) {
    32.  
    33.             fixed4 c         = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    34.             fixed3 detail     = tex2D (_DetailTex, IN.uv3_DetailTex);
    35.          
    36.             o.Albedo = c.rgb * detail;
    37.  
    38.             o.Metallic = _Metallic;
    39.             o.Smoothness = _Glossiness;
    40.             o.Alpha = c.a;
    41.         }
    42.         ENDCG
    43.     }
    44.     FallBack "Diffuse"
    45. }
    46.  
    The result:



    so anyone knows how to use this?
     
    Last edited: Mar 16, 2015
  2. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    Ok here's what I found.
    Using UV2 works if you didn't check generate lightmap uv on fbx, but the the lightmap uv is not good.

    Using UV3 works when no lightmap is baked, when lightmap is backed the UV changes to I don't know what.

    Using UV4 works both in realtime and when baked, however you need to have 4 uv coords in 3dsmax to make it work.
     
    Last edited: Mar 16, 2015
    MagicZelda likes this.
  3. OskarSwierad

    OskarSwierad

    Joined:
    Dec 17, 2014
    Posts:
    25
    UV2 is baked lightmap. UV3 is Enlighten. Your issue is probably caused by Static Batching. You have to use UV4 for custom things. Yeah, I know, a late reply :D
     
  4. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    Yeah that's what I found out! thanks anyways! :D