Saturday, May 07, 2005

New Shader!

I've added a new shader to the HLSL Shaders on my web site. You can grab it here:
http://www.bencloward.com/resources_shaders.html

This new shader is the same as my Normal Map Specular shader but it adds support for three point lights. I was impressed with how much nicer the lighting looks when you can have a key light, a fill light, and a kicker/rim light. Here's an example:

All Three Lights

I'm doing all three point lights in one pass, so this shaders requires 68 pixel shader instructions. That puts it over the limit of 64 instruction in Pixel Shader 2.0 so I had to switch it to use Pixel shader 2.a. That means it requires a higher end graphics card.

A lot of people have been asking about my global illumination shader and how it works so I've also started writing a new tutorial on my method of real-time global illumination. When it's done, the tutorial will cover the use and creation of diffusely convolved cubic environment maps as well as how to create ambient occlusion maps. I'll get it done as quick as I can.

8 Comments:

Anonymous Daniel said...

Looks very nice...the extra lighting has had a significant effect. I'd recommend downloading and viewing this in Max, its striking.

- Daniel

May 10, 2005 5:08 PM  
Anonymous Anonymous said...

Great Work!

I have a couple questions for you, though. How do you count the instruction of your shader? And with what program do you usally code your shader?
-James

May 19, 2005 5:40 AM  
Blogger Ben Cloward said...

I use Nvidia's FXComposer to edit my shaders. It has a performance analizer tool that tells you how many instructions the shader compiles to as well as how many cycles and registers the shader requires on all the different Nvidia boards. It's a great tool.

Also, if you go over the limit for shader instructions, Max pops up an error and tells you what the limit is and how many instructions you're trying to use.

-Ben

May 19, 2005 6:21 AM  
Anonymous Anonymous said...

Thanks, Ben!

I've tried using FX Composer before, but I had ran into compatibility issues between max and FX Composer because how these two handles annotation and symantics differently. How do you recommand me to resolve such an issue!?

-James

May 22, 2005 3:47 AM  
Blogger Ben Cloward said...

FXComposer does have different symantics than Max - which is a little frustrating - but it still works fine as long as you don't worry about trying to use the previewer in FXComposer. I use the Max symantics which sometimes prevents the shader from drawing in the preview window of FXComposer - but I don't really care because I'm really only interested in viewing the shader in Max. I just save it in FXComposer and then load it up in Max to see what it looks like. Once it's loaded in Max I can switch back to FX Composer, make some changes and save, and Max will instantly update. Nice!

What symantics problems are you having? More recently I've found that the main symantic problems I have are caused by the abreviations of the matricies - such as using "WorldI" instead of "WorldInverse." If you don't abreviate them, then both FXComposer and Max understand them and the problem goes away!

May 22, 2005 8:35 AM  
Anonymous Anonymous said...

Wow, that is an awesome tip, and quite a brute-forced method, I must add. he he :P

To be honest, while I learn a new language (I was doing max script before), I tend not to try and mess up code beyond what I know. So I have been tring to stick to what I am sure to work with max. But writting a shader for max is challanging because there is no document to go about. The only examples that I could go by were your awesome codes and the fx files that came with max. So it is a great relief to know that the complete version of WorldI (WorldInverse) would work for max. I will definetly try it out as soon as I am done typing!

Most problems I had were indeed the symantics like WorldI. I have also had problem with scripts that I had to remove when getting codes from other place.

Anyway, I remember I've read an article somewhere. It was talking about Microsoft's Standard Annotation and Symantics(DXSAS) which is supposedly to standardize all the Annotation and Symantics for all software for improve code portability. I hope it would solve most of such problems.

Also with examples from fx composers, I've also had problem with codes that require the includsion of external header files such as quad.fxh. I assume that it is the screen filling quad for rendering purpose. But I might be off by a few million yard.

While reading articles from Nvidia site, they were talking about Percentage Closer Shadow, deffered rendering, radiance transfer between one object and another. But the shaders depends on data that application to get from one ojbect to another. Are you aware if these rendering techniques are possible to be done in max? Is that what the Script is really for?

Finally, let me come back to earth. how do you know what are the symantics and scripts that are being supported by max?

I am so excited that there finally is a place that I can learn about tips that would help my shader to work for max. Thanks!
-James

May 22, 2005 1:32 PM  
Blogger Ben Cloward said...

James -

When I started writing HLSL shaders for Max I had the the exact same problems that you're describing - and I still do sometimes. There just isn't enough documentation at all. I did find one document that describes the symantics that Max supports. You can see it here:

http://sparks.discreet.com/knowledgebase/techdocs/searchable/techdoc_DXMaterialFormat/DxMaterial_Effect_format.htm

I hope that it is helpful for you. It was helpful to me - but I found that it was pretty limited in scope. There is a lot of data in Max that I'd like to use in the shader but I just don't know how to access it. For example, I'd like to use the Max environment color as the ambient color in my shader, but I don't know how to pass that color in.

FXComposer can do a lot of things that I've never figured out how to get FX shaders in Max to do such as using the frame buffer as a texture, rendering somewhere else other than the frame buffer, etc. I'd really like to be able to write shaders the created cool effects such as glow, blurr, light bloom, etc - but I don't know how to get Max to render to an off-screen buffer and then apply that as a texture. I don't think it's possible. If anyone else knows how to do this, I really want to know!

May 22, 2005 6:11 PM  
Anonymous Anonymous said...

The document seem to solve a lot of problem for me! Thanks Again!

Actually, as for the Environment as Ambient, I think you can parameter-wire the emvironment color up with the color of a dead light. Use the light as input, transfer its color to ambient. I just thought of it out of my head.. never tried it.. ha ha!

Although probably not exactly what you were talking about, but at least for other folks to know about. I did get texture glow to work, as there is a demo in Max called hammer time. It is not a correct demo as the transparency was not enabled. Enable it, and the Tron-ish glow would work. Also, a couple other demo also had problems and very unstable with different driver and video cards.

But as for glow that glows beyond the object's boundary would require the problem we were talking about. Rendering to other object. I do hope somebody can help us out on that one.

By the way, do you know of any way to access the screen/viewport information? Such as Screen center, width, and height?

-James

May 22, 2005 7:01 PM  

Post a Comment

<< Home