From 196b7d4331e567b647c1feee7fb14f5f78c1f830 Mon Sep 17 00:00:00 2001 From: Deamon87 Date: Fri, 10 Mar 2023 19:58:37 +0200 Subject: [PATCH 1/3] Add fixes for 10.1 --- src/main.cpp | 10 +- src/ui/FrontendUI.cpp | 4 +- .../DatabaseUpdateWorkflow.cpp | 9 +- wowViewerLib/3rdparty/oneTbb | 2 +- .../shaders/glsl/common/commonFunctions.glsl | 42 ++++-- .../shaders/glsl/vulkan/wmoShader.frag | 20 +-- .../src/engine/objects/ViewsObjects.cpp | 2 +- .../src/engine/shader/ShaderDefinitions.h | 124 +++++++++--------- .../src/gapi/vulkan/GDeviceVulkan.cpp | 5 + 9 files changed, 126 insertions(+), 92 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ab52021a6..4a8a0e2ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -323,7 +323,7 @@ static LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS * ExceptionInfo) double currentFrame; double lastFrame; -int main(){ +int main(int argc, char *argv[]) { // std::ofstream out("log.txt"); // std::streambuf *coutbuf = std::cout.rdbuf(); //save old buf // std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt! @@ -352,8 +352,12 @@ int main(){ #endif // std::string rendererName = "ogl2"; -// std::string rendererName = "ogl3"; - std::string rendererName = "vulkan"; + std::string rendererName = "ogl3"; +// std::string rendererName = "vulkan"; + + if (argc > 1 && std::string(argv[1]) == "-vulkan") { + rendererName = "vulkan"; + } //FOR OGL diff --git a/src/ui/FrontendUI.cpp b/src/ui/FrontendUI.cpp index 71d17fdc3..781153c6b 100644 --- a/src/ui/FrontendUI.cpp +++ b/src/ui/FrontendUI.cpp @@ -715,8 +715,8 @@ void FrontendUI::showQuickLinksDialog() { std::vector replacementTextureFDids = {}; ImGui::Begin("Quick Links", &showQuickLinks); - if (ImGui::Button("nightborne model", ImVec2(-1, 0))) { - openM2SceneByfdid(1810676, replacementTextureFDids); + if (ImGui::Button("Primal enchant", ImVec2(-1, 0))) { + openM2SceneByfdid(4636728, replacementTextureFDids); } if (ImGui::Button("Tomb of sargares hall", ImVec2(-1, 0))) { openMapByIdAndWDTId(1676, 1532459, 6289, -801, 3028); diff --git a/src/ui/childWindow/databaseUpdateWorkflow/DatabaseUpdateWorkflow.cpp b/src/ui/childWindow/databaseUpdateWorkflow/DatabaseUpdateWorkflow.cpp index 84e6ec533..325f133c5 100644 --- a/src/ui/childWindow/databaseUpdateWorkflow/DatabaseUpdateWorkflow.cpp +++ b/src/ui/childWindow/databaseUpdateWorkflow/DatabaseUpdateWorkflow.cpp @@ -11,6 +11,7 @@ #include "../../../../3rdparty/DBImporter/fileReaders/DBD/DBDFileStorage.h" #include "../../../../3rdparty/DBImporter/exporters/sqlite/CSQLLiteExporter.h" #include "../../../../3rdparty/DBImporter/importers/WDC3/WDC3Importer.h" +#include "../../../../3rdparty/DBImporter/fileReaders/WDC4/DB2Ver4.h" struct RequiredTableStruct { int fileDataId; @@ -195,7 +196,13 @@ void DatabaseUpdateWorkflow::db2UpdateLogic() { std::shared_ptr csqlLiteExporter = std::make_shared("export.db3"); addTableLambda = [fileDBDStorage, csqlLiteExporter](std::string tableName, std::shared_ptr db2File) -> bool { - std::shared_ptr db2Base = std::make_shared(); + std::shared_ptr db2Base = nullptr; + if (*(uint32_t *)db2File->getContent()->data() == '4CDW') { + db2Base = std::make_shared(); + } else { + db2Base = std::make_shared(); + } + db2Base->process(db2File->getContent(), ""); DBDFile::BuildConfig *buildConfig = nullptr; diff --git a/wowViewerLib/3rdparty/oneTbb b/wowViewerLib/3rdparty/oneTbb index a927a6bba..28c87bcf4 160000 --- a/wowViewerLib/3rdparty/oneTbb +++ b/wowViewerLib/3rdparty/oneTbb @@ -1 +1 @@ -Subproject commit a927a6bba93b77037b8377ddef025047d0270650 +Subproject commit 28c87bcf46ca82bcba2b27182dbc52967ef85b67 diff --git a/wowViewerLib/shaders/glsl/common/commonFunctions.glsl b/wowViewerLib/shaders/glsl/common/commonFunctions.glsl index e1a27ae16..caf3f121a 100644 --- a/wowViewerLib/shaders/glsl/common/commonFunctions.glsl +++ b/wowViewerLib/shaders/glsl/common/commonFunctions.glsl @@ -1,12 +1,10 @@ -vec2 posToTexCoord(vec3 cameraPoint, vec3 normal){ -// vec3 normPos = -normalize(cameraPoint.xyz); -// vec3 normPos = cameraPoint.xyz; -// vec3 reflection = reflect(normPos, normal); -// return (normalize(vec3(reflection.r, reflection.g, reflection.b + 1.0)).rg * 0.5) + vec2(0.5); - - vec3 normPos_495 = normalize(cameraPoint.xyz); - vec3 temp_500 = (normPos_495 - (normal * (2.0 * dot(normPos_495, normal)))); - vec3 temp_657 = vec3(temp_500.x, temp_500.y, (temp_500.z + 1.0)); +vec2 posToTexCoord(const vec3 vertexPosInView, const vec3 normal){ + //Blizz seems to have vertex in view space as vector from "vertex to eye", while in this implementation, it's + //vector from "eye to vertex". So the minus here is not needed + //vec3 viewVecNormalized = -normalize(cameraPoint.xyz); + vec3 viewVecNormalized = normalize(vertexPosInView.xyz); + vec3 reflection = reflect(viewVecNormalized, normalize(normal)); + vec3 temp_657 = vec3(reflection.x, reflection.y, (reflection.z + 1.0)); return ((normalize(temp_657).xy * 0.5) + vec2(0.5)); } @@ -24,3 +22,29 @@ mat3 blizzTranspose(mat4 value) { ); } + +#ifdef FRAGMENT_SHADER +//From: https://pdfslide.tips/technology/shaderx5-26normalmappingwithoutprecomputedtangents-130318-1.html?page=14 +mat3 contangent_frame(vec3 N, vec3 p, vec2 uv) +{ + // Get edge vectors of the pixel triangle + vec3 dp1 = dFdx(p); + vec3 dp2 = dFdy(p); + vec2 duv1 = dFdx(uv); + vec2 duv2 = dFdy(uv); + // Solve the linear system + vec3 dp2perp = cross(dp2, N); + vec3 dp1perp = cross(N, dp1); + vec3 T = dp2perp * duv1.x + dp1perp * duv2.x; + vec3 B = dp2perp * duv1.y + dp1perp * duv2.y; + // Construct a scale-invariant frame + float invmax = inversesqrt(max(dot(T,T), dot(B,B))); + return mat3(T * invmax, B * invmax, N); +} +#else +//Temp implementation. +//TODO: add implementation for raytracing case +mat3 contangent_frame(vec3 N, vec3 p, vec2 uv) { + return mat3(1.0); +} +#endif \ No newline at end of file diff --git a/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag b/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag index de5b8795e..ec128dd4b 100644 --- a/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag +++ b/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag @@ -4,6 +4,8 @@ precision highp float; precision highp int; +#define FRAGMENT_SHADER + #include "../common/commonLightFunctions.glsl" #include "../common/commonFogFunctions.glsl" #include "../common/commonFunctions.glsl" @@ -243,22 +245,14 @@ void main() { finalOpacity = tex.a; } if (uPixelShader == 19) { //MapObjParallax vec4 tex_6 = texture(uTexture6, vTexCoord2).rgba; - vec3 crossDy = cross(dFdy(vPosition.xyz), vNormal); - vec3 crossDx = cross(vNormal, dFdx(vPosition.xyz)); - vec2 dTexCoord2Dx = dFdx(vTexCoord2); - vec2 dTexCoord2Dy = dFdy(vTexCoord2); - - vec3 sum1 = dTexCoord2Dy.x * crossDx + dTexCoord2Dx.x * crossDy; - vec3 sum2 = dTexCoord2Dy.y * crossDx + dTexCoord2Dx.y * crossDy; - float maxInverseDot = inversesqrt(max(dot(sum1,sum1), dot(sum2, sum2))); - float cosAlpha = dot(normalize(vPosition.xyz), vNormal); + mat3 TBN = contangent_frame(vNormal.xyz, -vPosition.xyz, vTexCoord2); - float dot1 = dot(maxInverseDot * sum1, normalize(vPosition.xyz)) / cosAlpha; - float dot2 = dot(maxInverseDot * sum2, normalize(vPosition.xyz)) / cosAlpha; + float cosAlpha = dot(normalize(vPosition.xyz), vNormal.xyz); + vec2 dotResult = (TBN * (normalize(-vPosition.xyz) / cosAlpha)).xy; - vec4 tex_4 = texture(uTexture4, vTexCoord2 - (vec2(dot1, dot2)* tex_6.r * 0.25)).rgba; - vec4 tex_5 = texture(uTexture5, vTexCoord3 - (vec2(dot1, dot2)* tex_6.r * 0.25)).rgba; + vec4 tex_4 = texture(uTexture4, vTexCoord2 - (dotResult * tex_6.r * 0.25)).rgba; + vec4 tex_5 = texture(uTexture5, vTexCoord3 - (dotResult * tex_6.r * 0.25)).rgba; vec4 tex_3 = texture(uTexture3, vTexCoord2).rgba; vec3 mix1 = tex_5.rgb + tex_4.rgb * tex_4.a; diff --git a/wowViewerLib/src/engine/objects/ViewsObjects.cpp b/wowViewerLib/src/engine/objects/ViewsObjects.cpp index bb6acc45d..c991053b8 100644 --- a/wowViewerLib/src/engine/objects/ViewsObjects.cpp +++ b/wowViewerLib/src/engine/objects/ViewsObjects.cpp @@ -76,7 +76,7 @@ void GeneralView::setM2Lights(std::shared_ptr &m2Object) { m2Object->setUseLocalLighting(false); } -static std::array DrawPortalBindings = { +static std::array DrawPortalBindings = { {+drawPortalShader::Attribute::aPosition, 3, GBindingType::GFLOAT, false, 12, 0 }, // 0 //24 }; diff --git a/wowViewerLib/src/engine/shader/ShaderDefinitions.h b/wowViewerLib/src/engine/shader/ShaderDefinitions.h index 6ff59e99f..1cba25458 100644 --- a/wowViewerLib/src/engine/shader/ShaderDefinitions.h +++ b/wowViewerLib/src/engine/shader/ShaderDefinitions.h @@ -625,36 +625,36 @@ const std::unordered_map GDeviceVLK::getShader(std::string shaderName sharedPtr.reset(iPremutation); sharedPtr->compileShader("",""); m_shaderPermutCache[hash] = sharedPtr; + } else if (shaderName == "drawPortalShader") { + IShaderPermutation *iPremutation = new GDrawBoundingBoxVLK(shaderName, this); + sharedPtr.reset(iPremutation); + sharedPtr->compileShader("",""); + m_shaderPermutCache[hash] = sharedPtr; } else if (shaderName == "imguiShader") { IShaderPermutation *iPremutation = new GImguiShaderPermutation(shaderName, this); sharedPtr.reset(iPremutation); From 82380767764e3764a0f81cf6ff2b97e3106a932e Mon Sep 17 00:00:00 2001 From: Deamon87 Date: Fri, 10 Mar 2023 20:30:23 +0200 Subject: [PATCH 2/3] trd]] --- 3rdparty/DBImporter | 2 +- wowViewerLib/shaders/glsl/vulkan/m2ParticleShader.frag | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/3rdparty/DBImporter b/3rdparty/DBImporter index 4c3c79c03..a4a1d8713 160000 --- a/3rdparty/DBImporter +++ b/3rdparty/DBImporter @@ -1 +1 @@ -Subproject commit 4c3c79c036308ffce91b5ea2c3d5712e64258964 +Subproject commit a4a1d8713e23ae7391f6dc8dd409fea6f4d8a941 diff --git a/wowViewerLib/shaders/glsl/vulkan/m2ParticleShader.frag b/wowViewerLib/shaders/glsl/vulkan/m2ParticleShader.frag index 1b75687e0..4dde9646d 100644 --- a/wowViewerLib/shaders/glsl/vulkan/m2ParticleShader.frag +++ b/wowViewerLib/shaders/glsl/vulkan/m2ParticleShader.frag @@ -27,6 +27,7 @@ layout(std140, binding=4) uniform meshWideBlockPS { }; layout(set=1,binding=5) uniform sampler2D uTexture; + layout(set=1,binding=6) uniform sampler2D uTexture2; layout(set=1,binding=7) uniform sampler2D uTexture3; From d8e8f8195e7806b8326ab928c8bb29030ca45c5c Mon Sep 17 00:00:00 2001 From: Deamon87 Date: Fri, 10 Mar 2023 20:50:14 +0200 Subject: [PATCH 3/3] fix for shader 7 --- wowViewerLib/shaders/glsl/vulkan/wmoShader.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag b/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag index ec128dd4b..bf2d1fb0a 100644 --- a/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag +++ b/wowViewerLib/shaders/glsl/vulkan/wmoShader.frag @@ -161,7 +161,7 @@ void main() { finalOpacity = tex.a; } else if (uPixelShader == 7) { //MapObjTwoLayerEnvMetal - vec4 colorMix = mix(tex, tex2, vColor2.a); + vec4 colorMix = mix(tex, tex2, 1.0 - vColor2.a); matDiffuse = colorMix.rgb ; emissive = (colorMix.rgb * colorMix.a) * tex3.rgb * distFade;