About HLSL's Semantic

Started by
7 comments, last by zonozz 11 years ago

Hi everyone !

I use RenderMonkey to try SSAO effect, I need vertex shader output position normal structure like this :

struct VS_OUTPUT

{

float4 position : POSITION0;

float3 normal : NORMAL0;

};

and I make structure for pixel shader to adapt to vertex shader output like this :

struct PS_INPUT

{

float4 position : POSITION1 ;( Here is a problem, when compiled pixel shader, it told me POSITION index from 1 - 15 )

float3 normal : NORMAL0;

};

My question is : In vertex shader output structure position with POSITION0. But pixel shader input structure position is POSITION1.

How could pixel shader find vertex shader output variable - " position " ? They have different semantic !.?

I use RenderMonkey to implement SSAO, But when I check render target "Normal" and "Position" ( Next pass needs these vars ) , I just see

Normal texture is correct result.

I dont know the figure is right or not ? But I try 2 PC have different GPU, they displayed the different pictures.

This can not display the position renderTexture & view renderTexture

[attachment=14649:SSAO 1.jpg]

But on this computer displayed all (I dont know view renderTexture & normalTexture are correct ?)

[attachment=14650:SSAO 2.jpg]

Advertisement

Maybe you would fill the POSITION1 value as the vertex shader's output.

Is is possible, that the Monkey has a bug, and you can create a new project from scratch.

You could also put the position into a TEXCOORD0 semantic when output from your vertex shader, and then use that for input into your pixel shader.

POSITION0 is meant to be output from the vertex shader for the rasterizer, it isn't meant for input into the pixel shader (though I guess it works on some graphics cards?).

Yo zonozz,

From what I can remember, it is illegal in HLSL to pass the Position semantic to the pixel shader, at least in DirectX 9. Try creating a VS_OUTPUT that has a TEXCOORD semantic in addition to the POSITION semantic. Then, in your vertex shader, write the value of the position to both of the semantics. Have your PS_INPUT semantic read the TEXCOORD but not the position.

Something like this:

struct VS_OUTPUT

{

float4 position : POSITION0;

float4 pixelShaderPos : TEXCOORD1;

float3 normal : NORMAL0;

};

struct PS_INPUT

{

float4 pixelShaderPos : TEXCOORD1;

float3 normal : NORMAL0;

};

http://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx#VPOS

Yo zonozz,

From what I can remember, it is illegal in HLSL to pass the Position semantic to the pixel shader, at least in DirectX 9. Try creating a VS_OUTPUT that has a TEXCOORD semantic in addition to the POSITION semantic. Then, in your vertex shader, write the value of the position to both of the semantics. Have your PS_INPUT semantic read the TEXCOORD but not the position.

Something like this:

struct VS_OUTPUT

{

float4 position : POSITION0;

float4 pixelShaderPos : TEXCOORD1;

float3 normal : NORMAL0;

};

struct PS_INPUT

{

float4 pixelShaderPos : TEXCOORD1;

float3 normal : NORMAL0;

};

Thank you , I changed my code like your way, but I dont know this result is correct ? It looks odd ?

[attachment=14662:SSAO 3.jpg]

Pixel shader code :

[attachment=14663:SSAO 4.jpg]

http://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx#VPOS

Thank you, I'll have a look

I changed my code like your way, but I dont know this result is correct ? It looks odd ?

You're outputting the post-projection position, which should be in the range ([-1, 1], [-1, 1], [0, 1]). You're right, I wouldn't expect it to look quite like that.

What format is the render target you're using for position?

As for VPOS, that will work great if all you need is the (x, y) of the current pixel being rendered. If you also need the z, then it won't help you.

I changed my code like your way, but I dont know this result is correct ? It looks odd ?

You're outputting the post-projection position, which should be in the range ([-1, 1], [-1, 1], [0, 1]). You're right, I wouldn't expect it to look quite like that.

What format is the render target you're using for position?

As for VPOS, that will work great if all you need is the (x, y) of the current pixel being rendered. If you also need the z, then it won't help you.

I use A32B32G32R32F pixel format for all render targets.

This topic is closed to new replies.

Advertisement