-
Notifications
You must be signed in to change notification settings - Fork 4
Guide: Loading & Applying Effects
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
Getting Started
Drawing Sprites
Loading & Applying Effects
Loading Textures
Creating vertex & index buffers and drawing geometry
Using render buffers
Playing sound effects & music
Routing sound through buses & applying filters
Game
GameWindow
GraphicsDevice
SpriteBatch
Audio
Keyboard
Mouse
GamepadDevice