File size: 15,248 Bytes
0c51b93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/*
 * Copyright (c) 2008-2017, NVIDIA CORPORATION.  All rights reserved.
 *
 * NVIDIA CORPORATION and its licensors retain all intellectual property
 * and proprietary rights in and to this software, related documentation
 * and any modifications thereto.  Any use, reproduction, disclosure or
 * distribution of this software and related documentation without an express
 * license agreement from NVIDIA CORPORATION is strictly prohibited.
 */

//direct3d headers

#define NOMINMAX 

#include <d3d11.h>

// include the Direct3D Library file
#pragma comment (lib, "d3d11.lib")

#include <math.h>

#include "appD3D11Ctx.h"

#include "fluidRenderD3D11.h"

#include "../d3d/shaders/pointThicknessVS.hlsl.h"
#include "../d3d/shaders/pointThicknessGS.hlsl.h"
#include "../d3d/shaders/pointThicknessPS.hlsl.h"
#include "../d3d/shaders/ellipsoidDepthVS.hlsl.h"
#include "../d3d/shaders/ellipsoidDepthGS.hlsl.h"
#include "../d3d/shaders/ellipsoidDepthPS.hlsl.h"
#include "../d3d/shaders/passThroughVS.hlsl.h"
#include "../d3d/shaders/blurDepthPS.hlsl.h"
#include "../d3d/shaders/compositePS.hlsl.h"

#include "../d3d/shaderCommonD3D.h"

#include "renderTargetD3D11.h"
#include "shadowMapD3D11.h"

#include "shaders.h"

typedef DirectX::XMFLOAT2 float2;

using namespace DirectX;

struct PassthroughVertex
{
	float3 position;
	float3 normal;
	float2 texcoords;
	float4 color;
};

void FluidRendererD3D11::init(ID3D11Device* device, ID3D11DeviceContext* context, int width, int height)
{
	m_sceneWidth = width;
	m_sceneHeight = height;

	m_thicknessTexture.init(device, width, height);
	m_depthTexture.init(device, width, height);
	m_depthSmoothTexture.init(device, width, height, false);

	m_device = device;
	m_deviceContext = context;

	// create the input layout
	{
		D3D11_INPUT_ELEMENT_DESC inputElementDescs[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "U", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "V", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "W", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		};

		m_device->CreateInputLayout(inputElementDescs, 4, g_pointThicknessVS, sizeof(g_pointThicknessVS), &m_pointThicknessLayout);
	}

	// create the shaders
	m_device->CreateVertexShader(g_pointThicknessVS, sizeof(g_pointThicknessVS), nullptr, &m_pointThicknessVs);
	m_device->CreateGeometryShader(g_pointThicknessGS, sizeof(g_pointThicknessGS), nullptr, &m_pointThicknessGs);
	m_device->CreatePixelShader(g_pointThicknessPS, sizeof(g_pointThicknessPS), nullptr, &m_pointThicknessPs);
	
	// create the input layout
	{
		D3D11_INPUT_ELEMENT_DESC inputElementDescs[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "U", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "V", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 2, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "W", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 3, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		};

		m_device->CreateInputLayout(inputElementDescs, 4, g_ellipsoidDepthVS, sizeof(g_ellipsoidDepthVS), &m_ellipsoidDepthLayout);
	}

	// create the shaders
	m_device->CreateVertexShader(g_ellipsoidDepthVS, sizeof(g_ellipsoidDepthVS), nullptr, &m_ellipsoidDepthVs);
	m_device->CreateGeometryShader(g_ellipsoidDepthGS, sizeof(g_ellipsoidDepthGS), nullptr, &m_ellipsoidDepthGs);
	m_device->CreatePixelShader(g_ellipsoidDepthPS, sizeof(g_ellipsoidDepthPS), nullptr, &m_ellipsoidDepthPs);

	// create the input layout
	{
		D3D11_INPUT_ELEMENT_DESC inputElementDescs[] =
		{
			{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
		};

		m_device->CreateInputLayout(inputElementDescs, 4, g_passThroughVS, sizeof(g_passThroughVS), &m_passThroughLayout);
	}

	// pass through shader
	m_device->CreateVertexShader(g_passThroughVS, sizeof(g_passThroughVS), nullptr, &m_passThroughVs);

	// full screen pixel shaders
	m_device->CreatePixelShader(g_blurDepthPS, sizeof(g_blurDepthPS), nullptr, &m_blurDepthPs);
	m_device->CreatePixelShader(g_compositePS, sizeof(g_compositePS), nullptr, &m_compositePs);

	// create a constant buffer
	{
		D3D11_BUFFER_DESC bufDesc;
		bufDesc.ByteWidth = sizeof(Hlsl::FluidShaderConst); // 64 * sizeof(float);
		bufDesc.Usage = D3D11_USAGE_DYNAMIC;
		bufDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
		bufDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
		bufDesc.MiscFlags = 0;

		m_device->CreateBuffer(&bufDesc, nullptr, &m_constantBuffer);
	}

	// create the rastersizer state
	for (int i = 0; i < NUM_FLUID_RENDER_MODES; i++)
	{
		for (int j = 0; j < NUM_FLUID_CULL_MODES; j++)
		{
			D3D11_RASTERIZER_DESC desc = {};
			desc.FillMode = (D3D11_FILL_MODE)(D3D11_FILL_WIREFRAME + i);
			desc.CullMode = (D3D11_CULL_MODE)(D3D11_CULL_NONE + j);
			desc.FrontCounterClockwise = TRUE;	// This is non-default
			desc.DepthBias = 0;
			desc.DepthBiasClamp = 0.f;
			desc.SlopeScaledDepthBias = 0.f;
			desc.DepthClipEnable = TRUE;
			desc.ScissorEnable = FALSE;
			desc.MultisampleEnable = FALSE;
			desc.AntialiasedLineEnable = FALSE;

			m_device->CreateRasterizerState(&desc, &m_rasterizerState[i][j]);
		}
	}

	_createScreenQuad();
}

void FluidRendererD3D11::_createScreenQuad()
{
	// create an index buffer
	{
		D3D11_BUFFER_DESC bufDesc;
		bufDesc.ByteWidth = 4*sizeof(UINT);
		bufDesc.Usage = D3D11_USAGE_IMMUTABLE;
		bufDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
		bufDesc.CPUAccessFlags = DXGI_CPU_ACCESS_NONE;
		bufDesc.MiscFlags = 0;

		unsigned int quad_indices[4] = { 0, 1, 3, 2 };
		
		D3D11_SUBRESOURCE_DATA data = { 0 };
		data.pSysMem = quad_indices;

		m_device->CreateBuffer(&bufDesc, &data, &m_quadIndexBuffer);
	}

	// create a vertex buffer
	{
		
		D3D11_BUFFER_DESC bufDesc;
		bufDesc.ByteWidth = 4*sizeof(PassthroughVertex);
		bufDesc.Usage = D3D11_USAGE_IMMUTABLE;
		bufDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
		bufDesc.CPUAccessFlags = DXGI_CPU_ACCESS_NONE;
		bufDesc.MiscFlags = 0;

		D3D11_SUBRESOURCE_DATA data = { 0 };


		PassthroughVertex vertices[4] =
		{
		 	{ {-1.0f, -1.0f, 0.0f},  {0, 1, 0}, {0.0f, 0.0f}, {1, 1, 1, 1}},
			{ { 1.0f, -1.0f, 0.0f},  {0, 1, 0}, {1.0f, 0.0f}, {1, 1, 1, 1}},
			{ { 1.0f,  1.0f, 0.0f},  {0, 1, 0}, {1.0f, 1.0f}, {1, 1, 1, 1}},
			{ {-1.0f,  1.0f, 0.0f},  {0, 1, 0}, {0.0f, 1.0f}, {1, 1, 1, 1}},
		};

		data.pSysMem = vertices;

		m_device->CreateBuffer(&bufDesc, &data, &m_quadVertexBuffer);
	}
}

void FluidRendererD3D11::drawThickness(const FluidDrawParamsD3D* params, const FluidRenderBuffersD3D11* buffers)
{
	ID3D11DeviceContext* deviceContext = m_deviceContext;

	// update constant buffer
	{

		D3D11_BUFFER_DESC desc;
		m_constantBuffer->GetDesc(&desc);

		D3D11_MAPPED_SUBRESOURCE mappedResource = {};
		if (SUCCEEDED(deviceContext->Map(m_constantBuffer.Get(), 0u, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource)))
		{
			Hlsl::FluidShaderConst constBuf;
			RenderParamsUtilD3D::calcFluidConstantBuffer(*params, constBuf);
			memcpy(mappedResource.pData, &constBuf, sizeof(Hlsl::FluidShaderConst));
			deviceContext->Unmap(m_constantBuffer.Get(), 0u);
		}
	}

	deviceContext->VSSetShader(m_pointThicknessVs.Get(), nullptr, 0u);
	deviceContext->GSSetShader(m_pointThicknessGs.Get(), nullptr, 0u);
	deviceContext->PSSetShader(m_pointThicknessPs.Get(), nullptr, 0u);

	deviceContext->IASetInputLayout(m_pointThicknessLayout.Get());
	deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);

	deviceContext->VSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf());
	deviceContext->GSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf());
	deviceContext->PSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf());

	ID3D11Buffer* vertexBuffers[4] =
	{
		buffers->m_positions.Get(),
		buffers->m_anisotropiesArr[0].Get(),
		buffers->m_anisotropiesArr[1].Get(),
		buffers->m_anisotropiesArr[2].Get()
	};

	unsigned int vertexBufferStrides[4] =
	{
		sizeof(float4),
		sizeof(float4),
		sizeof(float4),
		sizeof(float4)
	};

	unsigned int vertexBufferOffsets[4] = { 0 };

	deviceContext->IASetVertexBuffers(0, 4, vertexBuffers, vertexBufferStrides, vertexBufferOffsets);
	deviceContext->IASetIndexBuffer(buffers->m_indices.Get(), DXGI_FORMAT_R32_UINT, 0u);

	float depthSign = DirectX::XMVectorGetW(params->projection.r[2]);
	if (depthSign < 0.f)
	{
		deviceContext->RSSetState(m_rasterizerState[params->renderMode][params->cullMode].Get());
	}

	deviceContext->DrawIndexed(params->n, params->offset, 0);

	if (depthSign < 0.f)
	{
		deviceContext->RSSetState(nullptr);
	}
}

void FluidRendererD3D11::drawEllipsoids(const FluidDrawParamsD3D* params, const FluidRenderBuffersD3D11* buffers)
{
	ID3D11DeviceContext* deviceContext = m_deviceContext;

	// update constant buffer
	{

		D3D11_BUFFER_DESC desc;
		m_constantBuffer->GetDesc(&desc);

		D3D11_MAPPED_SUBRESOURCE mappedResource = {};
		if (SUCCEEDED(deviceContext->Map(m_constantBuffer.Get(), 0u, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource)))
		{
			Hlsl::FluidShaderConst constBuf;
			RenderParamsUtilD3D::calcFluidConstantBuffer(*params, constBuf);
			memcpy(mappedResource.pData, &constBuf, sizeof(Hlsl::FluidShaderConst));
			deviceContext->Unmap(m_constantBuffer.Get(), 0u);
		}
	}

	deviceContext->VSSetShader(m_ellipsoidDepthVs.Get(), nullptr, 0u);
	deviceContext->GSSetShader(m_ellipsoidDepthGs.Get(), nullptr, 0u);
	deviceContext->PSSetShader(m_ellipsoidDepthPs.Get(), nullptr, 0u);

	deviceContext->IASetInputLayout(m_ellipsoidDepthLayout.Get());
	deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);

	deviceContext->VSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf());
	deviceContext->GSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf());
	deviceContext->PSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf());

	ID3D11Buffer* vertexBuffers[4] =
	{
		buffers->m_positions.Get(),
		buffers->m_anisotropiesArr[0].Get(),
		buffers->m_anisotropiesArr[1].Get(),
		buffers->m_anisotropiesArr[2].Get()
	};

	unsigned int vertexBufferStrides[4] =
	{
		sizeof(float4),
		sizeof(float4),
		sizeof(float4),
		sizeof(float4)
	};

	unsigned int vertexBufferOffsets[4] = { 0 };

	deviceContext->IASetVertexBuffers(0, 4, vertexBuffers, vertexBufferStrides, vertexBufferOffsets);
	deviceContext->IASetIndexBuffer(buffers->m_indices.Get(), DXGI_FORMAT_R32_UINT, 0u);

	float depthSign = DirectX::XMVectorGetW(params->projection.r[2]);
	if (depthSign < 0.f)
	{
		deviceContext->RSSetState(m_rasterizerState[params->renderMode][params->cullMode].Get());
	}

	deviceContext->DrawIndexed(params->n, params->offset, 0);

	if (depthSign < 0.f)
	{
		deviceContext->RSSetState(nullptr);
	}
}

void FluidRendererD3D11::drawBlurDepth(const FluidDrawParamsD3D* params)
{
	ID3D11DeviceContext* deviceContext = m_deviceContext;

	// update constant buffer
	{
		D3D11_MAPPED_SUBRESOURCE mappedResource = {};
		if (SUCCEEDED(deviceContext->Map(m_constantBuffer.Get(), 0u, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource)))
		{
			Hlsl::FluidShaderConst constBuf;
			RenderParamsUtilD3D::calcFluidConstantBuffer(*params, constBuf);
			memcpy(mappedResource.pData, &constBuf, sizeof(Hlsl::FluidShaderConst));
			deviceContext->Unmap(m_constantBuffer.Get(), 0u);
		}
	}

	deviceContext->VSSetShader(m_passThroughVs.Get(), nullptr, 0u);
	deviceContext->GSSetShader(nullptr, nullptr, 0u);
	deviceContext->PSSetShader(m_blurDepthPs.Get(), nullptr, 0u);

	ID3D11ShaderResourceView* srvs[2] = { m_depthTexture.m_backSrv.Get(), m_thicknessTexture.m_backSrv.Get() };
	deviceContext->PSSetShaderResources(0, 2, srvs);

	ID3D11SamplerState* samps[1] = { m_thicknessTexture.m_linearSampler.Get() };
	deviceContext->PSSetSamplers(0, 1, samps);

	deviceContext->IASetInputLayout(m_passThroughLayout.Get());
	deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);

	deviceContext->VSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf());
	deviceContext->PSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf());

	UINT vertexStride = sizeof(PassthroughVertex);
	UINT offset = 0u;
	deviceContext->IASetVertexBuffers(0, 1, m_quadVertexBuffer.GetAddressOf(), &vertexStride, &offset);
	deviceContext->IASetIndexBuffer(m_quadIndexBuffer.Get(), DXGI_FORMAT_R32_UINT, 0u);

	float depthSign = DirectX::XMVectorGetW(params->projection.r[2]);
	if (depthSign < 0.f)
	{
		deviceContext->RSSetState(m_rasterizerState[params->renderMode][params->cullMode].Get());
	}

	deviceContext->DrawIndexed((UINT)4, 0, 0);

	if (depthSign < 0.f)
	{
		deviceContext->RSSetState(nullptr);
	}
}

void FluidRendererD3D11::drawComposite(const FluidDrawParamsD3D* params, ID3D11ShaderResourceView* sceneMap)
{
	ID3D11DeviceContext* deviceContext = m_deviceContext;

	// update constant buffer
	{
		D3D11_MAPPED_SUBRESOURCE mappedResource = {};
		if (SUCCEEDED(deviceContext->Map(m_constantBuffer.Get(), 0u, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource)))
		{
			Hlsl::FluidShaderConst constBuf;
			RenderParamsUtilD3D::calcFluidCompositeConstantBuffer(*params, constBuf);
			memcpy(mappedResource.pData, &constBuf, sizeof(Hlsl::FluidShaderConst));
			deviceContext->Unmap(m_constantBuffer.Get(), 0u);
		}
	}

	deviceContext->VSSetShader(m_passThroughVs.Get(), nullptr, 0u);
	deviceContext->GSSetShader(nullptr, nullptr, 0u);
	deviceContext->PSSetShader(m_compositePs.Get(), nullptr, 0u);

	RenderTargetD3D11* depthMap = &m_depthSmoothTexture;
	ShadowMapD3D11* shadowMap = (ShadowMapD3D11*)params->shadowMap;

	ID3D11ShaderResourceView* srvs[3] = 
	{ 
		depthMap->m_backSrv.Get(),
		sceneMap,
		shadowMap->m_depthSrv.Get()

	};
	deviceContext->PSSetShaderResources(0, 3, srvs);

	ID3D11SamplerState* samps[2] = 
	{ 
		depthMap->m_linearSampler.Get() ,
		shadowMap->m_linearSampler.Get()
	};
	deviceContext->PSSetSamplers(0, 2, samps);

	deviceContext->IASetInputLayout(m_passThroughLayout.Get());
	deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);

	deviceContext->VSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf());
	deviceContext->PSSetConstantBuffers(0, 1, m_constantBuffer.GetAddressOf());

	UINT vertexStride = sizeof(PassthroughVertex);
	UINT offset = 0u;
	deviceContext->IASetVertexBuffers(0, 1, m_quadVertexBuffer.GetAddressOf(), &vertexStride, &offset);
	deviceContext->IASetIndexBuffer(m_quadIndexBuffer.Get(), DXGI_FORMAT_R32_UINT, 0u);

	float depthSign = DirectX::XMVectorGetW(params->projection.r[2]);
	if (depthSign < 0.f)
	{
		deviceContext->RSSetState(m_rasterizerState[params->renderMode][params->cullMode].Get());
	}

	deviceContext->DrawIndexed((UINT)4, 0, 0);

	if (depthSign < 0.f)
	{
		deviceContext->RSSetState(nullptr);
	}

	// reset srvs
	ID3D11ShaderResourceView* zero[3] = { NULL, NULL, NULL };
	deviceContext->PSSetShaderResources(0, 3, zero);
}