Shaders

just comment that line

//float lightIntensity = dot (normal, DiffuseLightDirection);

had an exception from the main call, had to comment out

//          Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * world));
//          effect.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix);

and got this screen

Good, so we know normals on model are fine and my main suspect is your WorldInverseTransposeMatrix, since the moment you did
float4 normal = mul (input.Normal, WorldInverseTranspose);
you get pure black no matter what, so I suspect this operation will result in something negative no matter what.

Check mesh.ParentBone.Transform and your world matrix… ofc revert debugging changes.

I’ll be sending Mr Whitaker a line to see what he says, least you pointed me in the right direction, i don’t know if you looked at my original post, all i wanted to do was put a texture on a sprite :frowning: only reason i copied whitakers example was to get to the texture tutorial and got bombed out with this translation stuff, i’m not even doing a 3D game, 2D all the way!
anyway, since you obviously know what your doing any suggestions on just putting a texture on a sprite like my original question :wink:
Thanks for everything, Paul

Wrong order… you have to use textures in same order as you sample them, that’s actually not ideal behavior but that’s the case, so to clean this up:

texture rainbowpic;
sampler Sampler0 : register(s0)
{

};
sampler Sampler1  : register(s1)
{
  Texture = (rainbowpic);
};

float4 PixelShaderFunction(float2 coords : TEXCOORD0) : COLOR0
{
  float4 color = tex2D(Sampler0, coords);
  float4 rainbow_color = tex2D(Sampler1 , coords);
  if(color.a > 0.5f) //I honestly dont know what check you have intended there
  {
    color = rainbow_color;
  }
  return color;
}
technique Technique1
{
  pass Pass1
  {
    PixelShader = compile ps_3_0 PixelShaderFunction();
  }
}

yeah sorry about that mess, it should read

texture rainbowpic;
sampler Sampler0  : register(s0)
{
  Texture = (rainbowpic);
};

float4 PixelShaderFunction (float2 coords : TEXCOORD0) : COLOR0
{
  return tex2D (Sampler0 , coords);
}
technique Technique1
{
  pass Pass1
  {
    PixelShader = compile ps_3_0 PixelShaderFunction ();
  }
}

and the call is just

protected override void Draw(GameTime gameTime)
{
  GraphicsDevice.Clear(Color.CornflowerBlue);
  // TODO: Add your drawing code here
  spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
  // heres the shader at work
  effect.Parameters["rainbowpic"].SetValue(rainbow);
  effect.CurrentTechnique.Passes[0].Apply();
  spriteBatch.Draw(texture, new Vector2(0, 0), Color.White);
  spriteBatch.End();

  base.Draw(gameTime);
}

if anything pops off your head

And what happens when you do this? I mean this will render single texture and you are actually overwriting texture you set as paramater with texture that is assigned by spriteBatch on draw call when flushing this:

spriteBatch.Draw(texture, new Vector2(0, 0), Color.White);

thus this will simply render “texture”.

What result are you getting?

and also header should look like this:

float4 PixelShaderFunction(float4 position : SV_Position, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR0

error unexpected token TEXCOORD0

Umm, just double check it… that´s definitely aint unexpected token, it should be on single line, obviously.

my bad, heres what i’m trying to do

I have this

want to put this

in it as an overlay
reason being i intend to manipulate the second texture via a color table to produce scrolling color bars al la C64

Define overlay…
also again, what results are you getting atm? What´s the issue, do you have issue to render underlay texture? Or that part is working fine?

i can print the first sprite easy, i want the texture inside the letters to = the rainbow texture
all it’s printing right now is the original image

texture rainbowpic;
sampler Sampler0 : register(s0)
{

};
sampler Sampler1  : register(s1)
{
  Texture = (rainbowpic);
};

float4 PixelShaderFunction(float4 position : SV_Position, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR0
{
  float4 color = tex2D(Sampler0, coords);
  float4 rainbow_color = tex2D(Sampler1 , coords);
  color = lerp(color, rainbow_color, 0.5f)

  return color;
}
technique Technique1
{
  pass Pass1
  {
    PixelShader = compile ps_3_0 PixelShaderFunction();
  }
}

And again, you can do this, this will blend color between textures with 0.5f bias (half - half), if you want to pan one texture it is easy enough but we need to make sure we are on same page and everything else is working, results are as expected at that stage and everyone understand code so far.

wanted to replace the pixels in the text with pixels from the second texture

good but that doesnt answer important question: Where are we right now, are you having trouble rendering single texture? If you want to replace based on alpha, so for instance you want to use second texture if alpha of first texture is 0.2 or lower then:

texture rainbowpic;
sampler Sampler0 : register(s0)
{

};
sampler Sampler1  : register(s1)
{
  Texture = (rainbowpic);
};

float4 PixelShaderFunction(float4 position : SV_Position, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR0
{
  float4 color = tex2D(Sampler0, coords);
  float4 rainbow_color = tex2D(Sampler1 , coords);
  if(color.a < 0.2)
  {
  color = rainbow_color;
  }
  
  //or if based on second texture which is probably what you mean by overlay
  //if(rainbow_color.a > 0.0)
  //{
  //color = rainbow_color;
  //}

  return color;
}
technique Technique1
{
  pass Pass1
  {
    PixelShader = compile ps_3_0 PixelShaderFunction();
  }
}

single texture

displayed no problem
want the second text displayed in the first basically switch texture A with texture B and keep the lettering

ok got it sorted

texture text;
texture rainbowpic;
sampler Sampler0 : register(s0)
{
  Texture = (text);
};
sampler Sampler1  : register(s1)
{
  Texture = (rainbowpic);
};

float4 PixelShaderFunction (float4 position : SV_Position, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR0
{
  color = tex2D (Sampler0, coords);
  float4 rainbow_color = tex2D (Sampler1 , coords);
  if (color.a )
  {
    color = rainbow_color;
  }

  //or if based on second texture which is probably what you mean by overlay
  //if(rainbow_color.a > 0.0)
  //{
  //color = rainbow_color;
  //}

  return color;
}

produces

Thank you SOOOOOOOOOOOO much you da man and todays hero

So what you wanted to do was to use alpha of one texture as alpha of another, basically you wanted to mask second texture. Just for future reference.

Your code is very poorly optimized for such a simple task, I would like to recommend:

float4 PixelShaderFunction (float4 position : SV_Position, float4 color : COLOR0, float2 coords : TEXCOORD0) : COLOR0
{
  //sample alpha from first texture
  float mask = tex2D (Sampler0, coords).a;
  //sample rgb and alpha from second
  float4 rainbow_color = tex2D (Sampler1 , coords);
  //multiply alpha channels, only pixels that are visible on both should remain visible AND operation
  rainbow_color.a *= mask;
  //render
  return rainbow_color;
}

This would also preserve antialiasing from original text if there would be any.