Search Unity

TexGen EyeLinear

Discussion in 'Shaders' started by antenna-tree, Mar 26, 2007.

  1. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    I have a sneaking suspicion that I'm going to get quite annoying in the next couple of months asking a ton of questions here as I stubbornly try to learn creating custom Shaders :wink:

    I'm playing around with TexGen tonight trying to get a gradient texture to project across the entire screen (which I thought TexGen EyeLinear would do) but instead it projects the texture into a small fraction of the screen. Changing the Tiling kind of works to stretch the texture out to the size of the screen, but I'm not sure if this is the best method. Or if it is the best method what is the formula to stretch the texture out to the entire view frustum?
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    EyeLinear texture generation mode generates UVs in "camera space". So the texture still covers one meter, it's just oriented with camera.

    What you could do is: use EyeLinear like you do now, and additionally transform the UV with a matrix in the SetTexture command. The matrix would need to get from camera space into post-perspective space, then scale&bias to get into texture space. In short, the matrix should be like:
    Code (csharp):
    1. textureOffsetMatrix * camera.projectionMatrix
    where textureOffsetMatrix is
    Code (csharp):
    1.  
    2. 0.5   0   0 0.5
    3.   0 0.5   0 0.5
    4.   0   0 0.5 0.5
    5.   0   0   0   1
    6.  
    This texture offset matrix is needed just because post-perspective space goes from -1 to 1 on the screen, but if you want to cover it with a texture once it should go from 0 to 1. So what it does is scales by 0.5 and adds 0.5 to texture coordinates.
     
  3. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Thanks as always Aras. Your suggestions here and in this thread set me straight.