Archived

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

DaJudge

PS: tex2d() with just 1 param???

Recommended Posts

Hi all, The following is a pixel shader taken from the NVSDK sample "Hardware Shadowmapping in Cg":
struct v2f_simple  {
    float4 HPosition : POSITION;
    float4 TexCoord0 : TEXCOORD0;
    float4 TexCoord1 : TEXCOORD1;
    float4 Color0 : COLOR0;
};

fragout main(v2f_simple IN, 
               uniform sampler2D ShadowMap, 
               uniform sampler2D SpotLight) 
{
    fragout OUT;
    
    float4 shadow    = tex2D(ShadowMap);
    float4 spotlight = tex2D(SpotLight);
    float4 lighting  = IN.Color0;
    
    OUT.col = spotlight * shadow * lighting;
    
    return OUT;
}
 
What I am actually pretty confused about is the fact that it uses only ONE parameter to the tex2D() calls. I looked up in the Cg users manual and there is absolutely no prototype specified for a function tex2D() with only one parameter... Now, maybe anyone of you can explain that to me? Slowly it appears to me that pixel shaders are a hell of a lot more complicated than I thought (syntax-wise)... Thanks, Alex

Share this post


Link to post
Share on other sites
Think about it. ShadowMap and SpotLight are 2d-samplers. tex2D fetches the current texel from such things as them. Or so I would guess.. I don''t really know anything about this...

Share this post


Link to post
Share on other sites
My problem is that all the other overloaded versions of tex2D() take UV coordinates as parameters (basically) which is perfectly logical for a texture-lookup. However, this call doesn''t do so, so which texel does it return?

Share this post


Link to post
Share on other sites
looks like this is code for ps1.1 or something, where texcoordunits and texturesampling units where united..




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites
Okay, so here goes the more detailed problem explanation:
my simple question is which texel a call like this will actually return. where does it take the required UV-coords?

Thanks,
Alex

Share this post


Link to post
Share on other sites
as i said. if you sample from texsampleunit1 it will use texcoord1, etc.. this is true for ps1.1 and such, as there you could not specify your own texcoords as you wanted, but you had to just set texcoord0 to sample from texture0, texcoord1 for texture1, etc..

and thats exactly the coords that get used.. just map sampler units and coord units together and you know the answer..




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites
Now that''s exactly what I wanted to know. Thanks!
Yet I don''t understand why I can''t find that in the Cg users manual. Makes me wonder how many more of this undocumented (or just hard to find) caveats are bound to pixel shaders.

Thanks again...

Alex

Share this post


Link to post
Share on other sites
my opinion: forget about cg.. but its your choise




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites
its proprietary nvidia nv30 hyping marketing shit from last year.. they drop support from it bit by bit each month till it died out.




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites
quote:
Original post by davepermen
its proprietary nvidia nv30 hyping marketing shit from last year.. they drop support from it bit by bit each month till it died out.




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net


and what other alternatives do you suggest that give you the speed of development of CG and its ease of use/simplicity?

Share this post


Link to post
Share on other sites
haven''t had myself problems working with ARB_fp.. asm style is no problem, and it has all the other high level constructs of c (namely, variables with names:D)

but for the sake of coolness to have c-style shaders, i''ll suggest glslang (its there, just not enabled in the drivers), or hlsl, depending on the api.




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites
get cg 1.1, it has explicit texcoord passing for ps1.x (but still makes sure you don''t use inappropriate texcoords for a texunit).

Share this post


Link to post
Share on other sites