Home Unity

Importing animated UVs

polycounter
Offline / Send Message
Mathew O polycounter
Hey guys, I was wondering if any of you knew a work around for importing animated UVs from Blender to unity?

Unity doesn't seem to import UV animation from FBX or .blend.

Thanks guys

Replies

  • gsokol
    Options
    Offline / Send Message
    Somebody can correct me if I'm wrong, but I don't believe there is a way to import UV animation.

    Your 2 best options are to either:

    A: animate your uvs in Unity's animation editor with tile offset or

    B: make/find a uv scrolling script. Here is a good starting place.

    I hope that helps.
  • Farfarer
    Options
    Offline / Send Message
    No, there is no way to import animated UVs into Unity.

    It's possible to script it, as gsokol mentioned.
  • Mathew O
    Options
    Offline / Send Message
    Mathew O polycounter
    Hmmm, thanks guys. What I need to do is to have the UVs expand from a small area of the UV space until it takes up the entirety of it.

    Do you recon that could be scripted? (By one of our programmers of course)
  • Mathew O
    Options
    Offline / Send Message
    Mathew O polycounter
    Here's an example of what I want to do :)

    H6omh.gif

    The green square being the UV island.
  • Farfarer
    Options
    Offline / Send Message
    Yes, that's possible via scripting.

    You'd want to look at the Mesh class http://docs.unity3d.com/Documentation/ScriptReference/Mesh.html

    Pull mesh.uv into a new array, edit them as you like, then pass the array back in to the mesh (you can't just edit them directly from mesh.uv, you have to feed it the entire array at once like mesh.uv = myEditedUVArray; ).

    Be careful with editing the mesh or the sharedMesh values. mesh is that specific instance of the mesh, sharedMesh will actually edit the source mesh and thus affect all versions of that mesh in your scene (and if you're working in the editor, it actually affects the mesh itself and will keep any changes you make until you reimport it into your project).

    EDIT: Or, as kio suggests below, edit the material's settings for offset and scale :)
  • kio
    Options
    Offline / Send Message
    kio polycounter lvl 15
    yeah that should be quite easy.

    just animate the offsert&scale value of the texture. ( maybe unity fbx import even supports that on a material level? )

    if you want to do it in code - this should get you started:
    http://docs.unity3d.com/Documentation/ScriptReference/Material.SetTextureOffset.html
    http://docs.unity3d.com/Documentation/ScriptReference/Material.SetTextureScale.html
  • Mathew O
    Options
    Offline / Send Message
    Mathew O polycounter
    You guys are both awesome, Thanks :D

    I managed to getting it working by animating the offset and scale like kio suggested, now all i need is for that animated node to work as the alpha for tiled diffuse but when i tile the diffuse the alpha tiles with it... even though it says 10x10 next to diffuse and still 1x1 next to the alpha. Recon I'd have to have two separate UV sets?
  • Farfarer
    Options
    Offline / Send Message
    Depends on the shader code. I'm guessing it's custom 'cause the built-in stuff doesn't have a separate alpha.

    Probably it's using the same offset settings as the diffuse at the moment. Worth checking that the alpha and diffuse aren't sampling using the same lookup uv (generated inside the shader by altering the uv coords by the offset/scale of a given texture).
  • Mathew O
    Options
    Offline / Send Message
    Mathew O polycounter
    SO you're totally right, it's using the same UV lookup. Here be my shader:

    .........................................
    Shader "Transparent/Diffuse + Extra Alpha"
    {
    Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    _AlphaMap ("Additional Alpha Map (Greyscale)", 2D) = "white" {}
    }

    SubShader {
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    LOD 200

    CGPROGRAM
    #pragma surface surf Lambert alpha

    sampler2D _MainTex;
    sampler2D _AlphaMap;
    float4 _Color;

    struct Input {
    float2 uv_MainTex;
    };

    void surf (Input IN, inout SurfaceOutput o) {
    half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    o.Albedo = c.rgb;
    o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_MainTex).r;
    }
    ENDCG
    }

    Fallback "Transparent/VertexLit"
    }
    .........................................

    However when I changed it to this:

    .........................................
    Shader "Transparent/Diffuse + Extra Alpha"
    {
    Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    _AlphaMap ("Additional Alpha Map (Greyscale)", 2D) = "white" {}
    }

    SubShader {
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    LOD 200

    CGPROGRAM
    #pragma surface surf Lambert alpha

    sampler2D _MainTex;
    sampler2D _AlphaMap;
    float4 _Color;

    struct Input {
    float2 uv_MainTex;
    float2 uv_Alpha;
    };

    void surf (Input IN, inout SurfaceOutput o) {
    half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    o.Albedo = c.rgb;
    o.Alpha = c.a * tex2D(_AlphaMap, IN.uv_Alpha).r;
    }
    ENDCG
    }

    Fallback "Transparent/VertexLit"
    }
    .........................................

    That broke it :P Can you tell i'm no coder? :P
  • Farfarer
    Options
    Offline / Send Message
    Ah, you're almost right, but it needs to be uv_AlphaMap

    It shares the same name as the texture property you're after the settings for, which is _AlphaMap in this case :)
  • Mathew O
    Options
    Offline / Send Message
    Mathew O polycounter
    AH that worked! :D I owe you a beer James ;)
Sign In or Register to comment.