Lighting Shader Tutorial?

Topics: Developer Forum, Project Management Forum, User Forum
Apr 5, 2007 at 7:05 AM
Edited Apr 5, 2007 at 7:26 AM
Anyone knows where I can find some good tutorials on fx files for xna or this animation library? I can't seem to find any on the web and it's kinda frustrating me, since I've spent almost a week looking and found nothing.

Helps are very appreciated here.. thanks..

PS : anyone know how to find a certain member here? i got a mail from a member and now i don't know how to reply to him. silly i know..
Apr 5, 2007 at 9:12 AM
Edited Apr 5, 2007 at 9:15 AM
Once you have an fx file written (works the same way in xna as it does in directx, and there are plenty of guides out there for getting you started on that), it's pretty straight forward to convert it to an fx that works with hardware skinning on the animation library.

In fact, I could ALMOST write a program that converts an fx file to a version that supports skinning. Thinking about it a bit more, I COULD write a program that takes an fx file, and the names of the world/view/projection matrices you use, and spits out an fx file with the same functionality that works with skinning. Would be an interesting side project if I wasn't already so busy (I have a bad habit of getting involved with tons of projects).

It's more or less algorithmic, but just has a fair amount of steps to it. Post your fx file and I'll post a version that works with the library and tell you how to convert it step by step.
Apr 5, 2007 at 9:12 AM
PS: The only way I know if is by clicking on their name. You just just have to hope that they posted somewhere on codeplex :)
Apr 5, 2007 at 9:19 AM
Edited Apr 5, 2007 at 9:25 AM
In my rambling I think I missed your question!

You have to search for "HLSL tutorial" rather than "fx tutorial" to get good results. Here is one example of a good starting tutorial:

Also, if you only need the functionality of BasicEffect type lighting, you can just use BasicPaletteEffect.
Apr 5, 2007 at 10:14 AM

dastle wrote:

Also, if you only need the functionality of BasicEffect type lighting, you can just use BasicPaletteEffect.

are you saying that BasicPaletteEffect already have the basic lighting that BasicEffect don't have?
Apr 5, 2007 at 11:00 AM
Edited Apr 5, 2007 at 11:01 AM
What? BasicPaletteEffect can be thought of as an implementation of BasicEffect that supports the hardware skinning used by the library. Is there some sort of specific lighting you are going for? BasicPaletteEffect supports up to 3 directional lights.
Apr 8, 2007 at 5:11 AM
ok, i'm kinda confused here. to have a lighting effect, i always need a fx file right? well i tried the link you gave me (the hazymind one) and when i tried it to the dwarf model, it won't animate. it got the lighting but it won't move.

well, for now i only need a lighting effect that can give some shadows so my model will have more realistic look. any suggestion?
Apr 8, 2007 at 7:05 AM
I'm sorry if I wasn't clear enough! I thought you were just asking for how to make a .fx file, and then planned on trying to make it compatible with skinning.

Since you seem to be having problems with this, I'll send you a solution with a custom fx file that works with the library. It's late here and I got to head to bed, but tomorrow I can dig up the code to the tutorial on this subject and simplify it.

I hope that will help!
Apr 8, 2007 at 7:10 AM
Edited Apr 8, 2007 at 7:12 AM
But also, it would help others if you could tell me which part of the "using custom effects" tutorial linked on the tutorial home ( ) that you don't understand, since this tutorial is exactly on this subject.
Apr 9, 2007 at 2:20 AM
well for start, the effect code that you provide didn't seem to work with the model. if i used the effect code, the model just disappeared. i don't know what went wrong, i followed your tutorial, but it won't work.

and then, there's this link to i tried the effect there once before but it was using a still model. and when i applied the effect he wrote there to the animated dwarf model, the model just went still. i can still rotate it using the modelviewer but it's not animating.

well maybe i'm still new to this HLSL thing so i still need more tutorials and samples to understand it more. any help would be very much appreciated.

PS : to tepcode, if you ever read this post, please send me your email so i can reply to you. and yes, i'm an indonesian. thanks.
Apr 9, 2007 at 4:06 AM
Edited Apr 9, 2007 at 4:11 AM
I posted the completed solution for the custom effect tutorial. You can download it here:

Note that I made the simplest effect possible that would work with the library. It's just meant to show how to make your own shader compatible with the library, and does assume you have a basic understanding of shaders.
Apr 9, 2007 at 8:04 AM
okay, i checked out your solution, and it turned out that i accidentally fiddled a bit at the view Matrix. instead of

view = Matrix.CreateLookAt(new Vector3(0, 10, -20), new Vector3(), Vector3.Up);

i put

view = Matrix.CreateLookAt(new Vector3(0, 10, -20), new Vector3(0, 0, -50), Vector3.Up);

also i noticed that the code only support BasicPaletteEffect skin since my model with BasicEffect doesn't shows up when i apply the effect. and lastly everytime i used modelviewer, it says that "Object reference not set to an instance of an object." and it worked if i'm using the modelanimator.

any idea why?
Apr 9, 2007 at 9:08 AM
Edited Apr 9, 2007 at 9:10 AM
Yah, ModelViewer class makes assumptions on what effect you use since it manages view/projection matrices, so custom effects don't work on it. I'll add support for custom effects that use view/projection matrices next release then. Easy to implement and can't hurt.

And models that use BasicEffect won't work with that tutorial. The library differentiates between skinned models and nonskinned models for performance reasons, so you need to make an effect that doesn't use the matrix palette for unskinned meshes. Good observation - I guess i'll update that solution tomorrow to compensate. This can be counterintuitive.