![]() ![]() |
Sep 12 2007, 07:27 PM
Post
#1
|
|
![]() Advanced Member ![]() ![]() ![]() Group: Members Posts: 360 Joined: 9-July 07 From: Redwood City, California Member No.: 13 |
Part of the September 10 Shader Library Update is a CgFX-only effect called DrawSharedShadow. This effect doesn't draw anything to the screen at all! It's meant exclusively for drawing shadow maps into COLLADA shared surfaces via "Render to Texture" -- such shadow maps can then be accessed and used from COLLADA or CgFX effects.
![]() Look for this icon "DrawSharedShadow" is easiest to use if you let Python do most of the click-drag heavy lifting. With that in mind, I'm attaching to this post a Python script called SharedShadow.py. Here is the description from that file's header (or __doc__ string for python afficionados): CODE Rapid Setup for using DrawSharedShadow.cgfx setup() -- makes sure there's a scene and spotlight in the scene, brings in the DrawSharedShadow.cgfx, converts to COLLADA-Cg, sets up shared surfacs and appropriate passes. Optional arguments let you specify a lamp (or the name of a lamp, if you want setup() to create a lamp for you) and the specific formats of the color and depth passes. Currently the defaults are D24S8_SHADOWMAP for the depth target, and R16F (with depth encoded into it) for the color target. apply() -- applies shared surfaces as defined by setup() to the designated material (which better be able to accept them!) -- if no material is specified, checks the current UI selection (if any) These variables are exposed and ar loaded by running setup(): SpotLamp - FXLightInstance (or None) ShadowMtl - FXMaterial that draws shadow maps ColorTgt, DepthTgt - Shared Surfaces Typical usage might be: 1. create a scene with some object(s) 2. In the python script window, enter (a lamp will be created): import SharedShadow SharedShadow.setup() 5. Position the new spotlamp appropriately (you may be able to see the objects in the materialpane for the "DrawSharedShadow" material) 3. Drag material(s) that can use shared shadows onto the objects(s) 4. Make sure they are compiled with USE_SHARED_SHADOW defined 5. Select the target material 6. In the script window, enter: SharedShadow.apply() 7. The light and shadow maps should connect to the material Many of the effects already in the shader library contain support for shared shadows -- look for the line CODE // #define USE_SHARED_SHADOW remove the "//" comment to activate the macro and hit Ctrl-F7 to recompile the effect. Questions and suggestions extemely welcome! (And yes, you CAN assign the setup() and apply() methods to toolbar buttons)
Attached File(s)
-------------------- |
|
|
|
Sep 21 2007, 12:01 AM
Post
#2
|
|
![]() Advanced Member ![]() ![]() ![]() Group: Members Posts: 360 Joined: 9-July 07 From: Redwood City, California Member No.: 13 |
I'm appending this picture because it shows an answer to the questions: "What is Shared-Surface Shadowing?" and "Why should I care?" If you think about it, every material in the Ninja-Girl demo is able to cast a shadow on every other material. How do these varying shaders communicate? They are able to share the shadow information because a preliminary effect (as in the previous message) draws a shadow map containing ALL objects -- and then each objects's material, as that object is drawn into the final visible view, is able to access that "shared surface" shadow map. ![]() In this example, the same thing is going on -- note that the teapot, which is using the "Durer" effect, is drawing the shadow itself in a thicker brush strokes -- that is, it's not just an overlay, but a shared map that can be used by any shader as that shader sees fit (in this case, it draws thicker strokes, rather than just entirely obscuring the shadowed area) (Yes I need a bigger picture! But hey, try it yourself -------------------- |
|
|
|
Jan 26 2009, 06:41 PM
Post
#3
|
|
|
Member ![]() ![]() Group: Members Posts: 7 Joined: 4-January 09 Member No.: 7,143 |
Hi Kevin,
Im having real difficulty getting my head around setting up shared surfaces for rendering the shadowmap, and then using that to render the shadows. I followed the steps in the above example, but I get either this error: Did not find the parameter: "Phong_Material.DepthShadTarget" Did not find the parameter: "Phong_Material.ColorShadTarget" Are you certain that "#define USE_SHARED_SHADOW" is enabled on for Material "Phong_Material" and its effect "Phong"? (and i did #define USE_SHARED_SHADOW) or, when i run it from a custom button: Error Error running script : name 'ShadowMtl' not defined -1 Even rendering to a shared texture and then displaying that texture eludes me. But I think I confuse the terms 'texture' and 'surface'. Do you have a comprehensive tutorial on how to set up and use such (shared) textures ? Thanks, Jonathan |
|
|
|
![]() ![]() |
|
Copyright © 2008 NVIDIA® Corporation. Terms of Use | Legal Info | Privacy Policy | Time is now: 23rd November 2009 - 11:38 AM |