2017-10-12 100 views
0

下面是我做的一個簡單的外殼着色器代碼,試圖瞭解鑲嵌細分。 我只是找不到這個代碼有什麼問題,但編譯函數總是返回false。這裏是我的代碼:無法編譯HLSL Hull着色器代碼

我的輸入和輸出結構:

[domain("tri")] // indicates a triangle patch (3 verts) 
[partitioning("fractional_odd")] // fractional avoids popping 
// vertex ordering for the output triangles 
[outputtopology("triangle_cw")] 
[outputcontrolpoints(3)] 
// name of the patch constant hull shader 
[patchconstantfunc("ConstantsHS")] 
//[maxtessfactor(7.0)] 


cbuffer TessellationBuffer 
{ 
    float tessellationAmount; 
    float3 padding; 
}; 

struct VS_CONTROL_POINT_OUTPUT 
{ 
    float3 vWorldPos : POSITION; 
    float2 vTexCoord : TEXCOORD0; 
    float3 vNormal : NORMAL0; 
}; 

struct HS_CONTROL_POINT_OUTPUT 
{ 
    float3 vWorldPos : POSITION; 
    float2 vTexCoord : TEXCOORD0; 
    float3 vNormal : NORMAL0; 
}; 

struct HS_CONSTANT_DATA_OUTPUT 
{ 
    float Edges[3] : SV_TessFactor; 
    float Inside : SV_InsideTessFactor; 
}; 

我的功能:

HS_CONTROL_POINT_OUTPUT HS(InputPatch<VS_CONTROL_POINT_OUTPUT, 3> inputPatch, uint uCPID : SV_OutputControlPointID, uint patchId : SV_PrimitiveID) 
{ 
    HS_CONTROL_POINT_OUTPUT Output; 
    Output.vWorldPos = inputPatch[uCPID].vWorldPos; 
    Output.vTexCoord = inputPatch[uCPID].vTexCoord; 
    Output.vNormal = inputPatch[uCPID].vNormal; 

    return Output; 
}; 

HS_CONSTANT_DATA_OUTPUT ConstantsHS(InputPatch<VS_CONTROL_POINT_OUTPUT, 3> inputPatch, uint PatchID : SV_PrimitiveID ) 
{ 
    HS_CONSTANT_DATA_OUTPUT Output; 

    Output.Edges[0] = tessellationAmount; 
    Output.Edges[1] = tessellationAmount; 
    Output.Edges[2] = tessellationAmount; 
    Output.Inside = tessellationAmount; 
    return Output; 
}; 

感謝您的幫助。

回答

1

的屬性已經對入口點像下面設置,那麼你的外殼着色器是有效的:

[domain("tri")] // indicates a triangle patch (3 verts) 
[partitioning("fractional_odd")] // fractional avoids popping 
// vertex ordering for the output triangles 
[outputtopology("triangle_cw")] 
[outputcontrolpoints(3)] 
// name of the patch constant hull shader 
[patchconstantfunc("ConstantsHS")] 
//[maxtessfactor(7.0)] 
HS_CONTROL_POINT_OUTPUT HS(InputPatch<VS_CONTROL_POINT_OUTPUT, 3> inputPatch, uint uCPID : SV_OutputControlPointID, uint patchId : SV_PrimitiveID) 

在一個側面說明,命令行工具FXC.exe必須打印,將有一個錯誤信息把你在正確的方向:error X3000: syntax error: unexpected token 'cbuffer'

而且我不確定的是什麼工作,你指的是,D3DCompile在失敗的情況下返回HRESULT,而不是一個布爾值,也輸出一個blob爲你的錯誤消息。

+0

它的工作原理,謝謝!我不知道這個命令。我的函數只是對D3DCompile的調用,並不打印錯誤緩衝區。 – mondlicht