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 5 of 5

Thread: Texture lookup into vertex and fragment shader with Cg

  1. #1
    Intern Contributor
    Join Date
    Jul 2004
    Location
    Weimar /Germany
    Posts
    59

    Texture lookup into vertex and fragment shader with Cg

    hi, I've got a problem when runnging a Cg (v1.4) vertex shader doing a texture lookup (32f, GL_NEAREST - runs HW-accelerated) and a fragment shader which is doing a lookup into another texture. It seems that the fragment shader does a lookup into the texture which was bound to the vertex shader.

    So my question:
    is it possible to do texture lookups into different textures in a vertex and fragment shader in one render pass?

    In my Cg code I didn't set the TEXUNITS for both textures (Cg doesn't require this) - I just bound the one textureid to the vertex, the other to the fragment shader. Does anyone know if it might work if I set the TEXUNITS? Or maybe with GLSL

    -AnselmG

  2. #2
    Senior Member OpenGL Pro cass's Avatar
    Join Date
    Feb 2000
    Location
    Austin, TX, USA
    Posts
    1,058

    Re: Texture lookup into vertex and fragment shader with Cg

    Hi AnselmG,

    Can you show us the shaders (vertex and fragment)?

    Thanks -
    Cass
    Cass Everitt -- cass@xyzw.us

  3. #3
    Intern Contributor
    Join Date
    Jul 2004
    Location
    Weimar /Germany
    Posts
    59

    Re: Texture lookup into vertex and fragment shader with Cg

    ok, I can give you more details:
    (my HW is a GF 6800 Ultra AGP, driver: 81.98)

    I need to do a 2D displacement for every pixel. therefore I render a GL_POINT at every pixel location with approprialte texture coordinates. then the vertex shader does a lookup into a texture GL_TEXTURE_2D NPOT with display res. this texture stores a new location for that point...the shader looks like this:

    vertout main (appin IN
    ,uniform sampler2D lookupTexture
    ){
    vertout OUT;
    float2 tc = IN.texcoord.xy;
    float2 offset = tex2D(lookupTexture, tc).xy;
    float4 newPos = float4(offset.xy, IN.position.zw);
    OUT.position = mul(glstate.matrix.mvp, newPos);
    OUT.texcoords = tc.xy;
    return OUT;
    }

    that works fine...in the fragment shader I now tried to apply an image texture onto that fragments:

    pixout main(vertout IN,
    uniform sampler2D image
    ) {

    pixout OUT;

    OUT.color = tex2D(image, IN.texcoords.xy);
    return OUT;
    }

    but that didn't work - the result was an image textured with the looup texture from the vertex shader. I did a workaround and used the fragment shader to encode the displaced texcoords into the RG channels and rendered this into and 32f FBO - doing the image lookup in another render pass...but well...this doesn't seem to be the most efficent way to me....

    thanks
    anselm

  4. #4
    Member Regular Contributor CrazyButcher's Avatar
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    402

    Re: Texture lookup into vertex and fragment shader with Cg

    my pick would be to do: "uniform sampler2D image : TEXUNIT1" and the other TEXUNIT0 for the vertexshader..

    you should add those : TEXUNITx things,else Cg doesnt know which texture you want to use... unless you use the cgruntime to the binding, which I never used so far, always bind with gl...

    maybe that does the trick, however I havent used any vertex texture fetches yet, so pure guessing here

  5. #5
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    The Round Table at Camelot
    Posts
    1,537

    Re: Texture lookup into vertex and fragment shader with Cg

    If you don't specify which texture unit a sampler is bound to (either in the shader or through the runtime), then the compiler will choose resources for you. Since you have a vertex and fragment shader (note they are separate shaders) the compiler is auto assigning TEXUNIT0 to the sampler in each shader.


    -SirKnight
    -SirKnight

Posting Permissions

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