Hey guys,
I wanted to share a new shader with you guys. First off, a big thank you to my colleague
Niklas Hansson whom I created this shader with. He's the guy with the theoretical know-how of the inner workings of this shading method, he helped out with guiding me through the shader creation in Mental Mill as well as some MSL(HLSL like) coding for custom shader components in Mental Mill.
So I give you,
TGA_Physically_Based_Lighting_Shader. A realtime CGFX shader for the Maya viewport.
This shader uses a whole new way of handling lighting and in particular the specular and reflection contribution. Instead of the traditional specular, gloss and reflectivity you now use a substance and roughness texture to define your materials in a more realistic manner. There's also familiar textures such as Albedo(Diffuse), Tangent Space Normal map, Cube Map and Ambient Occlusion. This way of shading is already adopted by several triple A studios in the industry. For instance Treyarc's
COD Black Ops.
Here's the highlight features of the shader.
- A real life material based fresnel term that alters specularity and reflections.
- A substance texture to mimic how materials reflect and refract light in real life.
- A roughness texture to define a materials surface structure(smooth/rough).
- Image based lighting via a cube map for reflections and ambient lighting.
- Roughness controlled pre-blurred mip levels of the cube map for reflections.
- Blended Normals to give a subtle skin effect in conjunction with normal maps.
- Emissive Texture to fake emissive surfaces.
- Fully linear shading pipeline.
- A bundled cheat sheet image with color swatches for several substance values.
- Shadow Map(pre-baked) support fully integrated with the shader (This feature is experimental and only works with 1 direct light source).
- Added transparency support. Use the albedo texture alpha channel.
You can
Download the shader from
my website.
ATI users should be aware that CGFX shaders in general do not seem to work well in Maya with ATI cards. I have not been able to verify if this one works or not, I'm assuming it does not.
I created some examples to show the shaders capabilities. I started of with a gold bar, and continued making variations of it.
Feel free to ask questions and discuss the shader in this thread.
Replies
[size=+1]Albedo[/size]
This is just like a diffuse texture you are familiar with. Remember only to paint the materials color, not light variations. In other words, generally more flat then traditional hand painted diffuse textures. You also generally want to increase the Albedo texture's saturation a bit above how you would generally have your saturation levels in a diffuse texture. I'd advice you not to blatantly just multiply your Ambient Occlusion in the Albedo, this information is meant to be used the Ambient Occlusion texture.
[size=+1]Roughness[/size]
This texture is used to define material surfaces in terms of roughness. For a perfectly smooth surface use white color, for a really really rough surface use black color. The effect of this map is how wide/narrow specular highlights will be. It is also used to determine what mip level to use from your environment cube map for reflections. It's highly advised to use pre-blurred cube map mip levels. Leave mip level 0 crisp and blur a bit for each mip level you traverse down. Have a look at the Diffusely Convolved Cube Map page on the PC Wiki if you are unfamiliar with this. Here's a freebie Cube Map with pre-blurred mips if you can't be bothered. Source images for the cube map are from humus.name.
[size=+1]Substance[/size]
This texture is used to define what type of material you are trying to mimic. What the texture actually mimics is how light is reflect/refracted on the surface. A brighter value will make the material specular and reflective in more angles. A darker value will make the material on specular and reflective in glancing angles. For instance, most metals have a high substance value and therefor reflect in almost all angles. Since this feature is based on real life IOR(Index Of Refraction) values I'd advice you to use the bundled "Cheat Sheet" image which has several color swatches you can sample colors from to use for your substance textures. Of course you can diverge from these presets, but they are a good start. Remember to sample from the Gamma Space column as this texture is treated as a gamma space texture by the shader. You generally want to leave this texture quite flat.
[size=+1]Ambient Occlusion(AO)[/size]
This texture works just as it does in traditional usages. But besides occluding ambient light it also occludes reflections and also specular highlights. Occluding the specularity might not be that physically correct, but we liked the effect of this as it made specular highlights pop more. You could say that the AO texture plays a more important role in this shader as it controls more parts of the shading than in traditional usages.
thank you for sharing yet another awesome shader!
Do you have a test scene with all these materials in it ?
Looking really good!
Pior> Yes indeed I do. The scene with the bars used for the images in the original post. Around 1GB of a Maya project folder full of raw uncompressed textures, PSDs, etc.
also, i think gloss/rough only goes up to 256? raise it further! when you're using cubemaps in conjunction with gloss, not being able to get a highlight as sharp as the reflection can be a real pain! i mean it's not like you need to worry about too sharp highlights with phong specular.
I was under the impression it was called Roughness by most people adopting this type of shading and therefor I wanted to stick to the same name. Also, roughness seems to make sense to me. In my opinion an artist can easily relate to that. A smooth surface will reflect many rays straight back to the viewer resulting in a sharp reflection. A rough surface will scatter the rays to a higher degree and therefor not as many rays will go straight back at the eye and since they got bent along the way this will result in a blurrier reflection that is not as intense.
As I pointed out further up, the AO masks ambient light, reflections and specularity. The specularity part not necessarily as physically correct, but we liked the effect. It gave specular highlights more contrast and got details to "pop" more.
Regarding roughness to 256 you might be right. This is still all new to me and I've understood that other implementations have used a higher value like you mention. I'm going to give it a go with altering this to a higher value and see how it turns out. Wouldn't this however stretch the accuracy overall and therefor making it hard to define differences in the lower end? Not that I think that would be a major problem though.
We've been moving towards something like this at work as well, and the transition from the old method has been a bit strange, will be interseting to compare with your shader.
Nice work as always dude!
generally speaking the loss of precision with higher max roughness values shouldn't be a problem, but you obviously don't want to go too high. if you want more accuracy in one end, you can cube or square roughness, but with specular normalization, the overall low intensity in that range means that people don't easily discern exact roughness anyway. Otherwise more people would probably use beckmann instead of blinn-phong.
cman2k> Hehe... Maybe I have been reading your mind. Nice to hear that several are moving towards this, gives me reassurance. Thanks.
equil> Hmm.. not familiar with Beckmann. I'll try to read up on it. Should be fairly easy to just jack up the levels to start with, and if it does become a problem I might look at some way of adjusting the levels as you mention. You do make a valid point about the intensity in the lower end.
Also with the small bit of tinkering iv done, there seems to be an update problem when disconnecting maps, light. Particularly when i disconected the environment cube map, i still saw the reflections.
another quick question, i'm getting a weird fresnel effect im very new to this, what is causing this?
Image does NOT reflect quality of shader, i just don't know what i'm doing
Which is the weird fresnel effect you are referring to? Also, in your screenshot you are missing some textures. Did you just disconnect them or did you not try to use them yet? I recommend you use all the textures available for the shader to function properly.
Regarding the gold bar you mention, it was never made available in this thread. Not yet anyways. ^^
The fresnel effect area i'm talking about is the pink stuff on the handle, near the center and at the tip. I think it's the environment texture still coming through. Plus these are all just slightly tweaked textures made for a specular/diffuse/normal/gloss type shader, some better authoring will be needed for proper testing.
EDIT, yeah the pink glancing angle was the cube map, and yeah theres some update bug, either maya or other. Once i reloaded the scene it was gone.
Any recommendations on really specular reliant materials? aka nickel plating/polished aluminum/ worn finished metal.
Are you able to handle things like glass nicely?
Keg> You mean like transparent materials? No I haven't looked into it. Nor does it handle light scattering around in wider areas than 1 pixel, i.e. SSS. I'd love to be able to implement that somehow. I've considered adding support for blended normals.
Does your model look fine with other real-time shading solutions in the Maya viewport? Say a regular blinn shader with the normal map?
r_fletch_r> I'm afraid not. It should be possible to export to 3DSMax from Mental Mill. But there has been several hand edited additions to the .cgfx file after exporting. Mainly to get the mip-level functionality working since Mental Mill doesn't support texCUBElod command. Also to get a passable UI in Maya without lots of strange names and messy layout. I'm not sure how edit and tweak this to get it working in 3DSMax as I'm a Maya user.
I think what would differ are certain UI commands and handling the fact that maya and max has differing world axises setup.
You could just try loading it as it is. At best it might load but your cube maps would probably be rotated. That would probably be a simple swizzle of the components which would probably be fairly easy to hand-edit.
The newer version is available on my website.
From 0.2.1 to 0.2.2:
-Fixed a bug with how reflections were handled in conjunction with a normal map.
Example of the bugfix:
When I get a chance I might see if I can knock up the same in shader fx. I had started something similar a while back. (anyone looking for it shouldnt hold their breath)
will have to look at how you did the IOR stuff.
Therefor I decide to take the leap and try to implement Shadow Map support for this shader and my coming projects. So far I just created a proof of concept test case for myself to see this in action. It seems to work just fine. Major issue will be to handle the creation and updating process of these Shadow Maps. Light directions and intensities need to sync, etc. Also, my ambition is to streamline this as much as possible to make it easy for the user to create and update the Shadow Maps. The shadow maps will be based on a secondary UV-set to keep the option of having overlapping/stacked UVs.
Here's a quick video of where I'm at for the moment.
[ame="http://www.youtube.com/watch?v=DkufMgryb4o"]Proof of concept: CGFX w Shadow Map support in Maya - YouTube[/ame]
Is this something been done through the hypershade and you're plugging that in as a file?
It would be epic if you actually had access to the realtime Zbuffer but that seems like a very far cry...
It is baked shadows I'm talking about. My intention is to streamline the process of working with this setup by a script. Best case scenario you would just push a button to update the shadow map after you've edited your light setup.
haiddasalami> I'm going to try to utilize the Polygon Module > Color > Batch Bake(Mental Ray) with ray traced shadows. This will render to a texture which I will connect to the CGFX shader.
Also you might run into some issues with smooth curving surfaces, where there is no direct transition from unlit surface to shadowed surface. I get these problems when adjusting the shading function (like using Half Lambert), you actually see bias problems where the shadows start to appear. Don't know how it'll be for baked maps and not realtime ones.
Unfortunately I can't show off the one of the dressing right now, but it needs some more tweaking texture-wise anyway. We still need to use Mental Ray on some parts, like the dressing window (to view the IV sites), but your shader has really sped up production and looks great too. Our AO pass is now the most time consuming thing we render lol... you've essentially beat out Mental Ray for most of our needs!
Xoliul> Thanks for the heads-up. I think I know what you are talking about and I am confident that I will run into a heap of different problems and challenges
I have a general idea of all the involved steps and I feel fairy confident that I will be able to solve it to some degree. But I'll just have to go step by step and take it from there.
Stradigos> Thanks for sharing. Nice to hear that you find it useful. Couldn't the SSAO from viewport 2.0 be used for AO or do you need better accuracy? I mean if it's quality is good enough you could probably save even more time.
By the way, are you using the Blended Normals feature on your human skin materials? If not, check it out.
Any tips? Using a diffuse, normal, spec, not using DXT5nm style, using skin blended normals, no cube map, and one directional light. If you want more details I can give them.
Thanks for the tip After some testing today, I found that the SSAO just wasn't as accurate as a quick AO bake from Mental Ray. I'm not surprised. I managed to get the SSAO really close at one point, but as soon as the camera distance changed, it was like I had to find new settings for it because the shadows began to tear.
Was happy to find the viewport anti-aliasing settings while looking through those settings though
Well I cannot tell right off the bat whats up with that shading on the left hand model. But if you're already using Leo's shader then I'm not sure if you stand to gain much if anything with getting proper results with my shader. I'm not entirely familiar with his.
I'm going to be posting some WIP screenshots soon based on Lee-Perry Smith's free head model, that should give you an indication of what is possible to mimic in terms of human skin with the PBL shader.
I haven't put that much effort to tweaking the textures to perfection. The substance and roughness are pretty much one solid color all over. There's one directional light from top right corner and the cube map which is lighting the model in this example.
The new features are:
- Blended Normals to give a subtle skin effect in conjunction with normal maps.
- Shadow Map(pre-baked) support fully integrated with the shader.
Also, AO was using the same UV-set as the other textures in the older versions. Instead it now uses TEXCOORD3 to allow the user to create a separate UV-set for the AO/Shadow Map.PS: Do you have any recommendations for a cube map? I think not having one is killing any possible good renders I get from it.
Check my post nr2 in this thread. You really should learn how to create and tweak your own pre-blurred cube maps, but there's a freebie to get your started