Results 1 to 2 of 2

Thread: eye coord to texture coord

  1. #1
    Member Contributor
    Join Date
    Jul 2018
    Posts
    63

    eye coord to texture coord

    Hi



    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?

    thanks

  2. #2
    Member Contributor Brokenmind's Avatar
    Join Date
    Feb 2014
    Location
    Aachen / Germany
    Posts
    78
    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ą!

Similar Threads

  1. COVERSION: world coord -> screen coord -> world coord
    By Albert85 in forum OpenGL: GLSL
    Replies: 8
    Last Post: 01-12-2015, 06:41 PM
  2. Compute eye space coord from window space coord?
    By karx11erx in forum OpenGL: Advanced Coding
    Replies: 55
    Last Post: 04-20-2011, 02:41 AM
  3. Texture coord to memory coord mapping
    By imported_Budric in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-27-2010, 06:02 PM
  4. Is there a way to calculate the 3d coord from screen coord?
    By Coconut_Crab in forum OpenGL: Advanced Coding
    Replies: 14
    Last Post: 12-23-2003, 02:13 AM
  5. Mouse coord to glScene coord
    By Lanstorp in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-20-2002, 02:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean