Render an entity with the necessary components. This method checks if the entity has the required components and renders it using the appropriate shader.
48 {
49
50
51 auto transform = entity->GetComponent<TransformComponent>();
52 auto render = entity->GetComponent<RenderComponent>();
53 auto shader = entity->GetComponent<ShaderComponent>();
54
55 if (!transform || !render || !shader || !render->GetModel())
56 return false;
57
58
59 XMMATRIX scaleMatrix = transform->GetScaleMatrix();
60 XMMATRIX rotateMatrix = transform->GetRotateMatrix();
61 XMMATRIX translateMatrix = transform->GetTranslateMatrix();
62
63 XMMATRIX worldMatrix = XMMatrixMultiply(
64 XMMatrixMultiply(scaleMatrix, rotateMatrix),
65 translateMatrix
66 );
67
68
69 render->Render(m_deviceContext);
70
71
72 switch (shader->GetActiveShader()) {
73 case ShaderType::ALPHA_MAPPING:
74 return m_shaderManager->render_alpha_map_shader(
75 m_deviceContext,
76 render->GetIndexCount(),
77 worldMatrix,
78 viewMatrix,
79 projectionMatrix,
80 render->GetTexture(TextureType::Diffuse, 0),
81 render->GetTexture(TextureType::Diffuse, 1),
82 render->GetTexture(TextureType::Alpha, 0)
83 );
84
85 case ShaderType::CEL_SHADING:
86 return m_shaderManager->render_cel_shading_shader(
87 m_deviceContext,
88 render->GetIndexCount(),
89 worldMatrix,
90 viewMatrix,
91 projectionMatrix,
92 render->GetTexture(TextureType::Diffuse, 0),
93 sunlightDiffuse,
94 sunlightAmbient,
95 sunlightDirection,
96 sunlightIntensity
97 );
98
99 case ShaderType::NORMAL_MAPPING:
100 return m_shaderManager->render_normal_map_shader(
101 m_deviceContext,
102 render->GetIndexCount(),
103 worldMatrix,
104 viewMatrix,
105 projectionMatrix,
106 render->GetTexture(TextureType::Diffuse, 0),
107 render->GetTexture(TextureType::Normal, 0),
108 sunlightDirection,
109 sunlightDiffuse
110 );
111
112 case ShaderType::SPECULAR_MAPPING:
113
114 return m_shaderManager->render_spec_map_shader(
115 m_deviceContext,
116 render->GetIndexCount(),
117 worldMatrix,
118 viewMatrix,
119 projectionMatrix,
120 render->GetTexture(TextureType::Diffuse, 0),
121 render->GetTexture(TextureType::Normal, 0),
122 render->GetTexture(TextureType::Specular, 0),
123 sunlightDirection,
124 sunlightDiffuse,
125 cameraPosition,
126 sunlightDiffuse,
127 16.0f
128 );
129
130 case ShaderType::LIGHTING:
131 {
132
133 DirectX::XMFLOAT4 localDiffuseColors[4];
134 DirectX::XMFLOAT4 localLightPositions[4];
135 DirectX::XMFLOAT4 localAmbientColors[4];
136
137
138 for (int i = 0; i < 4; i++) {
139 localDiffuseColors[i] = diffuseColors[i];
140 localLightPositions[i] = lightPositions[i];
141 localAmbientColors[i] = ambientColors[i];
142 }
143
144 return m_shaderManager->renderlight_shader(
145 m_deviceContext,
146 render->GetIndexCount(),
147 worldMatrix,
148 viewMatrix,
149 projectionMatrix,
150 render->GetTexture(TextureType::Diffuse, 0),
151 localDiffuseColors,
152 localLightPositions,
153 localAmbientColors
154 );
155 }
156
157 case ShaderType::SUNLIGHT:
158 return m_shaderManager->render_sunlight_shader(
159 m_deviceContext,
160 render->GetIndexCount(),
161 worldMatrix,
162 viewMatrix,
163 projectionMatrix,
164 render->GetTexture(TextureType::Diffuse, 0),
165 sunlightDiffuse,
166 sunlightAmbient,
167 sunlightDirection,
168 sunlightIntensity
169 );
170
171 case ShaderType::SKYBOX:
172 return m_shaderManager->render_skybox_shader(
173 m_deviceContext,
174 render->GetIndexCount(),
175 worldMatrix,
176 viewMatrix,
177 projectionMatrix,
178 render->GetTexture(TextureType::Diffuse, 0),
179 sunlightDiffuse,
180 sunlightAmbient,
181 sunlightDirection,
182 sunlightIntensity
183 );
184
185 case ShaderType::TEXTURE:
186 default:
187 return m_shaderManager->render_texture_shader(
188 m_deviceContext,
189 render->GetIndexCount(),
190 worldMatrix,
191 viewMatrix,
192 projectionMatrix,
193 render->GetTexture(TextureType::Diffuse, 0)
194 );
195 }
196 }