Game::Game() { device = irr::createDevice(irr::video::EDT_OPENGL, {640,480}, 16, false, false, false, &event_receiver); assert(device); device->setWindowCaption(L"Eternal Sonata"); driver = device->getVideoDriver(); scene_manager = device->getSceneManager(); environment = device->getGUIEnvironment(); menu.setDevice(device); menu.setDevice(device); this->mapSelector = 0; this->game_set = false; character.setEventReceiver(&event_receiver); loadMeshes(); loadMap(); loadPlayer(); getMenu().showMainMenu(); getPlayer().debugCharacter(); }
void AssetImporter::importScene( ID3D11Device* d3dDevice, std::wstring& path, GRAPHICS::Scene& outScene ) { Assimp::Importer importer; std::string assetPath(path.begin(), path.end()); const aiScene* scene = importer.ReadFile(assetPath.c_str(), aiProcess_ConvertToLeftHanded | aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_FlipWindingOrder | aiProcess_GenUVCoords | aiProcess_GenSmoothNormals | aiProcess_SortByPType); if (!scene) { printf("Failed to import asset: %s", assetPath.c_str()); } GRAPHICS::RESOURCES::Mesh* meshArr = loadMeshes(d3dDevice, scene); GRAPHICS::RESOURCES::Material* materialArr = loadMaterials(d3dDevice, scene); nextNode(d3dDevice, scene, scene->mRootNode, scene->mRootNode->mTransformation, meshArr, materialArr, outScene); loadLights(d3dDevice, outScene, scene); delete[] meshArr; delete[] materialArr; }
void prepare() { VulkanExampleBase::prepare(); loadMeshes(); setupVertexDescriptions(); prepareUniformBuffers(); setupDescriptorSetLayout(); preparePipelines(); setupDescriptorPool(); setupDescriptorSet(); buildCommandBuffers(); prepared = true; }
void prepare() { VulkanExampleBase::prepare(); // Create a fence for synchronization VkFenceCreateInfo fenceCreateInfo = vkTools::initializers::fenceCreateInfo(VK_FLAGS_NONE); vkCreateFence(device, &fenceCreateInfo, NULL, &renderFence); loadMeshes(); setupVertexDescriptions(); setupPipelineLayout(); preparePipelines(); prepareMultiThreadedRenderer(); updateMatrices(); prepared = true; }
void FBXModel::load(const GraphicsDevice& device, const std::string& filename, unsigned keyframes) { if (effect.resource == 0) effect = Effect::createFromFile<FBXEffect>(device, Config::getValue(ConfigKeys::fbxEffectPath)); defaultTexture = Texture::createFromFile(device, defaultTexturePath); vertexDeclaration = device.createVertexDeclaration(FBXInstance::vertexElements); KFbxSdkManager* sdkManager = KFbxSdkManager::Create(); KFbxIOSettings* ios = KFbxIOSettings::Create(sdkManager, IOSROOT); sdkManager->SetIOSettings(ios); // Create an importer using our sdk manager. KFbxImporter* importer = KFbxImporter::Create(sdkManager, ""); importer->Initialize(filename.c_str(), -1, sdkManager->GetIOSettings()); // Create a new scene so it can be populated by the imported file. KFbxScene* scene = KFbxScene::Create(sdkManager, ""); // Import the contents of the file into the scene. importer->Import(scene); KFbxNode* rootBone = 0; KFbxNode* rootNode = scene->GetRootNode(); KFbxAnimStack* animStack = KFbxCast<KFbxAnimStack>(scene->GetSrcObject(FBX_TYPE(KFbxAnimStack), 0)); KFbxAnimLayer* animLayer = 0; if (animStack) { animLayer = animStack->GetMember(FBX_TYPE(KFbxAnimLayer), 0); scene->GetEvaluator()->SetContext(animStack); } loadBones(rootNode, &rootBone, animLayer); loadMeshes(rootNode, device, KFbxGeometryConverter(sdkManager)); if (animLayer) { for (unsigned i = 0; i <= keyframes; ++i) boneMatricesMap[i] = traverseBones(i, rootBone, Matrix::identity, MatrixCollection(bones.size())); } sdkManager->Destroy(); loaded = true; }
void FBXModel::loadMeshes(KFbxNode* node, const GraphicsDevice& device, KFbxGeometryConverter& converter) { const char* name = node->GetName(); if (node->GetNodeAttribute()) { KFbxNodeAttribute::EAttributeType attributeType = node->GetNodeAttribute()->GetAttributeType(); if (attributeType == KFbxNodeAttribute::eMESH) { KFbxMesh* kfbxMesh = converter.TriangulateMesh((KFbxMesh*)node->GetNodeAttribute()); VertexCollection vertices = getVertices(kfbxMesh); MaterialCollection materials = getMaterials(device, node); unsigned long numFaces = kfbxMesh->GetPolygonCount(); unsigned long numVertices = kfbxMesh->GetControlPointsCount(); Mesh mesh = Mesh::create(device, numFaces, numVertices, FBXVertex::vertexElements, D3DXMESH_MANAGED | D3DXMESH_32BIT); mesh.getVertexBuffer().setData(vertices); mesh.getIndexBuffer().setData(kfbxMesh->GetPolygonVertices(), kfbxMesh->GetPolygonVertexCount()); KFbxLayerElementArrayTemplate<int>* materialIndices; kfbxMesh->GetMaterialIndices(&materialIndices); unsigned long* buffer = mesh.lockAttributeBuffer(); for(int i = 0; i < kfbxMesh->GetPolygonCount(); ++i) buffer[i] = materialIndices->GetAt(i); mesh.unlockAttributeBuffer(); Mesh::Adjacency adjacency = mesh.generateAdjacency(); mesh.clean(D3DXCLEAN_SIMPLIFICATION, adjacency); mesh.optimizeInplace(D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, adjacency); mesh.computeNormals(adjacency); meshes[name] = FBXMesh(mesh, materials, name); } } for (int i = 0; i < node->GetChildCount(); i++) loadMeshes(node->GetChild(i), device, converter); }
void prepare() { VulkanExampleBase::prepare(); loadMeshes(); setupVertexDescriptions(); prepareUniformBuffers(); loadTexture( "./../data/textures/cubemap_yokohama.ktx", VK_FORMAT_BC3_UNORM_BLOCK, false); setupDescriptorSetLayout(); preparePipelines(); setupDescriptorPool(); setupDescriptorSets(); buildCommandBuffers(); prepared = true; }
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); } void prepare() { VulkanExampleBase::prepare(); generateQuad(); loadMeshes(); setupVertexDescriptions(); prepareUniformBuffers(); prepareTextureTarget(TEX_DIM, TEX_DIM, DEPTH_FORMAT); setupDescriptorSetLayout(); preparePipelines(); setupDescriptorPool(); setupDescriptorSets(); prepareOffscreenFramebuffer();
// Create a model by deserializing it from Json Model::Model(const Json::Value& root, const std::string& directory, TextureCache &_textureCache) : meshes(0, NULL), skeleton(new Node()), textureCache(_textureCache), previousProgram(NULL), uploaded(false) { // Load animations loadAnimations(root); // Load materials loadMaterials(root, directory); // Load mesh data loadMeshes(root); // Load node data loadSkeleton(root); // Load parts loadParts(root); }
void prepare() { // Check if device supports tessellation shaders if (!deviceFeatures.tessellationShader) { vkTools::exitFatal("Selected GPU does not support tessellation shaders!", "Feature not supported"); } VulkanExampleBase::prepare(); loadTextures(); loadMeshes(); setupVertexDescriptions(); prepareUniformBuffers(); setupDescriptorSetLayout(); preparePipelines(); setupDescriptorPool(); setupDescriptorSet(); buildCommandBuffers(); prepared = true; }
void MyView:: windowViewWillStart(std::shared_ptr<tygra::Window> window) { assert(scene_ != nullptr); glEnable(GL_TEXTURE_2D); //shadow maps glGenTextures(1, &shadowMap_tex_); glBindTexture(GL_TEXTURE_2D_ARRAY, shadowMap_tex_); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT16, 1024, 1024, 5, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); //the 256 is number of layers, change this to number of shadow casting lights glGenFramebuffers(1, &shadowMap_fbo_); glBindFramebuffer(GL_FRAMEBUFFER, shadowMap_fbo_); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowMap_tex_, 0); glDrawBuffer(GL_NONE); // No color buffer is drawn to. check_fbo(); shadowMap_program_ = glCreateProgram(); GLuint fs = getFragmentShader("shadowMap_fs.glsl"); GLuint vs = getVertexShader("shadowMap_vs.glsl"); glAttachShader(shadowMap_program_, vs); glDeleteShader(vs); glAttachShader(shadowMap_program_, fs); glDeleteShader(fs); glLinkProgram(shadowMap_program_); //test program GLint link_status = 0; glGetProgramiv(shadowMap_program_, GL_LINK_STATUS, &link_status); if (link_status != GL_TRUE) { const int string_length = 1024; GLchar log[string_length] = ""; glGetProgramInfoLog(shadowMap_program_, string_length, NULL, log); std::cerr << log << std::endl; } //ssma textures glGenTextures(1, &albedo_tex); glBindTexture(GL_TEXTURE_2D, albedo_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, SCREEN_WIDTH, SCREEN_HEIGHT, 0, GL_RGBA, GL_FLOAT, 0); glGenTextures(1, &edge_tex); glBindTexture(GL_TEXTURE_2D, edge_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, SCREEN_WIDTH, SCREEN_HEIGHT, 0, GL_RGBA, GL_FLOAT, 0); glGenTextures(1, &blend_tex); glBindTexture(GL_TEXTURE_2D, blend_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, SCREEN_WIDTH, SCREEN_HEIGHT, 0, GL_RGBA, GL_FLOAT, 0); unsigned char* buffer = 0; FILE* f = 0; buffer = new unsigned char[1024 * 1024]; f = fopen((app_path + "smaa_area.raw").c_str(), "rb"); //rb stands for "read binary file" if (!f) { std::cerr << "Couldn't open smaa_area.raw.\n"; exit(1); } fread(buffer, AREATEX_WIDTH * AREATEX_HEIGHT * 2, 1, f); fclose(f); f = 0; glGenTextures(1, &area_tex); glBindTexture(GL_TEXTURE_2D, area_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, (GLsizei)AREATEX_WIDTH, (GLsizei)AREATEX_HEIGHT, 0, GL_RG, GL_UNSIGNED_BYTE, buffer); f = fopen((app_path + "smaa_search.raw").c_str(), "rb"); if (!f) { std::cerr << "Couldn't open smaa_search.raw.\n"; exit(1); } fread(buffer, SEARCHTEX_WIDTH * SEARCHTEX_HEIGHT, 1, f); fclose(f); f = 0; glGenTextures(1, &search_tex); glBindTexture(GL_TEXTURE_2D, search_tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, (GLsizei)SEARCHTEX_WIDTH, (GLsizei)SEARCHTEX_HEIGHT, 0, GL_RED, GL_UNSIGNED_BYTE, buffer); delete[] buffer; get_opengl_error(); /* * Initialize FBOs */ GLenum modes[] = { GL_COLOR_ATTACHMENT0 }; glGenFramebuffers(1, &albedo_fbo); glBindFramebuffer(GL_FRAMEBUFFER, albedo_fbo); glDrawBuffers(1, modes); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, albedo_tex, 0); check_fbo(); glGenFramebuffers(1, &edge_fbo); glBindFramebuffer(GL_FRAMEBUFFER, edge_fbo); glDrawBuffers(1, modes); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, edge_tex, 0); check_fbo(); glGenFramebuffers(1, &blend_fbo); glBindFramebuffer(GL_FRAMEBUFFER, blend_fbo); glDrawBuffers(1, modes); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, blend_tex, 0); check_fbo(); glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); get_opengl_error(); /* * Set up shaders */ /* * EDGE SHADER */ create_shader(&edge_vs, &edge_ps, &edge_shader); //SET UNIFORMS glUseProgram(edge_shader); glUniform1i(glGetUniformLocation(edge_shader, "albedo_tex"), 0); glUseProgram(0); //VALIDATE validate_program(edge_shader); get_opengl_error(); /* * BLEND SHADER */ create_shader(&blend_vs, &blend_ps, &blend_shader); //SET UNIFORMS glUseProgram(blend_shader); glUniform1i(glGetUniformLocation(blend_shader, "edge_tex"), 0); glUniform1i(glGetUniformLocation(blend_shader, "area_tex"), 1); glUniform1i(glGetUniformLocation(blend_shader, "search_tex"), 2); glUseProgram(0); //VALIDATE validate_program(blend_shader); get_opengl_error(); /* * NEIGHBORHOOD SHADER */ create_shader(&neighborhood_vs, &neighborhood_ps, &neighborhood_shader); //SET UNIFORMS glUseProgram(neighborhood_shader); glUniform1i(glGetUniformLocation(neighborhood_shader, "albedo_tex"), 0); glUniform1i(glGetUniformLocation(neighborhood_shader, "blend_tex"), 1); glUseProgram(0); //VALIDATE validate_program(neighborhood_shader); get_opengl_error(); //anything that is done once on load goes here materialCount_ = scene_->getAllMaterials().size(); spotLightCount_ = scene_->getAllSpotLights().size(); pointLightCount_ = scene_->getAllPointLights().size(); directionalLightCount_ = scene_->getAllDirectionalLights().size(); loadShaders(); loadMeshes(); loadUniformBuffers(); glEnable(GL_CULL_FACE); glClearColor(0.f, 0.f, 0.25f, 0.f); //GBUFER TEXTURES glGenTextures(1, &gbuffer_position_tex_); glGenTextures(1, &gbuffer_normal_tex_); glGenTextures(1, &gbuffer_matColour_tex_); glGenFramebuffers(1, &lbuffer_fbo_); glGenRenderbuffers(1, &lbuffer_colour_rbo_); glGenFramebuffers(1, &gbuffer_fbo_); glGenRenderbuffers(1, &gbuffer_depth_rbo_); //only need to set this once glUseProgram(shaderPrograms_[AMBIENT_LIGHT]); GLuint ambient = glGetUniformLocation(shaderPrograms_[AMBIENT_LIGHT], "ambientLight"); glUniform3fv(ambient, 1, glm::value_ptr(scene_->getAmbientLightIntensity())); }
HRESULT ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* context, MutableString&& string) { HRESULT hr = E_FAIL; hr = BasicObject::Initialize(device, context); if (FAILED(hr)) { return hr; } std::string filename = string.getMultiByteString(); unsigned int ppsteps = aiProcess_CalcTangentSpace | // calculate tangents and bitangents if possible aiProcess_JoinIdenticalVertices | // join identical vertices/ optimize indexing aiProcess_ValidateDataStructure | // perform a full validation of the loader's output aiProcess_ImproveCacheLocality | // improve the cache locality of the output vertices aiProcess_RemoveRedundantMaterials | // remove redundant materials aiProcess_FindDegenerates | // remove degenerated polygons from the import aiProcess_FindInvalidData | // detect invalid model data, such as invalid nor vectors aiProcess_GenUVCoords | // convert spherical, cylindrical, box and planar mapping to proper UVs aiProcess_TransformUVCoords | // preprocess UV transformations (scaling, translation ...) aiProcess_FindInstances | // search for instanced meshes and remove them by references to one master aiProcess_LimitBoneWeights | // limit bone weights to 4 per SkinVertex aiProcess_OptimizeMeshes | // join small meshes, if possible; aiProcess_SplitByBoneCount | // split meshes with too many bones. Necessary for our (limited) hardware skinning shader 0; // 使用导入器导入选定的模型文件 importer.reset(new Assimp::Importer); scene = (aiScene*)importer->ReadFile(filename.c_str(), ppsteps | aiProcess_GenSmoothNormals | aiProcess_SplitLargeMeshes | aiProcess_Triangulate | aiProcess_ConvertToLeftHanded | aiProcess_SortByPType | 0); if (scene == nullptr) { //failed on loading asset. //if so get error message & output to console. std::cout << importer->GetErrorString() << std::endl; return E_FAIL; } sceneAnimator.reset(new SceneAnimator(scene)); //update the fileLocation modelLocation.reset(new std::string(getModelLocation(filename.c_str()))); hr = boneTransformations.Initialize(device, context, 3); if (FAILED(hr)) { return hr; } //load the texturess of this model. loadTextures(device, context, scene, string.getMultiByteString().c_str()); //load the meshes of this model. loadMeshes(scene); if (vertices.empty() || indices.empty()) { return E_FAIL; } //send vertices into vertex buffers. for (int i = 0; i < vertices.size(); i++) { auto& currentBuffer = vertexBuffer[i]; hr = currentBuffer->Initialize(device, context, vertices[i]->data(), vertices[i]->size(), indices[i]->data(), indices[i]->size()); if (FAILED(hr)) { return hr; } } return S_OK; }