Cogs.Core
RenderContext.h
1#pragma once
2
3#include "ClipmapTerrainTypes.h"
4
5#include "Rendering/IGraphicsDevice.h"
6
7#include <functional>
8#include <vector>
9
10namespace
11{
12 glm::vec2 quadVertices[] = {
13 { 0.0f, 0.0f },
14 { 1.0f, 0.0f },
15 { 1.0f, 1.0f },
16
17 { 0.0f, 0.0f },
18 { 1.0f, 1.0f },
19 { 0.0f, 1.0f }
20 };
21}
22
23namespace Cogs
24{
26 {
27 bool enableUpdate = true;
28 bool enableCulling = true;
29
30 bool invalidateNormals = false;
31 };
32
35 {
37 {
55 };
56 };
58 {
59 float heightExaggeration = 1.0f;
60
61 Vector4d worldScale = Vector4d(1, 1, 1, 1);
62
63 bool enableNoData = false;
64
66 };
67
69 {
70 Vector4 shallowColor = Vector4(0.15f, 0.28f, 0.35f, 0.9f);
71 Vector4 deepColor = Vector4(0.1f, 0.2f, 0.3f, 0.95f);
72 Vector4 roughColor = Vector4(0.15f, 0.35f, 0.28f, 0.95f);
73
74 float worldSpaceMeter = 1.f; //< Size of one meter in world space.
75 float baseTileLength = 500; //< Side-length of base tile in meters.
76 int baseTileSizeLog2 = 8; //< Number of samples along side of tile.
77 float significantWaveHeight = 2.f; //< Significant wave height of spectrum, in meters.
78 float significantWavePeriod = 6.f; //< Significant wave period of spectrum, in seconds.
79 float swellDirection = 0.f; //< Direction of waves, zero implies waves that arrive from positive X.
80 float shoale = 0.f; //< Depth at which shoaling of waves start, in world space units.
81 float roughness = 0.f; //< How rough the sea should appear to be, value between 0.0 and 1.0.
82 float detailFactor = 9.13f;
83
84 float foamDetectionScale = 0.1f;
85 float foamErosionValue = 2.f;
86 float shoalingEffectFactor = 0.f;
87
88 float lodDisplaceStart = 2.f;
89 float lodDisplaceTransition = 1.f;
90 float lodNormalStart = 0.01f;
91 float lodNormalTransition = 2.5f;
92
93 float lodDetailStart = 25.f;
94 float lodDetailTransition = 150.f;
95 float lodFoamStart = 0.75f;
96 float lodFoamTransition = 0.3f;
97
98 bool enableImagery = true;
99 };
100
102 {
103 bool showImagery = true;
104 bool showBlendRegions = false;
105
106 bool enableBlending = true;
107
108 bool showLevelColors = false;
109
110 Vector4 blendRegionColor = Vector4(0, 0, 1, 1);
111 Vector4 diffuseColor = Vector4(0.4f, 0.5f, 0.4f, 1);
112
113 float lodBias = 0.0f;
114
115 bool enableMipMapping = false;
116
117 bool enableCulling = true;
118 };
119
121 {
122 bool showDepthBuffer = false;
123 bool showHeightMaps = false;
124 bool showTextures = false;
125
126 Vector2 textureOverlaySize = Vector2(256, 256);
127 };
128
130 {
131 enum ETerrainRenderPass
132 {
133 Main = 0,
134 Reflection,
135 Refraction,
136 Other
137 };
138 };
139
142 {
143 EffectHandle clipmapEffect;
144 EffectHandle clipmapDepthEffect;
145
146 EffectHandle oceanEffect;
147 };
148
150 {
151 PermutationDependentRenderContextData & getPermutationDependentRenderContextData(const size_t index)
152 {
153 if (permutationDependentRenderContextData.size() <= index)
154 permutationDependentRenderContextData.resize(index + 4);
155
156 return permutationDependentRenderContextData[index];
157 }
158
159 IGraphicsDevice * device;
160 IContext * context;
161
162 RenderTargetHandle renderTarget;
163 DepthStencilHandle depthStencilTarget;
164
165 TerrainRenderPass::ETerrainRenderPass renderPass = TerrainRenderPass::Main;
166
167 uint16_t viewportX;
168 uint16_t viewportY;
169
170 uint16_t width;
171 uint16_t height;
172
173 bool wireframe = false;
174
175 size_t maxAppliedTilesPerFrame = 2;
176
177 Vector3d origin;
178 Vector3d center;
179 Vector3 sampleCenter;
180 Vector3d sampleOrigin;
181 Vector3d sampleCameraCenter;
182 float distance;
183 bool initialized = false;
184
185 // Offset to apply to terrain extents, in world coordinates.
186 Vector3d offset;
187
188 struct Scene
189 {
190 Matrix viewMatrix;
191 Matrix projectionMatrix;
192 Matrix viewMatrixInverse;
193 } scene;
194
195 Vector3d cullOrigin;
196 ViewVolume cullVolume;
197
198 size_t permutation = 0;
199 bool isOIT = false;
200
201 std::function<void(EffectHandle)> callback;
202
203 bool offsetEnabled;
204
205 bool oceanEnabled;
206
207 bool reverseDepth = false;
208
209 std::function<void(EffectHandle)> oceanCallback;
210
211 int rayPickIndex = -1;
212
213 private:
214 std::vector<PermutationDependentRenderContextData> permutationDependentRenderContextData;
215 };
216
218 {
219 bool changed = false;
220 int numTextures;
221 int numActiveImagery;
222 bool precomputeNormals = false;
223 };
224}
Represents a graphics device used to manage graphics resources and issue drawing commands.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Policies for determining the center of the clipmap.
Definition: RenderContext.h:35
@ TerrainProjected
Find the projected center of the screen on the terrain and center the clipmap on these coordinates.
Definition: RenderContext.h:46
@ Projected
Project the lower center of the screen onto the XY-plane and center the clipmap on these coordinates.
Definition: RenderContext.h:50
@ Vertical
Project the camera coordinates onto the XY-plane and center the clipmap on these coordinates.
Definition: RenderContext.h:54
Represents a graphics device context which can receive rendering commands.
Definition: IContext.h:43
Part of the render context that depends on the selected permutation.