Announcement

Collapse
No announcement yet.

How does FVertexFactoryInput works?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How does FVertexFactoryInput works?

    Hello,

    I'm trying to create my vertex factory and currently I have a problem, that d3dDevice can't create InputLayout. I have a very informative d3d error:
    Code:
    E_INVALIDARG
    Ok, I need to specify layout somehow. I'm opening LocalVertexFactory.usf and see this:
    Code:
    struct FVertexFactoryInput
    {
    	float4	Position	: ATTRIBUTE0;
    	half3	TangentX	: ATTRIBUTE1;
    	// TangentZ.w contains sign of tangent basis determinant
    	half4	TangentZ	: ATTRIBUTE2;
    	half4	Color		: ATTRIBUTE3;
    
    // + a lot of other attributes
    ...
    }
    Next, I'm opening FStaticMeshLODResources::InitVertexFactory:
    Code:
    Data.PositionComponent = FVertexStreamComponent(
    				&Params.LODResources->PositionVertexBuffer,
    				STRUCT_OFFSET(FPositionVertex,Position),
    				Params.LODResources->PositionVertexBuffer.GetStride(),
    				VET_Float3
    				);
    			Data.TangentBasisComponents[0] = FVertexStreamComponent(
    				&Params.LODResources->VertexBuffer,
    				STRUCT_OFFSET(FStaticMeshFullVertex,TangentX),
    				Params.LODResources->VertexBuffer.GetStride(),
    				VET_PackedNormal
    				);
    			Data.TangentBasisComponents[1] = FVertexStreamComponent(
    				&Params.LODResources->VertexBuffer,
    				STRUCT_OFFSET(FStaticMeshFullVertex,TangentZ),
    				Params.LODResources->VertexBuffer.GetStride(),
    				VET_PackedNormal
    				);
    And here my questions:
    1. Why Position attribute in *.usf have float4 type, and here - on params initialization it have VET_Float3 type? How does it work?
    2. In *.usf there's a Color attribute, but in params initialization it absent. Why the code works?
    3. Who initialize other parameters?

    #2
    Huge thanks to Ehamloptiran. He answered my questions and the answers are:

    1. Need to run with -d3ddebug in order to set debug flag to device. Now I have informative errors descriptions.
    2. float3 to float4 conversion is automatic for position elements, so thats why its defined as a float3 in code and float4 in the shader, And of course it's legal to use VET_Float4 for initialization.
    3. this Data.PositionComponent = FVertexStreamComponent actually says which field in vertex structure points to which field in the stream. The actual binding of *.usf and code fields are done, for example, in FLocalVertexFactory::InitRHI - attribute index is plays main role.
    4. Similar way other attributes initialized in appropriate classes. In FInstancedStaticMeshVertexFactory::InitRHI, for example.

    Comment

    Working...
    X