Skip to main content
Didnt read the question right so i had to make big changes
Source Link

Something like this should work, here we are using a constant to change the pixel colourI use it for drawing my sprites with sharpDX toolkit.spritebatch so I'm hoping with some changes it may work for you.

HLSL:

cbufferTexture2D<float4> SettingTexture : register(b0t0);
{
// SpriteBatch expects that default texture sampler parameter will have   name 'TextureSampler'
sampler TextureSampler : register(s0);

// effectSpriteBatch peramexpects color
that default float4vertex color;transform parameter will have name 'MatrixTransform'
}row_major float4x4 MatrixTransform;


float4
void PixelShaderFunctionVSMain(
inout float4 poscolor : SV_POSITIONCOLOR0,
inout float2 texCoord : TEXCOORD0,
inout float4 color1position : COLOR0SV_Position)
{
position = mul(position, MatrixTransform);
}

struct PixelShaderOutput
{

float4 texCoordColor : SV_Target0;

};


// Blurs the input image horizontally
PixelShaderOutput PS(float4 color : COLOR, float2 UV : TEXCOORD0) : SV_Target0
{

PixelShaderOutput output = (PixelShaderOutput) 0;
float4 c = Texture.Sample(TextureSampler, UV);

output.Color.rgb = color.rgb * c.rgb;
output.Color.a = c.a;


return color;output ;
}



technique Tech
{
pass P0
{
 
    SetVertexShader(CompileShader(vs_5_0, VSMain()));
    SetPixelShader(CompileShader(ps_5_0, PS()));
}
}

on the cpu it would beOr something like this: could work(made a change to your code)

EffectVars.Setsampler2D TextureSampler = sampler_state
{
Texture = <Texture>;
};

float4 PixelShaderFunction("color"float4 pos : SV_POSITION, float4 color1 : COLOR0,    float4 texCoord : TEXCOORD0) : SV_TARGET0
{
float4 color = tex2D(TextureSampler, texCoord);

float high = .6;
float low = .4;

if (color.whiter > high) color.r = 1;
else if (color.r < low) color.r = 0;

if (color.g > high) color.g = 1;
else if (color.g < low) color.g = 0;

if (color.b > high) color.b = 1;
else if (color.b < low) color.b = 0;

return color1 * color;
}

technique Technique1
{
pass Pass1
{
    PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
}
}

Something like this should work, here we are using a constant to change the pixel colour.

HLSL

cbuffer Setting : register(b0)
{
  // effect peram color
  float4 color;
}


float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, float4 texCoord : TEXCOORD0) : SV_Target0
{    

return color;
}

on the cpu it would be something like this:

EffectVars.Set("color", color.white)

Something like this should work, I use it for drawing my sprites with sharpDX toolkit.spritebatch so I'm hoping with some changes it may work for you.

HLSL:

Texture2D<float4> Texture : register(t0);

// SpriteBatch expects that default texture sampler parameter will have   name 'TextureSampler'
sampler TextureSampler : register(s0);

// SpriteBatch expects that default vertex transform parameter will have name 'MatrixTransform'
row_major float4x4 MatrixTransform;



void VSMain(
inout float4 color : COLOR0,
inout float2 texCoord : TEXCOORD0,
inout float4 position : SV_Position)
{
position = mul(position, MatrixTransform);
}

struct PixelShaderOutput
{

float4 Color : SV_Target0;

};


// Blurs the input image horizontally
PixelShaderOutput PS(float4 color : COLOR, float2 UV : TEXCOORD0) : SV_Target0
{

PixelShaderOutput output = (PixelShaderOutput) 0;
float4 c = Texture.Sample(TextureSampler, UV);

output.Color.rgb = color.rgb * c.rgb;
output.Color.a = c.a;


return output ;
}



technique Tech
{
pass P0
{
 
    SetVertexShader(CompileShader(vs_5_0, VSMain()));
    SetPixelShader(CompileShader(ps_5_0, PS()));
}
}

Or something like this could work(made a change to your code)

sampler2D TextureSampler = sampler_state
{
Texture = <Texture>;
};

float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0,    float4 texCoord : TEXCOORD0) : SV_TARGET0
{
float4 color = tex2D(TextureSampler, texCoord);

float high = .6;
float low = .4;

if (color.r > high) color.r = 1;
else if (color.r < low) color.r = 0;

if (color.g > high) color.g = 1;
else if (color.g < low) color.g = 0;

if (color.b > high) color.b = 1;
else if (color.b < low) color.b = 0;

return color1 * color;
}

technique Technique1
{
pass Pass1
{
    PixelShader = compile ps_4_0_level_9_1 PixelShaderFunction();
}
}
Source Link

Something like this should work, here we are using a constant to change the pixel colour.

HLSL

cbuffer Setting : register(b0)
{
  // effect peram color
  float4 color;
}


float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, float4 texCoord : TEXCOORD0) : SV_Target0
{    

return color;
}

on the cpu it would be something like this:

EffectVars.Set("color", color.white)