Skip to content

Guide: Loading & Applying Effects

Alan Stagner edited this page Jun 9, 2020 · 1 revision

BNA allows for arbitrary shaders to be loaded, and makes use of compiled HLSL Effect files for this. These files were traditionally compiled using the fxc.exe compiler, although as a replacement you may consider an alternative like Effect-Build to compile your .fx files.

Loading compiled effect files is super simple:

using BNA.Graphics;

// ...

Effect myEffect;
if(Effect.Load(graphicsDevice, "./Content/Shaders/myEffect.fxo") case .Ok(let effect))
{
    // effect has been loaded!
    myEffect = effect;
}

Once your effect has been loaded, you can set parameters:

myEffect.SetVec4("Color", Vec4(1.0f, 1.0f, 0.0f, 1.0f));
myEffect.SetTexture("MainTexture", myTexture, .(.Linear, .Wrap));

And then set the current technique and apply a pass for future draw calls to use:

myEffect.SetTechnique(0); // set to first technique in file
myEffect.ApplyEffect(0); // apply first pass of technique for subsequent draw calls