Jump to content
  • Advertisement
Sign in to follow this  
Goishin

Vertex shader compilation error with SV_Position

This topic is 2771 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,

I can't seem to figure out what's up with this compilation error I get with the following shader. The error is:


Failed to compile effect. Code 16389n
error x4541: vertex shader must minimally write all four components of SV_Position

I've looked all over the internet for what that means, and the only other relevant post comes from here. But in that example the poster had a miss-labeled variable. For the life of me, I can't seem to find something like that in my code. But then again, I really have very little understanding of what I'm doing, so I'm simply not seeing the cause of this error. Can someone show me?

My shader code is:
[[color="#1C2837"]source lang="hlsl"]

//--------------------------------------------------------------------------------------
// File: SimpleSample.hlsl
//
// The HLSL file for the SimpleSample sample for the Direct3D 11 device
//
// Copyright © Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------
// Constant Buffers
//--------------------------------------------------------------------------------------
cbuffer cbPerObject : register( b0 )
{
matrix g_mWorldViewProjection : packoffset( c0 );
matrix g_mWorld : packoffset( c4 );
float4 g_MaterialAmbientColor : packoffset( c8 );
float4 g_MaterialDiffuseColor : packoffset( c9 );
}

cbuffer cbPerFrame : register( b1 )
{
float3 g_vLightDir : packoffset( c0 );
float g_fTime : packoffset( c0.w );
float4 g_LightDiffuse : packoffset( c1 );
};

//-----------------------------------------------------------------------------------------
// Textures and Samplers
//-----------------------------------------------------------------------------------------
Texture2D g_txDiffuse : register( t0 );
SamplerState g_samLinear : register( s0 );

//--------------------------------------------------------------------------------------
// shader input/output structure
//--------------------------------------------------------------------------------------
struct VS_INPUT
{
float4 Position : POSITION; // vertex position
float3 Normal : NORMAL; // this normal comes in per-vertex
float4 Color0 : COLOR0; // vertex color
};

struct VS_OUTPUT
{
float4 Position : SV_POSITION; // vertex position
float4 Diffuse : COLOR0; // vertex diffuse color (note that COLOR0 is clamped from 0..1)
};

//--------------------------------------------------------------------------------------
// This shader computes standard transform and lighting
//--------------------------------------------------------------------------------------
VS_OUTPUT RenderSceneVS( VS_INPUT input )
{
VS_OUTPUT Output;
float3 vNormalWorldSpace;

// Transform the position from object space to homogeneous projection space
Output.Position = mul( input.Position, g_mWorldViewProjection );

// Transform the normal from object space to world space
vNormalWorldSpace = normalize(mul(input.Normal, (float3x3)g_mWorld)); // normal (world space)

// Calc diffuse color
Output.Diffuse = input.Color0;

return Output;
}

//--------------------------------------------------------------------------------------
// This shader outputs the pixel's color by modulating the texture's
// color with diffuse material color
//--------------------------------------------------------------------------------------
float4 RenderScenePS( VS_OUTPUT In ) : COLOR0 //SV_TARGET
{
return In.Diffuse;
}
[/[color="#1C2837"]source]

Edit: code formatting issues, but I fixed them

Share this post


Link to post
Share on other sites
Advertisement
Weird... as a complete guess:
Try using a 3D input position, and then explicitly promoting it to 4D with a hard-coded W of 1struct VS_INPUT
{
float3 Position : POSITION; // vertex position
...

Output.Position = mul( float4(input.Position,1.0), g_mWorldViewProjection );

Share this post


Link to post
Share on other sites
Hmmmm, compiles fine with fxc here (version 9.29.952.3111, June SDK). Are you working with an older SDK ?

Share this post


Link to post
Share on other sites
Ah, I got it. Unbird, you got me going in the right direction. I wasn't aware of fxc, so I found the copy on my machine and started playing around with it. When I tried compiling the pixel shader and linking "RenderScenePS" I got the same error as below. But when I did it with "RenderSceneVS" and didn't get the error I realized that my code was trying to compile the pixel shader as the vertex shader, and the error made sense.

So I fixed my code, and it works now! Thanks!

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!