Jump to content
  • Advertisement
Sign in to follow this  
paperplane

DX11 How to compile shaders in DX11

This topic is 1005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello and sorry if this is a stupid question, I am new to DirectX.

I am working on a project for college (a simple DX11 application) and I'm using Frank Luna's Intro to Game programming with DX11.
The thing is, he uses Effects framework and my professor referred to that framework as being old (I may have misunderstood that, but I don't think I did).

I found some materials that don't use effects framework, but all those were for Windows Metro applications (I am building a win32 application).

So, do I have to download DirectX SDK and use effects framework, or can I get around that with something from Windows SDK?

 

Thanks for reply and I sorry for any typos, grammar errors (not a native English speaker)

Edited by paperplane

Share this post


Link to post
Share on other sites
Advertisement

So i just have to create *.hlsl files and read the binaries from *.cso?

That is way easier than I hoped... 

 

Thank you both for your answers!

Share this post


Link to post
Share on other sites

So i just have to create *.hlsl files and read the binaries from *.cso?
That is way easier than I hoped...

Thank you both for your answers!

If you are using Visual Studio, yes. But there's a little detail: you need to specify what profile you want the shader to compile to (what kind of shader and what version of HLSL). That's pretty easy, you just need to go to the properties of the HLSL file (right-click the file in the solution explorer and click properties) and set it up.

If you need any help and you can't find it on Google or MSDN, just ask.

EDIT: Take a look at this. Look for "Shader type" and "Shader model".

EDIT2: Also, you either need to name your main function "main" or you must set the Entrypoint name parameter to whatever you're using (like PSTextured), so the compiler knows where your code starts from.

Share this post


Link to post
Share on other sites
Note that it's perfectly possible to use effects 11 in your case. You can compile and generate the needed debug and release LIB in your own VS environment.

It all depends on your learning curve. I choose to use effects 11 because I need(ed) to learn so much other things from the Luna d3d11 book (I'll get rond of effects11 later on)

Share this post


Link to post
Share on other sites

 

So i just have to create *.hlsl files and read the binaries from *.cso?
That is way easier than I hoped...

Thank you both for your answers!

If you are using Visual Studio, yes. But there's a little detail: you need to specify what profile you want the shader to compile to (what kind of shader and what version of HLSL). That's pretty easy, you just need to go to the properties of the HLSL file (right-click the file in the solution explorer and click properties) and set it up.

If you need any help and you can't find it on Google or MSDN, just ask.

EDIT: Take a look at this. Look for "Shader type" and "Shader model".

EDIT2: Also, you either need to name your main function "main" or you must set the Entrypoint name parameter to whatever you're using (like PSTextured), so the compiler knows where your code starts from.

 

Thanks a lot for your answer, that link was very informative!
I hope I won't have to ask too many questions (although, some of these things are really hard to google). 

Share this post


Link to post
Share on other sites

Note that it's perfectly possible to use effects 11 in your case. You can compile and generate the needed debug and release LIB in your own VS environment.

It all depends on your learning curve. I choose to use effects 11 because I need(ed) to learn so much other things from the Luna d3d11 book (I'll get rond of effects11 later on)

 

When you say effects 11, do you mean this? https://github.com/Microsoft/FX11

So, I can just include it in my VS project and compile the effects code from the FL's book without changes?

Thanks for the reply!

Share this post


Link to post
Share on other sites

 

Note that it's perfectly possible to use effects 11 in your case. You can compile and generate the needed debug and release LIB in your own VS environment.

It all depends on your learning curve. I choose to use effects 11 because I need(ed) to learn so much other things from the Luna d3d11 book (I'll get rond of effects11 later on)

 

When you say effects 11, do you mean this? https://github.com/Microsoft/FX11

So, I can just include it in my VS project and compile the effects code from the FL's book without changes?

Thanks for the reply!

 

 

I've never used that library, so I can't say for sure, but I took a look and it seems that the answer is yes. It seems there's some differences from the original Effects 11 (take a look at this page) but not many.

 

Still, I recommend you to only use effects for educational purposes. Throw them away when you start working in something serious.

Share this post


Link to post
Share on other sites

I've been using Visual Studio 2015 recently for a little hobby project. Instead of compiling into cso files and loading your shaders from files, you can compile them into header files. I also think this was available in at least one previous version of Visual Studio, if you're not using 2015.

The advantage is that you can now load the shader directly from a byte buffer, which is very convenient, because you do not have to mess around with files. The disadvantage is that the byte buffer is always going to taking up some of your memory, which probably isn't ideal for a AAA game with a bunch of different complex shader options consuming the precious address space in its 32-bit build.

To build a shader into a header, you have to set a header file name and header variable name in the properties for the hlsl file. Then you include the header file somewhere and directly pass the variable into the device's CreateWhateverShader function.

The compiler also dumps a ton of comments into the headers it creates, so you can read the compiler's output.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!