-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleRenderer.cpp
More file actions
585 lines (470 loc) · 20 KB
/
Copy pathModuleRenderer.cpp
File metadata and controls
585 lines (470 loc) · 20 KB
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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
#include "Globals.h"
#include "ModuleRenderer.h"
#include "Application.h"
#include "ModuleD3D12.h"
#include "ModuleCamera.h"
#include "ModuleResource.h"
#include "ModuleImGui.h"
#include "ReadData.h"
#include "SimpleMath.h"
#include <d3d12.h>
#include "d3dx12.h"
struct LightDataForShader
{
DirectX::SimpleMath::Vector3 direction;
float pad0;
DirectX::SimpleMath::Vector3 color;
float pad1;
DirectX::SimpleMath::Vector3 ambient;
float pad2;
DirectX::SimpleMath::Vector3 viewPos;
float pad3;
};
struct MaterialDataForShader
{
DirectX::XMFLOAT4 diffuseColor;
DirectX::XMFLOAT4 specularColor;
float shininess;
float hasTexture;
float padding[2];
};
ModuleRenderer::ModuleRenderer() : debugDraw(nullptr) {}
ModuleRenderer::~ModuleRenderer() {
if (debugDraw) {
delete debugDraw;
debugDraw = nullptr;
}
if (materialConstantBuffer && materialConstantBufferMapped) {
materialConstantBuffer->Unmap(0, nullptr);
materialConstantBufferMapped = nullptr;
}
if (lightConstantBuffer && lightConstantBufferMapped) {
lightConstantBuffer->Unmap(0, nullptr);
lightConstantBufferMapped = nullptr;
}
}
bool ModuleRenderer::init() {
ModuleD3D12* d3d12 = app->getD3D12();
if (!d3d12) return false;
auto device = d3d12->getDevice();
auto commandQueue = d3d12->getDrawCommandQueue();
// Create debug draw pass
debugDraw = new DebugDrawPass(device, commandQueue);
if (!debugDraw) return false;
// Create geometry
if (!createVertexBuffer()) return false;
// Create root signature
if (!createRootSignature()) return false;
// Create pipeline state
if (!createPipelineState()) return false;
CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
//Create material constant buffer
LOG("Creating material constant buffer, size: %zu bytes", sizeof(MaterialDataForShader));
CD3DX12_RESOURCE_DESC materialBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(sizeof(MaterialDataForShader));
if (FAILED(device->CreateCommittedResource(
&heapProps,
D3D12_HEAP_FLAG_NONE,
&materialBufferDesc,
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&materialConstantBuffer)))) {
LOG("Failed to create material constant buffer");
return false;
}
// Maps buffer to write data
if (FAILED(materialConstantBuffer->Map(0, nullptr, &materialConstantBufferMapped))) {
LOG("Failed to map material constant buffer");
return false;
}
LOG("Material constant buffer created successfully");
CD3DX12_RESOURCE_DESC lightBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(sizeof(LightDataForShader));
if (FAILED(device->CreateCommittedResource(
&heapProps,
D3D12_HEAP_FLAG_NONE,
&lightBufferDesc,
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&lightConstantBuffer)))) {
LOG("Failed to create light constant buffer");
return false;
}
if (FAILED(lightConstantBuffer->Map(0, nullptr, &lightConstantBufferMapped))) {
LOG("Failed to map light constant buffer");
return false;
}
LOG("Light constant buffer created successfully");
modelLoaded = false;
std::filesystem::path modelPath = std::filesystem::current_path() / "Game" / "Assets" / "Duck.gltf";
if (!std::filesystem::exists(modelPath))
{
// Fall back to Debug path
modelPath = std::filesystem::current_path() / "3rdParty" / "tinygltf" / "models" / "Duck" / "Duck.gltf";
}
if (std::filesystem::exists(modelPath))
{
model.Load(modelPath.string().c_str());
modelLoaded = true;
LOG("Model loaded successfully");
}
else
{
LOG("Could not find Duck.gltf at: %s", modelPath.string().c_str());
}
return true;
}
void ModuleRenderer::preRender() {
}
void ModuleRenderer::render() {
auto d3d12 = app->getD3D12();
auto commandList = d3d12->getCommandList();
if (!commandList) return;
if (modelLoaded)
{
//renderModel();
renderModelWithPhong();
LOG("Loading the ducky for you");
}
else
{
LOG("No model loaded, skipping rendering");
}
renderDebugDraw();
}
void ModuleRenderer::postRender() {
}
bool ModuleRenderer::createVertexBuffer() {
struct Vertex {
DirectX::SimpleMath::Vector3 position;
DirectX::SimpleMath::Vector2 uv;
DirectX::SimpleMath::Vector3 color;
};
// Triángulo 3D con textura
Vertex vertices[] = {
// Base del triángulo
{ DirectX::SimpleMath::Vector3(0.0f, 1.0f, 0.0f), DirectX::SimpleMath::Vector2(0.5f, 0.0f), DirectX::SimpleMath::Vector3(1.0f, 0.0f, 0.0f) },
{ DirectX::SimpleMath::Vector3(-1.0f, -1.0f, 0.0f), DirectX::SimpleMath::Vector2(0.0f, 1.0f), DirectX::SimpleMath::Vector3(0.0f, 1.0f, 0.0f) },
{ DirectX::SimpleMath::Vector3(1.0f, -1.0f, 0.0f), DirectX::SimpleMath::Vector2(1.0f, 1.0f), DirectX::SimpleMath::Vector3(0.0f, 0.0f, 1.0f) },
// Cuad para textura (opcional)
{ DirectX::SimpleMath::Vector3(-1.0f, 1.0f, 0.0f), DirectX::SimpleMath::Vector2(0.0f, 0.0f), DirectX::SimpleMath::Vector3(1.0f, 1.0f, 1.0f) },
{ DirectX::SimpleMath::Vector3(1.0f, 1.0f, 0.0f), DirectX::SimpleMath::Vector2(1.0f, 0.0f), DirectX::SimpleMath::Vector3(1.0f, 1.0f, 1.0f) },
{ DirectX::SimpleMath::Vector3(-1.0f, -1.0f, 0.0f), DirectX::SimpleMath::Vector2(0.0f, 1.0f), DirectX::SimpleMath::Vector3(1.0f, 1.0f, 1.0f) },
{ DirectX::SimpleMath::Vector3(1.0f, 1.0f, 0.0f), DirectX::SimpleMath::Vector2(1.0f, 0.0f), DirectX::SimpleMath::Vector3(1.0f, 1.0f, 1.0f) },
{ DirectX::SimpleMath::Vector3(1.0f, -1.0f, 0.0f), DirectX::SimpleMath::Vector2(1.0f, 1.0f), DirectX::SimpleMath::Vector3(1.0f, 1.0f, 1.0f) },
{ DirectX::SimpleMath::Vector3(-1.0f, -1.0f, 0.0f), DirectX::SimpleMath::Vector2(0.0f, 1.0f), DirectX::SimpleMath::Vector3(1.0f, 1.0f, 1.0f) }
};
auto resources = app->getResources();
vertexBuffer = resources->createDefaultBuffer(vertices, sizeof(vertices), "TriangleVB");
if (!vertexBuffer) return false;
vertexBufferView.BufferLocation = vertexBuffer->GetGPUVirtualAddress();
vertexBufferView.StrideInBytes = sizeof(Vertex);
vertexBufferView.SizeInBytes = sizeof(vertices);
vertexCount = sizeof(vertices) / sizeof(Vertex);
return true;
}
bool ModuleRenderer::createRootSignature() {
ModuleD3D12* d3d12 = app->getD3D12();
auto device = d3d12->getDevice();
CD3DX12_DESCRIPTOR_RANGE srvTable;
CD3DX12_DESCRIPTOR_RANGE samplerTable;
srvTable.Init(D3D12_DESCRIPTOR_RANGE_TYPE_SRV, 1, 0);
samplerTable.Init(D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER, 1, 0);
CD3DX12_ROOT_PARAMETER rootParameters[5] = {}; //For the Phong we use 5 parameters
rootParameters[0].InitAsConstants(16, 0, 0, D3D12_SHADER_VISIBILITY_VERTEX);
//Model and Normal matrices
rootParameters[1].InitAsConstants(32, 1, 0, D3D12_SHADER_VISIBILITY_VERTEX);
//Light constant buffer
rootParameters[2].InitAsConstantBufferView(2, 0, D3D12_SHADER_VISIBILITY_PIXEL);
//Material constant buffer
rootParameters[3].InitAsConstantBufferView(3, 0, D3D12_SHADER_VISIBILITY_PIXEL);
//Texture SRV descriptor table
rootParameters[4].InitAsDescriptorTable(1, &srvTable, D3D12_SHADER_VISIBILITY_PIXEL);
// CREATE SAMPLER
D3D12_STATIC_SAMPLER_DESC sampler = {};
sampler.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
sampler.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
sampler.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
sampler.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
sampler.MipLODBias = 0;
sampler.MaxAnisotropy = 0;
sampler.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER;
sampler.BorderColor = D3D12_STATIC_BORDER_COLOR_TRANSPARENT_BLACK;
sampler.MinLOD = 0.0f;
sampler.MaxLOD = D3D12_FLOAT32_MAX;
sampler.ShaderRegister = 0;
sampler.RegisterSpace = 0;
sampler.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
rootSignatureDesc.Init(5, rootParameters, 1, &sampler, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
Microsoft::WRL::ComPtr<ID3DBlob> signature;
Microsoft::WRL::ComPtr<ID3DBlob> error;
if (FAILED(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error))) {
if (error) {
OutputDebugStringA((char*)error->GetBufferPointer());
}
return false;
}
return SUCCEEDED(device->CreateRootSignature(0, signature->GetBufferPointer(),
signature->GetBufferSize(), IID_PPV_ARGS(&rootSignature)));
}
bool ModuleRenderer::createPipelineState() {
ModuleD3D12* d3d12 = app->getD3D12();
auto device = d3d12->getDevice();
// Input layout
D3D12_INPUT_ELEMENT_DESC layout[] = {
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }
};
// Leer shaders
auto vs = DX::ReadData(L"PhongVS.cso");
auto ps = DX::ReadData(L"PhongPS.cso");
if (vs.empty() || ps.empty()) {
// Fallback to simple shaders if model shaders aren't found
LOG("Model shaders not found, trying default shaders...");
vs = DX::ReadData(L"ModelVS.cso");
ps = DX::ReadData(L"ModelPs.cso");
if (vs.empty() || ps.empty()) {
OutputDebugStringA("ERROR: Shaders not found!\n");
return false;
}
}
// Pipeline state description for model rendering
D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
psoDesc.InputLayout = { layout, _countof(layout) };
psoDesc.pRootSignature = rootSignature.Get();
psoDesc.VS = { vs.data(), vs.size() };
psoDesc.PS = { ps.data(), ps.size() };
// Rasterizer state - Set for counter-clockwise winding (glTF default)
psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
psoDesc.RasterizerState.CullMode = D3D12_CULL_MODE_BACK;
psoDesc.RasterizerState.FrontCounterClockwise = TRUE;
psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
psoDesc.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT);
psoDesc.SampleMask = UINT_MAX;
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
psoDesc.NumRenderTargets = 1;
psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
psoDesc.DSVFormat = DXGI_FORMAT_D32_FLOAT;
psoDesc.SampleDesc.Count = 1;
return SUCCEEDED(device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pipelineState)));
}
void ModuleRenderer::renderModelWithPhong() {
auto d3d12 = app->getD3D12();
auto camera = app->getCamera();
auto commandList = d3d12->getCommandList();
if (!commandList || !pipelineState || !camera) {
LOG("ERROR: Missing components in renderModelWithPhong");
return;
}
auto imGui = app->getImGui();
if (!imGui) {
LOG("ERROR: ImGui module not found");
return;
}
// Get light and material data from ImGui
auto imGuiLightData = imGui->getLightData();
auto imGuiMaterialData = imGui->getMaterialData();
auto transformData = imGui->getTransformData();
// Prepare light data for shader
LightDataForShader lightData;
lightData.direction = imGuiLightData.direction;
lightData.color = imGuiLightData.color;
lightData.ambient = imGuiLightData.ambient;
lightData.viewPos = imGuiLightData.viewPos;
// Prepare material data for shader
MaterialDataForShader materialData;
// Get the duck's material
if (!model.materials.empty())
{
const auto& duckMaterial = model.materials[0];
// Use texture if available, otherwise use ImGui diffuse color
if (duckMaterial.texture)
{
materialData.diffuseColor = DirectX::XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); // White for texture
materialData.hasTexture = 1.0f;
}
else
{
materialData.diffuseColor = imGuiMaterialData.diffuseColor;
materialData.hasTexture = 0.0f;
}
// Use ImGui controls for everything else
materialData.specularColor = imGuiMaterialData.specularColor;
materialData.shininess = imGuiMaterialData.shininess;
LOG("Using Blinn-Phong:");
LOG(" Diffuse: (%.2f, %.2f, %.2f)",
materialData.diffuseColor.x, materialData.diffuseColor.y, materialData.diffuseColor.z);
LOG(" Specular: (%.2f, %.2f, %.2f)",
materialData.specularColor.x, materialData.specularColor.y, materialData.specularColor.z);
LOG(" Shininess: %.0f", materialData.shininess);
}
// Rest of your rendering code remains the same...
// Set pipeline state
commandList->SetPipelineState(pipelineState.Get());
commandList->SetGraphicsRootSignature(rootSignature.Get());
commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
// Set viewport and scissor
float w = (float)d3d12->getWindowWidth();
float h = (float)d3d12->getWindowHeight();
D3D12_VIEWPORT vp{ 0.0f, 0.0f, w, h, 0.0f, 1.0f };
D3D12_RECT sr{ 0, 0, (LONG)w, (LONG)h };
commandList->RSSetViewports(1, &vp);
commandList->RSSetScissorRects(1, &sr);
// Get matrices from camera
auto view = camera->getViewMatrix();
auto proj = camera->getProjectionMatrix();
// Scale duck down
auto modelMatrix = DirectX::SimpleMath::Matrix::CreateScale(transformData.scale) *
DirectX::SimpleMath::Matrix::CreateFromYawPitchRoll(
DirectX::XMConvertToRadians(transformData.rotation.y),
DirectX::XMConvertToRadians(transformData.rotation.x),
DirectX::XMConvertToRadians(transformData.rotation.z)) *
DirectX::SimpleMath::Matrix::CreateTranslation(transformData.translation);
// Create normal matrix
auto normalMatrix = modelMatrix;
normalMatrix.Invert();
normalMatrix.Transpose();
// Calculate MVP
auto mvp = modelMatrix * view * proj;
// Transpose for HLSL
mvp = mvp.Transpose();
modelMatrix = modelMatrix.Transpose();
normalMatrix = normalMatrix.Transpose();
// Set root parameters
commandList->SetGraphicsRoot32BitConstants(0, 16, &mvp, 0);
// Model + Normal matrices
float modelNormalMatrices[32];
memcpy(modelNormalMatrices, &modelMatrix, sizeof(DirectX::SimpleMath::Matrix));
memcpy(modelNormalMatrices + 16, &normalMatrix, sizeof(DirectX::SimpleMath::Matrix));
commandList->SetGraphicsRoot32BitConstants(1, 32, modelNormalMatrices, 0);
// Update constant buffers
memcpy(lightConstantBufferMapped, &lightData, sizeof(LightDataForShader));
memcpy(materialConstantBufferMapped, &materialData, sizeof(MaterialDataForShader));
// Light constant buffer
commandList->SetGraphicsRootConstantBufferView(2, lightConstantBuffer->GetGPUVirtualAddress());
// Material constant buffer
commandList->SetGraphicsRootConstantBufferView(3, materialConstantBuffer->GetGPUVirtualAddress());
// Set descriptor heap for textures
ID3D12DescriptorHeap* heaps[] = { app->getShaderDescriptors()->getDescriptorHeap() };
commandList->SetDescriptorHeaps(1, heaps);
// Render the model
for (size_t i = 0; i < model.meshes.size(); ++i)
{
const auto& mesh = model.meshes[i];
// ALWAYS set the texture from the model material
if (mesh.getMaterialIndex() < model.materials.size())
{
const auto& material = model.materials[mesh.getMaterialIndex()];
if (material.texture && material.srvIndex != 0)
{
auto srvHandle = material.getSRVHandle();
if (srvHandle.ptr != 0)
{
// Parameter 4: Texture SRV descriptor table
commandList->SetGraphicsRootDescriptorTable(4, srvHandle);
LOG("DEBUG: Bound texture SRV for mesh %zu", i);
}
}
else
{
LOG("WARNING: Mesh %zu has no texture", i);
}
}
// Bind and draw mesh
mesh.BindBuffers(commandList);
mesh.Draw(commandList);
}
}
void ModuleRenderer::renderModel()
{
auto d3d12 = app->getD3D12();
auto camera = app->getCamera();
auto commandList = d3d12->getCommandList();
if (!commandList || !pipelineState || !camera) {
LOG("renderModel: Missing required components!");
return;
}
LOG("renderModel: Starting to render...");
// Configure viewport and scissor
float w = (float)d3d12->getWindowWidth();
float h = (float)d3d12->getWindowHeight();
D3D12_VIEWPORT vp{ 0.0f, 0.0f, w, h, 0.0f, 1.0f };
D3D12_RECT sr{ 0, 0, (LONG)w, (LONG)h };
commandList->RSSetViewports(1, &vp);
commandList->RSSetScissorRects(1, &sr);
// Configure pipeline
commandList->SetPipelineState(pipelineState.Get());
commandList->SetGraphicsRootSignature(rootSignature.Get());
//Binding descriptro heaps
ID3D12DescriptorHeap* heaps[] = { app->getShaderDescriptors()->getDescriptorHeap() };
commandList->SetDescriptorHeaps(1, heaps);
// Get matrices from camera
DirectX::SimpleMath::Matrix view = camera->getViewMatrix();
DirectX::SimpleMath::Matrix proj = camera->getProjectionMatrix();
// MAKE DUCK SMALL
float scale = 0.025f;
// Create model matrix with tiny scale
DirectX::SimpleMath::Matrix modelMatrix =
DirectX::SimpleMath::Matrix::CreateScale(scale) *
DirectX::SimpleMath::Matrix::CreateRotationY(0.0f) * // No rotation needed
DirectX::SimpleMath::Matrix::CreateTranslation(0.0f, 0.0f, 2.0f); // Move it 2 units in front
LOG("renderModel: Duck scale = %f (VERY SMALL!)", scale);
// Create MVP matrix
DirectX::SimpleMath::Matrix mvp = modelMatrix * view * proj;
mvp = mvp.Transpose(); // HLSL expects column-major
commandList->SetGraphicsRoot32BitConstants(0, 16, &mvp, 0);
// Pass material
if (materialConstantBuffer && materialConstantBufferMapped) {
struct MaterialData {
DirectX::XMFLOAT4 baseColor;
float metallic;
float roughness;
float padding[2];
};
MaterialData material;
// Use the duck's actual texture material
if (!model.materials.empty()) {
material.baseColor = model.materials[0].baseColor;
material.metallic = 0.5f;
material.roughness = 0.5f;
LOG("renderModel: Using material from model");
}
else {
// Fallback to yellow
material.baseColor = DirectX::XMFLOAT4(1.0f, 1.0f, 0.0f, 1.0f);
material.metallic = 0.5f;
material.roughness = 0.5f;
}
memcpy(materialConstantBufferMapped, &material, sizeof(MaterialData));
commandList->SetGraphicsRootConstantBufferView(
1,
materialConstantBuffer->GetGPUVirtualAddress()
);
}
// Render the model
LOG("renderModel: Calling model.Render()...");
model.Render(commandList, materialConstantBuffer->GetGPUVirtualAddress());
LOG("renderModel: Finished rendering tiny duck!");
}
void ModuleRenderer::renderDebugDraw() {
if (!debugDraw) return;
auto d3d12 = app->getD3D12();
auto camera = app->getCamera();
auto commandList = d3d12->getCommandList();
if (!commandList || !camera) return;
// Dibujar grid si está activado
if (showGrid) {
dd::xzSquareGrid(-10.0f, 10.0f, 0.0f, 1.0f, dd::colors::LightGray);
}
// Dibujar ejes si está activado
if (showAxis) {
DirectX::SimpleMath::Matrix identity = DirectX::SimpleMath::Matrix::Identity;
dd::axisTriad(&identity._11, 0.1f, 1.5f);
}
// Grabar comandos de debug draw
debugDraw->record(commandList,
d3d12->getWindowWidth(),
d3d12->getWindowHeight(),
camera->getViewMatrix(),
camera->getProjectionMatrix());
}