Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How to affect normals and viewDir DX11 hull/domain

Discussion in 'Shaders' started by Phantomx, Jan 7, 2016.

  1. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    Hi,
    I made a DX11 shader with tessellation and displacement and I want the normals and the viewDir of the surface to be affected by the displacement.

    so I calculate my viewDir inside the domain shader but it doesn't work, I get the viewDir as if the mesh had no displacement at all.

    Domain Shader:
    Code (CSharp):
    1. [domain("tri")]
    2. v2f domain (OutputPatchConstant tessFactors, const OutputPatch<TessVertex,3> vi, float3 bary : SV_DomainLocation) {
    3.  
    4. appdata v = (appdata)0;
    5.  
    6. displacement(v);
    7.  
    8. v.vertex = vi[0].vertex*bary.x + vi[1].vertex*bary.y + vi[2].vertex*bary.z;
    9. v.normal = vi[0].normal*bary.x + vi[1].normal*bary.y + vi[2].normal*bary.z;
    10. v.tangent = vi[0].tangent*bary.x + vi[1].tangent*bary.y + vi[2].tangent*bary.z;
    11. v.texcoord = vi[0].texcoord*bary.x + vi[1].texcoord*bary.y + vi[2].texcoord*bary.z;
    12.  
    13. v2f o = vert(v);
    14.  
    15. TANGENT_SPACE_ROTATION;
    16. o.viewDir = mul(rotation, ObjSpaceViewDir(v.vertex));
    17. o.lightDir = mul(rotation, ObjSpaceLightDir(v.vertex));
    18.  
    19. return o;
    20. }
    Thanks!
     
unityunity