Search Unity

Question Shadergraph shader not working on imported FBX from Blender

Discussion in 'General Graphics' started by Jointy87, Nov 21, 2020.

  1. Jointy87

    Jointy87

    Joined:
    Dec 19, 2019
    Posts:
    21
    Hiya,

    I've made a simple tree in Blender and imported it as FBX to Unity. But when I try to apply a shader that I made, it doesn't work correctly. See gif:

    Shader_Bug_001.gif

    The shader lerps between 2 colors and I can set where in the model it lerps. As you can see, on a ProBuilder cube, made in unity, the lerping works fine. On the tree, it's either 1 color or the other. No lerping.

    I've come across a few old post that gave me some tips so I made sure to follow those. I've made sure to UV unwrap the globes in Blender according to a YouTube tutorial (I'm super new to Blender, as you may have noticed).

    This is what an unwrapped globe looks like:
    upload_2020-11-21_18-55-26.png

    I've also made sure my model scale inside Blender is 1 across the board.

    Beyond that, I couldn't find anything else online that would point me into the right direction of why this could be happening.

    Hope somebody can help me out on this :) Thanks!
     
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    You haven't said how you're lerping, but if the shader itself and the scaling is okay, my first assumption would be that the shader relies on specific vertex data (some use vertical component of UV for example), maybe the two meshes don't have the same channels or their data isn't what you're expecting. You could first confirm which channels are in each mesh by selecting them and looking in the Inspector. If a difference there isn't the problem, you'll need to inspect the meshes more closely. I don't know a built-in way to view per-vertex data without writing something, but the Preview in the Inspector has a dropdown for visualization of uvs, tangents, vertex color etc. - there's got to be a difference.

    Maybe try exporting a Cube from Blender the same way? That'll be easier to compare with the ProBuilder cube.
     
  3. Jointy87

    Jointy87

    Joined:
    Dec 19, 2019
    Posts:
    21
    Heya! Thanks for the reply

    To paint a better picture of the shader itself, this is the shader I'm using:
    upload_2020-11-21_20-11-49.png

    I've compared the mesh channels as you mentioned and they do indeed differ.

    The ProBuilder cube mesh vs the Blender sphere mesh:
    upload_2020-11-21_20-7-32.png upload_2020-11-21_20-25-0.png

    The Blender mesh doesn't seem to have a Color channel. Also Bounds size is not 1,1,1 (even though I exported all as 1, 1, 1?) So a few differences there. Good call!

    So then my next question is, could any of these difference be the culprit, and if so, how do I go about fixing this?

    In the meantime I'll do as you mentioned and make a simple cube in Blender and import it to unity and then check the tangents/normals in the inspecter visualization.

    Thanks so much!
     
  4. Jointy87

    Jointy87

    Joined:
    Dec 19, 2019
    Posts:
    21
    Ok, so the tangents differ as well:

    Pro builder cube mesh vs Blender sphere mesh tangents:
    upload_2020-11-21_20-35-48.png upload_2020-11-21_20-36-0.png

    The normals look pretty similar except for how a surface is split (upper right surface)

    Pro builder cube mesh vs Blender sphere mesh normals:
    upload_2020-11-21_20-37-27.png upload_2020-11-21_20-37-34.png

    I'm afraid my question remains as it did in my previous post: Could any of this be the culprit and if so, how do I go about fixing it? I'm new to 3D modeling and importing so all these things don't mean a lot to me yet. But any nudge in the right direction you could give me would be amazing and hopefully I can figure the rest out myself by means of google/tutorials.

    Thanks again!
     
  5. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    If your sphere and the cube are both visually the same size next to each other (roughly), and the bounds on the sphere are correct about only being 0.01-ish, the sphere must be scaled to about 100. So with object space in the shader you'd have to either multiply the spread and the min/max clamp values by 100, or multiply/divide something by the Scene->Object node scale. Or the bounds are incorrect, but I'm not sure that would affect the shading - either way if they are you can correct them by calling GetComponent<MeshFilter>().sharedMesh.RecalculateBounds() in Awake of an attached component to see.

    Edit: "multiply the spread and the min/max clamp values by 100" - probably meant divide, since you want to increase the difference. The culprit seems to be that according to the bounds, the mesh is 1/100 of the size it needs to be. Might start there?
     
  6. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    So in other words, the reason your color change is so quick, is because your minimum spread is 0.1 but your entire mesh is only 0.01.

    Edit: As for tangents - I can't help much there, I have issues with them as well :rolleyes: but from what I understand they are supposed to point in the positive direction of the u component of texture mapping (note it's been a while since I read up on that and could be confused, so do confirm it if you need to know). You can also call mesh.RecalculateTangents() to try fixing them if there's a noticeable issue.
     
    Last edited: Nov 21, 2020
  7. Jointy87

    Jointy87

    Joined:
    Dec 19, 2019
    Posts:
    21
    Thanks again for taking the time!

    As you figured, it was indeed a problem with the scaling (and for some reason, rotation too). After fiddling a bit with different scaling options and different 'what is forward, what is up' options in the Blender export settings I managed to get it working mostly the way I want it to. Good enough for now! Ha!

    Thanks so much for the help! Cheers!
     
    adamgolden likes this.
  8. pangpoi

    pangpoi

    Joined:
    Feb 20, 2019
    Posts:
    1
    I try to unwrap the UVs using cube projections, it’s work for me