Sign in to follow this  
zonozz

About HLSL's Semantic

Recommended Posts

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]

Edited by zonozz

Share this post


Link to post
Share on other sites

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?).

Share this post


Link to post
Share on other sites

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;

};

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

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