Sign in to follow this  
stefan5000

vertex shader + rhw problem

Recommended Posts

Hello, as you know, this is a simple shader:
struct VS_INPUT
{
	float4 Position		: POSITION;
	float4 Color		: COLOR0;
};

struct VS_OUTPUT
{
	float4 Position		: POSITION;
	float4 Color		: COLOR0;
};

float4x4 WorldViewProj;

VS_OUTPUT vs_main( in VS_INPUT In )
{
	VS_OUTPUT Out;

	Out.Position = mul(In.Position,
			   WorldViewProj);
	Out.Color = In.Color;

	return Out;
}
This code works fine for untransformed vertices. But now I want to use transformed ones and changed the code to:
struct VS_INPUT
{
	float4 Position		: POSITION;
	float4 Color		: COLOR0;
};

struct VS_OUTPUT
{
	float4 Position		: POSITION;
	float4 Color		: COLOR0;
};

float4x4 WorldViewProj;

VS_OUTPUT vs_main( in VS_INPUT In )
{
	VS_OUTPUT Out;

	Out.Position = In.Position; <-- changed this line
	Out.Color = In.Color;

	return Out;
}
Well, I thought this might work. I use values between -1.0f and 1.0f for x/y of Position, z = 0.5f...but nothing is visible now. Does somebody has an ideo what's wrong / whar I forgot??? I could imagine that it has to do with the w-component, but I'm not sure about this.

Share this post


Link to post
Share on other sites
Okay guys - I'm sorry!

Found the mistake:

my rectangle (-> two trianlges) "started" at (0.0f ; 1.0f) and has been drawn from there one unit to the right and one unit upwards...but it needed to be downwards to get visible, because (0.0f ; 0.0f) is screen centre.

So what I had:


****
*RE* <- rectangle
********
* *
*Screen*
* *
********

But now it is all right:

********
* *RE*
* ****
*Screen*
********

Share this post


Link to post
Share on other sites
Hi stefan5000,

This is from the DX docs:
Quote:

The presence of the D3DFVF_XYZRHW component on FVF vertex buffers indicates that the vertices in that buffer have been processed. Vertex buffers used for ProcessVertices destination vertex buffers must be post-processed. Vertex buffers used for fixed function shader inputs can be either preprocessed or postprocessed. If the vertex buffer is post-processed, then the shader is effectively bypassed and the data is passed directly to the primitive clipping and setup module.

Emphasis is mine.

As far as I understand this statement, it means that tranformed (rwh) vertices are not transformed again by the vertex shader. I may be wrong - I never tried to use rwh with shaders, as I always assumed that it would not work.

You might try to change your "transformed" VS in a way that make the change obvious (for example by negating the vertices colors). If you don't notice any change then it is probable that your VS is not even called.

Regards,

Share this post


Link to post
Share on other sites
You are correct, but only so far as the vertex declaration (or FVF) specifies that the vertices are pre-transformed. If the declaration specifies regular old POSITION or D3DFVF_XYZ (not D3DFVF_XYZRHW) formats, the shader will still run. This doesn't stop you from actually sending pre-transformed (screen space) vertices, though.

In fact, this is generally the better method as it gives you more flexibility.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
You are correct, but only so far as the vertex declaration (or FVF) specifies that the vertices are pre-transformed. If the declaration specifies regular old POSITION or D3DFVF_XYZ (not D3DFVF_XYZRHW) formats, the shader will still run. This doesn't stop you from actually sending pre-transformed (screen space) vertices, though.

In fact, this is generally the better method as it gives you more flexibility.


From the OP
Quote:
I could imagine that it has to do with the w-component, but I'm not sure about this.

This is why I assumed that he was using RWH - I may be wrong, of course :)

Share this post


Link to post
Share on other sites

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