sharpdx / SharpDX-Samples

Official repository for all SharpDX Samples
346 stars 222 forks source link

More samples for high level shader classes with using WinRT + XAML (SwapchainPanel) #13

Closed QuantumDeveloper closed 9 years ago

QuantumDeveloper commented 9 years ago

Please, could you create more samples with all type of shaders fro WinRT+ XAML (swapchainpanel), because now it is not fully understandable how to use high level shader wrappers with high level XNA like API. How to use compute shaders, hull shaders and other with more comments in code.

There are a lot of sample how to use d3ddevicecontext.PixelShaders and so one, but how to use Effect classes (which is high level wrappers for shaders as I understand) it is not fully clear. Where to write my code for shaders and so on.

Could you please make such samples???

Also not clear situation with shader file for WinRT. Which file typea are native for WinRT? .hlsl, fx or what? Could you please also clarify this momemnt?

P.S. would be perfect to provide shader sample not only for d2d1, but also for d3d.

xoofx commented 9 years ago

There is already a custom effect sample that is pretty simple, no?

QuantumDeveloper commented 9 years ago

Yes, but I have few questions regarding that example. What is fx? Can I use other files as shader resources and so on. This example is simple, but it loose a lot of faces. Maybe it would better to create more complex example that developer can see how to rule and manage all aspects of effect class (and not only effect class). Still stays question about compute shaders usage and other shader types.

xoofx commented 9 years ago

What is fx?

Fx files are pretty standard effect files as seen in XNA fx shaders (though they are ShaderModel 3) or legacy Direct3D Effects that you can find all around in their samples and SDK. Compute shaders are simple to compile, just one entry point and a call to Device.Dispatch from C#.

I recommend you to use a book like "Introduction to 3D Game programming in DirectX11" by F.D.Luna you should understand how to use them.

I'm sorry but I don't have time to prepare a sample or help on usage, but it is just a few lines of code (more complicated if you want to setup some tessellation samples), so you should be able to figure out.

Also not clear situation with shader file for WinRT. Which file typea are native for WinRT? .hlsl, fx or what? Could you please also clarify this momemnt?

If you do a google of "hlsl vs fx" you should get more information there.

hlsl and fx files are both hlsl files and are usually used at editing time and compiled in binary code used at runtime (they can also be compiled at runtime). fx files is just slightly an extension of plain HLSL files as they support pass/techniques. A fx combines a whole GPU setup pipeline (set VS,PS...etc.) while a HLSL contains only a single entry point shader that needs to be setup manully on the device. In the old DirectX June 2010 SDK, you will often find boths (plain hlsl, with manual compilation of entry points and fx), but as Microsoft has somewhat discontinued the development of FX files and they are more using directly HLSL files, compiling directly each stage entry and setup the pipeline manually. But basically, for the Toolkit, it is similar to XNA.

At runtime, WinRT, as on Desktop only support running compiled shaders, so fx or hlsl files need to be compile to bytecode (using fxc.exe or d3d11compiler_xx.dll)

QuantumDeveloper commented 9 years ago

So Effect class using .fx files also support shader model 5.0 if I understand correctly?

xoofx commented 9 years ago

Yes, simply use "Profile = 11.0" in the pass, as similar in the CustomEffect sample file. This syntax is specific to SharpDX Toolkit but it also support the common syntax SetPixelShader( CompileShader( ps_5_0, PS() ) ); as seen in regular fx files using SM5.0

QuantumDeveloper commented 9 years ago

OK, thanks, I will try to deal with it, but It is imperative to create more examples if (when) you will have time to cover all aspect of your framework because sometimes it is extremely deiffer for WinRT from desktop and there are almost no documentation for methods and classes, so only examples can help.