Jump to content
  • Advertisement
Sign in to follow this  
Mercenarey

GUI on shader: I can't seem to offset

This topic is 3739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im currently implementing GUI, but I seem to have a wierd problem, in that my Vertex Shader ignores all my attempts to alter the incoming vertices. If you look in the VS, then this code (see shader below): l_output.position.x += g_GUIoffset[0]; l_output.position.y += g_GUIoffset[1]; Will be ignored, no matter what I set the offsets to. I have tried to hardcode an offset: l_output.position.x += 100.0f; l_output.position.y += 100.0f; just to make sure that I didn't mess up in transferring offsets, but still nothing happens. Alterations work fine if I go directly into the VertexBuffer and alter the values there, but not at the shader-level. What is wrong? My shader code looks something like this:
// ---------------------------
// ---------------------------
float g_GUIoffset[2];

// ---------------------------
// ---------------------------
struct VERTEX_OUTPUT_GUI
{
	float4 position : POSITION;
	float2 texcoord0 : TEXCOORD0;
};

// ---------------------------
// ---------------------------
VERTEX_OUTPUT_GUI VS_GUI(float4 a_position: POSITION, float2 a_texcoord0: TEXCOORD0)
{
	VERTEX_OUTPUT_GUI l_output;

	l_output.position = a_position;
	l_output.position.x += g_GUIoffset[0];
	l_output.position.y += g_GUIoffset[1];
	l_output.texcoord0 = a_texcoord0;

	return l_output;
}

// ---------------------------
// ---------------------------
float4 PS_singlecolorGUI(float2 a_texcoord0: TEXCOORD0) : COLOR
{
	return 0;
}

// ---------------------------
// ---------------------------
technique SinglecolorGUI
{
	pass p0
	{
		VertexShader = compile vs_2_0 VS_GUI();
		PixelShader = compile ps_2_0 PS_singlecolorGUI();
	}
}

Share this post


Link to post
Share on other sites
Advertisement
Is it getting into your shader at all? You might have RHW in the vertex structure and if this is the case then the shader will be missed out altogether.

Share this post


Link to post
Share on other sites
Argh, yes, you are right, that was the problem (D3DDECLUSAGE_POSITIONT)...

So how do I do my own transformation properly? Ah well, I guess Im off to some research :)

Thanks alot.

Share this post


Link to post
Share on other sites
Assuming you are passing in your position in pixels, the vertex shader needs to do 2 things:

1. Convert the pixel coordinates to the range 0-1 using the back buffer dimensions (which you have to provide to the shader).
2. Scale to fit the view port of -1 - 1 on both axis.

The following code should do it:


float4 ConvertToScreen2D( float4 input )
{
float4 output = input;

output.xy = ( output.xy * 2 ) - 1;
output.y *= -1;

return output;
}

float2 ScaleToBackBufferDimensions( float2 input )
{
float2 result;

result.x = input.x / fBackBufferDimensions.x;
result.y = input.y / fBackBufferDimensions.y;

return result;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!