# HLSL : Problem sending 2D verts in screen space.

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

## 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 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 on other sites
Quote:
 Original post by jollyjeffersDo 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 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 on other sites

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.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013747
×