Jump to content
  • Advertisement
Sign in to follow this  

Vertex Shader oddity with view projection

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

Hello there! I was hoping someone could help me with the following. I'm using a vertex shader to convert the transformed x/y into vertex coordinates; effectively making one bitmap stretch over the entire screen. The problem is, however, that whilst this works with orthogonal projection, on perspective projection it somehow does not. In HLSL:
output.Position = mul(Matrix, input.Position);
output.Texture.x = (output.Position.x * 0.5f) + 0.5f;
This chunk of code (where Matrix is the total matrix, transform and projection) it does works when the matrix is orthogonal, but not when it is perspective:
D3DXMatrixPerspectiveFovLH(&Projection, 0.35f * D3DX_PI, 1.25f, 145.0f, 1000.0f);
D3DXMatrixOrthoOffCenterLH(&Projection, -10.0f, 10.0f, -10.0f, 10.0f, 1450.0f, 1000.0f);
The second projection gives me the geometry with the fullscreen texture, the former projection somehow has not transformed the vertex locations into the [-1; 1] range inside the vertex shader when I use it for the texture, but it's vertex locations appear on screen properly. This really got me stumped, seeing as it's rather illogical. Are there any mythical settings which change when you use the 'D3DXMatrixPerspectiveFovLH' function? Cheers, -Jeroen

Share this post


Link to post
Share on other sites
Advertisement
Projection shouldn't come into it so i dont really know where you are going wrong. However i will post this:


/******************************************************* Filename: dxg_position_only.fx
Author: David Lovegrove
Date: 19/05/2006 22:17:54
Desc: Effect for rendering the DXG controls
while considering only the 2D position.
\*******************************************************/


float2 coffset; // Current childs offset into its parent.
float2 resolution; // Dimensions of the back buffer.

texture tex;

sampler sampTex = sampler_state
{
texture = (tex);
minfilter = ANISOTROPIC;
magfilter = ANISOTROPIC;
};

struct VS_INPUT
{
float4 position: POSITION;
float2 tex : TEXCOORD0;
};

struct VS_OUTPUT
{
float4 position: POSITION;
float2 tex : TEXCOORD0;
};

VS_OUTPUT vs_main( VS_INPUT input )
{
VS_OUTPUT output = (VS_OUTPUT) 0;
float2 nearDiff, farDiff;

/* To begin with simply set the output vertex to the
input vertex.
*/

output = input;

/* All incoming vertices are described as if the top-left
of the control is at (0,0) therefore the vertices need
to be offset into their correct position.
*/

output.position.xy = input.position.xy + coffset.xy;

/* Convert the vertex position in pixels into the equivelent
position in the range (0,0)-(1,1).
*/

output.position.xy /= resolution.xy;

/* Convert the (0,0)-(1,1) ranged positionsn into its
(-1,-1)-(1,1) counterpart.
*/

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

return output;
}

float4 ps_main( VS_OUTPUT input ) : COLOR
{
return tex2D( sampTex, input.tex );
}

technique t1
{
pass P0
{
VertexShader = compile vs_2_0 vs_main();
PixelShader = compile ps_2_0 ps_main();
}
}



This is a shader for 2D that i use in my GUI.

Hope it helps,

Dave

Share this post


Link to post
Share on other sites
Thanks for your code, but I'm afraid it isn't help enough: the error involves the projection, I've used screen-texture coordinates before and they work.

I've narrowed it down to the 11th float in the projection matrix; that one somehow makes a mess out of the vertex shader. In case it isn't clear;

I have a mesh and use a vertex shader to project it using a matrix. Then, afterwards, the visible vertices should be in the [-1, 1] range, so I change the texture coordinates to the vertex' XY.

However, somehow, something causes a mess, making the transformed vertices outside of the [-1, 1] range, so the texture coordinates become off, and then (without it being in my shader) somehow transforms them into that [-1, 1] range, causing the texture to be horridly transformed.

Share this post


Link to post
Share on other sites
Bump :-/
I've done some more extensive debugging, and now it seems that my projection matrix leaves the 'w' component of the vertices at non-1 value. I presume this means that after my vertex shader, the vertices are further transformed, which somehow messes with my transformed UV? And.. the follow-up question is: is there any way to solve this?

I hope I'm not asking stupid questions here and that I'm making sense :)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!