Archived

This topic is now archived and is closed to further replies.

DaJudge

Texture stage / sampler2D() binding problem

Recommended Posts

Hi all. How is a texture stage bound to the uniform inputs of a pixel shader? As far as I get it the order of the uniform decls in the pshader represent the texture stages... I use DX8 and Cg. If so, how can the following pshader change output if the texture stage 0 is changed?

struct v2f_simple  {
    float4 HPosition : POSITION;
    float2 TexCoord0 : TEXCOORD0;
    float2 TexCoord1 : TEXCOORD1;
    float4 Color0 : COLOR0;
};

fragout main(v2f_simple IN, 
               uniform sampler2D ShadowMap, 
               uniform sampler2D SpotLight) 
{
    fragout OUT;
    
    float4 temp = tex2D(ShadowMap);
    OUT.col = tex2D(SpotLight);
    
    return OUT;
}
  
Thanks, Alex

Share this post


Link to post
Share on other sites
mmhh.. don''t know with DirectX, but in OpenGl it would be something like:

cgGLSetTextureParameter(cgGetNamedParameter, cg_fragment_program_handle, "ShaowMap"), shadowmap_texture_id);

the function name should be pretty much the same for D3D... try looking in cgD3D.h (or something like that, for OpenGL it''s cgGL.h)
or just go download and read the CG programmer manual, it will be much better

Share this post


Link to post
Share on other sites
Now, let''s just assume I don''t use the Cg library for some reason and I have to bind the textures in the fragment program to numerically counted texture stages in the API? How does DirectX handle that texture binding?

Come on! Someone just HAS to know that!

Thanks,
Alex

Share this post


Link to post
Share on other sites
if you had taken time to have a look at the CG documentation, you woudn't have needed to create this "thread" in the first place...
is it too hard to download a pdf? or to look into the header file?

here is your function, as it is defined in the cg header file YOU already have... (cgD3D.h and cgD3D8.h)

CGD3D8DLL_API
HRESULT cgD3D8SetTexture(
CGparameter param,
IDirect3DBaseTexture8* tex
);

.......

probably using it like that:

cgD3D8SetTexture(cgGetNamedParameter(cg_fragment_program_handle, "param_name"), texture_pointer);

clicky

edit: for your last question... I don't know, but you probably don't need the answer any more, as you now know you've got a nice header file containing all the prototypes of the functions you seek... and that people took time to write a documentation for CG...

[edited by - sBibi on October 21, 2003 9:21:49 PM]

Share this post


Link to post
Share on other sites
Well, either it''s that dumb and nobody wants to answer my original question (in that case - shame on me) OR maybe it isn''t and nobody (including you sBibi ) could answer it until now...

Thanks for your answers sBibi and yes, I do make it a habit before posting something in the forums. I find those posts annoying myself.

Specifying my original question again (which was probably not clear enough in the first post - sorry about that):
Now, assuming I don''t use the Cg runtime library, how is a texture bound to a sampler2D in Cg / Dx8? Anyone?

Thanks,
Alex

Share this post


Link to post
Share on other sites
Even NVIDIA themselves use the SetTexture() function of DX8 in their shadow mapping sample! Yet I don''t fully grasp that OR I do have a serious problem! I have a fragmen program (see original posting) that uses 2 sampler2D parameters and I set two textures with SetTexture(). Then the fragment program uses the 2nd sampler (AND NOTHING ELSE) to generate the output color. Now, if samplers are bound to texture stage indexes by the order they appear in the declaration then that''d mean that changing the first texture stage doesn''t change a thing!
But it does!!!

Please help!

Thanks,
Alex

Share this post


Link to post
Share on other sites