Can't figure out Shaders for DirectX11?

ぐ巨炮叔叔 提交于 2019-12-23 03:15:55

问题


So, I have no idea how to use shaders. Coding them is easy, but not actually using them. MSDN is really useless to me, meaning they have the worst tutorials out there. I am currently reading Frank Luna's Direct3d 11 book, and I am finally to the part where I actually get to draw stuff. Exciting, except for the fact that it doesn't work. His BoxDemo - I'm sure worked 3 years ago when the book was made, but now with all of the new DirectX stuff - omitting the DirectX SDK and now using "Windows SDK", FX being deprecated, no more D3DX libraries... So frustrating. I went ahead and downgraded to the DirectX 2010 SDK - just so I can actually use a tutorial. Almost every D3D tutorial out there uses the D3DX libraries.

Anyway... now to my question. Visual Studio has an option to make .hlsl files. But, it also has the ability make .fx files (if you just type .fx at the end of the file name it creates .fx file). So, I could use the deprecated .fx way and learn how to use it easily with all of the tutorials teaching it - OR I can learn the new HLSL way, and have the hardest, most frustrating time trying to learn it with no tutorials.

I know they both use the HLSL language. But they both are used in the program differently. (CreateEffectFromMemory, CompileFromFile, etc). I kind of hope to learn the new way, but if I don't that is fine. Although, I pretty much have an entire program using an .fx file. I'm sure it will work, but I just need help building and utilizing "Effects11.lib".

Sorry for the dragging on post - in fact, I am sure I will not get any replies for a while - if I do get any - due to the length. I am pretty frustrated because learning DirectX has put my programming career on a massive hiatus for the past month, 2 months. Please and thank you for any help


回答1:


The file extension .hlsl vs. .fx is arbitrary. It's like the difference between .cpp and cxx. Historically .fx is used for HLSL shaders that included vertex shaders, pixel shaders, and the Effects (FX) techniques/passes, and .hlsl is a file that didn't include the Effects (FX) techniques/passes, but is just a convention. There's plenty of both used out there.

What matters is how the file is compiled. If you use fx_5_0, then it requires the Effects 11 runtime to actually use them. This itself is really nothing special. It effectively just invoke the same compiler for each combination of compile statements you provided for the Effects (FX) techniques/passes and bundles it up with some meta-data. In fact, you can often invoke the FXC compiler on a .fx file containing techniques/and passes using something like vs_5_0 or ps_4_0 and it will compile the appropriate stage-specific shader if you get the parameters just right.

RE: Effects11

The main issue with Effects 11 is that it requires the D3DCompile DLL at runtime because it uses that to extract the metadata required to wire up the state and shaders. This D3DCompile DLL is not usable with Windows Store apps in Windows 8.0 and Windows phone 8.0 when you actually deployed the app, only when you were developing the app. Thus, Effects 11 wasn't usable for those platforms.

This is no longer a technical issue for Windows Store apps for Windows 8.1 or Windows phone 8.1, but the compiler support for fx_5_0 is still deprecated. It has a few issues that are fixed for the other profiles vs_5_0, etc. A such, it's up to you if you want to use it or not as long as you understand it's limitations.

The latest version of Effects 11 is on CodePlex and I address the limitations there. There are some simple tutorials that use it, as well as a few samples. This version of Effects 11 actually doesn't need the legacy DirectX SDK at all.

In short, YMMV w.r.t. to Effects 11 but you can still use it for Win32 desktop apps, Windows Store apps for Windows 8.1, Windows phone 8.1 apps, and in theory with Xbox One apps too.

RE: D3DX

I can understand the frustration, but it's a common issue with the book publishing industry and technical books being way behind the ball in terms of changes. DirectX 11 was introduced back in 2008. The transition to the Windows 8 SDK came in 2012 and most developers much less book publishers completed missed it. I have some notes on that book on my blog.

For a complete list of 'modern' alternatives, see Living without D3DX.

For Win32 desktop apps, you can continue to use the legacy DirectX SDK. The main thing to note is that with the Windows 8.x SDK that comes with VS 2012 and VS 2013, the include and lib path orders are reversed than they were with VS 2010. See MSDN for details.

RE: Learning Direct3D 11

Have you looked at the DirectX Tool Kit?

Getting Started with Direct3D 11

Direct3D Feature Levels

HLSL, FXC, and D3DCompile

As for tutorials and samples, try DirectX SDK Samples Catalog.



来源:https://stackoverflow.com/questions/27326461/cant-figure-out-shaders-for-directx11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!