Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

why this extremely simple effect doesn't work??

$
0
0

@GeonBit wrote:

I don't know whats going on anymore.. I wrote this basic effect:

#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

Texture2D SpriteTexture;
matrix MatrixTransform;

sampler2D SpriteTextureSampler = sampler_state
{
	Texture = <SpriteTexture>;
};

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

// vertex shader main
VertexShaderOutput MainVS(float4 position	: POSITION0,
	float4 color : COLOR0,
	float2 texCoord : TEXCOORD0)
{
	VertexShaderOutput output;
	output.Position = mul(position, MatrixTransform);
	output.Color = color;
	output.TextureCoordinates = texCoord;
	return output;
}

float4 MainPS(VertexShaderOutput input) : COLOR
{
	return tex2D(SpriteTextureSampler, input.TextureCoordinates) * input.Color;
}

technique SpriteDrawing
{
	pass P0
	{
		PixelShader = compile PS_SHADERMODEL MainPS();
		VertexShader = compile VS_SHADERMODEL MainVS();
	}
};

And I set the matrix like this:

var projection = Matrix.CreateOrthographicOffCenter(0, viewport.Width, viewport.Height, 0, 0, 1);
            _hpGlobeEffect.Parameters["MatrixTransform"].SetValue(projection);

But I see nothing on the screen, no matter what I draw. I tried every possible value as the matrix, for example this:

Matrix projection = Matrix.CreateOrthographicOffCenter(0, viewport.Width, viewport.Height, 0, 0, 1);
            Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
            _hpGlobeEffect.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection);

I tried like million different examples I found and stuff which I think logically should work.. and nada! except doing brute force using loops to generate every possible matrix in existence I think I tried everything. and nothing works..

Note that once I remove the vertex shader part and use only the pixel shader everything draws normally.

Anyone see the problem?

Thanks! :slight_smile:

Posts: 8

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles