Why do I need VertexPositionColor?
You don’t with the example you just posted which is actually really a bad idea.
You did with your previous question.
Also you seem to be asking one thing then showing code for other things.
As for what you just posted
.
Yes you would probably want to make your own shader to do this.
However im still a little unclear on what exactly you want to do.
SpriteBatch can accept your shader and use it.
Or you can manually draw quads like in your example code.
Do you want to do this with spriteBatch or not ?
Also this example is a absolutely horrible way to do what is being shown.
Shaders don’t like all those if’'s and especially don’t like the if else logic chain set up.
That fx will give a rainbow but it will be a set of solid bars.
Further those colors are shader constants you wouldn’t need to pass them in to a custom effect.
They are already in that shader.
If you wanted to pass them you would define them as soo.
float4 red;
float4 orange;
float4 yellow;
ect… ect…
Then you could pass the colors for each via…
myExampleEffect.Parameters[“red”].SetValue( new Color(1f,0f,0f,1f) );
myExampleEffect.Parameters[“orange”].SetValue(Color.Orange);
myExampleEffect.Parameters[“yellow”].SetValue(Color.Yellow);
And no.
You cant pass those into or set them in BasicEffect as that is not part of basic effect.
It’s just some terrible random shader someone made up, probably as a test for something else.
Anyways just to be clear.
You make your own shader by first double clicking the pipline tool.
The orange icon.
You’'ll see the something like this but empty.
https://i0.wp.com/darkgenesis.zenithmoon.com/wp-content/uploads/2016/08/image_thumb-1.png?resize=244%2C195
Right click on the content then select ‘add new item’
pick a ‘effect’ name it (e.g. ‘MyEffect’)
save and then build all.
While your in there right click on the file and open it up for editing… later on.
Go to your Game1 class.
At the top add a global Effect reference
Effect myEffect;
in LoadContent load it like so.
myEffect = Content.Load("myEffect);
from here changes you make to the file will be rebuilt with rebuild all.
Now you need to edit the shader.
Inside the effect file is a pre-made shader you should see the following.
This is were you add that shader stuff.
#if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
#else
#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1
#endif
matrix WorldViewProjection;
struct VertexShaderInput
{
float4 Position : POSITION0;
float4 Color : COLOR0;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
};
VertexShaderOutput MainVS(in VertexShaderInput input)
{
VertexShaderOutput output = (VertexShaderOutput)0;
output.Position = mul(input.Position, WorldViewProjection);
output.Color = input.Color;
return output;
}
float4 MainPS(VertexShaderOutput input) : COLOR
{
return input.Color;
}
technique BasicColorDrawing
{
pass P0
{
VertexShader = compile VS_SHADERMODEL MainVS();
PixelShader = compile PS_SHADERMODEL MainPS();
}
};
If you want to use it with sprite batch you have to pass in your effect to spritebatch begin(.,.,., ).
Or just draw it the way you were trying to in the previous example code and use your effect to do it.