Jump to content
  • Advertisement
Sign in to follow this  
Norman Barrows

HLSL auto-converts float3 vertex position to float4 shader parameter?

This topic is 616 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

HLSL auto-converts float3 vertex position to float4 shader parameter?

 

DX v9.0c

 

shader model 2 code

 

meshes from blender via .x file are float3 position, float3 normal, float2 UV. 

 

const DWORD ZFVF=(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0)  );    

 

D3DVERTEXELEMENT9 vertex_format[] =
{
' stream 0, offset 0, float3, no tesselation, position, usage index 0
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
' stream 0, offset 12, float3, no tesselation, normal, usage index 0
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
' stream 0, offset 24, float2, no tesselation, tex coords, usage index 0
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};
 
the VS shader input params use a float4  (this code is based on the BasicHLSL sample)
 
VS_OUTPUT RenderSceneVS( float4 vPos : POSITION, 
                         float3 vNormal : NORMAL,
                         float2 vTexCoord0 : TEXCOORD0,
                         uniform int nNumLights)
 
but it works just fine with a vertex with float3 position.
 
is it automatically converting the float3 to a float4? 
 
I remember reading something about HLSL doing automatic conversions, but i've been through so much material on the subject recently, i can't quite recall where it was or what it said.  probably dx9 docs.
 
I have a shader up and running with texturing and lighting and such, and was making a simpler version that used the fixed function pipeline for the pixel shader stage, IE: 
 
technique RenderSceneWithTexture1Light
{
pass P0
    {          
    VertexShader = compile vs_2_0 RenderSceneVS(1);
    // PixelShader  = compile ps_2_0 RenderScenePS();
    PixelShader  = NULL
    }
}
 
In the process of stripping it down, i noticed the mismatch in vertex format vs shader input.
 
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
 
vs:
 
VS_OUTPUT RenderSceneVS( float4 vPos : POSITION, 
 
so is that what's happening here? the HLSL compiler is automatically emitting code that coverts those float3 positions to float4s before invoking the shader code?
Edited by Norman Barrows

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!