Skip to content

Commit 430824f

Browse files
authored
Fix out-of-date tutorials (#336)
* Fix expired API and paths * Fix mogwai option flags * Fix typos and add description for reflect() * Fix unfollowing codes to coding conventions * Fix heading level of reflect() description * Fix incorrect description of object replace 'array' with 'dictionary' and fix typo of 'perframeCB'.
1 parent 703eb30 commit 430824f

File tree

4 files changed

+59
-18
lines changed

4 files changed

+59
-18
lines changed

docs/tutorials/01-mogwai-usage.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Run Mogwai from within Visual Studio (by pressing Ctrl+F5), or from the command
2424
2525
-h, --help Display this help menu.
2626
-s[path], --script=[path] Python script file to run.
27+
--deferred The script is loaded deferred.
2728
-S[path], --scene=[path] Scene file (for example, a .pyscene
2829
file) to open.
2930
-l[path], --logfile=[path] File to write log into.
@@ -42,6 +43,8 @@ Run Mogwai from within Visual Studio (by pressing Ctrl+F5), or from the command
4243
-d, --debug-shaders Generate shader debug info.
4344
--enable-debug-layer Enable debug layer (enabled by default
4445
in Debug build).
46+
--precise Force all slang programs to run in
47+
precise mode
4548
```
4649

4750
Using `--silent` together with `--script` allows to run Mogwai for rendering in the background.
@@ -53,7 +56,7 @@ If you start it without specifying any options, Mogwai starts with a blank scree
5356
With Mogwai up and running, we'll proceed to loading something. You can load two kinds of files: scripts (which usually contain some global settings and render graphs) and scenes.
5457

5558
### Loading a Script (.py)
56-
Open the load script dialog by either going to `File -> Load Script` or hitting `Ctrl + O`. Navigate to the location of the script you wish to run and select it to load and run it. Alternatively, dragging-and-dropping a script into Mogwai will also work. Note that scripts intended for use with Mogwai must be written in Python. Full scripting documentation can be found [here](../Usage/Scripting.md).
59+
Open the load script dialog by either going to `File -> Load Script` or hitting `Ctrl + O`. Navigate to the location of the script you wish to run and select it to load and run it. Alternatively, dragging-and-dropping a script into Mogwai will also work. Note that scripts intended for use with Mogwai must be written in Python. Full scripting documentation can be found [here](../usage/scripting.md).
5760

5861
Here, we'll load the Forward Renderer, located at `Source/Mogwai/Data/ForwardRenderer.py`.
5962

docs/tutorials/02-implementing-a-render-pass.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ You can adjust the description of the render pass library by adjusting the follo
8282
const RenderPass::Info ExampleBlitPass::kInfo { "ExampleBlitPass", "Blits a texture into another texture." };
8383
```
8484
85-
We will ignore further details regarding render passes and their implementation for the purposes of this tutorial. Additional information can be found [here](../Usage/Render-Passes.md).
85+
We will ignore further details regarding render passes and their implementation for the purposes of this tutorial. Additional information can be found [here](../usage/render-passes.md).

docs/tutorials/03-creating-and-editing-render-graphs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Creating a render graph through scripting follows similar steps as creating it t
6161
- `markOutput()` takes an optional `mask` parameter specifying which color channels to output for frame capture.
6262
- Multiple calls to `markOutput()` with different masks can be made, frame capture will generate separate output files.
6363

64-
*For more information on the scripting API, you can find the documentation [here](../Usage/Scripting.md).*
64+
*For more information on the scripting API, you can find the documentation [here](../usage/scripting.md).*
6565

6666
To create a render graph through scripting:
6767
1. Create a function to contain the commands. This is not required, but recommended.

docs/tutorials/04-writing-shaders.md

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Writing Shaders
66

7-
Now that we've written a basic render pass and render graph, let's look at writing more complex passes that use shaders. Falcor uses the Slang shading language and compiler, and files should use one of the following extensions: `.slang`, `.slangh`, `.hlsl`, `.hlsli`. For more information on best practices for working with shaders in Falcor, please refer to the *Using Shaders and Data Files* section of the [Getting Started](../Getting-Started.md) page.
7+
Now that we've written a basic render pass and render graph, let's look at writing more complex passes that use shaders. Falcor uses the Slang shading language and compiler, and files should use one of the following extensions: `.slang`, `.slangh`, `.hlsl`, `.hlsli`. For more information on best practices for working with shaders in Falcor, please refer to the *Using Shaders and Data Files* section of the [Getting Started](../getting-started.md) page.
88

99
For this tutorial, we'll create a pass that renders a scene as a wireframe of a particular color.
1010

@@ -53,10 +53,10 @@ While `create()` does not need to do more than calling the constructor and retur
5353

5454
The constructor should look similar to this:
5555
```c++
56-
WireframePass::WireframePass()
56+
WireframePass::WireframePass() : RenderPass(kInfo)
5757
{
58-
mpProgram = GraphicsProgram::createFromFile("RenderPasses/WireframePass/Wireframe.3d.slang", "vsMain", "psMain");
59-
58+
mpProgram = GraphicsProgram::createFromFile("RenderPasses/Wireframe/Wireframe.3d.slang", "vsMain",
59+
"psMain");
6060
RasterizerState::Desc wireframeDesc;
6161
wireframeDesc.setFillMode(RasterizerState::FillMode::Wireframe);
6262
wireframeDesc.setCullMode(RasterizerState::CullMode::None);
@@ -67,6 +67,16 @@ WireframePass::WireframePass()
6767
mpGraphicsState->setRasterizerState(mpRasterState);
6868
}
6969
```
70+
### `reflect()`
71+
As in the Implementing a Render Pass tutorial, you simply set the Output for the Wireframe view.
72+
```c++
73+
RenderPassReflection WireframePass::reflect(const CompileData& compileData)
74+
{
75+
RenderPassReflection reflector;
76+
reflector.addOutput("output", "Wireframe view texture");
77+
return reflector;
78+
}
79+
```
7080

7181
### `setScene()`
7282
Our first render pass had no need for a `Scene` object; however, this pass does and will need this function to set `mpScene`. We first need to set `mpScene` to the scene that's passed in then add all scene defines to `mpProgram`. We then create our `GraphicsVars` so that we can bind shader variables later in `execute()`. These are done like so:
@@ -93,38 +103,66 @@ pRenderContext->clearFbo(pTargetFbo.get(), clearColor, 1.0f, 0, FboAttachmentTyp
93103
mpGraphicsState->setFbo(pTargetFbo);
94104
```
95105

96-
#### Setting the Render State
97-
We need to perform two operations here: indicate that we want to use a custom `RasterizerState` and bind all necessary values to our shader. We can indicate that we're using a custom `RasterizerState` by creating a `Scene::Renderflags` object and setting the flag `Scene::RenderFlags::UserRasterizerState`. Binding shader values is also fairly straightforward as Falcor allows you to set shader values in the `GraphicsVars` object in the same way as you would set values in an array. Our shader requires a single color value, `gColor`, which is located inside the `perFrameCB` constant buffer. This step should look like this:
106+
#### Binding the shader
107+
Binding shader values is also fairly straightforward as Falcor allows you to set shader values in the `GraphicsVars` object in the same way as you would set values in a dictionary. Our shader requires a single color value, `gColor`, which is located inside the `PerFrameCB` constant buffer. This step should look like this:
98108
```c++
99-
Scene::RenderFlags renderFlags = Scene::RenderFlags::UserRasterizerState;
100-
mpVars["perFrameCB"]["gColor"] = float4(0, 1, 0, 1);
109+
mpVars["PerFrameCB"]["gColor"] = float4(0, 1, 0, 1);
101110
```
102111

103112
#### Rendering a Scene Using the Shader
104113
With our scene, shader, and both the `GraphicsState` and `RasterizerState` set up, we can finally render our scene at the end of `execute()`. This is done through the `render()` method of `mpScene`, like so:
105114
```c++
106-
mpScene->rasterize(pRenderContext, mpGraphicsState.get(), mpGraphicsVars.get(), renderFlags);
115+
mpScene->rasterize(pRenderContext, mpGraphicsState.get(), mpVars.get(), mpRasterState, mpRasterState);
107116
```
108117
Your `execute()` function should now look like this, with a check for `mpScene` so we avoid accessing the scene when it isn't set:
109118
```c++
110119
void WireframePass::execute(RenderContext* pRenderContext, const RenderData& renderData)
111120
{
112-
auto pTargetFbo = Fbo::create({ renderData.getTexture("output") });
121+
auto pTargetFbo = Fbo::create({renderData.getTexture("output")});
113122
const float4 clearColor(0, 0, 0, 1);
114123
pRenderContext->clearFbo(pTargetFbo.get(), clearColor, 1.0f, 0, FboAttachmentType::All);
115124
mpGraphicsState->setFbo(pTargetFbo);
116-
117125
if (mpScene)
118126
{
119-
// Set render state
120-
Scene::RenderFlags renderFlags = Scene::RenderFlags::UserRasterizerState;
121127
mpVars["PerFrameCB"]["gColor"] = float4(0, 1, 0, 1);
122128
123-
mpScene->rasterize(pRenderContext, mpGraphicsState.get(), mpVars.get(), renderFlags);
129+
mpScene->rasterize(pRenderContext, mpGraphicsState.get(), mpVars.get(), mpRasterState, mpRasterState);
124130
}
125131
}
126132
```
127133

128-
Using the Render Graph Editor, create a graph solely containing this pass then launch it in Mogwai. You should see a black screen as there is no scene currently loaded. Load a scene by going to `File -> Load Scene`, and you should now see the wireframe for the scene you selected. We used `media/Arcade/Arcade.pyscene`, which looks like this:
134+
And you need to create CMakeLists.txt to include your C++ and Slang files in the build target.
135+
```CMake
136+
add_renderpass(WireframePass)
137+
138+
target_sources(WireframePass PRIVATE
139+
WireframePass.cpp
140+
WireframePass.h
141+
WireframePass.3d.slang
142+
)
143+
target_copy_shaders(WireframePass RenderPasses/WireframePass)
144+
145+
target_source_group(WireframePass "RenderPasses")
146+
```
147+
148+
149+
Using the Render Graph Editor, create a graph solely containing this pass then launch it in Mogwai, or create a python script.
150+
```python
151+
from falcor import *
152+
153+
def render_graph_WireframePass():
154+
g = RenderGraph('WireframePass')
155+
loadRenderPassLibrary('WireframePass.dll')
156+
Wireframe = createPass('WireframePass')
157+
g.addPass(WireframePass, 'WireframePass')
158+
g.markOutput('WireframePass.output')
159+
return g
160+
161+
WireframePass = render_graph_WireframePass()
162+
try: m.addGraph(WireframePass)
163+
except NameError: None
164+
```
165+
166+
You should see a green screen as there is no scene currently loaded. Load a scene by going to `File -> Load Scene`, and you should now see the wireframe for the scene you selected. We used `media/Arcade/Arcade.pyscene`, which looks like this:
129167

130168
![WireframePass](./images/wireframe-pass.png)

0 commit comments

Comments
 (0)