Results 1 to 2 of 2

Thread: Compute ray direction

  1. #1
    Member Contributor
    Join Date
    Mar 2014
    Posts
    59

    Compute ray direction

    Hi all,

    I need to compute primary ray direction in fragment shader. I do this like that :
    - compute the 4 ndc cornners of near plane
    Code :
        vec3 hg = (invV*vec4(-1, 1,-1,1)).xyz;
        vec3 bg = (invV*vec4(-1,-1,-1,1)).xyz;
        vec3 hd = (invV*vec4( 1, 1,-1,1)).xyz;
        vec3 bd = (invV*vec4( 1,-1,-1,1)).xyz;
    - put uv between [-1,1]
    Code :
        vec2 uv = 0.5*(vec2(-1)+2*texCoord.xy);
    - compute the position of a pixel on near plane
    Code :
     vec3 pt = mix(mix(bg,bd,texCoord.x),mix(hg,hd,texCoord.x),texCoord.y);
    - at last compute the ray direction
    Code :
        vec3 dir  = normalize(pt-camPos.xyz);
        vec3 orig = camPos.xyz;

    Am i right?

  2. #2
    Member Contributor
    Join Date
    Nov 2016
    Posts
    67
    You can do it simpler :

    Code :
    vec3 pt = (invV*vec4(uv,-1,1)).xyz;

Similar Threads

  1. Replies: 3
    Last Post: 05-03-2018, 03:52 PM
  2. Compute fragment's ray direction (world's coordinates)
    By prunkdump in forum OpenGL: GLSL
    Replies: 1
    Last Post: 09-17-2012, 06:41 AM
  3. Light with a direction
    By joejoe in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-16-2010, 03:05 AM
  4. 3D Rotation in every direction
    By tito_h in forum OpenGL: General
    Replies: 3
    Last Post: 06-25-2009, 09:47 AM
  5. Direction of axes.
    By Sergei in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 11-09-2000, 02:24 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