3DTotal Forums

3DTotal Forums (http://forums.3dtotal.com/index.php)
-   Realtime/Low poly art (http://forums.3dtotal.com/forumdisplay.php?f=7)
-   -   DirectX Shaders (http://forums.3dtotal.com/showthread.php?t=63244)

Buzzy 23-11-2008 05:46 PM

DirectX Shaders
 
Buzzy's 3dsMax DirectX Shaders

Latest Update 5/01/09
New Shader, codenamed 'Bleach' (for reasons I'll explain in a moment):
- Improved Vertex Color and Alpha support
- Tweaked the glow system to reduce blown-out glowing
- Added Light Attenuation (not yet linked to the lights' actual attenuation settings, but very good for moody lighting)
- Added Fresnel Highlights
- Added some simple subsurface scattering (nice alliteration, eh?)
- Added 'glowthru' subsurface scattering
- Half-Lambert is now tied to the alpha channel of the SSS map for added control
- Added a "Bleach Bypass" filter. Hence the shaders name. This is by no
means the marquee feature, its just a nifty little addition.

This shader is still a bit raw I feel, so I wanted to get it into your hands and see if you folks can exploit it to the point of breaking. So test the heck out of this and give me some feedback. With DomWar going on, I'm sure you all have nearly-complete characters to use as guinea pigs. ;)

Shader_Donze_Bleach_Beta.fx
Shader_Donze_Bleach_NoShad.fx




Important Info Concerning All Shaders
Any of the reflective shaders require DDS format cube maps for the environment. Since alot of folks don't know what a cube map or DDS is (or how to make them), here are a few samples that you can use:
Desert Scene
City Scene
Blurred version of Desert Scene (Good for brushed metal look)

I would like to encourage any of you to post images of work you've created with these shaders. Particularly when I start posting some of my more advanced shaders, I'd be very interested to see how you can get the most out of them. Hope you enjoy them!

Each shader has a 'No-Shadows' counterpart. Versions of Max prior to 2008 don't support shadows, so you'll need the no shadow version if you have Max9 or something.




NEW! COMPLETE SHADER - (requires Pixel Shader 3.0)
LAST UPDATED 4/13/09 - Version 1.1 Improved glow and added Vertex Color support
Shader_Donze_Complete.fx
Shader_Donze_Comp_NoShadows.fx



http://duocartoons.com/David/threedy/shaders/std.gif
STANDARD SHADER
LAST UPDATED 1/30/09 - 4 lights and proper opacity support.
Shader_Donze_Std.fx
Shader_Donze_Std_NoShadows.fx



http://duocartoons.com/David/threedy/shaders/glow.gif
GLOW SHADER - (requires Pixel Shader 3.0 support for now)
LAST UPDATED 1/30/09 - 4 lights and proper opacity support.
Shader_Donze_Glow.fx
Shader_Donze_Glow_NoShadows.fx
Note: Still has one odd little bug, but I've not been able to fix it yet. Most people will never notice it anyway.



http://duocartoons.com/David/threedy/shaders/env.gif
ENVIRONMENT SHADER - (requires Pixel Shader 3.0)
LAST UPDATED 1/30/09 - 4 lights and proper opacity support plus Fresnel reflectivity.
Shader_Donze_Env.fx
Shader_Donze_Env_NoShadows.fx



http://duocartoons.com/David/threedy/shaders/skin.gif
SKIN SHADER - (requires Pixel Shader 3.0)
LAST UPDATED 12/5/08 - first pass at skin.
Shader_Donze_Skin.fx
Shader_Donze_Skin_NoShadows.fx
Note: The skin shader has a lot of advanced features. For an explanation of them go HERE.



http://duocartoons.com/David/threedy/shaders/glass.gif
GLASS SHADER - (requires Pixel Shader 3.0)
LAST UPDATED 12/14/08 - first pass at glass.
Shader_Donze_Glass.fx
Shader_Donze_Glass_NoShadows.fx



http://duocartoons.com/David/threedy/shaders/toon.gif
TOON SHADER - (requires Pixel Shader 3.0)
LAST UPDATED 11/30/08 - first pass at toon shading.
Shader_Donze_Toon.fx
Shader_Donze_Toon_NoShadows.fx
Note: The outline part of the code is a bit shaky right now so the 'Line Thickness' setting is currently inactive.[/url]

Here's a quick explanation of the basic features available in all of my shaders. First, for those of you that have no idea how to even get a shader onto a model, here's a quick tut:

Bring up your Material Editor. Choose a material that you would like to be a DX Shader. Now in the top right there is a button that probably says "Standard" (circled in red here). Click that and you'll be presented with the menu pictured on the left. Choose "DirectX Shader" from that menu.
http://duocartoons.com/David/threedy.../matEditor.jpg



Voila, your material is now a shader. Now, to make it a specific shader (like the one you just downloaded from this thread) click on the big button at the top, circled here in red.
http://duocartoons.com/David/threedy...s/dxEditor.jpg


This is a path to an .fx file. So, find the one you like and select it. There are actually a bunch that ship with Max, but they are mostly for demonstraion and not all that useful.


So, once you've loaded my shader, your Material Editor will turn into this:
http://duocartoons.com/David/threedy...aderEditor.jpg

Now, let me explain what all of this means (most of it is pretty self-explanatory)
First, lets actually start at the bottom. The Material slot can pretty much be ignored. But, if you have an insatiable thirst for knowledge, this is a separate material that Max will use to display your model if you disable DirectX or if you try to render the scene (DirectX shaders don't render, but they really don't need to)

More importantly, at the bottom is also an option for "Technique." You have 2 options here, SingleLight and DualLight. This will tell the shader how many lights to use to light your model.

Now, back at the top, you'll see there are slots where you can specify lights and shadow casters. These, obviously, are where you specify what lights to use. If you have the Technique set to Single Light, then only "Light Position 1" and "shadowCaster1" will matter. Generally you will want the Light Position to match its cooresponding shadowCaster.

Below the lights, there is a slew of map options. First are the Diffuse Map options. This will set the color of the model. There is a "Diffuse Map" and a "Diffuse Color." If you check the box that says "Enable Diff Map" then the shader will use the Map you have selected in the Diffuse Map slot. If you uncheck "Enable Diff Map" then the shader will just use the color that you've selected in the Diffuse Color slot.

The same applies for the Specular Map. The spec map however, also has a few extra options for Glossiness. This shader is set up so that the alpha channel of the Spec Map can be used to control glossiness. If you do not want that option, you can just uncheck the box and use the spinner to control glossiness.

Next is the Normal Map. The only tricky thing here is the "Invert Green Channel" option. Basically, Max uses a somewhat oddball coordinate system. Because of this, your normal map's Green Channel needs to be inverted depending on how you generated your normal maps. So, if you select a normal map and it looks a little weird, try using this option.

You can also turn on "Half-Lambert" lighting. This is a little trick developed by Valve a long time ago. It basically softens the lighting, giving a more appealing but less-accurate look.

Buzzy 23-11-2008 05:59 PM

I forgot to mention something important. This shader doesn't create its own shadows, it uses Max's internal shadow calculations. Therefore, you must have shadows enabled in the viewport for the lights you want to use.

Another point I should make : This shader has only been tested on Max2008. I can't say whether it works with any other version. This probably only pertains to the shadow casting, because everything else is just HLSL code and has nothing to do with Max.

On that note, this shader uses Pixel and Vertex Shader 3.0. If your video card does not support either of these, then this shader won't work.
I'm not sure that the shader really NEEDS to be 3.0.....it doesn't use any crazy advanced stuff so I can probably get away with 2.0. I'll look into that post an update later.

Buzzy 23-11-2008 06:30 PM

Ok, ignore the previous comments about Pixel Shader 3.0. I have just updated the file so it uses Pixel Shader 2.0. Now, if your video card does not support Pixel Shader 2.0...then....well....you need a new video card.

poopipe 24-11-2008 03:48 PM

I've had a quick fiddle with this - very nice.

that shadow code looks very much like the code I put into another shader that made my work machine crash - I've got new graphics hardware now though so it's all good for me :)

had any joy with Alpha channel support on the diffuse?

Buzzy 24-11-2008 04:03 PM

Yeah, honestly Max seems to have issues with alpha...particularly when sorting. I haven't really worked on the alpha much with this shader, so I'm not sure how well it works in the current version.

The biggest source of sorting issues in Max is how it structures the scene. Objects are sorted internally based on the order in which they were created (not by name or heirarchy). And Max's directX engine doesn't render the things based on distance like a game engine would, it renders each object seperately. And it draws them in the order they are sorted in the scene - i.e. the order they were created. So, if you have an object that was created earlier and it is in front of an object that was created later, the alpha won't work correctly.

Alpha is admittedly a major drawback in this shader. I'm still working on it though. Hopefully I can improve it.

poopipe 24-11-2008 04:45 PM

That'll go a long way to explaining why the hair on my witch went funny during that last comp.


I'm guessing here cos I'm not up on HLSL at all but can you turn off the alpha blending and fall back to a simple alpha test?

I've not seen anyone get sorting right on alpha blended geometry without shattering objects into individual tris yet - assassins creed, farcry 2 etc all use simple alpha tests for their foliage and it looks fine til you get right up close.

Chung Wong 25-11-2008 12:43 AM

Wow, neat, you are the dude. I've been meaning to get into shaders and this looks like a perfect place to start. Thanks dude... now you would be the dude meister if you were to put up a tut for the rig you did on your awesome warrior hint hint.

Edit:Pant's, I just tried your ace looking shader but can't seem to get it working in 3dsmax 9 (not 09) I noticed you did mention that this is for 2008 and probably above. Looks like its upgrade time or am I just plain stupid and can't get it to work? Doesn't matter though. Thanks for the shader, I'm sure I'll get it working sooner or later :)

poopipe 25-11-2008 09:36 AM

you need the viewport shadows for it to cast shadows so you need max 2008.

There's no shortage of non-shadow casting .fx materials floating around. Ben cloward has released one that works in lots of max versions.

Chung Wong 25-11-2008 03:41 PM

Cheers poopipe. Downloaded them all now, will give them a bash. Really want to get a skin shader working. Just in case anyone else wants a go, here's the link: http://www.bencloward.com/resources_shaders.shtml

Buzzy 25-11-2008 04:11 PM

Hey Chung, I'll spend a few minutes today and make a version of this shader with the shadows disabled for people with pre-2008 versions of Max.

And I'll see if I can get my skin shader to an acceptable state and post it too. It has alot of experimental tech in it and I'd love to get it out to the public and see what people can come up with.

Buzzy 25-11-2008 04:19 PM

Ok, here's a version with all of the shadow code removed. Should work on Max9 but no guarantees. I don't have max9 on my computer anymore so I can't test it myself. Let me know if it works Chung
Shader_Donze_Std_NoShadows.fx

Chung Wong 25-11-2008 07:07 PM

Sweet, thanks buzzy. I'll let you know later on tonight.

Edit: Nice, it worked, I couldn't get it looking as nice as your warrior though, could seem to get the fuzzy see-through like texture to happen, any idea's why? I like the shader a lot, just seems that I'm missing something and not making the most out of it. But anyway, here's what came out...

http://s253.photobucket.com/albums/h...uzzyshader.jpg

poopipe 26-11-2008 11:05 AM

1 Attachment(s)
wee!

I hacked a version with Ambient and Glow maps in today

I'd upload it but it's a dirty hack and requires SM3 to support all the calculations - they're just simple adds (I multiplied the ambient value by 0.3)

I'm having difficulties on 2009 with the alpha not working - any clues?

here's my dom war entry looking all shadowy and glowy

Buzzy 26-11-2008 04:17 PM

I think that looks pretty awesome Chung.

And nice glowiness poopipe.

I think I'm going to spend some quality time today working on the alpha and blending code....see if I can't come up with anything better. Hopefully I can address the issues you two have. I also spent some time yesterday going over my skin shader and I should be able to post that soon....hopefully tonight if I'm feeling super motivated.

Chung Wong 26-11-2008 08:20 PM

Yes please! I love this shader and looking forwards to more exellent shaders from you. Just so I know what I'm doing, am I right in saying that these are real-time and what you see on screen is what you get? Therefore if I need a shot, I just make a screen grab and not a render? Sorry for the silly questions. Btw, I have a piece of finished work and have credited you. Thanks a bunch!

http://i253.photobucket.com/albums/h...ssspeccopy.jpg


All times are GMT. The time now is 11:40 PM.

Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
all images displayed on this site are copyright the original artists and may not be reproduced, copied or published elsewhere without their express permission