Search Unity

Access tSpace0, tSpace1 and tSpace2 in surf function

Discussion in 'Shaders' started by Blastom, Nov 22, 2017.

  1. Blastom

    Blastom

    Joined:
    Aug 13, 2013
    Posts:
    24
    Currently, I'm working on some kind of fake specular for baked terrain. I used a vector property as the light directon to bypass the baking.
    I need the rotation matrix from tangent space to world space or vise verse, to match the normal map (which is in tangent space) with the fake light (which is in world space).
    The common solution is pass the rotation matrix as 3 texcoord from vert to surf function. But I've run out of texcoord, which means I cannot pass anymore parameters.

    I've read the generated code of the surf shaders, it has the matrix saved in 3 parameters call tSpace0, tSpace1 and tSpace2. But I have no way to access them.
    Is there anyone has the idea to access them or use some other way to convert the normals from normal maps into world space?
    Many thanks.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
  3. Blastom

    Blastom

    Joined:
    Aug 13, 2013
    Posts:
    24
    That's it. Thanks a lot.
    I've already changed the meathod to get tangent space light direction and view direction in vertex function, which requires one less value to be passed and is faster.