2017-10-12 19 views
0

Voici un code de shader de coque simple que j'ai fait, pour essayer de comprendre la tessellation. Je ne trouve rien de mal avec ce code, mais la fonction de compilation renvoie toujours false. Voici mon code:Impossible de compiler le code de shader HLSL Hull

Mes entrée et sortie structures:

[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; 
}; 

Mes fonctions:

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; 
}; 

Merci pour toute aide.

Répondre

1

Les attributs doivent être définis sur le point d'entrée comme ci-dessous, votre shader coque est valide:

[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) 

Sur une note de côté, l'outil de ligne de commande FXC.exe devrait imprimer un message d'erreur qui aurait vous mettre dans la bonne direction: error X3000: syntax error: unexpected token 'cbuffer'

et je ne suis pas sûr de ce que la fonction que vous faites référence, D3DCompile retourner un HRESULT, pas un booléen, et il a également un blob pour vous sortie avec les messages d'erreur en cas d'échec.

+0

Ça marche, merci! Je ne connaissais pas cet ordre. Ma fonction est juste un appel à D3DCompile et ne pas imprimer le tampon d'erreur. – mondlicht