Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Problem using tex1D in CG fragment shader Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Cygnus

March 02, 2005, 10:19 AM

Hi!

I'm having a problem using textures in my fragment shader. This is my fragment shader :

  1.  
  2. struct vertexOutput {
  3.         float4 HPosition : POSITION;
  4.         float2 TexCoord : TEXCOORD0;
  5.         float3 Normal : TEXCOORD1;
  6. };
  7.  
  8. struct PixelOut {
  9.         float4 Color : COLOR;
  10. };
  11.  
  12. PixelOut main(vertexOutput IN, uniform sampler1D gaussianTex)
  13. {
  14.         PixelOut OUT;
  15.         float index = ...; // calculate offset between 0.0 and 1.0, this works correctly
  16.         if (dz <= 1.0f)
  17.         {
  18.                 OUT.Color = float4(1.0f,0.0f,0.0f,1.0f); // give red color
  19.                 OUT.Color.w = tex1D(gaussianTex,index); // <- the problem, always returns 0.0
  20.         }
  21.         else
  22.                 OUT.Color = float4(0.0f,0.0f,1.0f,1.0f); // draw blue contour
  23.        
  24.         return OUT;
  25. }


And my c++-code :
  1.  
  2. // initialisation part :
  3. {
  4.         m_pSplatTexture = new CSplatTexture(); // my simple texture-class, which works
  5.         m_pSplatTexture->loadTARFile("gauss.tga");
  6.         // ...
  7.         m_cgFragmentProg = cgCreateProgramFromFile(m_cgContext, CG_SOURCE, "../cg/fragment.cg", m_cgFragmentProfile, "main", NULL);
  8.         // ...
  9.         cgGLLoadProgram(m_cgFragmentProg);
  10.         CGparameter param = cgGetNamedProgramParameter(m_cgFragmentProg, CG_PROGRAM, "gaussianTex");
  11.         cgGLSetTextureParameter(param,m_pSplatTexture->getID());
  12. }
  13.  
  14. // during rendering :
  15. {
  16.         cgGLBindProgram( m_cgFragmentProg );
  17.         cgGLEnableProfile( m_cgFragmentProfile );
  18.         cgGLEnableTextureParameter(cgGetNamedProgramParameter(m_cgFragmentProg, CG_PROGRAM, "gaussianTex"));
  19.  
  20.         // render
  21.  
  22.         cgGLDisableProfile( m_cgFragmentProfile );
  23. }
  24.  


The problem is that the tex1D()-function always returns 0.0f, instead of the value that I want.

My tga-texture is a 32x1-texture that goes from 0 tot 255 by a gaussian function. I tried using it on a simple quad in c++/opengl and it works, so I don't think that's causing the problem.

The shader and cg itself are initialised correctly, because I can see the blue contour of the quad/sprite.

I tried a lot of things and now I'm desperate :)
I hope someone can help, any help is very much appreciated!

 
Reedbeta

March 02, 2005, 02:58 PM

Hmm....usually, when I have had problems with samplers returning 0, it is because the texture is not set up correctly, for instance mipmapping is enabled but not all mipmap levels are loaded. Check to see if something like this could be happening.

 
gjaegy

March 03, 2005, 03:37 AM

is your texture declared as GL_TEXTURE_2D or GL_TEXTURE_1D? in the first case the tex1D function won't work. you can use tex2D(tex,u,0) instead.

in the second case, your parameter may not be bind correctly. try to set it each time you bind the shader (each render loop)...

 
Cygnus

March 03, 2005, 05:19 AM

Thanks for your replies, Reedbeta & gjaegy!

gjaegy : Your comment helped me a lot, I'm now using tex2D(tex,float2(u,0)) and it works! :D

 
This thread contains 4 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.