Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

assuming I want my game to have a Cel-shaded look. There are plenty of tutorials how to implement Cel-shading in hlsl f.e. But what is the point? If I am creating my assets with Blender or 3d-max I have a lot of possibilities to add materials and shaders in the modeling software.

So why write shaders?

share|improve this question
    
Less work in Blender? –  Zolomon Jan 7 '12 at 11:57
2  
Because you probably can't use those materials in a game? Even if you could, those materials are designed for batch rendering and not real-time. –  Jonathan Dickinson Jan 7 '12 at 12:09
    
So whats the point of adding materials to formats like .x or .fbx then? They are mostly used in games? Aren't they? –  bodycountPP Jan 7 '12 at 12:22
3  
@bodycountPP No they usually aren't. The materials will most like just contain information about the diffuse color, specularity, ambient factor and probably the used texture. They won't generate shader code that you can directly use in game (which would be required for toon shading). –  bummzack Jan 7 '12 at 13:13
2  
Is this actually a problem you're facing, as per gamedev.stackexchange.com/faq#dontask? It kind of sounds like you're going on a fishing expedition, here, and have made no attempt to actually do anything related to this question. –  Trevor Powell Jan 8 '12 at 1:08
show 2 more comments

3 Answers

up vote 6 down vote accepted

First, ok-to-good question. Definitely not a bad question. To answer it, you just have to know what a shader is and why you need one.

A shader is exactly what it sounds like - it "shades" vertices and pixels different colors. "Shading" isn't just "making it darker" (as the technical artistic term means I believe), it's application of textures, lighting, and everything else that gives a vertex it's final color.

"Shading" often makes the most sense if you think about some light source. You can't really have toon shading without a light source. You have to have light (and an angle to the light) to know how to shade an object in that light. And that's the job of the shader.

So, now you have a vertex/pixel shader that will do toon shading in Blender. Great. Why do you need to know HLSL if you can make a toon shader in Blender?

If Blender exports HLSL code that you can plug into XNA, then you don't need to write the HLSL yourself. You are correct. You wouldn't need to hear about, see, or touch HLSL code if Blender exports it for you. But I'm not sure if Blender can do that.

So if Blender does not HLSL shading code, then you need to write a toon shader in HLSL because all you'd get is the model and vertices and their respective solid colors, but you wouldn't get "how it should look at every single angle and under every possible light source" right - that needs to be computed at runtime (by a shader).

share|improve this answer
    
+1 this is a good "introduction to shaders and why we care" answer –  ashes999 Dec 21 '12 at 18:03
add comment

Materials made for a 3D modeling program won't translate directly into the materials used in your game. You would have to construct a content pipeline for your Blender or 3DS assets, or use one that's pre-made, and then you have to tell the hardware how to use the data extracted in these assets to display the graphics. That is what shaders are responsible for. Your program cannot guess exactly how these files are supposed to be used.

Shaders are especially useful in applying screen-space effects, which do not take in regard the geometry in the scene, at least not discreetly. Even if you use BasicEffect in XNA, you are using some sort of shader, just a pre-built one.

Unlike DirectX 9, XNA does not have a fixed function pipeline. So even diffuse texturing is a very simple use of a shader. There are ways to minimize shader use, by using the 3D modeling software to bake the effects to your models as textures, such as ambient occlusion. But these tricks do not work well for dynamic scenes.

share|improve this answer
add comment

Shaders are not only used to draw textures and effects on an object, would you for example be able to create a motion blur without shaders? Besides, most materials in 3DS max have shaders underneath to create the texture with its effect.

share|improve this answer
1  
"most materials in 3DS max have shaders underneath" ...what? –  jhocking Jan 8 '12 at 0:11
    
try searching your 3ds max 2011 install folder for .fx files, you will find a lot of them –  Thomas Jan 8 '12 at 10:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.