HLSL VPOS semantic

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
faeX
Posts: 1
Joined: Tue Feb 14, 2012 8:05 pm

HLSL VPOS semantic

Post by faeX »

Hi community.

I'm new to shader programing, so excuse me if I made a stupid mistake.

I want to use the Pixelposition in worldspace in my pixelshader. Therefore I pass the pixelposition on the screen using the VPOS semantic to the pixel shader, to recalculate it afterwards in 3d space using an inverse projection matrix. I don't know if that would work, but the problem is a little bit more basic:

Although listed in the HLSL semantic list ( http://msdn.microsoft.com/en-us/library ... .aspx#VPOS ), the console gives out an error:
HLSL pixel shader compilation failed:
(35): error X4502: invalid input semantic 'VPOS'
This is my shader.

Code: Select all

float4x4 worldViewProj;  // World * View * Projection transformation
float3 lightDir;         // Light direction
//float3 viewPos;       // camera position
float4x4 invProj; // inverse Projection transformation
 
 
struct VS_OUTPUT
{
        float4 Position   : POSITION0;   // vertex position 
        float3 lightDir : TEXCOORD0;
};
 
 
VS_OUTPUT vertexMain(in float4 vPosition : POSITION0)
{
        VS_OUTPUT Output;
 
        Output.Position = mul(vPosition, worldViewProj);
                
        Output.lightDir = lightDir;
        
        return Output;
}
 
 
struct PS_OUTPUT
{
    float4 RGBColor : COLOR0;  // Pixel color    
};
 
 
sampler2D tex0;
        
PS_OUTPUT pixelMain(float4 Position : POSITION0,
                                        float4 PixelPos : VPOS,
                                        float3 lightDir : TEXCOORD0) 
{ 
        PS_OUTPUT Output;
        
        float4 worldpos = mul(invProj, PixelPos);
        float3 pos = float3(worldpos.x, worldpos.y, worldpos.z);
        Output.RGBColor = float4(1, 1, 1, 0)*(dot(pos, lightDir));
 
        return Output;
}
 
 
Or is there even another way to calculate the 3Dcoordinates of a pixel? I really need this position for every pixel individually. A color interpolation is really not enough for my purpose.
Thanks for helping! :)
Mel
Competition winner
Posts: 2293
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: HLSL VPOS semantic

Post by Mel »

VPOS is a Shader Model 3 semantic only, and it is a float2. Are you doing that? Compile your shader for PS_3_0 and check again if it fails.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply