2
\$\begingroup\$

If I don't use the vertex shader, it gives me white textures which is what the default color is. Once I add the vertex shader, the screen is black.

I figure it is something wrong with the Matrices I give the shader, but I am not sure.

    #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 : SV_POSITION;
    float4 Color : COLOR0;
    float2 texCoord : TEXCOORD0;
};

struct VertexShaderOutput
{
    float4 Position : SV_POSITION;
    float4 Color : COLOR0;
    float2 texCoord : TEXCOORD0;
};



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();
    }
};

My projection matrix(The default that spritebatch uses).

projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) * Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, -1)

Setting my WorldViewProjection matrix.

negEffect.Parameters["WorldViewProjection"].SetValue(projection);

Only projection since I turned off my camera to make it easier to debug.

The drawing code.

GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(Color.Black);
var debugMatrix = debugCamera.GetViewMatrix();



spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend, SamplerState.LinearClamp, null, null, negEffect);


spaceObjectManager.Draw(spriteBatch);
spaceEnemyManager.Draw(spriteBatch);
playerShip.projectileManager.Draw(spriteBatch);
playerShip.Draw(spriteBatch);

spriteBatch.End();

GraphicsDevice.SetRenderTarget(null);



spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null);
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
spriteBatch.End();


physicsDebug.RenderDebugData(ref SimProjection, ref debugMatrix);

VertexShader off.

VertexShader off

VertexShader on.

VertexShader on

Thanks in advanced!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.