Skip to main content
GameDev.net gamedev.net
🔒 Locked

pixel shader compile error

Started by codehunter13 Sep 12, 2005 at 4:26 PM 10 replies 6.5k views
Original Post
codehunter13
codehunter13
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]
Cypher19
Cypher19
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?
codehunter13
codehunter13
yes i know i don't need the last element of the vector4. But i was just wondering if a simple exemple shader from CG could be wrong.
JohnBolton
JohnBolton
Just a guess:

The type of BaseTexture is "sampler", but the type of the parameter (as reported by the error message) is "sampler2D".
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
codehunter13
codehunter13
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]
janos
janos
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
Act of War - EugenSystems/Atari
codehunter13
codehunter13
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" :(
paic
paic
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 ... ^^)
paulc
paulc
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...
codehunter13
codehunter13
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]
paulc
paulc
double doh. Your right, the only thing a pixel shader should return is the final colour of the pixel. Wasn't looking closely enough.
janos
janos
Try this :
Make the pixein and verteout structs the same
that is include a float4 pos : POSITION in pixin, even though you will not be able to access it.
BTW, I tested your code as is on Cg ps_2_0 profile and on HLSL, and it works fine.
Act of War - EugenSystems/Atari

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.