Tutorial 3: "Adding Smart material"

In this tutorial we will add smart material to the scene. Example of smart material itself is already made and provided with Tutorial, I'll show what need to be added to rendering pipeline itself so smart material would correctly work. Typical scenario is to use smart materials for most of your 3d objects and several custom HLSL channels for objects with specific shading. In this tutorial we will use smart material only for 3d model of statue and in the next tutorial we will change arbitrary shader to support shadows, so scene would use smart material and custom HLSL channel at the same time.

1. Open "\Start Scene\startgroup.cgr", this is the final scene of Tutorial 1. Remove HLSL channel and shotcuts from statue, so it would look like this:



Smart material is build in the same way as example shader in tutorial, it needs a set of input values, but we cannot directly provide it with such values so we will use a separate channel group, that will read input values from our channel logic, than smart materials will use this channel group to get needed input.

2. Import "\Additional channel groups\smart material support group.cgr", save into your project folder and open it. You will get an error as Public callers will not find a needed channel group. We need to fix that. There are three external parameters that is read from other channel groups using Public callers:



Global technique value and Sun position vector can be linked right away, Pixel size need to be made Public first.

3. Pixel size is the one of the input vectors to the HLSL channel of the first 3d object. Locate it and make it public:



4. Now go back to "Smart material support group" and restore linking of public callers in this way:







Before loading actual smart material we need to be sure that it will receive correct input values, for this we need to update values stored in "Smart material support group" every time when we change technique.

5. Create channel caller and make it Public call channel with following linking:



6. In main channel group we need to call "Update Smart materials" channel two times, during depth render and final render. Connect it as show here:



NOTE: It's important to call "Update Smart materials" after setting "Global technique" value and before rendering your 3d objects.

7. We need to call "Update Smart materials" in "PSSM deffered shadows utility v1" several times as well. Open "PSSM deffered shadows utility v1" channel group and create Public caller with the same linking as on step #5, connect it as shown here:



Now we ready to apply smart material to the statue.

8. Go to the "Objects" panel and open smart surface tab, if you don't have it add it this way:



9. Load "\Additional channel groups\Materials source\PSSM&SSAO_Opaque_NoAlpha_Material.cgr" and apply it to the statue:



Adjust amount of diffuse, ambient and specular light to your taste.

NOTE: If you want to make changes into smart material or create your own with shadows support, don't forget to import (but not save) "Smart material support group". This is needed for Public call channels in smart material to work correctly after you saved smart material.

NOTE: Shadow maps bias values are hard coded into smart material's HLSL channel, when you found good values using example shader in startgroup put them into smart material's HLSL as well.




Go to product page...
http://3dvrm.com/shadows_solution/


Design © Kero 2009