EffectEdit Sample
Microsoft DirectX 9.0 SDK Update (October 2004)

EffectEdit Sample


The EffectEdit Sample implements a tool that allows easy experimentation with effects. Effects provide a convenient way to package multiple techniques for rendering an object, including render states, vertex shaders, pixel shaders, and multiple passes. Using the sample, you can load effect files, edit them, and see an object rendered with the effect. Changes to the effect are reflected immediately on the rendered object. To see the effect reference section, go to Effect Reference.

Path

Source:(SDK root)\Samples\C++\Direct3D\EffectEdit
Executable:(SDK root)\Samples\C++\Direct3D\Bin\EffectEdit.exe

User's Guide

The user interface is a window divided into four panes. You can press CTRL+TAB to change the keyboard focus between these panes.

The Effect file source code pane shows the source code for the current effect and provides text editing capability.

The Effect compilation results pane shows the results of compiling the current effect. You can double-click on errors to jump to the offending line in the source code pane. If there are no errors, the results pane will say "Compilation successful!" and you should see the rendered object.

The Rendered scene pane shows the rendered object, using the current effect. You can drag the left mouse button to rotate the object, the right mouse button to move the object, and click the scroll wheel to zoom the object.

The Rendering options pane lets you change various aspects of how the object is rendered. The Reset Camera button moves the camera back to the default position and orientation.

Programming Notes

The sample is a Microsoft Foundation Classes (MFC) application, using the single-document model. CEffectDoc is the class representing the document, which is mainly just the text contents of the effect. CMainFrame manages the display of the four different views used on this document and the splitter windows that control the panes containing the views. CTextView is the text editor, CErrorsView is the compilation results, COptionsView is the rendering options, and CRenderView is the rendered output. Only the last class really uses Microsoft Direct3D and Direct3D code. CRenderView is derived from both CFormView and CD3DApplication, so it can use familiar methods like FrameMove, InitDeviceObjects, etc.

This sample uses the sample framework code that is shared with other samples in the Microsoft DirectX software development kit (SDK). All common headers and source code can be found at:

(SDK root)\Samples\C++\Common

The sample provides a convenient application for shader development using effects. The application supports allows you to load an effect into an interactive edit environment for developing shader code. Sample code can be cut and pasted into a text edit window, which can be compiled on the fly. The render results can be automatically updated.

The sample takes advantage of semantics and annotations to decide what to do with certain types of parameters. This default effect uses the fixed function pipeline to blend the diffuse lighting with a solid, textured object. The model is in the file Tiger.x. To adjust the view in the render window, use the mouse to move or rotate the object or to move the light direction.

The sample renders four panes (listed here in clockwise order):

The Code Pane

The code pane displays the effect code. This includes the effect global variables, the shader functions and techniques and passes. You can use the scroll bars to navigate up and down in the code, or use the arrow keys to navigate. The nice thing about this pane is that you can enter new high-level shader language (HLSL) code here and it will be automatically recompiled and re-rendered for you. This makes it a handy test bed for code development.

The Render Pane

The render pane displays the rendered output. Like all the SDK samples, EffectEdit can display the frame rate. Use the arrow keys to rotate the object and view it from different camera angles. Click on the arrow that represents the direction of the light to move the light and watch the rendered result change.

The Rendering Options Pane

The rendering options pane gives you control over what gets rendered. The options include choosing which techniques and passes will be rendered, setting the rendering mode (wireframe, solid, or textured), and enabling or disabling automatic compiling and rendering.

The Compile Results Pane

The compile results pane displays the results of compiling whatever is in the code pane. When stepping through the debugger, any error messages are displayed in this pane. The error messages also provide the line number of the compile failures and may describe the shader validation rule that was violated. Often, the validation restrictions are displayed in this pane. If you double click on the line number of a line that fails to compile, the debugger will open to that line in the shader code.

Getting an Effect to Run in EffectEdit

The sample implements a tool that allows easy experimentation with effects. Effects provide a convenient way to package multiple techniques for rendering an object, including render states, vertex shaders, pixel shaders, and multiple passes. Using the sample, you can load effect files, edit them, and see an object rendered with the effect. Changes to the effect are reflected immediately on the rendered object.

The sample is set up to take advantage of these parameter combinations:

Here are the semantics that are recognized by the sample:

If the parameter has this semantic attached to it:EffectEdit will expect the parameter to contain:
WORLDWorld matrix
VIEWView matrix
PROJECTIONProjection matrix
WORLDVIEWWorld-view matrix
VIEWPROJECTIONView-projection matrix
WORLDVIEWPROJECTIONWorld-view-projection matrix

The Glow.fx effect uses the WORLDVIEW semantic to identify the composite world-view matrix:

float4x3 WorldView  : WORLDVIEW; 

Here are the annotations that are recognized by the sample:

If the parameter contains this annotation:EffectEdit will use the parameter for:
NAMEA texture file to be loaded
FUNCTIONA procedural texture file to be loaded
TARGETA procedural texture target (the default is "tx_1_0").
WIDTHThe texture width
HEIGHTThe texture height

Here are the string names that are recognized by the sample:

If the effect contains a string named:EffectEdit will use the string as:
BIMGA background image for the scene
XFileThe .x file containing the object

The default effect specifies the tiger.x file:

string XFile = "tiger.x";   // model

Here is an integer type that is recognized by the sample:

If the effect contains a string named:EffectEdit will use the integer value as:
BCLRThe background color of the scene

The default effect that uses BCLR to specify the background color is:

int    BCLR  = 0xff202080;  // background

A hexadecimal color is read in ARGB order, so this represents a color with full intensity alpha, whose blue component is four times the value of the red and green components. To see the color in EffectEdit Sample, comment out the statement that defines the background image and the background will be cleared to this shade of blue.



© 2004 Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center.