Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: changing vertex location in vertex shader

Hybrid View

  1. #1
    Newbie Newbie
    Join Date
    Dec 2012
    Posts
    1

    changing vertex location in vertex shader

    Hey

    I have a set of vertex locations (x,y) in an FBO/texture. I am trying to use a vertex shader which sets gl_Position to a given vertex. It sort of works, the problem is what should be randomly located points end up with a circular pattern

    These are the input points:



    This is the shader output:



    This is the shader code:

    Code :
    #version 120
    #extension GL_ARB_texture_rectangle : enable
     
    uniform sampler2DRect partloc;
     
    void main(void)
    {
        vec2 loc = gl_Vertex.xy;
        vec4 pixpos = texture2DRect(partloc, loc);
        gl_Position = gl_ModelViewProjectionMatrix * pixpos;
        gl_FrontColor = vec4(1.0);
    }

    Yes I am using GLSL 1.2, the app itself uses openFrameworks and the main bits of code are here: http://pastebin.com/wcUr17xZ. I am rendering to an FBO, and the texture it is reading from also comes from an FBO. I have checked the points themselves are ok by a) keeping a copy of the points and drawing them with:

    Code :
                glEnableClientState(GL_VERTEX_ARRAY);
                glVertexPointer(3, GL_FLOAT, 0, pos);
                glDrawArrays(GL_POINTS, 0, numParticles);
                glDisableClientState(GL_VERTEX_ARRAY)

    And also by going through the location texture and drawing points at the locations it contains. Both of them give the random pattern, so it seems like something is up with the shader.

    I feel like I am missing something, or something is being transformed when it should be, but I have no idea what. I am still relatively new to OpenGL & shaders.

    Thanks

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213
    Sure looks like you're managing to change the distribution from a box to being distributed throughout a sphere.

    Don't know for sure, but a couple of ideas for you to look at. First, I see your pulling your position from a texture. You're using all 4 components retrieved from the texture for transformation in your shader, though I think the texture itself only has 3 (with Z = 0). You may be getting an implicit w=1 here, but I'd stop using what you're not populating when you're using a texture for data like this.

    Also, I see you transforming your position by gl_ModelViewProjectionMatrix. I'd make sure 1) that your PROJECTION transform is orthographic, not perspective (i.e. set with glOrtho), and 2) that your MODELVIEW is set such that it's looking at the XY plane face-on (since it looks like all your data is in the XY plane). Or for testing, just stop using gl_ModelViewProjectionMatrix in the shader and place your data in clip space directly. For instance, set gl_Position.xy in (-1,-1)..(1,1), .z = 0, .w = 1.

    Keep playing with it -- you'll figure it out.

Posting Permissions

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