Jump to content
  • Advertisement
Sign in to follow this  
codehunter13

pixel shader compile error

This topic is 4812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, it's the first time i use vertex and pixel shaders. I tried the shaders out of the minimal interface example in the file cgRuntime.chm from the CG language. The vertex shader compiles fine. But i get the following erros when compiling the pixelshader: D:\Program Files\NVIDIA Corporation\Cg\bin>cgc.exe SimpleDiffusePS.CG -entry Pix elShader -profile arbfp1 SimpleDiffusePS.CG SimpleDiffusePS.CG(18) : error C1101: ambiguous overloaded function reference "t ex2D" d:\bld\cg\rel1.4\src\cglang\stdlib\fp30_texture.cg(17) : arbfp1 float4 tex2D (sampler2D, float3) d:\bld\cg\rel1.4\src\cglang\stdlib\fp30_texture.cg(15) : arbfp1 float4 tex2D (sampler2D, float2) SimpleDiffusePS.CG(18) : error C1022: operands to "mul" must be numeric Here's the pixelshader(straight from the documention from CG):
struct Vert
{
    float4 pos  : POSITION;
    float4 dif  : COLOR0;
    float4 tex  : TEXCOORD0;
};

struct Pix
{
    float4 dif : COLOR0;
    float4 tex : TEXCOORD0;
};

Pix PixelShader(const Pix In, const uniform sampler BaseTexture, 
                const uniform float4 SomeColor)
{
  Pix Out;
  Out.dif = In.dif * tex2D(BaseTexture, In.tex) + SomeColor;
  return Out;
}



When i look into the CG toolkit.pdf i see there's only a tex2D function that takes a float3 or a float2. So is the example pixelshader which takes an float4 wrong?? thx in advance [Edited by - codehunter13 on September 13, 2005 9:37:08 AM]

Share this post


Link to post
Share on other sites
Advertisement
Yes.


Out of curiosity, seeing as how you're trying to output just the colour of a surface (with some simple lighting), have you asked yourself why you need a float4 texture coordinate?

Share this post


Link to post
Share on other sites
sorry that's a copy error of me. i actually have sampler2D.

when i change the "float4 tex : TEXCOORD0;" in "float3 tex : TEXCOORD0;" i get the following error:
SimpleDiffusePS.CG(14) : error C5109: variable "tex" domain conflicts with seman
tics "TEXCOORD"
20 lines, 1 errors.


[Edited by - codehunter13 on September 12, 2005 7:36:41 PM]

Share this post


Link to post
Share on other sites
Just write
In.dif * tex2D(BaseTexture, In.tex.xy) + SomeColor;
note the .xy at the end of In.tex

that should do it (that is because Cg supports an overloaded version of tex2D that uses a float3 as texcoord)

cheers
Janos

Share this post


Link to post
Share on other sites
Quote:

ust write
In.dif * tex2D(BaseTexture, In.tex.xy) + SomeColor;
note the .xy at the end of In.tex


i still get the error variable 'tex" conflicts with semantics "TEXCOORD" :(

Share this post


Link to post
Share on other sites
Hi,

I don't know CG at all, but I just saw "'tex" conflicts with semantics "TEXCOORD"" in your last reply : with don't you try to replace your "tex" variable with another name ? like "textureCoordinate". Maybe "tex" is a reserved word, or something else.

(I don't think that'll work, but who knows ... ^^)

Share this post


Link to post
Share on other sites
While this probably isn't it, could it be that you have used 'tex' in both structures? It really shouldn't cause a problem, but the error message suggests that it is a problem with 'tex', so it might be worth changing one of the instances to see if it fixes it.

Edit: doh - beaten to it, sort of...

Share this post


Link to post
Share on other sites
ive done the things you suggested but it didn't resolve anything.

it seems that the struct i return may not have a TEXCOORD0 element.
i made it like this and it compiles:


struct Vert
{
float4 pos : POSITION;
float4 tex : TEXCOORD0;
};

struct PixIn
{
float2 tex : TEXCOORD0;
float4 dif : COLOR0;
};

struct PixOut
{
float4 dif : COLOR0;
};

PixOut PixelShader(PixIn In, const uniform sampler2D BaseTexture)
{
PixOut Out;
Out.dif = In.dif * tex2D(BaseTexture, In.tex);
return Out;
}
[\source]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!