forked from vixorien/D3D11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Renderable.cpp
62 lines (51 loc) · 1.67 KB
/
Renderable.cpp
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
#include "Renderable.h"
Renderable::Renderable()
{
trf = Transform();
}
Renderable::Renderable(std::shared_ptr<Mesh> meshToUse, std::shared_ptr<Material> material)
:
mesh(meshToUse),
material(material)
{
trf = Transform();
}
std::shared_ptr<Mesh> Renderable::GetMesh()
{
return mesh;
}
std::shared_ptr<Material> Renderable::GetMaterial()
{
return material;
}
Transform* Renderable::GetTransform()
{
return &trf;
}
void Renderable::Draw(
Microsoft::WRL::ComPtr<ID3D11DeviceContext> context,
std::shared_ptr<Camera> camera,
float totalTime
)
{
// Do Simple Shader's stuff here
std::shared_ptr<SimpleVertexShader> vs = material->GetVS();
std::shared_ptr<SimplePixelShader> ps = material->GetPS();
// Setting all the values in the vertex shader to updated current values, BEFORE telling the material to prepare
vs->SetMatrix4x4("world", trf.GetWorldMatrix());
vs->SetMatrix4x4("view", camera->GetView());
vs->SetMatrix4x4("projection", camera->GetProjection());
vs->SetMatrix4x4("worldInvTrans", trf.GetWorldInverseTransposeMatrix());
// Setting all the values in the pixel shader too
ps->SetFloat4("colorTint", material->GetColorTint()); // Every pixel shader has a tint
ps->SetFloat3("cameraPosition", camera->GetTransform().GetPosition()); // And specular needs the camera position
// Extra values!! if a variable doesn't exist in our material's pixel shader, SimpleShader simply skips it
ps->SetFloat("totalTime", totalTime); // Only some pixel shaders have time
// Now send it over, then tell it go!
vs->CopyAllBufferData();
ps->CopyAllBufferData();
// Prep the material so its shaders are ready
material->PrepareMaterial();
// Drawing the meshes!
mesh->Draw();
}