Loads resources
| 148 | |
| 149 | // Loads resources |
| 150 | void MeshRenderer::Initialize(const Model* model_) |
| 151 | { |
| 152 | model = model_; |
| 153 | |
| 154 | const uint64 numMeshes = model->Meshes().Size(); |
| 155 | meshBoundingBoxes.Init(numMeshes); |
| 156 | meshDrawIndices.Init(numMeshes, uint32(-1)); |
| 157 | meshZDepths.Init(numMeshes, FloatMax); |
| 158 | for(uint64 i = 0; i < numMeshes; ++i) |
| 159 | { |
| 160 | const Mesh& mesh = model->Meshes()[i]; |
| 161 | DirectX::BoundingBox& boundingBox = meshBoundingBoxes[i]; |
| 162 | Float3 extents = (mesh.AABBMax() - mesh.AABBMin()) / 2.0f; |
| 163 | Float3 center = mesh.AABBMin() + extents; |
| 164 | boundingBox.Center = center.ToXMFLOAT3(); |
| 165 | boundingBox.Extents = extents.ToXMFLOAT3(); |
| 166 | } |
| 167 | |
| 168 | meshVSConstants.Initialize(BufferLifetime::Temporary); |
| 169 | meshPSConstants.Initialize(BufferLifetime::Temporary); |
| 170 | sunShadowConstants.Initialize(BufferLifetime::Temporary); |
| 171 | |
| 172 | LoadShaders(); |
| 173 | |
| 174 | sunShadowMap.Initialize(SunShadowMapSize, SunShadowMapSize, DXGI_FORMAT_D32_FLOAT, 1, NumCascades); |
| 175 | sunShadowMap.MakeReadable(DX12::CmdList); |
| 176 | |
| 177 | const uint64 numSpotLights = model->SpotLights().Size(); |
| 178 | spotLightShadowMap.Initialize(SpotLightShadowMapSize, SpotLightShadowMapSize, DXGI_FORMAT_D24_UNORM_S8_UINT, 1, numSpotLights); |
| 179 | spotLightShadowMap.MakeReadable(DX12::CmdList); |
| 180 | |
| 181 | { |
| 182 | // Spot light shadow matrix buffer |
| 183 | StructuredBufferInit sbInit; |
| 184 | sbInit.Stride = sizeof(Float4x4); |
| 185 | sbInit.NumElements = numSpotLights; |
| 186 | sbInit.Dynamic = true; |
| 187 | sbInit.Lifetime = BufferLifetime::Persistent; |
| 188 | spotLightShadowMatrices.Initialize(sbInit); |
| 189 | } |
| 190 | |
| 191 | { |
| 192 | // Create a structured buffer containing texture indices per-material |
| 193 | const Array<MeshMaterial>& materials = model->Materials(); |
| 194 | const uint64 numMaterials = materials.Size(); |
| 195 | Array<MaterialTextureIndices> textureIndices(numMaterials); |
| 196 | for(uint64 i = 0; i < numMaterials; ++i) |
| 197 | { |
| 198 | MaterialTextureIndices& matIndices = textureIndices[i]; |
| 199 | const MeshMaterial& material = materials[i]; |
| 200 | |
| 201 | matIndices.Albedo = material.TextureIndices[uint64(MaterialTextures::Albedo)]; |
| 202 | matIndices.Normal = material.TextureIndices[uint64(MaterialTextures::Normal)]; |
| 203 | matIndices.Roughness = material.TextureIndices[uint64(MaterialTextures::Roughness)]; |
| 204 | matIndices.Metallic = material.TextureIndices[uint64(MaterialTextures::Metallic)]; |
| 205 | } |
| 206 | |
| 207 | StructuredBufferInit sbInit; |
no test coverage detected