Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  3D texture problem  (Read 1187 times)
0 Members and 1 Guest are viewing this topic.
Offline magiccat

Senior Newbie





« Posted 2007-02-08 16:49:15 »

I have a Nvidia GeForce 6800 GS graphics card with 256 MB.   My 3D application uses the following code to set up 3D texture units and uniform variables for use in the Cg fragment shader.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// texture setup in the application
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
    gl.glGenTextures(1, temp1, 0);
    TextureID = temp1[0];
    gl.glBindTexture(GL.GL_TEXTURE_3D, TextureID);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);

// Generate normals
    gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
    gl.glGenTextures(1, temp16, 0);
    normal_ID = temp16[0];
    gl.glBindTexture(GL.GL_TEXTURE_3D, normal_ID);
    // gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);

   // setup Cg parameters
    Texture_Param = CgGL.cgGetNamedParameter(fProgram, "Texture");
    normal_Param = CgGL.cgGetNamedParameter(fProgram,"normals");
    CgGL.cgGLSetTextureParameter(Texture_Param, TextureID);
    CgGL.cgGLSetTextureParameter(normal_Param, normal_ID);
    CgGL.cgGLEnableTextureParameter(Texture_Param);
    CgGL.cgGLEnableTextureParameter(normal_Param);

--------------------------------------------------------------------------------------------------------------------------------------------------------
   // in Display()
 FloatBuffer volumeBuf = FloatBuffer.wrap(volumeBuffer);
      volumeBuf.rewind();
      gl.glActiveTexture(GL.GL_TEXTURE0);
      gl.glEnable(GL.GL_TEXTURE_3D);
      gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_OBJECT_LINEAR);
      gl.glBindTexture(GL.GL_TEXTURE_3D, TextureID);
      gl.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_RGBA, iWidth, iHeight, iDepth,
                      0, GL.GL_RGBA, GL.GL_FLOAT, volumeBuf);


     FloatBuffer normal_buf = FloatBuffer.wrap(normals);
     normal_buf.rewind();
     gl.glActiveTexture(GL.GL_TEXTURE1);
     gl.glEnable(GL.GL_TEXTURE_3D);
     gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_OBJECT_LINEAR);
     gl.glBindTexture(GL.GL_TEXTURE_3D, normal_ID);
     gl.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_RGB, iWidth, iHeight, iDepth,
                     0, GL.GL_RGB, GL.GL_FLOAT, normal_buf);

-------------------------------------------------------------------------------------------------------------------------------------------------

void FragmentProgram(in float4 inTex : TEXCOORD0, out float4 oColor : COLOR0,
                                            uniform sampler3D Texture,
                                  uniform sampler3D normals) {

  //get normal
  float3 normal;
  normal.rgb = tex3Dproj(normals, inTex).rgb;
 
 // Color look up
  float4 result;
  result.rgba =  tex3Dproj(USTexture, inTex).rgba;
             
 ..... ...... // calculate the lighting.

  oColor = result * light;

}

If I switch the order of normal and texture calculation in fragment program, i.e.

oid FragmentProgram(in float4 inTex : TEXCOORD0, out float4 oColor : COLOR0,
                                            uniform sampler3D Texture,
                                  uniform sampler3D normals) {

 // Color look up
  float4 result;
  result.rgba =  tex3Dproj(USTexture, inTex).rgba;
             
  //get normal
  float3 normal;
  normal.rgb = tex3Dproj(normals, inTex).rgb;
 
 ..... ...... // calculate th light.

  oColor = result * light;

}

The final volume image color changed quite a lot.   It turns to be an error.    Does anyone have the slightest clue about what could be the reason for such behavior?       Can Jogl correctly handle 3D texture sampler?   Or this due to my card issue? Or my OpenGL code doesn't setup 3D texture appropriately?

Thanks.   
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #1 - Posted 2007-02-08 17:05:07 »

Do you have a complete test case available?

You may get better answers by posting on NVidia's developer forums since this is a Cg-specific question.
Offline magiccat

Senior Newbie





« Reply #2 - Posted 2007-02-08 17:53:17 »

Ken,

I do have the whole application.  However, I can't give it to public.

I suspect the gl.glActiveTexture() primitive.   In general, do you think my Jogl part setup is correct? 
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (26 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (34 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!