Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: gl_nv_texture_shader help

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2002
    Posts
    101

    gl_nv_texture_shader help

    Hi all,

    I've been playing around with the nVidia texture shader extension now for about a month. I'm running into a problem when

    using the GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV (aka. the diffuse shader) with the GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV (aka. the

    reflect) shader. According to the info that I've read at nVidia's public developer's website, the diffuse shader is supposed

    to act the same as the GL_DOT_PRODUCT_TEXTURE_CUBE_MAP_NV (aka. the cube) shader. What happens is that I can get the plain

    reflect shader to work and produce the same reflection with a flat colored bump map as if I were running the cubemap texgen

    routines. So I know that I've got that one running right. If I use the cube shader itself, it accurately maps my objects just

    the way I want it. Yet when I run the reflection-diffuse shaders together, I get strange results. I'm currently running a

    GF2MX/400 w/ NV20Emulate, not doing anything with the register combiners, and have no idea why this isn't working. If you

    think you may know what is wrong and want to see a screenshot of what is happening, email me and I will send you one. My

    basic setup code is below.

    //rm := RenderMode
    **somegeometryclass**: rawGL(GLuint rm) {
    if(rm>=RM_BUMP_ENVIRONMENT) {
    if((nrmtex->GetTexNumber()==0)| |(envtex->GetTexNumber()==0)) {
    return;
    }
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glBindTexture(GL_TEXTURE_2D,nrmtex->GetTexNumber());
    glActiveTextureARB(GL_TEXTURE3_ARB);
    glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,envtex->GetTexNumber());
    glVertexAttribPointerNV(0,3,GL_DOUBLE,0,vtxpts);
    glVertexAttribPointerNV(8,2,GL_DOUBLE,0,texpts);
    glVertexAttribPointerNV(9,3,GL_DOUBLE,0,tanpts);
    glVertexAttribPointerNV(10,3,GL_DOUBLE,0,binpts);
    glVertexAttribPointerNV(11,3,GL_DOUBLE,0,nrmpts);
    }
    if(rm&RM_DIFFUSE_BUMP_ENVIRONMENT) {
    if(lighttex->GetTexNumber()==0) {
    return;
    }
    glActiveTextureARB(GL_TEXTURE2_ARB);
    glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,lighttex->GetTexNumber());
    }
    //loops to draw geometry here!
    }

    ...

    //rm := RenderMode
    void ConfigRender(GLuint rm) {
    for(unsigned int i=0;i<4;i=i+1) {
    glActiveTextureARB(GL_TEXTURE3_ARB-j);
    glClientActiveTextureARB(GL_TEXTURE3_ARB-j);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_TEXTURE_CUBE_MAP_ARB);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);
    //BUG!!! weird problems happen when disabling tex_gen_r
    //glDisable(GL_TEXTURE_GEN_R);
    glDisable(GL_TEXTURE_GEN_Q);
    }
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    for(j=0;j<16;j=j+1) {
    glDisableClientState(GL_VERTEX_ATTRIB_ARRAY15_NV-j);
    }
    glDisable(GL_VERTEX_PROGRAM_NV);
    glDisable(GL_TEXTURE_SHADER_NV);
    if(rm==RM_NONE) {
    return;
    }
    if(rm&RM_WIREFRAME) {
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    glDisable(GL_CULL_FACE);
    }
    if(rm>=RM_BUMP_ENVIRONMENT) {
    glEnable(GL_VERTEX_PROGRAM_NV);
    glEnable(GL_TEXTURE_SHADER_NV);
    glBindProgramNV(GL_VERTEX_PROGRAM_NV,vp_num);
    glEnable(GL_TEXTURE_2D);
    //turn on vertex program attrib arrays for...
    // attrib_array0 ~ vertex array
    // attrib_array8 ~ tex0 tex coord array ~ normal map coord
    // attrib_array9 ~ tex1 tex coord array ~ surface tangent
    // attrib_array10 ~ tex2 tex coord array ~ surface binormal
    // attrib_array11 ~ tex3 tex coord array ~ surface normal
    glEnableClientState(GL_VERTEX_ATTRIB_ARRAY0_NV);
    glEnableClientState(GL_VERTEX_ATTRIB_ARRAY8_NV);
    glEnableClientState(GL_VERTEX_ATTRIB_ARRAY9_NV);
    glEnableClientState(GL_VERTEX_ATTRIB_ARRAY10_NV);
    glEnableClientState(GL_VERTEX_ATTRIB_ARRAY11_NV);
    //c[0-3] ~ projection * modelview, row major
    //c[4-7] ~ modelview, row major
    //c[8-11] ~ modelview, column major
    //c[12-15] ~ modelview-inverse, row major
    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV,0,GL_MODELVIE W_PROJECTION_NV,
    GL_IDENTITY_NV);
    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV,4,GL_MODELVIE W,
    GL_IDENTITY_NV);
    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV,8,GL_MODELVIE W,
    GL_TRANSPOSE_NV);
    glTrackMatrixNV(GL_VERTEX_PROGRAM_NV,12,GL_MODELVI EW,
    GL_INVERSE_NV);
    //c[16-19] ~ cubemap rotation matrix
    glProgramParameters4dvNV(GL_VERTEX_PROGRAM_NV,16,4 ,cuberot.dData);
    //constants {-1,0,1,2}
    glProgramParameter4dNV(GL_VERTEX_PROGRAM_NV,32,-1.0,0.0,1.0,2.0);
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_NO NE);
    glTexEnvi(GL_TEXTURE_SHADER_NV,GL_SHADER_OPERATION _NV,
    GL_TEXTURE_2D);
    glActiveTextureARB(GL_TEXTURE1_ARB);
    glTexEnvi(GL_TEXTURE_SHADER_NV,
    GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV,GL_EXPAND_ NORMAL_NV);
    glTexEnvi(GL_TEXTURE_SHADER_NV,GL_PREVIOUS_TEXTURE _INPUT_NV,
    GL_TEXTURE0_ARB);
    glTexEnvi(GL_TEXTURE_SHADER_NV,GL_SHADER_OPERATION _NV,
    GL_DOT_PRODUCT_NV);
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_NO NE);
    glActiveTextureARB(GL_TEXTURE2_ARB);
    if(rm&RM_DIFFUSE_BUMP_ENVIRONMENT) {
    glEnable(GL_TEXTURE_CUBE_MAP_ARB);
    glTexEnvi(GL_TEXTURE_SHADER_NV,GL_SHADER_OPERATION _NV,
    GL_DOT_PRODUCT_DIFFUSE_CUBE_MAP_NV);
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE);
    } else {
    glTexEnvi(GL_TEXTURE_SHADER_NV,GL_SHADER_OPERATION _NV,
    GL_DOT_PRODUCT_NV);
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_NO NE);
    }
    glTexEnvi(GL_TEXTURE_SHADER_NV,
    GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV,GL_EXPAND_ NORMAL_NV);
    glTexEnvi(GL_TEXTURE_SHADER_NV,GL_PREVIOUS_TEXTURE _INPUT_NV,
    GL_TEXTURE0_ARB);
    glActiveTextureARB(GL_TEXTURE3_ARB);
    glEnable(GL_TEXTURE_CUBE_MAP_ARB);
    glTexEnvi(GL_TEXTURE_SHADER_NV,
    GL_RGBA_UNSIGNED_DOT_PRODUCT_MAPPING_NV,GL_EXPAND_ NORMAL_NV);
    glTexEnvi(GL_TEXTURE_SHADER_NV,GL_PREVIOUS_TEXTURE _INPUT_NV,
    GL_TEXTURE0_ARB);
    glTexEnvi(GL_TEXTURE_SHADER_NV,GL_SHADER_OPERATION _NV,
    GL_DOT_PRODUCT_REFLECT_CUBE_MAP_NV);
    if(rm&RM_DIFFUSE_BUMP_ENVIRONMENT) {
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MO DULATE);
    } else {
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE);
    }
    }
    }

    ...

    //rm := RenderMode
    **someobjectclass**: rawGL(GLuint rm) {
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    //object translation & rotation here
    //vertex program update values code here
    glExecuteProgramNV(GL_VERTEX_STATE_PROGRAM_NV,vsp_ num,junkfloatptr);
    for(unsigned int i=0;i<itemcount;i=i+1) {
    **somegeometryclassarray**[i].DrawGL(rm);
    }
    glPopMatrix();
    }

    ...

    //main draw loop
    void DrawGL(void) {
    //typical stuff like clear and perspective setup here!
    glPushAttrib(GL_ALL_ATTRIB_BITS);
    glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
    ConfigRender(RenderMode);
    for(unsigned int i=0;i<objcount;i=i+1) {
    **someobjectclassarray**[i].DrawGL(RenderMode);
    }
    glPopClientAttrib();
    glPopAttrib();
    }


    It's 4am, I better take a quick nap before I go to work.

  2. #2
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: gl_nv_texture_shader help

    I can't see the wood for the trees, if you see what I mean.
    nvparse script would be a lot easier to read (and program) - except for davep, who seems to like reading stuff set up with the original interface

    Sorry I can't help.
    Knackered

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: gl_nv_texture_shader help

    well i did not read it, too much trees as knacky said..

    but i'll take a look
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: gl_nv_texture_shader help

    for(unsigned int i=0;i<4;i=i+1) {
    glActiveTextureARB(GL_TEXTURE3_ARB-j);
    glClientActiveTextureARB(GL_TEXTURE3_ARB-j);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_TEXTURE_CUBE_MAP_ARB);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);
    //BUG!!! weird problems happen when disabling tex_gen_r
    //glDisable(GL_TEXTURE_GEN_R);
    glDisable(GL_TEXTURE_GEN_Q);
    }

    u use i in the loop but j in the code.. hum?

    how does your light-cube-map looks like?
    it should be a nice cubemap with only (1,1,1) in, so you then should see the same reflection as before..
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  5. #5
    Junior Member Regular Contributor
    Join Date
    Apr 2002
    Posts
    101

    Re: gl_nv_texture_shader help

    The i and j thing are because I was reformatting some of the code in notepad before I pasted it in, as you can tell, the pasting didn't go so well...

    But I do use j consistantly throughout the loop. You got an e-mail address that I can send you a couple of snapshots of what's going wrong?

    Dan

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: gl_nv_texture_shader help

    well.. they do look funny, the pics..not if you don't want them, but for me they look funny

    hum.. i can't see anything wrong in your code so far, and as far as i know, it should work.. but nontheless i'm not sure, so i hope any one else could check through it as well..

    and u use for sure always the completely same vertexprogram for setting the tangentspace-matrices in all the settings.. i guess so

    i just have to add i don't have a geforce3 yet so i'm not trained in texture_shaders at all, never touched them (except one time testing pass_trough with software-emulator at least, i got it working )

    ... i'll contact some other guys who possibly know some help, dunno yet..
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Aug 2000
    Location
    Portsmouth, Hampshire, England
    Posts
    1,063

    Re: gl_nv_texture_shader help

    Can you send me a small app, at nutty@nutty.org I wouldn't assume that NV20 emulation is gonna be perfect. I'll test it on my GF4 for you, to see if it shows the same problem.

    Thanks,
    Nutty

  8. #8
    Junior Member Regular Contributor
    Join Date
    Apr 2002
    Posts
    101

    Re: gl_nv_texture_shader help

    Thanks for your time anyways Dave. I willing to venture the guess that it's a problem with the emulation, but I've sworn that so many problems that I've run into in the past have been problems because of the emulation and they weren't. If you notice in my code above, I commented out where I disable tex_gen_r. That's because if I call that function at all, I cannot render anything having a texture bound of type TEXTURE_2D. I don't ask the questions, I just follow the rules. Also, I ran a problem when first running vertex programs in that the matrices that I tracked ended up being the matrices that should have been used from the previous frame. I actually have to call glGetProgramParameterdvNV(...) for any one of the parameter fields that maps into a tracked matrix. Of course, maybe that needs to happen and I'm just not aware of it, but I had assumed that the matrices were available at all times and that you didn't need to query them before you executed a program that needed them. And yes, all those shots use the same vertex state and vertex programs, so that's not it either...

    Nutty, I'm at school at the moment, I'll be heading home in about 20 minutes, and I live about 45 minutes away, oh joy. I have my executable and my texturemaps here, but we don't have any PC's on campus that have NV15 class cards, atleast none that I know of. So I'll wait till I get home to send you those pictures as well. BTW, that new demo you got going looks pretty cool!

    Dan

  9. #9
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: gl_nv_texture_shader help

    he has the pics yet.. i contacted him..

    yeah, his demo is cool..
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  10. #10
    Junior Member Regular Contributor
    Join Date
    Apr 2002
    Posts
    101

    Re: gl_nv_texture_shader help

    Thanks to Nutty's help (and his GF4), we've determined this to be a problem with the NV20 emulation. Now I might be able to sleep good at night (for a little while at least).

    Dan

Posting Permissions

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