Effects in DirectX 11

Warning! Some information on this page is older than 5 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

13:18
Sat
15
May 2010

Effects in DirectX 11

I no longer believe Microsoft did a good job complicating new DirectX so much. Effects framework - the API that supported loading and using effect files that grouped HLSL code and render states into passes and techniques - is no longer intrinsic part of D3DX. Instead they provided source code for this library so you have to compile it by yourself!

To do this: Enter your DX SDK subdirectory "Samples\C++\Effects11", open a "Effects11_*.sln" solution file appropriate for your Visual C++ version and compile the project in both Debug and Release configuration.

Then to use effects API in your project you have to include this header: "YOUR_DX_SDK_PATH\Samples\C++\Effects11\Inc\D3dx11effect.h" and link with this lib: "YOUR_DX_SDK_PATH\Samples\C++\Effects11\Debug\D3DX11EffectsD.lib (Debug) or "YOUR_DX_SDK_PATH\Samples\C++\Effects11\Release\D3DX11Effects.lib" (Release), as well as with "d3dcompiler.lib" (in both configurations).

Here is example of how to load an effect from file. You need to first compile a source code from file or memory into a blob binary effect and then create real effect object from this blob.

// Compile effect from HLSL file into binary Blob in memory
ID3D10Blob *effectBlob = 0, *errorsBlob = 0;
HRESULT hr = D3DX11CompileFromFile(
  "Effect1.fx", 0, 0, 0, "fx_5_0", 0, 0, 0, &effectBlob, &errorsBlob, 0);
assert(SUCCEEDED(hr) && effectBlob);
if (errorsBlob) errorsBlob->Release();
// Create D3DX11 effect from compiled binary memory block
ID3DX11Effect *g_Effect;
hr = D3DX11CreateEffectFromMemory(
  effectBlob->GetBufferPointer(), effectBlob->GetBufferSize(), 0, g_Dev, &g_Effect);
assert(SUCCEEDED(hr));
effectBlob->Release();

The effect itself is not enough. You need to retrieve object that represents "pass" to use it. So you get a technique from the effect (by index or by name) and then the pass from the technique.

ID3DX11EffectTechnique *g_EffectTechnique; // No need to be Release()-d.
g_EffectTechnique = g_Effect->GetTechniqueByIndex(0);
assert(g_EffectTechnique && g_EffectTechnique->IsValid());

ID3DX11EffectPass *g_EffectPass; // No need to be Release()-d.
g_EffectPass = g_EffectTechnique->GetPassByIndex(0);
assert(g_EffectPass && g_EffectPass->IsValid());

Now when you have this object, you can apply settings from this pass to the device context during rendering:

g_EffectPass->Apply(0, g_Ctx);
g_Ctx->Draw(3, 0);

But still one problem reamins. In DirectX 11 you need to pass a pointer to the bytecode with compiled shader when creating input layout - a step that you probably cannot omit. Fortunately there is a way to access this pointer stored inside loaded effect. You just need to pass through two descriptors, just like this:

D3DX11_PASS_SHADER_DESC effectVsDesc;
g_EffectPass->GetVertexShaderDesc(&effectVsDesc);
D3DX11_EFFECT_SHADER_DESC effectVsDesc2;
effectVsDesc.pShaderVariable->GetShaderDesc(effectVsDesc.ShaderIndex, &effectVsDesc2);
const void *vsCodePtr = effectVsDesc2.pBytecode;
unsigned vsCodeLen = effectVsDesc2.BytecodeLength;

ID3D11InputLayout *g_InputLayout;
D3D11_INPUT_ELEMENT_DESC inputDesc[] = { /* ... */ };
hr = g_Dev->CreateInputLayout(
  inputDesc, _countof(inputDesc), vsCodePtr, vsCodeLen, &g_InputLayout);

Luckily it looks like the effect framework doesn't add much functionality over pure HLSL shader supported by D3D11 itself, so you don't have to use it. Defining these techniques and passess is not so important after all...

Comments (3) | Tags: directx rendering | Author: Adam Sawicki | Share

Comments

leisi
2015-08-27 14:15:20
http://www.lancelpascherbien.fr
<a href="http://goo.gl/M9vWgP">L
2016-02-23 15:02:40
nice site
wty123
2016-03-23 07:27:51
A http://www.airjordans.us/ Man http://www.burberry-outlet.net.co/ who http://www.zxcoachoutlet.com/ passes http://www.longchamp-handbags.us.com/ his evening http://www.vans-shoes.co.uk/ as http://www.toms-shoesoutlet.net/ I http://www.nike-air-max.ca/ had http://www.burberrysoutlet2016.com/ passed mine, http://www.ralphlaurenepolo.com/ may go http://www.hollisterclothingstore.org/ to http://www.ralphlaurenonlineshop.de/ bed http://www.christian-louboutin-shoes.ca/ afterward http://www.gucci-taschen-outlet.de/ if he http://www.beatsbydre.com.co/ has http://www.nike-roshe-run.com.es/ nothing http://www.pumaonline-shop.de/ better to http://www.katespadeoutlet.gb.net/ do. http://www.bottega-veneta.us.com/ But http://www.ghd-hairstraightener.net/ he must http://www.oakleys-glasses.us.com/ not http://www.adidasshoes.top/ rank http://www.oakley-sunglasses-canada.ca/ among http://www.horloges-rolex.nl/ the http://www.michaelkorsoutlet.ar.com/ number http://www.ray-ban-outlet.us.com/ of http://www.cheapjerseys.com.co/ his http://www.vans-schuhe.com.de/ reasonable anticipations http://www.toryburchsale.com.co/ the http://www.replica-watches.com.co/ expectation http://www.louboutin.jp.net/ of getting http://www.swarovski-australia.com.au/ a http://www.ferragamo.com.co/ night&#8217;s http://www.fashionclothes.us.com/ rest. http://www.timberlandshoes.net.co/ The http://www.cheaprayban.com.co/ morning http://www.hermesbags.jp.net/ was http://www.cheapuggboots.us.com/ well http://www.levisjeans.com.co/ advanced, http://www.michael-kors-taschen.com.de/ and http://airhuarache.shoesoutlet.us.com/ the hotel http://www.mcm-bags.in.net/ was http://www.soccer-shoes.us.com/ astir, http://www.thenorthface.com.de/ before http://www.coach-factoryoutlet.net.co/ I http://www.eyeglassesonline.us.com/ at http://www.nike-rosherun.nl/ last http://www.rayban-wayfarer.in.net/ closed http://www.rayban-sunglasses.us.org/ my http://www.lauren-ralph.co.uk/ eyes http://www.louisvuitton.so/ in http://www.handbagsoutlet.net.co/ slumber. http://www.tommy-hilfiger-online-shop.de/ When http://www.instylers.us.com/ I http://www.mcmbags.net/ awoke, my http://www.the-northface.com.co/ watch http://www.tocoachoutlet.com/ informed http://www.nikestore.com.de/ me http://www.swarovski-crystal.us.com/ that http://www.thomas-sabo.com.de/ it http://www.soft-ballbats.com/ was http://uggaustralia.misblackfriday.com/ close on http://www.tnf-jackets.us.com/ noon.


I http://mcmbackpack.co-om.com/ rang http://www.oakley-sunglasses.mex.com/ the bell. http://www.celine-bags.org/ My http://www.omega-watches.us.com/ servant http://www.michaelkorsoutlet-online.ar.com/ appeared http://www.adidas-superstar.de/ with http://www.longchamp.com.co/ a http://www.jordanretro.org/ letter in http://www.nike-schoenen.co.nl/ his http://www.edhardy.us.org/ hand. http://www.burberry-outletstore.net/ It http://www.tiffany-jewelry.net/ had http://www.michael-kors.com.co/ been left http://www.kate-spade.in.net/ for http://www.northfaceoutlet.com.co/ me, http://www.maccosmetics.net.co/ three http://www.louis-vuitton-australia.com.au/ hours http://www.nike-air-max.com.au/ since, http://www.toms--outlet.com.co/ by a http://www.louis--vuitton.org.uk/ lady http://www.nike-air-max.us/ who http://www.burberry-outletonlinesale.in.net/ had http://www.louis-vuitton-taschen.com.de/ driven http://coachoutlet.euro-us.net/ to http://www.ugg-australia.com.de/ the http://www.michaelkors.so/ hotel http://www.juicycouture.com.co/ door http://www.abercrombie-hollister.nl/ in http://www.abercrombie-and-fitch.us.com/ a http://www.nike-shoesoutlet.us.com/ carriage, http://www.marcjacobs.us.com/ and http://www.swarovski--uk.me.uk/ had http://www.uggs-onsale.net/ then http://www.michaelkors-outlet-online.com.co/ driven http://www.jordanrelease-dates.us.com/ away http://www.adidas-superstar.nl/ again. The http://www.burberryoutlet-canada.ca/ man http://www.mmoncler-outlet.com/ had http://www.mcmhandbags.com.co/ found http://www.prada-handbags.com.co/ me http://www.chanelhandbags.net.in/ sleeping http://www.moncler-outlet.us.org/ when http://www.michael-korshandbags.org.uk/ he http://www.hollister-clothing.in.net/ entered http://www.coach-purseoutlet.net/ my http://michaelkors.euro-us.net/ bed-chamber, and, http://www.burberry-handbags2016.in.net/ having http://www.salvatoreferragamo.in.net/ received http://www.cheap-nike-shoes.net/ no orders http://www.prada.com.de/ to http://www.nike.org.es/ wake me http://www.coach-factory.in.net/ overnight, http://www.pandora-charms-canada.ca/ had http://www.louisvuittons.com.co/ left http://www.nike-free-run.de/ the http://coach.euro-us.net/ letter http://www.burberrybags-outlet.com/ on http://www.michaelkors.co.nl/ the http://www.nike-huarache.nl/ sitting-room http://www.chiflatiron.net.co/ table http://www.christianlouboutinshoes.jp.net/ until http://www.michael-kors-australia.com.au/ he http://www.canada-goosesjackets.us.com/ heard http://www.truereligion-outlet.us.org/ my http://www.toryburchoutlet-sale.us.com/ bell.


Easily http://www.louisvuitton-outlets.us/ guessing http://www.pandorajewellery.com.au/ who http://www.tommyhilfigeroutlet.in.net/ my http://www.nike-shoes-canada.ca/ correspondent http://www.adidas-schuhe-online.de/ was, http://www.polo-outlets.com.co/ I http://www.michaelkors-uk.org.uk/ opened http://www.newbalance-shoes.org/ the http://www.rayban.com.de/ letter. http://michaelkors.co-om.com/ An http://www.nikeair-max.es/ inclosure http://www.coco-chanels.us.com/ fell http://www.mizuno-running.net/ out http://www.supra-shoes.org/ of http://www.yoga-pants.net.co/ it http://www.guccishoes-uk.co.uk/ &#8212; http://www.newbalance-outlet.org/ to http://www.coco-chanel.com.de/ which, http://www.swarovskijewelry.com.co/ for http://www.rosherun.org.uk/ the http://www.polooutlets-store.com/ moment, http://www.outlet-burberry.net.co/ I http://www.ralphlaurenpolos.in.net/ paid http://www.guccishoes.us.org/ no attention. http://www.oakley--sunglasses.com.au/ I http://www.uggs.co.nl/ turned http://www.newbalance.com.es/ eagerly to http://www.woolrich-clearance.com/ the http://www.ferragamoshoes.in.net/ first http://www.tommy-hilfigeroutlet.com/ lines. http://www.abercrombie-kids.us.com/ They http://www.tommy-hilfiger-canada.ca/ announced that http://www.cheapshoes.com.co/ the writer http://www.lululemonoutlet.gb.net/ had http://www.mk-outlet.us.com/ escaped me http://www.nikeskos.dk/ for http://www.abercrombie-fitchs.us.com/ the second http://www.jimmy-choos.com/ time: http://www.hermesbirkin-bag.net/ early that http://www.cheap-jordans.net/ morning http://www.air-max.com.de/ she http://www.airhuarache.co.uk/ had http://www.nikefree-run.net/ left http://www.rayban.co.nl/ Edinburgh. The http://www.jimmy-chooshoes.com/ paper http://www.new-balance.ca/ inclosed http://www.guccihandbags.net.co/ proved http://www.nike-air-max.com.de/ to http://www.newoutletonlinemall.com/ be http://www.nike-air-force.de/ my http://www.the-north-face.ca/ letter of http://www.tiffany-und-co.de/ introduction http://nike.shoesoutlet.us.com/ to http://www.salomon-schuhe.com.de/ the http://www.thejoreseproject.com/ dressmaker http://www.uggboots.net.co/ returned http://www.hollister-abercrombie.com.se/ to http://www.tiffanyandco-canada.ca/ me.


I was http://www.hollisters-canada.ca/ more http://www.christian--louboutin.in.net/ than http://www.tommyhilfiger.net.co/ angry with her http://www.oakleysunglasses-cheap.in.net/ &#8212; http://www.cheapoakley-sunglasses.com/ I felt http://www.thenorth-faces.co.uk/ her http://www.wedding--dresses.ca/ second http://www.beatsbydrdre.co.com/ flight http://www.rolex-watch.me.uk/ from http://www.gucci-outletstore.com/ me http://www.cheap-raybans.com/ as http://www.oakleyoutlet-online.us.com/ a http://www.yoga-pants.ca/ downright http://www.nike-schuhe.com.de/ outrage. In http://www.rosheruns.us/ five http://www.airmax-90.org/ minutes I http://supra.shoesoutlet.us.com/ had http://monsterbeats.co-om.com/ hurried http://www.adidas.org.es/ on http://www.harrods-london.co.uk/ my http://www.pulseras-pandora.com.es/ clothes http://www.longchamphandbagsoutlet.net/ and http://www.burberry-outlets.co.uk/ was http://airmax.misblackfriday.com/ on http://www.nikerosherun.us/ my http://www.replica-handbags.in.net/ way http://www.burberryoutlet2016.us.com/ to http://www.christian-louboutinshoes.com.co/ the http://www.uggboots.com.de/ inn http://www.tommy-hilfiger.com.de/ in http://www.pradaoutlet.com.co/ the http://www.bcbg-max-azria.ca/ Canongate http://www.tomsoutlet-online.com/ as fast http://www.pumashoes.in.net/ as http://www.coach-outletonline.net.co/ a horse http://www.louis-vuittonblackfriday.com/ could draw http://www.air-huarache.co.uk/ me.


The http://www.nikefree5.net/ servants http://www.guccioutlet-sale.in.net/ could http://www.insanity-workout.us.com/ give http://www.ralphlaurenoutletonline.us.org/ me http://www.eyeglassframes.in.net/ no http://www.ralph-lauren.com.au/ information. http://www.tory-burchshoesoutlet.net/ Her escape http://www.michaelkorsoutletonline-sale.us.com/ had http://www.bebeclothing.in.net/ been http://www.ralphslauren-outlet.co.uk/ effected http://www.abercrombieand-fitch.ca/ without http://www.raybans.us.org/ their http://www.michael--kors.us.com/ knowledge.


The http://www.longchamp.com.de/ landlady, http://www.pandora.com.de/ to http://www.ugg-boots.us.org/ whom http://www.chanel-bags.com.co/ I http://www.louisvuitton-outlet.com.co/ next http://www.guccishoes.com.co/ addressed myself, http://www.cheap-michaelkors.com/ deliberately declined http://www.converse-shoesoutlet.com/ to http://www.pandorajewelry.top/ assist http://northfaceoutlet.co-om.com/ me in http://www.nike-skor.com.se/ any http://www.burberry2016.co.uk/ way http://www.ralphlaurenoutletonline.in.net/ whatever.


&#8220;I http://www.true-religion.com.co/ have given http://www.longchamp.us.org/ the http://www.cheapoakley-sunglasses.in.net/ lady my http://www.designer-handbagsoutlet.us.com/ promise,&#8221; http://www.coachoutletstore-online.com.co/ said http://www.christianlouboutinoutlet.net.co/ this obstinate http://www.cheap-baseballbats.net/ person, http://www.giuseppezanotti.com.co/ &#8220;to http://www.timberlandbootsoutlet.us.com/ answer http://www.guccishoes.in.net/ not http://www.abercrombie-fitchsale.com/ one http://www.ugg-uggboots.net/ word http://www.coachoutletstore.net.co/ to http://www.maccosmetics.gr.com/ any question http://www.toms-shoes.com.co/ that you http://www.ray--ban.ca/ may ask http://www.weddingdressesuk.org.uk/ me about her. http://www.montblanc--pens.in.net/ In http://www.adidas--canada.ca/ my http://www.thomas-sabos.org.uk/ belief, http://www.michaelkorsbags.us.org/ she http://www.vans-shoes.net/ is http://www.nike-air-max.com.se/ acting http://www.omegarelojes.es/ as http://www.retro-jordans.com/ becomes http://www.longchampoutlet.com.co/ an http://www.calvin-kleins.us.com/ honest http://www.jordan-shoes.com.co/ woman http://www.michaelkors.com.se/ in http://www.toms-shoes.net.co/ removing herself from http://www.iphone-cases.net.co/ any http://www.juicycoutureoutlet.net.co/ further http://www.oakleys-sunglasses.us.com/ communication http://www.lululemon-australia.com.au/ with http://www.polo-ralph-lauren.de/ you. I http://www.ralph-laurenoutlet.ca/ saw http://www.hollisteronlineshop.com.de/ you through http://www.michaeljordan.com.de/ the http://www.uggs.in.net/ keyhole http://www.kate-spade.gb.net/ last http://www.nikestore.us/ night, http://www.prada-shoes.com.co/ sir. I http://www.christianlouboutinshoesoutlet.org/ wish you good-morning.&#8221;


Returning http://www.swarovski-online-shop.de/ to http://www.longchamp-handbagsoutlet.us.com/ my http://www.asicsgels.de/ hotel, I http://www.rayban-sunglassesoutlet.co.uk/ left http://www.rolex-watches.us.com/ no http://www.barbour-factory.com/ attempt http://www.christianlouboutin.org.uk/ to discover http://www.toms-outlets.us.com/ her untried. http://www.burberryoutlet-sale.in.net/ I http://www.beats-by-dre.com.co/ traced http://www.ralphlaurenoutlet.us.com/ the http://www.adidas.com.se/ coachman http://www.tommy-hilfiger.co.nl/ who http://www.rolexwatches-canada.ca/ had http://www.nfl-jersey.us.com/ driven http://www.oakley-outletstore.in.net/ her. http://www.tiffanyandco.net.co/ He http://www.ugg-boots.ca/ had http://www.poloralphlaurenoutlet.net.co/ set http://www.coachblackfriday.com/ her http://www.pandora-charms.org.uk/ down http://www.truereligion-outlet.com.co/ at http://www.nikemercurial.in.net/ a http://www.louis-vuittonoutletcanada.ca/ shop, http://www.coach-factoryyoutletonline.net/ and http://www.swarovskicanada.ca/ had http://www.reebok.com.de/ then http://www.lululemoncanada.ca/ been http://www.louisvuitton.jp.net/ dismissed. http://www.rolexwatchesforsale.us.com/ I questioned http://www.the-northface.net.co/ the http://airmax.shoesoutlet.us.com/ shop-keeper. http://www.p90xworkout.us.com/ He http://www.oakley.org.es/ remembered http://www.converse.net.co/ that http://www.raybans-sunglassesoutlet.in.net/ he had http://www.michael-kors.net.co/ sold http://www.barbour-jacketsoutlet.com/ some http://www.michael-kors-handbags.us.com/ articles http://www.airmax-2015.org/ of http://www.giuseppe-zanotti.net/ linen http://www.truereligionjeans.net.co/ to http://www.oakley-sunglassoutlet.net/ a http://www.tomsshoes-outlet.us.com/ lady http://www.cheapjerseys.us.org/ with http://www.burberry-handbagsoutlet.com.co/ her http://www.beats-headphone.com.co/ veil http://www.ralph-laurens.org.uk/ down http://www.new-balance-schuhe.de/ and http://www.converse-shoes.net/ a http://www.hogan.com.de/ traveling-bag http://www.michael-kors-outlet.us.org/ in http://www.thenorthfacejackets.net.co/ her hand, http://www.ugg-bootsclearance.com/ and http://www.cheap-oakleyglasses.us.com/ he http://www.michael-kors-canada-outlet.ca/ remembered http://www.converse.com.de/ no http://www.tiffany-andco.com.au/ more. http://www.mcmsworldwide.com/ I http://www.nikeshoesoutlet.org.uk/ circulated a http://www.coachoutlet-online.com.co/ description http://www.coachhandbags2016.us.com/ of her http://www.ralphlaurenoutlet-online.us.com/ in http://www.ralphs-lauren.co.uk/ the http://www.toryburch-sandals.in.net/ different coach http://www.chi-flatiron.us.com/ offices. http://www.canadagooses-2016.com/ Three http://www.michael-kors.com.es/ &#8220;elegant http://www.asics-outlet.us.com/ young http://www.cheapmichaelkors.us.org/ ladies, http://www.pradahandbags.net.co/ with http://www.designerhandbagsoutlet.net.co/ their http://www.ugg-boots-australia.com.au/ veils http://www.bcbg-dresses.com/ down, http://www.mkoutletonline.us.com/ and http://www.babyliss-pro.us.com/ with traveling-bags http://www.rayban.org.es/ in http://www.oakley.com.de/ their http://www.burberryonlineshop.de/ hands,&#8221; http://www.basketballshoes.com.co/ answered http://www.uggsoutlet.com.co/ to http://www.hollister.us.org/ the http://www.nikefree-run.org.uk/ description; http://www.the-northfacejackets.us.com/ and which http://www.hermes-outlet.com.co/ of http://www.nikefactory.org/ the http://www.nike-roshe-run.de/ three http://www.uhren-shop.com.de/ was http://www.uggsaustralia.com.co/ the http://www.tomsoutletonline.net/ fugitive http://www.bottegaveneta-bagsoutlet.com/ of

http://www.michael-kors-outlet-online.us.org/

Post comment

Nick *
Your name or nickname
E-mail
Your contact information (optional, will not be shown)
Text *
Content of your comment
Calculate *
(* - required field)
STAT NO AD [Stat] [Admin] [STAT NO AD] [pub] [Mirror] Copyright © 2004-2017 Adam Sawicki
Copyright © 2004-2017 Adam Sawicki