Skip to content

Commit 3829810

Browse files
author
Floyd Huizinga
committed
fix up "RasterizerState" project
1 parent 19b0491 commit 3829810

19 files changed

+79
-754
lines changed

docs/1-introduction/1-3-basics/1-3-1-rasterizer-state.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ Let's step into the few variables we can control in D3D11.
1010
The first one is the FillMode, this only has two options and simply tells the rasterizer whether to completely fill a triangle, or to only show its edges (or as is more commonly known as "to display a wireframe").
1111
That's right, we don't need a fancy shader or render the geometry in lines in order to display a wireframe, it's a built-in feature of the rasterizer, one mostly used for debugging or special kinds of visualisation.
1212

13-
!!! error
14-
Show screenshot of triangle in wireframe mode / filled mode
15-
13+
![](../../images/1-3-1-fillmode.png)
1614

1715
The CullMode is a bit more useful, this controls when we cull certain triangles, and has three options, `Front`, `Back` and `None`. For most purposes we generally set this to `Back`, so what does this actually do?
1816

@@ -23,9 +21,6 @@ Think of foliage or tree leaves for example, it's way more helpful to only place
2321

2422
Some shadowing techniques may also rely on Frontface culling in order to get better results, but we won't go into detail about that here now.
2523

26-
!!! error
27-
Show screenshot of triangle in both front/backface culled (one will be empty)
28-
2924
Simple to explain, but perhaps a bit harder to understands is the "Vertex Winding Order" which is controlled by our input geometry as well as the rasteriser state.
3025

3126
Shortly explained, if `FrontCounterClockwise` is `true`, then a triangle is front facing if the vertices are in a **counter**-clockwise order , otherwise it is back facing.
@@ -49,6 +44,11 @@ For completeness-sake, the following is a "counter-clockwise triangle".
4944
1 2
5045
```
5146

47+
How it looks to have our triangle in `Front` and `Back` cull-modes.
48+
![](../../images/1-3-1-cullmode.png)
49+
50+
(Yes, the "missing" triangle is the expected result here, it's being culled after all!)
51+
5252

5353
The last few variables we can control require some knowledge on topics we'll cover in later chapters, for now the only important one that is set to `true` by default is:
5454
`DepthClipEnable`, which allows the rasterizer to discard triangles, or more correctly "fragments" that fall beyond our depth-range from the viewport.
4.86 KB
Loading
7.17 KB
Loading

src/Cpp/1-getting-started/1-3-1-RasterizerState/1-3-1-RasterizerState.vcxproj

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@
4747
<LinkIncremental>true</LinkIncremental>
4848
<OutDir>bin\$(Configuration)\</OutDir>
4949
<IntDir>obj\$(Configuration)\</IntDir>
50-
<IncludePath>$(SolutionDir)..\lib\glfw-3.3.6\include\;$(SolutionDir)..\lib\FreeImage\include\;$(SolutionDir)..\lib\DirectXTex\include\;$(SolutionDir)..\lib\assimp\include\;$(SolutionDir)..\lib\imgui\include\;$(SolutionDir)Cpp\Framework\;</IncludePath>
51-
<LibraryPath>$(SolutionDir)..\lib\glfw-3.3.6\lib-vc2022\;$(SolutionDir)..\lib\DirectXTex\lib\$(Configuration)\;$(SolutionDir)..\lib\FreeImage\lib\;$(SolutionDir)..\lib\assimp\lib\;$(LibraryPath);$(SolutionDir)Cpp\Framework\lib\$(Configuration)\;</LibraryPath>
50+
<IncludePath>$(SolutionDir)..\lib\glfw-3.3.6\include\;$(SolutionDir)Cpp\Framework\</IncludePath>
51+
<LibraryPath>$(SolutionDir)..\lib\glfw-3.3.6\lib-vc2022\;$(LibraryPath);$(SolutionDir)Cpp\Framework\lib\$(Configuration)\</LibraryPath>
5252
<SourcePath>$(SourcePath)</SourcePath>
5353
</PropertyGroup>
5454
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
5555
<LinkIncremental>false</LinkIncremental>
5656
<OutDir>bin\$(Configuration)\</OutDir>
5757
<IntDir>obj\$(Configuration)\</IntDir>
58-
<IncludePath>$(SolutionDir)..\lib\glfw-3.3.6\include\;$(SolutionDir)..\lib\FreeImage\include\;$(SolutionDir)..\lib\DirectXTex\include\;$(SolutionDir)..\lib\assimp\include\;$(SolutionDir)..\lib\imgui\include\;$(SolutionDir)Cpp\Framework\;</IncludePath>
59-
<LibraryPath>$(SolutionDir)..\lib\glfw-3.3.6\lib-vc2022\;$(SolutionDir)..\lib\DirectXTex\lib\$(Configuration)\;$(SolutionDir)..\lib\FreeImage\lib\;$(SolutionDir)..\lib\assimp\lib\;$(LibraryPath);$(SolutionDir)Cpp\Framework\lib\$(Configuration)\;</LibraryPath>
58+
<IncludePath>$(SolutionDir)..\lib\glfw-3.3.6\include\;$(SolutionDir)Cpp\Framework\</IncludePath>
59+
<LibraryPath>$(SolutionDir)..\lib\glfw-3.3.6\lib-vc2022\;$(LibraryPath);$(SolutionDir)Cpp\Framework\lib\$(Configuration)\</LibraryPath>
6060
<SourcePath>$(SourcePath)</SourcePath>
6161
</PropertyGroup>
6262
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -70,7 +70,7 @@
7070
<Link>
7171
<SubSystem>Console</SubSystem>
7272
<GenerateDebugInformation>true</GenerateDebugInformation>
73-
<AdditionalDependencies>Framework.lib;assimp.lib;FreeImage.lib;DirectXTex.lib;glfw3.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
73+
<AdditionalDependencies>Framework.lib;glfw3.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
7474
<IgnoreSpecificDefaultLibraries>msvcrt</IgnoreSpecificDefaultLibraries>
7575
</Link>
7676
<PostBuildEvent>
@@ -98,7 +98,7 @@ xcopy /Y $(ProjectDir)Assets\Textures\*.* $(OutDir)Assets\Textures\</Command>
9898
<EnableCOMDATFolding>true</EnableCOMDATFolding>
9999
<OptimizeReferences>true</OptimizeReferences>
100100
<GenerateDebugInformation>true</GenerateDebugInformation>
101-
<AdditionalDependencies>Framework.lib;assimp.lib;FreeImage.lib;DirectXTex.lib;glfw3.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
101+
<AdditionalDependencies>Framework.lib;glfw3.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
102102
<IgnoreSpecificDefaultLibraries>
103103
</IgnoreSpecificDefaultLibraries>
104104
</Link>
@@ -113,30 +113,19 @@ xcopy /Y $(ProjectDir)Assets\Textures\*.* $(OutDir)Assets\Textures\</Command>
113113
</PostBuildEvent>
114114
</ItemDefinitionGroup>
115115
<ItemGroup>
116-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\backend\imgui_impl_dx11.cpp" />
117-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\backend\imgui_impl_glfw.cpp" />
118-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\imgui.cpp" />
119-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\imgui_demo.cpp" />
120-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\imgui_draw.cpp" />
121-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\imgui_tables.cpp" />
122-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\imgui_widgets.cpp" />
123116
<ClCompile Include="DeviceContext.cpp" />
124117
<ClCompile Include="Main.cpp" />
125118
<ClCompile Include="RasterizerStateApplication.cpp" />
126-
<ClCompile Include="ModelFactory.cpp" />
127119
<ClCompile Include="Pipeline.cpp" />
128120
<ClCompile Include="PipelineFactory.cpp" />
129-
<ClCompile Include="TextureFactory.cpp" />
130121
</ItemGroup>
131122
<ItemGroup>
132123
<ClInclude Include="Definitions.hpp" />
133124
<ClInclude Include="DeviceContext.hpp" />
134125
<ClInclude Include="RasterizerStateApplication.hpp" />
135-
<ClInclude Include="ModelFactory.hpp" />
136126
<ClInclude Include="Pipeline.hpp" />
137127
<ClInclude Include="PipelineFactory.hpp" />
138128
<ClInclude Include="ResourceDescriptor.hpp" />
139-
<ClInclude Include="TextureFactory.hpp" />
140129
<ClInclude Include="VertexType.hpp" />
141130
</ItemGroup>
142131
<ItemGroup>

src/Cpp/1-getting-started/1-3-1-RasterizerState/1-3-1-RasterizerState.vcxproj.filters

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121
<ClCompile Include="RasterizerStateApplication.cpp">
2222
<Filter>Source Files</Filter>
2323
</ClCompile>
24-
<ClCompile Include="TextureFactory.cpp">
25-
<Filter>Source Files</Filter>
26-
</ClCompile>
27-
<ClCompile Include="ModelFactory.cpp">
28-
<Filter>Source Files</Filter>
29-
</ClCompile>
3024
<ClCompile Include="PipelineFactory.cpp">
3125
<Filter>Source Files</Filter>
3226
</ClCompile>
@@ -36,41 +30,14 @@
3630
<ClCompile Include="DeviceContext.cpp">
3731
<Filter>Source Files</Filter>
3832
</ClCompile>
39-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\imgui.cpp">
40-
<Filter>Source Files</Filter>
41-
</ClCompile>
42-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\imgui_demo.cpp">
43-
<Filter>Source Files</Filter>
44-
</ClCompile>
45-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\imgui_draw.cpp">
46-
<Filter>Source Files</Filter>
47-
</ClCompile>
48-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\imgui_tables.cpp">
49-
<Filter>Source Files</Filter>
50-
</ClCompile>
51-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\imgui_widgets.cpp">
52-
<Filter>Source Files</Filter>
53-
</ClCompile>
54-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\backend\imgui_impl_dx11.cpp">
55-
<Filter>Source Files</Filter>
56-
</ClCompile>
57-
<ClCompile Include="..\..\..\..\lib\imgui\include\imgui\backend\imgui_impl_glfw.cpp">
58-
<Filter>Source Files</Filter>
59-
</ClCompile>
6033
</ItemGroup>
6134
<ItemGroup>
6235
<ClInclude Include="RasterizerStateApplication.hpp">
6336
<Filter>Header Files</Filter>
6437
</ClInclude>
65-
<ClInclude Include="TextureFactory.hpp">
66-
<Filter>Header Files</Filter>
67-
</ClInclude>
6838
<ClInclude Include="Definitions.hpp">
6939
<Filter>Header Files</Filter>
7040
</ClInclude>
71-
<ClInclude Include="ModelFactory.hpp">
72-
<Filter>Header Files</Filter>
73-
</ClInclude>
7441
<ClInclude Include="VertexType.hpp">
7542
<Filter>Header Files</Filter>
7643
</ClInclude>
Binary file not shown.

src/Cpp/1-getting-started/1-3-1-RasterizerState/Assets/Shaders/Main.ps.hlsl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@ struct VSOutput
22
{
33
float4 Position: SV_Position;
44
float3 Color: COLOR0;
5-
float2 Uv: TEXCOORD0;
65
};
76

8-
sampler LinearSampler : register(s0);
9-
10-
Texture2D Texture : register(t0);
117

128
float4 Main(VSOutput input): SV_Target
139
{
14-
float4 texel = Texture.Sample(LinearSampler, input.Uv);
15-
//return float4(input.Color, 1.0f) + 0.5 * texel;
16-
return texel;
10+
return float4(input.Color, 1.0f);
1711
}

src/Cpp/1-getting-started/1-3-1-RasterizerState/Assets/Shaders/Main.vs.hlsl

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,18 @@ struct VSInput
22
{
33
float3 Position: POSITION;
44
float3 Color: COLOR0;
5-
float2 Uv: TEXCOORD0;
65
};
76

87
struct VSOutput
98
{
109
float4 Position: SV_Position;
1110
float3 Color: COLOR0;
12-
float2 Uv: TEXCOORD0;
1311
};
1412

15-
cbuffer PerApplication
16-
{
17-
row_major matrix ProjectionMatrix;
18-
}
19-
20-
cbuffer PerFrame
21-
{
22-
row_major matrix ViewMatrix;
23-
}
24-
25-
cbuffer PerObject
26-
{
27-
row_major matrix WorldMatrix;
28-
}
29-
3013
VSOutput Main(VSInput input)
3114
{
32-
const matrix modelViewProjection = mul(WorldMatrix, mul(ViewMatrix, ProjectionMatrix));
33-
3415
VSOutput output = (VSOutput)0;
35-
output.Position = mul(float4(input.Position, 1.0f), modelViewProjection);
16+
output.Position = float4(input.Position, 1.0f);
3617
output.Color = input.Color;
37-
output.Uv = input.Uv;
3818
return output;
3919
}
Binary file not shown.

src/Cpp/1-getting-started/1-3-1-RasterizerState/DeviceContext.cpp

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "DeviceContext.hpp"
22
#include "Pipeline.hpp"
33

4-
#include <imgui/backend/imgui_impl_dx11.h>
54
#include <utility>
65

76
DeviceContext::DeviceContext(
@@ -12,32 +11,22 @@ DeviceContext::DeviceContext(
1211
_activePipeline = nullptr;
1312
_drawVertices = 0;
1413
_drawIndices = 0;
15-
ImGui_ImplDX11_Init(device.Get(), _deviceContext.Get());
1614
}
1715

1816
DeviceContext::~DeviceContext()
1917
{
20-
ImGui_ImplDX11_Shutdown();
18+
2119
}
2220

2321
void DeviceContext::Clear(
2422
ID3D11RenderTargetView* renderTarget,
25-
float clearColor[4],
26-
ID3D11DepthStencilView* depthStencilView,
27-
float clearDepth) const
23+
float clearColor[4]) const
2824
{
2925
_deviceContext->ClearRenderTargetView(
3026
renderTarget,
3127
clearColor);
32-
if (depthStencilView != nullptr)
33-
{
34-
_deviceContext->ClearDepthStencilView(
35-
depthStencilView,
36-
D3D11_CLEAR_FLAG::D3D11_CLEAR_DEPTH,
37-
clearDepth,
38-
0);
39-
}
40-
_deviceContext->OMSetRenderTargets(1, &renderTarget, depthStencilView);
28+
29+
_deviceContext->OMSetRenderTargets(1, &renderTarget, nullptr);
4130
}
4231

4332
void DeviceContext::SetPipeline(const Pipeline* pipeline)
@@ -48,33 +37,6 @@ void DeviceContext::SetPipeline(const Pipeline* pipeline)
4837
_deviceContext->VSSetShader(pipeline->_vertexShader.Get(), nullptr, 0);
4938
_deviceContext->PSSetShader(pipeline->_pixelShader.Get(), nullptr, 0);
5039

51-
for (auto [descriptor, resource] : pipeline->_resources)
52-
{
53-
switch (descriptor.Type)
54-
{
55-
case ResourceType::Sampler:
56-
_deviceContext->PSSetSamplers(descriptor.SlotIndex, 1, reinterpret_cast<ID3D11SamplerState**>(&resource));
57-
break;
58-
59-
case ResourceType::Texture:
60-
_deviceContext->PSSetShaderResources(descriptor.SlotIndex, 1, reinterpret_cast<ID3D11ShaderResourceView**>(&resource));
61-
break;
62-
63-
case ResourceType::Buffer:
64-
switch (descriptor.Stage)
65-
{
66-
case ResourceStage::VertexStage:
67-
_deviceContext->VSSetConstantBuffers(descriptor.SlotIndex, 1, reinterpret_cast<ID3D11Buffer**>(&resource));
68-
break;
69-
case ResourceStage::PixelStage:
70-
_deviceContext->PSSetConstantBuffers(descriptor.SlotIndex, 1, reinterpret_cast<ID3D11Buffer**>(&resource));
71-
break;
72-
}
73-
break;
74-
}
75-
}
76-
77-
_deviceContext->OMSetDepthStencilState(pipeline->_depthStencilState.Get(), 0);
7840
_deviceContext->RSSetViewports(1, &pipeline->_viewport);
7941
_deviceContext->RSSetState(pipeline->_rasterizerState.Get());
8042
}

0 commit comments

Comments
 (0)