Sign in to follow this  

[DX9/HLSL] == operator

This topic is 4303 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

I'm trying to compare 2 vectors in my pixel shader and it keeps saying "expected float". I'm trying just a simple if check:
sampler BaseTex;
struct PS_INPUT
{
	float2 base		: TEXCOORD0;
};

struct PS_OUTPUT
{
	float4 diffuse	: COLOR;
};


PS_OUTPUT ps_main(PS_INPUT input)
{
    PS_OUTPUT output = (PS_OUTPUT)0;
    float2 Position = input.base;
    float4 CurrentPixel = tex2D(BaseTex, Position);

    if(CurrentPixel == vector4(255.0f, 255.0f, 255.0f, 255.0f))
    {
    }
    return output;
}
I'm just starting with vertex/pixel shaders, so I don't know if this is the wrong way of doing it. I searched on google, but I can't seem to find any examples that compare 2 vector/float4 types. Also, this is using pixel shader version 1.1. Edit: Oh, and the error appears on the line of the if() statement. Edit2: Okay, for some reason this works:
bool bEqual = (CurrentPixel == vector(255.0f, 255.0f, 255.0f, 255.0f));
Edit3: It won't even let me compare 2 vector variables:
vector White = vector(255.0f, 255.0f, 255.0f, 255.0f);
if(CurrentPixel == White)
{
}
I also tried changing it from vector to float4 and it still won't work. The only error I'm getting is the one above. Thanks! [Edited by - Programmer16 on March 2, 2006 1:34:05 PM]

Share this post


Link to post
Share on other sites
Can you please post what is float4 and vector4 (their full structure/class) ?
From what I see it might be that the vector type doesn't override the == operator.
Try overriding the == operator for the float4 type or for the vector type as follows :

class vector
{
public :
bool operator==(const float4& f)
{
if (this.x == f.x && this.y == f.y && this.z == f.z && this.w == f.w)
return true;
else
return false;
}

// Other implementation
}

this way a vector knows how to compare itself with a float4 type

P.S.

If I havn't guessed float4/vector fields correctly, change them accordingly.

Share this post


Link to post
Share on other sites
Quote:
Original post by DesignerX
Can you please post what is float4 and vector4 (their full structure/class) ?
From what I see it might be that the vector type doesn't override the == operator.
Try overriding the == operator for the float4 type or for the vector type as follows :

class vector
{
public :
bool operator==(const float4& f)
{
if (this.x == f.x && this.y == f.y && this.z == f.z && this.w == f.w)
return true;
else
return false;
}

// Other implementation
}

this way a vector knows how to compare itself with a float4 type

P.S.

If I havn't guessed float4/vector fields correctly, change them accordingly.


It uses HLSL, not C++ (I guess I shouldn't have put that in the title, sorry) so I can't override them.

Edit: I figured I'd add what I'm trying to do, maybe that will help. I want to make a pixel shader that checks whether or not the pixel to the left or to the right is a specified color. If so, I want to set the current pixel's color to green (this will outline the character).

Ok, I think the problem is that I'm using 255.0f instead of 1.0f, I'm checking this now.

Share this post


Link to post
Share on other sites

This topic is 4303 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this