Best Approach For ...

Dec 30, 2013 at 10:35 PM
Hi everyone!

The latest version of the DirectXTK is aweseome! My FBX files from XNA days of yore look great with the basic effect. I am REALLY enjoying programming in VC++ with DirectXTK. It is way harder but I like the results more than using Unity or MonoGame. MonoGame is a serious contender but I decided to use the CMO content pipeline in VS2013 and it gets the job done. (It would be great if the output texture DDS format could be selected...)

I wanted to ask, what is the best approach for using the DirectXTK Model class when the effect and/or textures may change? I have a planet Model, which contains one mesh, and I am swapping out the texture used in the effect on the draw call. The thing is -- it looks like initial phong effect and texture is being loaded with the model. Is there a best approach for what I am trying to do?

I am thinking I might comment out the texture loading code in the DirectXTK for effect on model load, or add overloads to accomplish this. Alternatively, I could try setting a default texture that is very small, i.e. 1x1. That seems like a hack -- well, both do, since I don't want to modify the DirectXTK source if I can help it.

What do you think?
Coordinator
Dec 30, 2013 at 11:10 PM
Edited Dec 30, 2013 at 11:11 PM
If your planet is just a sphere, perhaps a better approach would be to use the GeometricPrimitive::CreateSphere or CreateGeoSphere. You could apply a custom effect to it a well if you don't like the default BasicEffect...

For CMO, you could make use of the DGSL shader pipeline to provide a custom pixel shader for your effect. It's a bit tricksey for Feature Levels 9.x, but works fine for FL 10.0+. DirectXTK supports both a 'BasicEffect' approach or a 'DGSLEffect" approach.

Finally, you could provide a custom IEffectFactory and just use 'magic string names' as a way to substitute your own effect implementation at load-time.
Dec 31, 2013 at 12:09 AM
walbourn wrote:
For CMO, you could make use of the DGSL shader pipeline to provide a custom pixel shader for your effect. It's a bit tricksey for Feature Levels 9.x, but works fine for FL 10.0+. DirectXTK supports both a 'BasicEffect' approach or a 'DGSLEffect" approach.
That is very interesting! Could it be this easy: remove the effect in the FBX file and then DirectXTK defaults to BasicEffect? If true, this would eliminate the overhead of a Phong effect being created first. Or if I add a BasicEffect implementation to the FBX file before it is exported to CMO, I might save a load cycle. With respect to that latter approach, I am thinking FxFactory will maintain separate instances of the same 'BasicEffect' effect in memory since it is considered unique to the model -- which I am not keen to do. You may be right -- re-implement IEffectFactory or change existing code in DirectXTK.
Coordinator
Dec 31, 2013 at 1:32 AM
Edited Dec 31, 2013 at 1:34 AM
When you load a .CMO, you provide a IEffectFactory interface. If you provide an instance of EffectFactory, it uses BasicEffect or SkinnedEffect. If you use DGSLEffectFactory, then it uses DGSLEffect. These factories implement the 'caching' of textures and pixel shaders (for DGSL effect). You can derive from EffectFactory and overload only the CreateEffect() method to do your custom effect creation. If you use the stock implementation of CreateTexture, it handles caching of textures.
Marked as answer by walbourn on 12/30/2013 at 5:34 PM
Jan 4, 2014 at 6:58 PM
This worked for me, thank you!