Compare commits

...

14 Commits

Author SHA1 Message Date
InkSoul b80813c7ec
Merge pull request #3 from ink-soul/reconstruct-UI
Reconstruct UI
2023-06-19 10:10:18 +08:00
ink-soul ff2a16aa3b fix character not show correctly 2023-06-19 10:09:08 +08:00
ink-soul dc58fbad2b update chinese UI 2023-06-19 09:47:00 +08:00
ink-soul 3c1b0b8451 Merge branch 'reconstruct-UI' of https://github.com/ink-soul/littleRenderer into reconstruct-UI 2023-06-19 08:06:41 +08:00
ink-soul 8f9e736aca Update render.cpp 2023-06-19 08:05:13 +08:00
InkSoul 8e27b83b22 reconstruct UI complete 2023-06-17 01:18:15 +08:00
ink-soul 03dda388c2 add menu construct 2023-06-16 17:29:47 +08:00
ink-soul 3c0e745cdf Update ui.hpp 2023-06-16 17:03:51 +08:00
ink-soul d8f01324d0 fix loading error when loading from Chinese path 2023-06-13 14:50:25 +08:00
InkSoul 59ea17fe3f
Merge pull request #2 from ink-soul/Chinese-UI-and-asset-path-fix
Chinese UI and asset path fix
2023-06-13 09:06:55 +08:00
ink-soul 5c30ea82f7 Update render.cpp 2023-06-12 14:56:43 +08:00
ink-soul 4d567bf64a fix log complain 2023-06-12 11:11:52 +08:00
ink-soul a8fe315be6 bug fix : allow directory defined in cmakelist 2023-06-12 11:10:07 +08:00
ink-soul 5665ff4105 switch chinese UI asset path fix complete
allow asset path check more data path
2023-06-12 11:05:10 +08:00
6 changed files with 211 additions and 120 deletions

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.4 FATAL_ERROR)
cmake_policy(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
set(NAME games_106)
set(NAME PlumageRender)
project(${NAME})

View File

@ -3,14 +3,34 @@
#if !(defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
// iOS & macOS: VulkanExampleBase::getAssetPath() implemented externally to allow access to Objective-C components
const std::string getAssetPath()
{
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
return "";
#elif defined(VK_EXAMPLE_DATA_DIR)
return VK_EXAMPLE_DATA_DIR;
#else
if (_access("./../data/", 0) != -1)
{
return "./../data/";
}
else if (_access("./data/", 0) != -1)
{
return "./data/";
}
else if (_access("./../../data/", 0) != -1)
{
return "../../data/";
}
else
{
return VK_EXAMPLE_DATA_DIR;
}
#endif
}
#endif

View File

@ -1,10 +1,3 @@
/*
* Vulkan utilities
*
* Copyright(C) 2018 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license(MIT) (http://opensource.org/licenses/MIT)
*/
#pragma once

View File

@ -1,11 +1,4 @@
/*
* Vulkan Example - Physical based rendering a glTF 2.0 model with image based lighting
*
* Copyright (C) 2018 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/

#include <vector>
#include <array>
#include <map>
@ -68,7 +61,7 @@ public:
delete[] fontAsset;
#else
std::string ttfFilePath = getAssetPath() + "/STXINWEI.TTF";
io.Fonts->AddFontFromFileTTF(ttfFilePath.data(), 16.0f);
io.Fonts->AddFontFromFileTTF(ttfFilePath.data(), 16.0f,NULL, io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
#endif
io.Fonts->GetTexDataAsRGBA32(&fontData, &texWidth, &texHeight);
fontTexture.loadFromBuffer(fontData, texWidth * texHeight * 4 * sizeof(char), VK_FORMAT_R8G8B8A8_UNORM, texWidth, texHeight, vulkanDevice, queue);
@ -248,24 +241,7 @@ public:
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
vkDestroyDescriptorPool(device, descriptorPool, nullptr);
}
std::string string_to_utf8(const std::string& str)
{
int nwLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
wchar_t* pwBuf = new wchar_t[nwLen + 1];
memset(pwBuf, 0, nwLen * 2 + 2);
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen);
int nLen = WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL);
char* pBuf = new char[nLen + 1];
memset(pBuf, 0, nLen + 1);
WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL);
std::string ret = pBuf;
delete[]pwBuf;
delete[]pBuf;
return ret;
}
void draw(VkCommandBuffer cmdBuffer) {
vkCmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
vkCmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr);
@ -341,6 +317,40 @@ public:
bool button(const char *caption) {
return ImGui::Button(caption);
}
bool beginChild(const char* caption, ImVec2 size, bool border)
{
return ImGui::BeginChild(caption, size, border);
}
void endChild()
{
return ImGui::EndChild();
}
// menu GUI
bool beginMainMenuBar() {
return ImGui::BeginMainMenuBar();
}
bool beginMenu(const char* caption)
{
return ImGui::BeginMenu(caption);
}
bool menuItem(const char* caption)
{
return ImGui::MenuItem(caption);
}
void endMenu()
{
return ImGui::EndMenu();
}
void endMainMenuBar() {
return ImGui::EndMainMenuBar();
}
void text(const char *formatstr, ...) {
va_list args;
va_start(args, formatstr);

View File

@ -1,4 +1,4 @@

#ifndef TINYGLTF_IMPLEMENTATION
@ -222,7 +222,12 @@ PlumageRender::PlumageRender()
if (_access(assetpath.c_str(),0) != 0) {
std::string msg = "Could not locate asset path in \"" + assetpath + "\".\nMake sure binary is run from correct relative directory!";
std::cerr << msg << std::endl;
exit(-1);
system("pause");
//exit(-1);
}
else {
std::string msg = "asset path get " + assetpath;
std::cout << msg << std::endl;
}
readDirectory(assetpath + "environments", "*.ktx", environments, false);
@ -1670,49 +1675,61 @@ PlumageRender::PlumageRender()
bool updateShaderParams = false;
bool updateCBs = false;
float scale = 1.0f;
bool boolTitleWindowShow = false;
ImGui::NewFrame();
ImGui::SetNextWindowPos(ImVec2(10, 10));
ImGui::SetNextWindowSize(ImVec2(200 * scale, (models.scene.animations.size() > 0 ? 440 : 360) * scale), ImGuiSetCond_Always);
ImGui::Begin("Plumage Render", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
ImGui::SetNextWindowPos(ImVec2(10000, 10000));
//ImGui::SetNextWindowSize(ImVec2(200 * scale, (models.scene.animations.size() > 0 ? 440 : 360) * scale), ImGuiSetCond_Always);
ImGui::Begin("", nullptr, ImGuiWindowFlags_NoFocusOnAppearing|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PushItemWidth(100.0f * scale);
gui->text("%.1d fps (%.2f ms)", lastFPS, (1000.0f / lastFPS));
if (gui->header("model")) {
if (gui->button(gui->string_to_utf8("open gltf model").c_str())) {
std::string filename = "";
char buffer[MAX_PATH];
OPENFILENAME ofn;
if(gui->beginMainMenuBar()) {
if (gui->beginMenu(chineseUI.menuFile))
{
if (gui->menuItem(chineseUI.menuOpenNewModel))
{
std::wstring filename = L"";
wchar_t buffer[MAX_PATH];
OPENFILENAMEW ofn;
ZeroMemory(&buffer, sizeof(buffer));
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFilter = "glTF files\0*.gltf;*.glb\0";
ofn.lpstrFilter = L"glTF files\0*.gltf;*.glb\0";
ofn.lpstrFile = buffer;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = "Select a glTF file to load";
ofn.lpstrTitle = L"Select a glTF file to load";
ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
if (GetOpenFileNameA(&ofn)) {
if (GetOpenFileNameW(&ofn)) {
filename = buffer;
}
if (!filename.empty()) {
vkDeviceWaitIdle(device);
loadScene(filename);
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::string stringFilename = converter.to_bytes(filename);
loadScene(stringFilename);
setupDescriptors();
updateCBs = true;
}
}
if (gui->combo("Environment", selectedEnvironment, environments)) {
gui->endMenu();
}
if (gui->beginMenu(chineseUI.menuEnvironment))
{
if (gui->beginMenu(chineseUI.menuEnvironmentConfig))
{
if (gui->combo(chineseUI.environmentMap, selectedEnvironment, environments)) {
vkDeviceWaitIdle(device);
loadEnvironment(environments[selectedEnvironment]);
setupDescriptors();
updateCBs = true;
}
}
if (gui->header("Environment")) {
if (gui->checkbox("Background", &displayBackground)) {
if (gui->checkbox(chineseUI.environmentBackGround, &displayBackground)) {
updateShaderParams = true;
}
if (gui->slider("Exposure", &shaderData.exposure, 0.1f, 10.0f)) {
@ -1724,35 +1741,71 @@ PlumageRender::PlumageRender()
if (gui->slider("IBL", &shaderData.scaleIBLAmbient, 0.0f, 1.0f)) {
updateShaderParams = true;
}
gui->endMenu();
}
if (gui->header("Debug ")) {
gui->endMenu();
}
if (gui->beginMenu("debug"))
{
if (gui->beginMenu(chineseUI.menuDebugInput))
{
const std::vector<std::string> debugNamesInputs = {
"none", "Base color", "Normal", "Occlusion", "Emissive", "Metallic", "Roughness"
};
if (gui->combo("input", &debugViewInputs, debugNamesInputs)) {
if (gui->combo(chineseUI.debugInput, &debugViewInputs, debugNamesInputs)) {
shaderData.debugViewInputs = static_cast<float>(debugViewInputs);
updateShaderParams = true;
}
gui->endMenu();
}
if (gui->beginMenu("PBR"))
{
const std::vector<std::string> debugNamesEquation = {
"none", "Diff (l,n)", "F (l,h)", "G (l,v,h)", "D (h)", "Specular"
};
if (gui->combo("PBR equation", &debugViewEquation, debugNamesEquation)) {
if (gui->combo(chineseUI.debugPBREquation, &debugViewEquation, debugNamesEquation)) {
shaderData.debugViewEquation = static_cast<float>(debugViewEquation);
updateShaderParams = true;
}
gui->endMenu();
}
if (models.scene.animations.size() > 0) {
if (gui->header("animation")) {
gui->checkbox("pause", &animate);
if (gui->beginMenu(chineseUI.menuDebugFrameRate))
{
gui->text("%.1d fps (%.2f ms)", lastFPS, (1000.0f / lastFPS));
gui->endMenu();
}
gui->endMenu();
}
if (gui->beginMenu(chineseUI.menuAnimation))
{
if (models.scene.animations.size() > 0)
{
if (gui->beginMenu(chineseUI.menuAnimationActivation))
{
gui->checkbox(chineseUI.pauseAnimation, &animate);
gui->endMenu();
}
if (gui->beginMenu(chineseUI.menuAnimationAnimationSequence))
{
std::vector<std::string> animationNames;
for (auto animation : models.scene.animations) {
animationNames.push_back(animation.name);
}
gui->combo("animation", &animationIndex, animationNames);
gui->combo(chineseUI.animationSeq, &animationIndex, animationNames);
gui->endMenu();
}
}
else
{
gui->text(chineseUI.menuAnimationNoAnimation);
}
gui->endMenu();
}
gui->endMainMenuBar();
}
ImGui::PopItemWidth();
ImGui::End();

View File

@ -1,4 +1,4 @@
#pragma once
#pragma once
#include <stdio.h>
#include <stdlib.h>
@ -8,6 +8,8 @@
#include <chrono>
#include <map>
#include <io.h>
#include <locale>
#include <codecvt>
#include "algorithm"
@ -62,15 +64,28 @@ public:
} shaderData;
struct ChinesesUI
{
const char * model = "u8模型";
const char* openNewModel = "打开gltf模型";
const char* environmentMap = "环境贴图";
const char* environment = "环境光照";
const char* debugInput = "输入";
const char* debugPBREquation = "PBR计算参数";
const char* animation = "动画";
const char* pauseAnimation = "暂停动画";
const char* animationSeq = "动画序列";
const char * model = "模型";
const char* environmentMap = "环境贴图";
const char* environmentBackGround = "启用背景贴图";
const char* debugInput = "输入";
const char* debugPBREquation = "PBR计算参数";
const char* animation = "动画";
const char* pauseAnimation = "启用动画";
const char* animationSeq = "动画序列";
// menu item
const char* menuFile = "文件";
const char* menuOpenNewModel = "新模型..";
const char* menuEnvironment = "环境光照";
const char* menuEnvironmentConfig = "设置";
const char* menuAnimation = "动画";
const char* menuDebugFrameRate = "fps";
const char* menuDebugInput = "输入";
const char* menuAnimationNoAnimation = "当前模型没有动画!";
const char* menuAnimationActivation = "开关";
const char* menuAnimationAnimationSequence = "动画序列";
}chineseUI;
struct UniformBufferSet {