2017-05-10 8 views
0

J'utilise VS2015, directx11à propos du tampon d'entrée de pixel shader

Voici mon code Vertex Shader.

cbuffer cbperobject { 
    float4x4 gWorldViewProj; 
}; 

struct VertexIn { 
    float3 Pos : POSITION; 
    float2 tex : TEXCOORD0; 
}; 

struct VertexOut { 
    float4 PosH : SV_POSITION; 
    float2 tex : TEXCOORD0; 

}; 

VertexOut main(VertexIn vin) 
{ 
    VertexOut vOut; 

    vOut.PosH = mul(float4(vin.Pos, 1.0f), gWorldViewProj); 
    vOut.tex = vin.tex; 
    return vOut; 
} 

et c'est mon code de pixel shader

Texture2D shaderTexture; 
SamplerState SampleType; 
struct VertexIn { 
    float4 PosH : SV_POSITION; 
    float2 tex : TEXCOORD0; 
}; 


float4 main(VertexIn Pin) : SV_TARGET 
{ 
    float4 textureColor; 
    textureColor = shaderTexture.Sample(SampleType, Pin.tex); 
    return textureColor; 
} 

Pour mémoire tampon d'entrée de pixel shaders, je ne ai pas besoin tampon de position dans ce code. J'ai donc supprimé float4 PosH dans ce code. alors pixel shader ne fonctionne pas, je vois la caisse de bière noire. quand je retore la forme de structure qui a float4 pour l'information de position et float2 pour l'information de textcoord, cela fonctionne bien agian. Je pense que je ne comprends pas comment fonctionne ce pipeline de rendu. Pourriez-vous m'expliquer pourquoi cela fonctionne et comment le pipeline fonctionne-t-il? Je vous remercie.

+0

Le '' SV_POSITION'' est une sortie requise du Vertex Shader comme il est implicitement partie du traitement Pixel Shader. –

Répondre

0

Les shaders DirectX doivent avoir une entrée et une sortie correspondantes entre les étages de shader, sinon les alignements manqueront. Si vous utilisez le calque de débogage, vous devriez recevoir un avertissement.

Si votre pixel shader n'a pas besoin sv_position, vous pouvez le mettre à la fin de VertexOut

+0

oh c'est l'alignement. cet alignement me fatigue. Je vous remercie –