Strategies and Techniques for Real

advertisement
Strategies and Techniques for
Real-Time Shaders
Neil Hazzard
Software Engineer
Autodesk, Media and Entertainment
Overview
Recap from GDC 2005
 What’s new in 3ds max 8
 Scene Effects
 Extending effects with MAXscript
 Tips
 Lots of Demos…

Quick Recap from GDC 2005




3ds max supports HLSL Effect files
Dynamic UI creation based on Semantic and
Annotations in the file
Automatic update of changed file and bitmaps
Based on Parser Technology



Two Formats supported. 3ds max and DxSAS 0.8
MAXScript extendible
GDC 2005 session available

http://sparks.autodesk.com/downloads
What’s new in 3ds max 8

New Annotation “ColorChannel” specifies whether
a Map Channel contains color information.







int texcoord1 : Texcoord
<
int Texcoord = 1;
int MapChannel = 10;
bool ColorChannel = true;
>;
#define support - _3DSMAX_, 3DSMAX, MAX &
_MAX_
Easier support for max specific code, by using #ifdef _MAX_


Use of DiffuseMap semantic to provide better
Material Editor sample slot rendering
Scene Effects
Scene Effects

Effects that work at the scene level

Pre Effects – runs before any geometry is
drawn


Post Effects – runs after all geometry is
drawn


Useful for background images
Any “post production” work – blur, glow etc..
Environment Effects – special type that
process the scene for use in per object
rendering
Ideal for Shadow Maps or CubeMaps generation
 Only work with the DirectX 9 Shader Material

Using Scene Effects - 1/4

Scene effects use a ParamID of 0x003





Tells the system to use the correct parser
Uses bool PreShader = true; to help the parser with
usage.
Post effects receive the render target containing
the scene in a texture parameter called
SceneMap.
Pre Effects simply render into the current active
render target.
Load the scene effects using the Scene Effect
Loader Utility
Using Scene Effects - 2/4

Example of the post_output.fx file
#include "quad.fxh“
//helper file for drawing quads
string ParamID = "0x003"; //tells the system what parser
//Macro to define the Scene texture and sampler
DECLARE_QUAD_TEX(SceneMap,SceneSampler,"X8R8G8B8")
//Simple pixel shader that simply outputs the input scene data
float4 OutputPS(VertexOutput IN) : COLOR
{
float4 texCol = float4(tex2D(SceneSampler, IN.UV).xyz,1);
// Do anything else here
return texCol;
}
Using Scene Effects - 3/4

Environment Effects
Run before the main scene output starts
 Should run in conjunction with object based
shaders


Object shaders can then use specific transforms
setup by the environment stage



An Example is light transforms for Shadow maps
Use multiple techniques, one for environment pass
and another for final pass. Have a naming
convention so the parser can set them dynamically
Can create maps that would be used by
objects based effects
Using Scene Effects – 4/4
Developers can write their own scene
parsers
 Node sorting and filtering can be
implemented



The utility simply sorts based on the GBuffer ID
and filters non DirectX 9 Shader materials
New interfaces – see RTMax.h

IDxSceneManager, IValidateNodeCallback and
IDxSceneTransformManager
Extending with MAXScript
Scripted Material
Auto Generated UI
Extending with MAXScript

Scripted Material


Parameters use the name defined in the effect
file


plugin material StandardFX
name:"StandardFX"
classID:#(692421,413582)
extends:DirectX_9_Shader replaceUI:true version:1
(…)
You could still use “showproperties meditmaterials[1]”
to list the names
Simply use the delegate keyword to set the
value

The texture used by effects is actually a bitmap type
Extending with MAXScript

On Create Handler (Scripted_StandardFX.ms)
on create do
(
-- setup initial material
effectfile = GetDir #maxroot
effectfile = effectfile + "\\maps\\fx\\StandardFX.fx"
delegate.effectfile = effectfile
ambientlock = true
)
Extending with MAXScript

Button Handler (Scripted_StandardFX.ms)
on b_topDiffuseClr pressed do
(
b = selectbitmap caption: "Top Diffuse Map"
if b != undefined then
(
delegate.g_TopTexture = b
b_topDiffuseClr.text = b.filename
topdiffuseMap = b --defined as type:#bitmap
)
)
Extending with MAXScript
Generates custom and sophisticated UIs
 Allows data validation and Access control


E.g. power of two textures, or textures no greater
than a certain size.
Can provide workarounds for the UI widgets
generated by the parsers
 Scriptable values instead of UI generated
can drive delegate values


E.g. UV clamping etc..
Things to remember


Annotations are case sensitive
The three built in parsers are very different, don’t mix up
your annotations



3ds max is Z-up




Type verses ResourceType
name verses ResourceName
You soon find this out with cubemaps!!
Swap YZ around to make it work
Currently only camera based matrixes are support at the
object level.
Use Scripted materials


Good to work around “Auto UI” look and feel
Data management/validation
Resources

http://sparks.autodesk.com





http://developer.nvidia.com
http://www.ati.com/developer
msdn.microsoft.com/directx
Ben Cloward


Sample parsers available and documentation
http://www.monitorstudios.com/bcloward/resources.html
neil.hazzard@autodesk.com
Download