Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm using the DirectX Effects framework and I want to create an input layout automatically when compiling an effect. I've tried to call ID3DX11Effect->GetVariableByName() with the shader's name, to obtain a pointer to a ID3DX11EffectVariable interface, then doing ID3DX11EffectVariable->AsShader() to obtain a pointer to a ID3DX11EffectShaderVariable interface. The problem is that the pointer returned by ID3DX11Effect->GetVariableByName() is not valid (the IsValid() method returns false). So how can I get a pointer to the shaders of an effect file ?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The effect framework is based around the concepts of techniques and passes, so you will need to go through these to get to your shader. The API will let you get a list of techniques in the effect and a list of passes in a technique; you can then extract the shaders from the pass.

Here is the code from my engine that extracts the vertex shader from the first pass of the first technique of an effect and goes through its input signature. I've removed the error checking for brevity, but you can see how it would work.

ID3DX11EffectTechnique * pTech = m_pEffect->GetTechniqueByIndex(0);
D3DX11_TECHNIQUE_DESC techDesc;
pTech->GetDesc(&techDesc);

ID3DX11EffectPass * pPass = pTech->GetPassByIndex(0);
D3DX11_PASS_DESC passDesc;
pPass->GetDesc(&passDesc);

D3DX11_PASS_SHADER_DESC vsPassDesc;
pPass->GetVertexShaderDesc(&vsPassDesc);

ID3DX11EffectShaderVariable * pVs;
pVs = vsPassDesc.pShaderVariable->AsShader();

D3DX11_EFFECT_SHADER_DESC vsDesc;
pVs->GetShaderDesc(0, &vsDesc);

// Build the vertex format
for (UINT iInput = 0; iInput < vsDesc.NumInputSignatureEntries; ++iInput)
{
    D3D11_SIGNATURE_PARAMETER_DESC inputDesc;
    pVs->GetInputSignatureElementDesc(0, iInput, &inputDesc);
    // do something with the input element...
}
share|improve this answer
    
Thanks, I got it working now. Although I'm not certain if I should continue using the effects framework, since its pretty much dead from what I've been reading. –  user25894 Feb 3 '13 at 20:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.