Sign in to follow this  

HLSL : Problem sending 2D verts in screen space.

This topic is 4391 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

Hi all, I have an odd problem and I'm not quite sure what the cause is, nor how to fix it 'properly'. I have the following HLSL shader:
texture 	DIFFUSE_TEXTURE;
float		SCREEN_WIDTH;
float		SCREEN_HEIGHT;

struct VS_INPUT
{
    float3 vPosition    : POSITION;
    float3 vNormal	: NORMAL0;
    float3 vTexCoords   : TEXCOORD0;
    float4 vColor       : COLOR0;
};

struct VS_OUTPUT
{
    float4 Pos  : POSITION;
    float3 Tex  : TEXCOORD0;
    float4 Col	: COLOR0;
};

float3 ScreenToVert(float3 vert)
{		
	vert.x 		/= 1024.0f;
	vert.y 		/= 768.0f;

	vert.x 		*= 2.0f;
	vert.y 		*= 2.0f;

	vert.x 		-= 1.0f;
	vert.y 		-= 1.0f;	

	vert.y 		*= -1.0f;	
	
	vert.x 		-= (1.0 / SCREEN_WIDTH);
	vert.y 		+= (1.0 / SCREEN_HEIGHT);

        vert.z          = 0.0f;  // <<<< PROBLEM HERE?
	
	return vert;
}

VS_OUTPUT VS(const VS_INPUT input)
{
    VS_OUTPUT Out = (VS_OUTPUT)0;
	
    float3 pos = ScreenToVert(input.vPosition);
    Out.Pos.x  = pos.x;
    Out.Pos.y  = pos.y;
    Out.Pos.z  = pos.z;
    Out.Pos.w  = 1.0f;
    
    Out.Tex  = input.vTexCoords;
    Out.Col  = input.vColor;
    
    return Out;
}


I use this shader simply to draw 2D quads on the screen. The vertex information sent in is screen space (screen width, screen height) and I convert it over into vertex space [-1, +1]. This works in debug, but not in release. If I comment out the line "vert.z = 0.0f" it works fine. In other words, in debug all my 2D windows and quads show up fine, render correctly, and I'm off. In release none of my 2D objects render at all. I've also used the shader debugger and verified that my vertices have the correct values coming in and going out. Also, "vert.z = 0.0f" really has no effect as I set the z coord to 0.0f before rendering. I've also verified that vert.z IS 0.0f coming into the shader. For now I've commented out the vert.z portion, it runs in debug and release, but it worries me tremendously. Any help would be tremendously appreciated :) Graf

Share this post


Link to post
Share on other sites
Do you mean debug/release builds of the effect or the application?

I can't see anything obviously wrong with your code. Do you get any error messages, warnings, debug output? any shader compiler errors?

Cheers,
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
Do you mean debug/release builds of the effect or the application?

I can't see anything obviously wrong with your code. Do you get any error messages, warnings, debug output? any shader compiler errors?

Cheers,
Jack


Of the application itself.

Unfortunately I get no errors, warnings, or anything. During compile or runtime. Turning up the DX debug level didn't help either (in an attempt at getting information). Interestingly enough, checking the 'Maximum Validation' box in the DX Control Panel fixes it, but does not give me any additional information so I am uncertain as to why this breaks :/

Initially I thought that perhaps I was passing in a bad w component in my vertices, with the thought being that debug caught and corrected it. However, I am specifically setting w after I convert the coords, so the homogenous transform should not have any effect on my verts.

Share this post


Link to post
Share on other sites
Hmm, that definitely sounds like a strange fix [smile]

What SDK and compiler are you using?

Visual C++ 2005 and the October 2005 SDK seem to have the occasional glitch due to being out-of-sync. Alternatively, I'd try upgrading to a later compiler and/or SDK - it is possible you've found a bug [oh]

If it's something that the HLSL compiler is messing with then a later SDK might well have fixed/updated it accordingly.

If you have the latest-n-greatest then you could try emailing directx@microsoft.com with a reproduction test case and as much information as you can. This really doesn't sound like expected/normal behaviour to me [smile]

hth
Jack

Share this post


Link to post
Share on other sites
To give additional info:

Using VS.NET 2003, October 2005 SDK. In fact, this only started as soon as I got the October '05 SDK.

I remember seeing some discussion on the DirectXDev mailing lists on some of the Microsoft tutorial shaders stopped working in the latest SDK (August perhaps?). Methinks I'll have to dig through those threads and see if anything is relevant.

Share this post


Link to post
Share on other sites

This topic is 4391 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this