bool MallocTracker::Free(void * p, const char * FileName, const char * FunctionName, int LineNum) { std::lock_guard<std::mutex> lock(AllocLock); auto it = Allocations.find(p); if (it != Allocations.end()) { TotalMemory -= it->second.Size; Allocations.erase(it); return true; } else if (p != nullptr) { wchar_t error[256]; swprintf_s(error, 256, L"%s(%i): Could not find matching allocation %z.\n", FileName, LineNum, p); NE_WARN(error, L"MallocTracker"); OutputDebugString(error); } return false; }
void GlobalIlluminationPass::Execute(D3DRenderer* renderer) { if (mpSourceShadowMap == NULL) { NE_WARN("Shadow map reference is null.", "GlobalIlluminationPass"); return; } if (mpSourceGBuffer == NULL) { NE_WARN("GBuffer reference is null.", "GlobalIlluminationPass"); return; } unsigned int dispatchWidth = (mpDestinationTexture->getWidth() + 16 - 1) / 16; unsigned int dispatchHeight = (mpDestinationTexture->getHeight() + 16 - 1) / 16; D3D11_MAPPED_SUBRESOURCE resource; HR(renderer->context()->Map(mpConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource)); CBShadowPass* constantBuffer = static_cast<CBShadowPass*>(resource.pData); //constantBuffer->LightColor = Vector4(1.0f, 0.8541f, 0.7437f, 1.0f) * 2.0f; constantBuffer->LightColor = Vector4(1.0f, 0.8952f, 0.8666f, 1.0f); constantBuffer->LightDirection = mLightDirection; constantBuffer->ShadowIntensity = 1.0f; constantBuffer->WorldToShadow = mpSourceShadowMap->getSampleTransform(); constantBuffer->ShadowMapDimensions = Vector2i(mpSourceShadowMap->getTexture()->getWidth(), mpSourceShadowMap->getTexture()->getHeight()); constantBuffer->DiffuseSpecularInterpolation = Vector2(mDiffuseInterpolation, mSpecularInterpolation); renderer->context()->Unmap(mpConstantBuffer, 0); HR(renderer->context()->Map(mpVXGIBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &resource)); CBVoxelGI* vxgiBuffer = static_cast<CBVoxelGI*>(resource.pData); VoxelVolumeRenderTarget* voxelVolume = mpRadianceVolume->getSourceVolume(); int volumeResolution = voxelVolume->getResolution(); float voxelScale = voxelVolume->getBounds().x * (1.0f / static_cast<float>(volumeResolution)); vxgiBuffer->WorldToVoxelVolume = voxelVolume->getWorldToVolume(); vxgiBuffer->VoxelVolumeDim = Vector3i(volumeResolution); vxgiBuffer->VoxelMipCount = Math::MipMapCount(volumeResolution, volumeResolution) - 1; vxgiBuffer->VoxelScale = voxelScale * 0.5f; renderer->context()->Unmap(mpVXGIBuffer, 0); renderer->ResetRenderTarget(); renderer->setShader(mpGIShader); renderer->BindPerFrameBuffer(); renderer->ResetRenderTarget(); mpSourceGBuffer->BindTextures(); renderer->setConstantBuffer(2, mpVXGIBuffer); renderer->setConstantBuffer(3, mpConstantBuffer); renderer->setTextureResource(5, mpSourceShadowMap->getTexture()); renderer->setTextureResource(6, mpRadianceVolume->getRadianceVolume()); renderer->setTextureResource(7, mpRadianceVolume->getRadianceMips()); ID3D11UnorderedAccessView* outputUav = mpDestinationTexture->getUnorderedAccessView(); renderer->context()->CSSetUnorderedAccessViews(0, 1, &outputUav, 0); renderer->setSampler(0, mpShadowSamplerState); renderer->setSampler(1, mpConeTracingSamplerState); renderer->context()->Dispatch(dispatchWidth, dispatchHeight, 1); renderer->UnbindUAVs(); renderer->UnbindTextureResources(); renderer->ResetSamplerState(); }
void StaticMesh::Init(assettypes::Scene* meshes) { std::vector<Vertex> vertices; std::vector<unsigned int> indices; if (meshes != NULL) { for (auto it = meshes->mMeshes.cbegin(); it != meshes->mMeshes.cend(); ++it) { vertices.clear(); indices.clear(); vertices.reserve((*it)->mVertexCount); for (unsigned int i = 0; i < (*it)->mVertexCount; i++) { Vertex vertex; vertex.Position = (*it)->mVertices[i]; if ((*it)->hasNormals()) vertex.Normal = (*it)->mNormals[i]; else vertex.Normal = Vector3(0.0f); if ((*it)->hasTextureCoords()) vertex.TexCoord = (*it)->mTextureCoords[i]; else vertex.TexCoord = Vector2(0.0f); if ((*it)->mTangents != NULL) vertex.Tangent = (*it)->mTangents[i]; else vertex.Tangent = Vector3(0.0f); vertices.push_back(vertex); } bool indexWarnTriggered = false; for (unsigned int i = 0; i < (*it)->mFaceCount; i++) { if ((*it)->mFaces[i].mIndexCount == 3) { indices.push_back((*it)->mFaces[i].mIndices[0]); indices.push_back((*it)->mFaces[i].mIndices[1]); indices.push_back((*it)->mFaces[i].mIndices[2]); } else if ((*it)->mFaces[i].mIndexCount == 4) { if (!indexWarnTriggered) { NE_WARN("StaticMesh triangulation is depricated use MeshTriangulatePass during model loading instead", "StaticMesh"); indexWarnTriggered = true; } } } MeshRenderer<Vertex>* newMesh = AddMesh(vertices, indices); //Parse the mesh material if ((*it)->mMaterialId != -1) { StaticMeshMaterial* mat = NE_NEW StaticMeshMaterial(); mat->RenderMaterial.Diffuse = meshes->mMaterials[(*it)->mMaterialId]->diffuse; mat->RenderMaterial.SpecularColor = meshes->mMaterials[(*it)->mMaterialId]->specular; mat->RenderMaterial.Emissive = meshes->mMaterials[(*it)->mMaterialId]->emissive; mat->RenderMaterial.Roughness = 1.0f - meshes->mMaterials[(*it)->mMaterialId]->specularPow * 0.01f; mat->RenderMaterial.HasDiffuseTexture = false; mat->RenderMaterial.HasNormalTexture = false; mat->RenderMaterial.HasSpecularTexture = false; mMeshMaterials[newMesh] = mat; auto endIt = meshes->mMaterials[(*it)->mMaterialId]->texturePaths.cend(); for (auto texIt = meshes->mMaterials[(*it)->mMaterialId]->texturePaths.cbegin(); texIt != endIt; ++texIt) { switch (texIt->first) { case assettypes::TextureType::Diffuse: mat->Textures.push_back(std::pair<assettypes::TextureType::Type, Texture2D*>(assettypes::TextureType::Diffuse, EngineStatics::getResourceCache()->getResource<Texture2D>(texIt->second))); mat->RenderMaterial.HasDiffuseTexture = true; break; case assettypes::TextureType::Normal: mat->Textures.push_back(std::pair<assettypes::TextureType::Type, Texture2D*>(assettypes::TextureType::Normal, EngineStatics::getResourceCache()->getResource<Texture2D>(texIt->second))); mat->RenderMaterial.HasNormalTexture = true; break; case assettypes::TextureType::Specular: mat->Textures.push_back(std::pair<assettypes::TextureType::Type, Texture2D*>(assettypes::TextureType::Specular, EngineStatics::getResourceCache()->getResource<Texture2D>(texIt->second))); mat->RenderMaterial.HasSpecularTexture = true; break; } } } } } }