Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: eye coord to texture coord

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Intern Contributor
    Join Date
    Oct 2012

    eye coord to texture coord


    I have seen some examples where when trying to convert a point in eye coordinate to normalized tecture coordinate space (between 0 and 1) from within the fragment shader , the fllowing formula is applied.

    Code :
    float2 texc = ((IN.Pos.xy / IN.Pos.w) + 1) / 2;

    Note: IN.Pos is the modelviewprojected position.This calulation gives us the fragments screen position in the interval between [0,1]

    Why is the following true?


  2. #2
    Intern Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Aachen / Germany
    The modelviewprojected vector needs to have its w set to 1. After a projection, this w is usually something different, as well as the xyz part, and dividing this by w sort of normalises the vector.

    The rest is the same as if you wanted to transform the normal viewport to texture coordinates:
    A vector from the (-1, -1 .. 1, 1) space needs to be transformed to correspond the texture space (0, 0 .. 1, 1).
    First, (-1, -1 .. 1, 1) gets added 1 which results in (0, 0 .. 2, 2) and then divided by 2 which gets you (0, 0 .. 1, 1). Voilą!
    Last edited by Brokenmind; 04-16-2014 at 01:34 PM. Reason: typo

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts