Jump to content
  • Advertisement
Sign in to follow this  
RevGames_2009

XNA & SM 3.0

This topic is 3782 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

I learned over on the XNA Creators Club forums that you can use Shader Model 3.0 in your XNA, Windows-based games. But, I am unsure as to how to go about this. I have two questions: 1. How would you change the 'Check For Shader Model 2 Support' C# code to 'Check For Shader Model 3 Support?' 2. How would you go about implementing support of SM 3.0 into your games? Are there any good resources out on the web? Thanks for your time, and I can't wait to read and implement all of the information you give me.

Share this post


Link to post
Share on other sites
Advertisement
RevGames,

Yes, it's entirely possible to write Shader Model 3.0 shaders while using XNA.

Quote:
1. How would you change the 'Check For Shader Model 2 Support' C# code to 'Check For Shader Model 3 Support?'


To answer your first question, you simply modify the example provided by the SDK to check for a "3" instead of a "2". For example:


// Check the graphics device used by the game for the necessary shader support.
GraphicsDeviceCapabilities caps = graphics.GraphicsDevice.GraphicsDeviceCapabilities;
if (caps.MaxPixelShaderProfile < ShaderProfile.PS_3_0)
{
// This device does not support Shader Model 3.0.
System.Diagnostics.Debug.WriteLine("This adapter does not support Shader Model 3.0.");
}



Quote:
2. How would you go about implementing support of SM 3.0 into your games? Are there any good resources out on the web?


The best resource for shader instructions and capabilities is still the latest DirectX documentation that ships with the DirectX SDK. In the documentation there is a guide to writing pixel and vertex shaders, as well as a reference section which lists the features of SM 3.0, the new semantics, registers, and all available intrinsic functions.

To specifically answer your question the HLSL compiler that is part of XNA Game Studio will automatically compile into VS/PS 3.0 if necessary in order to accurately reproduce your HLSL code. Additionally, having support for VS/PS 3.0 means that the ASM compiler in XNA recognizes the instructions and semantics which exist in Shader Model 3.0. So there is no implementation "support" necessary. You simply write your shaders in VS/PS 3.0, or write it in HSLS and the rest happens automagically.

Cheers and Good Luck!

Share this post


Link to post
Share on other sites
Well, after editing the code for more than 30 minutes, I updated the entire Racing Game Starter Kit for XNA Game Studio 2.0 from Shader Model 2 to Shader Model 3. Well, I stared at the images created for a long while, and noticed, other than where and when the shot was taken, that the graphics were not very different.

Shader Model 2.0: (Original Game w/ some update code, mainly Vertex Shaders)

Racing Game Starter ~ SM 2.0

Shader Model 3.0: (Original Game w/ heavily update code, Pixel & Vertex Shaders)

Racing Game Starter ~ SM 3.0

Only other major thing I noted was a 7FPS performance increase in SM 2.0, which I can look past, since even in SM 3.0 I am getting frames over 60 FPS. Is it possible that I missed a couple lines of code for the shaders?

Share this post


Link to post
Share on other sites
Upgrading the shader model doesn't magically make it look any better. It just allows you to do different things with your shaders, and allows you more control over the pipeline. If you don't explicitly take advantage of this, it won't look any better.

Share this post


Link to post
Share on other sites

Well, whatever you want [smile]

SM3 has some general improvements over SM2 (instancing, *some* vertex texture fetch etc) and it allows you to set more constants and use more instructions, ie to just do more in your shader code. Exactly what these shaders do is completely up to you to code in using HLSL...

Maybe it helps to think of a shader as a material, which represents some textures (color, normal map etc) combined with a lighting model (diffuse, specular etc) to put on your scene. Shaders can do much more than that, but this is typically how they are used.

Share this post


Link to post
Share on other sites
RevGames,

When you program "Real-Time Shaders", whether SM 2.0 or 3.0 what you're doing is writing small programs that run directly on the video card's GPU. This allows you to offload some of the instructions involved in rendering your game to the video card, rather than leaving all the heavy lifting to your CPU. Ideally, this both increases performance and also frees up your CPU to focus on core game-play logic such as AI, Scene Management, or Physics (though it's now possible to do physics on the GPU as well).

So when you move a game from SM 2.0 to SM 3.0 this is functionally equivalent to porting your rendering code from one programming language to another. Doing this doesn't inherently make your graphics better, it simply changes the technology you're using. In this case, moving to SM 3.0 gives you more flexibility, increases the length your shader programs can be, and gives you some new instructions which offer powerful performance benefits. But regardless, it's still up to you to harness the power offered by the new Shader Model.

In the end, making the game look better will mean not only moving to SM 3.0, but also re-writing the existing Shaders in a way that utilizes the new features, as well as writing brand new shaders which do things the previous shaders did not. As for what you can do with shaders, it's all up to your imagination.

Do you want to change the ambient lighting model, the diffuse lighting model, add post-processing effects, real-time shadows, sub-surface scattering, atmospheric effects such as fog or haze, or particles such as rain or snow? What about procedurally generated clouds with light rays? You could also go another directly entirely and change your game to use a less realistic lighting model such as cel shading. Ultimately it's up to you to decide what will make your game look "better."

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!