Search Unity

Problem passing tangent value to shader. Not stable.

Discussion in 'Shaders' started by tsangwailam, Jul 22, 2016.

  1. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    Hello,

    I am making a shader which need to pass some calculated value to the shader. I am using mesh.tangents to pass the value and the value is set at the Awake() methods. It should not be changed afterward.

    Then shader is assigned to a object. The object is animated by script and continue rotating.

    But i found that the assigned target value is not stable in the shader, it sometime changed when running.

    My input structure is like below.
    Code (CSharp):
    1.             // Input stucture
    2.             struct appdata
    3.             {
    4.                 float4 tangent : TANGENT;
    5.                 float4 vertex : POSITION;
    6.                 float3 normal : NORMAL;
    7.             };
    Any idea why the input tangent value is not stable?

    P.S. I also try using uv for passing the value but same.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,336
    What kind of value are you passing? If it's a object relative position it might be your objects are getting dynamically batched making the position you're passing no longer accurate. Try passing a world space position instead, or disable batching on your shader.
    Tags{ "DisableBatching"="True" }
     
  3. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    I try to calculate a dedicated uv value for the mesh. The value should not be changed.

    And i found that the problem only occur for blender imported model. Seem not problem on other model.