• Advertisement
Sign in to follow this  

How do you match a colour in HLSL

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

What I'm doing is creating a selected object display. This is when a user selects a game object and a window has its detail and a image,
That may show its health status.

I'm working on the image part.
Each object has a .DDS icon image with alpha channel and its a image of the object rendered as a wire frame
the inner parts are coloured black, This is the colour I would Like to over ride.
I tryed three ways the last one works the best but it adds a line at the top and bottom.

I'm thinking its from the top and bottom of the image.

 

ReplaceColourShader.jpg?psid=1

 

here is my HLSL pixel shader snippit of code
//any other ways I should try.


float4 texColor = gTex.Sample( TexS, input.tex0 );
float4 diffuse = Mdiffuse * texColor;
	
// Kill transparent pixels.
clip(diffuse.a - 0.15f);
	
	
// Interpolated normals can become unnormal--so normalize.
input.normalW = normalize(input.normalW);
input.toEyeW  = normalize(input.toEyeW);
	
// Light vector is opposite the direction of the light.
float3 lightVecW = gLight.dir;
	
	
//shadow stuff
float shadowFactor = 0.0;
	
float3 removethiscolour = float3(0.0, .0, 0.0);//this will be user set later

//if the colour is black then we want to change that colour
//to our new colour

//try 1
//float val = diffuse.r + diffuse.g + diffuse.b;
	//if(val <= 0.55)
		//diffuse = float4(0.0, 1.0, 0.0, 1.0);
 //try 2
//find the colour to over write
	//if(diffuse.r == removethiscolour.r && diffuse.g == removethiscolour.g && diffuse.b == removethiscolour.b )
	//	diffuse = float4(0.25, 0.25, 0.105, 1.0);

//this one I like more
//this here has a nice look to it
float v1 = diffuse.r - removethiscolour.r;
float v2 = diffuse.g - removethiscolour.g;
float v3 = diffuse.b - removethiscolour.b;
float delta = 0.5;
if(v1 <= delta && v2 <= delta & v3 <= delta)
          diffuse = float4(1.0, 0.0, 0.0, 1.0);

 float4 spec    = Mspec;
 // Compute the lit color for this pixel.
 SurfaceInfo v = {input.posW, input.normalW, diffuse, spec};
    
  
 float3 litColor = ParallelLight(v, gLight, gEyePosW, shadowFactor);
	

 return float4(litColor * gSelectedColour, gAlpha);
    

Share this post


Link to post
Share on other sites
Advertisement

Just a quick question : how your sampler TexS is defined? Have you tried using point sampling?

 

Cheers!

Share this post


Link to post
Share on other sites

Good point.

Totally sliped my mind to change the sampler hehe.

 

But I still getting the line but is smaller in length, going to look at it in pix see whats going on there.

 

it was MIN_MAG_MIP_LINEAR;

then I tryed MIN_LINEAR_MAG_MIP_POINT

and using MIN_MAG_MIP_POINT now.

 

sampler...

SamplerState TexS

{

Filter = MIN_MAG_MIP_POINT;

AddressU = Wrap;

AddressV = Wrap;

};

 

Heres a Image with three ways of displaying the objects health

A is just replacing the the colour with the health colour.

B is the image with the health colour added to it.

C is change one colour with the Health colour.

 

I like B. then again C is looking ok. What do you all think..

SelectWhat1ToUse.jpg?psid=1

Edited by ankhd

Share this post


Link to post
Share on other sites

Ok I know what does it.

 

It's the Texture Address Mode

 

I have it set to wrap and it produces the lines all ways at the edge.

 

I change the Address mode to Clamp and the lines are gone fixed I think.

 

And after all that I think I don't like what the look of the health image looks like.  may do a icon of the obejct and the health colour over the top with no wire frame.

Edited by ankhd

Share this post


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

  • Advertisement