Merge fixes

This commit is contained in:
SirLynix 2022-08-07 20:17:23 +02:00 committed by Jérôme Leclercq
parent d60fce169a
commit a9801894e8
13 changed files with 89 additions and 68 deletions

View File

@ -91,7 +91,8 @@ int main()
Nz::MeshParams meshParams;
meshParams.center = true;
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
meshParams.vertexRotation = Nz::EulerAnglesf(0.f, -90.f, 0.f);
meshParams.vertexScale = Nz::Vector3f(0.002f);
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV);
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();

View File

@ -27,7 +27,8 @@ int main()
Nz::MeshParams meshParams;
meshParams.center = true;
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, -90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
meshParams.vertexRotation = Nz::EulerAnglesf(0.f, -90.f, 0.f);
meshParams.vertexScale = Nz::Vector3f(0.002f);
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV_Tangent);
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();

View File

@ -27,7 +27,8 @@ int main()
Nz::MeshParams meshParams;
meshParams.center = true;
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, -90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
meshParams.vertexRotation = Nz::EulerAnglesf(0.f, -90.f, 0.f);
meshParams.vertexScale = Nz::Vector3f(0.002f);
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV_Tangent);
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();

View File

@ -42,7 +42,8 @@ int main()
Nz::MeshParams meshParams;
meshParams.center = true;
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
meshParams.vertexRotation = Nz::EulerAnglesf(0.f, -90.f, 0.f);
meshParams.vertexScale = Nz::Vector3f(0.002f);
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV_Tangent);
std::shared_ptr<Nz::Mesh> spaceshipMesh = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams);

View File

@ -131,7 +131,8 @@ int main()
Nz::MeshParams meshParams;
meshParams.bufferFactory = Nz::GetRenderBufferFactory(device);
meshParams.center = true;
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, -90.f, 0.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
meshParams.vertexRotation = Nz::EulerAnglesf(0.f, -90.f, 0.f);
meshParams.vertexScale = Nz::Vector3f(0.002f);
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV);
std::shared_ptr<Nz::Mesh> spaceship = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams);

View File

@ -1,4 +1,5 @@
#include <Nazara/Core.hpp>
#include <Nazara/Core/Systems.hpp>
#include <Nazara/Platform.hpp>
#include <Nazara/Graphics.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
@ -9,11 +10,10 @@
#include <Nazara/Physics3D/Components.hpp>
#include <Nazara/Physics3D/Systems.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Shader.hpp>
#include <Nazara/Shader/SpirvConstantCache.hpp>
#include <Nazara/Shader/SpirvPrinter.hpp>
#include <Nazara/Utility.hpp>
#include <Nazara/Utility/Components.hpp>
#include <Nazara/Utils/CallOnExit.hpp>
#include <NZSL/Math/FieldOffsets.hpp>
#include <entt/entt.hpp>
#include <array>
#include <iostream>
@ -23,12 +23,12 @@ NAZARA_REQUEST_DEDICATED_GPU()
int main()
{
std::filesystem::path resourceDir = "resources";
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory(".." / resourceDir))
resourceDir = ".." / resourceDir;
std::filesystem::path resourceDir = "assets/examples";
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
resourceDir = "../.." / resourceDir;
Nz::Renderer::Config rendererConfig;
//rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL;
rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL;
Nz::Modules<Nz::Graphics> nazara(rendererConfig);
@ -40,18 +40,14 @@ int main()
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();
std::string windowTitle = "Skinning test";
Nz::RenderWindow window;
if (!window.Create(device, Nz::VideoMode(1280, 720, 32), windowTitle))
{
std::cout << "Failed to create Window" << std::endl;
return __LINE__;
}
entt::registry registry;
Nz::SystemGraph systemGraph(registry);
Nz::Physics3DSystem physSytem(registry);
Nz::RenderSystem renderSystem(registry);
Nz::Physics3DSystem& physSytem = systemGraph.AddSystem<Nz::Physics3DSystem>();
Nz::RenderSystem& renderSystem = systemGraph.AddSystem<Nz::RenderSystem>();
std::string windowTitle = "Skinning test";
Nz::RenderWindow& window = renderSystem.CreateWindow(device, Nz::VideoMode(1280, 720, 32), windowTitle);
physSytem.GetPhysWorld().SetGravity({ 0.f, -9.81f, 0.f });
@ -82,8 +78,8 @@ int main()
cameraComponent.UpdateClearColor(Nz::Color(0.5f, 0.5f, 0.5f));
}
Nz::FieldOffsets skeletalOffsets(Nz::StructLayout::Std140);
std::size_t arrayOffset = skeletalOffsets.AddMatrixArray(Nz::StructFieldType::Float1, 4, 4, true, 200);
nzsl::FieldOffsets skeletalOffsets(nzsl::StructLayout::Std140);
std::size_t arrayOffset = skeletalOffsets.AddMatrixArray(nzsl::StructFieldType::Float1, 4, 4, true, 200);
std::vector<Nz::UInt8> skeletalBufferMem(skeletalOffsets.GetAlignedSize());
Nz::Matrix4f* matrices = Nz::AccessByOffset<Nz::Matrix4f*>(skeletalBufferMem.data(), arrayOffset);
@ -143,14 +139,14 @@ int main()
std::shared_ptr<Nz::RenderBuffer> renderBuffer = device->InstantiateBuffer(Nz::BufferType::Uniform, skeletalBufferMem.size(), Nz::BufferUsage::Write, skeletalBufferMem.data());
const Nz::Boxf& bobAABB = bobMesh->GetAABB();
std::shared_ptr<Nz::GraphicalMesh> bobGfxMesh = std::make_shared<Nz::GraphicalMesh>(*bobMesh);
std::shared_ptr<Nz::GraphicalMesh> bobGfxMesh = Nz::GraphicalMesh::BuildFromMesh(*bobMesh);
std::shared_ptr<Nz::Model> bobModel = std::make_shared<Nz::Model>(std::move(bobGfxMesh), bobAABB);
std::vector<std::shared_ptr<Nz::Material>> materials(bobMesh->GetMaterialCount());
for (std::size_t i = 0; i < bobMesh->GetMaterialCount(); ++i)
{
std::string matPath;
bobMesh->GetMaterialData(i).GetStringParameter(Nz::MaterialData::DiffuseTexturePath, &matPath);
bobMesh->GetMaterialData(i).GetStringParameter(Nz::MaterialData::BaseColorTexturePath, &matPath);
std::shared_ptr<Nz::Material> bobMat = std::make_shared<Nz::Material>();
@ -175,7 +171,7 @@ int main()
bobMatPass->SetBlendFunc(Nz::BlendFunc::SrcAlpha, Nz::BlendFunc::InvSrcAlpha, Nz::BlendFunc::One, Nz::BlendFunc::Zero);
}
else
basicMat.SetDiffuseMap(Nz::Texture::LoadFromFile(path, texParams));
basicMat.SetBaseColorMap(Nz::Texture::LoadFromFile(path, texParams));
}
bobMat->AddPass("ForwardPass", bobMatPass);
@ -225,7 +221,7 @@ int main()
planeMesh.BuildSubMesh(Nz::Primitive::Plane(planeSize, Nz::Vector2ui(0u), Nz::Matrix4f::Identity(), Nz::Rectf(0.f, 0.f, 10.f, 10.f)), meshPrimitiveParams);
planeMesh.SetMaterialCount(1);
std::shared_ptr<Nz::GraphicalMesh> planeMeshGfx = std::make_shared<Nz::GraphicalMesh>(planeMesh);
std::shared_ptr<Nz::GraphicalMesh> planeMeshGfx = Nz::GraphicalMesh::BuildFromMesh(planeMesh);
std::shared_ptr<Nz::Material> planeMat = std::make_shared<Nz::Material>();
@ -233,13 +229,13 @@ int main()
planeMatPass->EnableDepthBuffer(true);
{
Nz::BasicMaterial basicMat(*planeMatPass);
basicMat.SetDiffuseMap(Nz::Texture::LoadFromFile(resourceDir / "dev_grey.png", texParams));
basicMat.SetBaseColorMap(Nz::Texture::LoadFromFile(resourceDir / "dev_grey.png", texParams));
Nz::TextureSamplerInfo planeSampler;
planeSampler.anisotropyLevel = 16;
planeSampler.wrapModeU = Nz::SamplerWrap::Repeat;
planeSampler.wrapModeV = Nz::SamplerWrap::Repeat;
basicMat.SetDiffuseSampler(planeSampler);
basicMat.SetBaseColorSampler(planeSampler);
}
planeMat->AddPass("ForwardPass", planeMatPass);
@ -308,8 +304,6 @@ int main()
{
float updateTime = updateClock.Restart() / 1'000'000.f;
physSytem.Update(registry, 1.f / 60.f);
auto& playerBody = registry.get<Nz::RigidBody3DComponent>(playerEntity);
float mass = playerBody.GetMass();
@ -414,7 +408,7 @@ int main()
builder.EndDebugRegion();
}, Nz::QueueType::Graphics);
renderSystem.Render(registry, frame);
systemGraph.Update();
frame.Present();

View File

@ -609,7 +609,10 @@ std::shared_ptr<Nz::SubMesh> ProcessSubMesh(const std::filesystem::path& originP
if (aiGetMaterialColor(aiMat, aiKey, aiType, aiIndex, &color) == aiReturn_SUCCESS)
{
matData.SetParameter(colorKey, Nz::Color(color.r, color.g, color.b, color.a));
return true;
}
return false;
};
auto SaveEmbeddedTextureToFile = [](const aiTexture* embeddedTexture, const std::filesystem::path& basePath, const char* filename) -> std::filesystem::path
@ -698,10 +701,10 @@ std::shared_ptr<Nz::SubMesh> ProcessSubMesh(const std::filesystem::path& originP
else
embeddedTexturePath = it->second;
matData.SetParameter(textureKey, embeddedTexturePath.generic_u8string());
matData.SetParameter(textureKey, Nz::PathToString(embeddedTexturePath));
}
else
matData.SetParameter(textureKey, (originPath / std::filesystem::u8path(path.data, path.data + path.length)).generic_u8string());
matData.SetParameter(textureKey, Nz::PathToString((originPath / std::filesystem::u8path(path.data, path.data + path.length))));
if (wrapKey)
{
@ -728,18 +731,29 @@ std::shared_ptr<Nz::SubMesh> ProcessSubMesh(const std::filesystem::path& originP
matData.SetParameter(wrapKey, static_cast<long long>(wrap));
}
return true;
}
return false;
};
ConvertColor(AI_MATKEY_COLOR_AMBIENT, Nz::MaterialData::AmbientColor);
ConvertColor(AI_MATKEY_COLOR_DIFFUSE, Nz::MaterialData::DiffuseColor);
if (!ConvertColor(AI_MATKEY_BASE_COLOR, Nz::MaterialData::BaseColor))
ConvertColor(AI_MATKEY_COLOR_DIFFUSE, Nz::MaterialData::BaseColor);
ConvertColor(AI_MATKEY_COLOR_SPECULAR, Nz::MaterialData::SpecularColor);
ConvertTexture(aiTextureType_DIFFUSE, Nz::MaterialData::DiffuseTexturePath, Nz::MaterialData::DiffuseWrap);
ConvertTexture(aiTextureType_EMISSIVE, Nz::MaterialData::EmissiveTexturePath);
ConvertTexture(aiTextureType_HEIGHT, Nz::MaterialData::HeightTexturePath);
ConvertTexture(aiTextureType_NORMALS, Nz::MaterialData::NormalTexturePath);
ConvertTexture(aiTextureType_OPACITY, Nz::MaterialData::AlphaTexturePath);
if (!ConvertTexture(aiTextureType_BASE_COLOR, Nz::MaterialData::BaseColorTexturePath, Nz::MaterialData::BaseColorWrap))
ConvertTexture(aiTextureType_DIFFUSE, Nz::MaterialData::BaseColorTexturePath, Nz::MaterialData::BaseColorWrap);
ConvertTexture(aiTextureType_DIFFUSE_ROUGHNESS, Nz::MaterialData::RoughnessTexturePath, Nz::MaterialData::RoughnessWrap);
ConvertTexture(aiTextureType_EMISSIVE, Nz::MaterialData::EmissiveTexturePath, Nz::MaterialData::EmissiveWrap);
ConvertTexture(aiTextureType_HEIGHT, Nz::MaterialData::HeightTexturePath, Nz::MaterialData::HeightWrap);
ConvertTexture(aiTextureType_METALNESS, Nz::MaterialData::MetallicTexturePath, Nz::MaterialData::MetallicWrap);
ConvertTexture(aiTextureType_NORMALS, Nz::MaterialData::NormalTexturePath, Nz::MaterialData::NormalWrap);
ConvertTexture(aiTextureType_OPACITY, Nz::MaterialData::AlphaTexturePath, Nz::MaterialData::AlphaWrap);
ConvertTexture(aiTextureType_SPECULAR, Nz::MaterialData::SpecularTexturePath, Nz::MaterialData::SpecularWrap);
aiString name;

View File

@ -188,7 +188,7 @@ namespace Nz
options.pbrTextureIndexes->emissive = settings.textures.size();
settings.textures.push_back({
7,
8,
"Emissive",
ImageType::E2D
});
@ -197,7 +197,7 @@ namespace Nz
options.pbrTextureIndexes->height = settings.textures.size();
settings.textures.push_back({
8,
9,
"Height",
ImageType::E2D
});
@ -206,7 +206,7 @@ namespace Nz
options.pbrTextureIndexes->metallic = settings.textures.size();
settings.textures.push_back({
9,
10,
"Metallic",
ImageType::E2D
});
@ -215,7 +215,7 @@ namespace Nz
options.pbrTextureIndexes->normal = settings.textures.size();
settings.textures.push_back({
10,
11,
"Normal",
ImageType::E2D
});
@ -224,7 +224,7 @@ namespace Nz
options.pbrTextureIndexes->roughness = settings.textures.size();
settings.textures.push_back({
11,
12,
"Roughness",
ImageType::E2D
});
@ -233,7 +233,7 @@ namespace Nz
options.pbrTextureIndexes->specular = settings.textures.size();
settings.textures.push_back({
12,
13,
"Specular",
ImageType::E2D
});
@ -249,8 +249,8 @@ namespace Nz
options.defaultValues
});
settings.sharedUniformBlocks.push_back(PredefinedLightData::GetUniformBlock(6, nzsl::ShaderStageType::Fragment));
settings.predefinedBindings[UnderlyingCast(PredefinedShaderBinding::LightDataUbo)] = 6;
settings.sharedUniformBlocks.push_back(PredefinedLightData::GetUniformBlock(7, nzsl::ShaderStageType::Fragment));
settings.predefinedBindings[UnderlyingCast(PredefinedShaderBinding::LightDataUbo)] = 7;
settings.shaders = options.shaders;

View File

@ -2,6 +2,7 @@
module BasicMaterial;
import InstanceData from Engine.InstanceData;
import SkeletalData from Engine.SkeletalData;
import ViewerData from Engine.ViewerData;
option HasBaseColorTexture: bool = false;
@ -34,14 +35,6 @@ struct MaterialSettings
BaseColor: vec4[f32]
}
const MaxJointCount: u32 = u32(200); //< FIXME: Fix integral value types
[layout(std140)]
struct SkeletalData
{
JointMatrices: array[mat4[f32], MaxJointCount]
}
external
{
[binding(0)] settings: uniform[MaterialSettings],
@ -163,7 +156,7 @@ fn billboardMain(input: VertIn) -> VertOut
fn main(input: VertIn) -> VertOut
{
let pos: vec3[f32];
const if (HasSkinning)
const if (HasSkinning && false)
{
pos = vec3[f32](0.0, 0.0, 0.0);

View File

@ -0,0 +1,11 @@
[nzsl_version("1.0")]
module Engine.SkeletalData;
const MaxJointCount: u32 = u32(200); //< FIXME: Fix integral value types
[export]
[layout(std140)]
struct SkeletalData
{
JointMatrices: array[mat4[f32], MaxJointCount]
}

View File

@ -3,6 +3,7 @@ module PhongMaterial;
import InstanceData from Engine.InstanceData;
import LightData from Engine.LightData;
import SkeletalData from Engine.SkeletalData;
import ViewerData from Engine.ViewerData;
// Basic material options
@ -62,6 +63,7 @@ external
[binding(3)] TextureOverlay: sampler2D[f32],
[binding(4)] instanceData: uniform[InstanceData],
[binding(5)] viewerData: uniform[ViewerData],
[binding(6)] skeletalData: uniform[SkeletalData],
[binding(7)] lightData: uniform[LightData],
[binding(8)] MaterialEmissiveMap: sampler2D[f32],
[binding(9)] MaterialHeightMap: sampler2D[f32],

View File

@ -3,6 +3,7 @@ module PhysicallyBasedMaterial;
import InstanceData from Engine.InstanceData;
import LightData from Engine.LightData;
import SkeletalData from Engine.SkeletalData;
import ViewerData from Engine.ViewerData;
// Basic material options
@ -64,13 +65,14 @@ external
[binding(3)] TextureOverlay: sampler2D[f32],
[binding(4)] instanceData: uniform[InstanceData],
[binding(5)] viewerData: uniform[ViewerData],
[binding(6)] lightData: uniform[LightData],
[binding(7)] MaterialEmissiveMap: sampler2D[f32],
[binding(8)] MaterialHeightMap: sampler2D[f32],
[binding(9)] MaterialMetallicMap: sampler2D[f32],
[binding(10)] MaterialNormalMap: sampler2D[f32],
[binding(11)] MaterialRoughnessMap: sampler2D[f32],
[binding(12)] MaterialSpecularMap: sampler2D[f32],
[binding(6)] skeletalData: uniform[SkeletalData],
[binding(7)] lightData: uniform[LightData],
[binding(8)] MaterialEmissiveMap: sampler2D[f32],
[binding(9)] MaterialHeightMap: sampler2D[f32],
[binding(10)] MaterialMetallicMap: sampler2D[f32],
[binding(11)] MaterialNormalMap: sampler2D[f32],
[binding(12)] MaterialRoughnessMap: sampler2D[f32],
[binding(13)] MaterialSpecularMap: sampler2D[f32],
}
struct VertToFrag

View File

@ -215,7 +215,7 @@ namespace Nz
// Material
ParameterList matData;
matData.SetParameter(MaterialData::DiffuseTexturePath, (baseDir / md5Mesh.shader).generic_u8string());
matData.SetParameter(MaterialData::BaseColorTexturePath, (baseDir / md5Mesh.shader).generic_u8string());
mesh->SetMaterialData(i, std::move(matData));
@ -341,7 +341,7 @@ namespace Nz
// Material
ParameterList matData;
matData.SetParameter(MaterialData::DiffuseTexturePath, (baseDir / md5Mesh.shader).generic_u8string());
matData.SetParameter(MaterialData::BaseColorTexturePath, (baseDir / md5Mesh.shader).generic_u8string());
mesh->SetMaterialData(i, std::move(matData));
}