Trying to fix shading
This commit is contained in:
@@ -71,8 +71,8 @@ string(TOLOWER ${SLANG_ROOT}/bin/windows-x64/release SLANG_BINARY_DIR)
|
|||||||
ExternalProject_Add(slang-build
|
ExternalProject_Add(slang-build
|
||||||
SOURCE_DIR ${SLANG_ROOT}
|
SOURCE_DIR ${SLANG_ROOT}
|
||||||
BINARY_DIR ${SLANG_ROOT}
|
BINARY_DIR ${SLANG_ROOT}
|
||||||
CONFIGURE_COMMAND ${SLANG_ROOT}/premake.bat vs2019 --file=${SLANG_ROOT}/premake5.lua gmake --arch=x64 --deps=true
|
CONFIGURE_COMMAND ${SLANG_ROOT}/premake.bat vs2019 --file=${SLANG_ROOT}/premake5.lua --arch=x64 --deps=true
|
||||||
BUILD_COMMAND msbuild -p:PlatformToolset=v143 -p:Configuration=Release -p:Platform=x64 build/visual-studio/slang/slang.vcxproj
|
BUILD_COMMAND msbuild -p:PlatformToolset=v143 -p:Configuration=Release -p:Platform=x64 slang.sln
|
||||||
INSTALL_COMMAND ""
|
INSTALL_COMMAND ""
|
||||||
)
|
)
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
|
|||||||
Vendored
+1
-1
Submodule external/slang updated: bfd3f39d04...4fb3b10b81
@@ -25,12 +25,12 @@ struct BlinnPhong : IBRDF
|
|||||||
|
|
||||||
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
||||||
{
|
{
|
||||||
float3 normal_WS = mul(tbn, normal);
|
float3 normal_WS = mul(normal, tbn);
|
||||||
float diffuse = max(dot(normal_WS, lightDir_WS), 0);
|
float diffuse = max(dot(normal_WS, lightDir_WS), 0);
|
||||||
float3 h = lightDir_WS + viewDir_WS;
|
float3 h = lightDir_WS + viewDir_WS;
|
||||||
float specular = dot(normal_WS, h);
|
float specular = dot(normal_WS, h);
|
||||||
|
|
||||||
return baseColor * (diffuse + specular) * lightColor;
|
return (viewDir_WS + float3(1, 1, 1)) / 2;//baseColor * (diffuse + specular) * lightColor;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ struct PointLight : ILightEnv
|
|||||||
float3 lightDir_WS = position_WS.xyz - params.position_WS;
|
float3 lightDir_WS = position_WS.xyz - params.position_WS;
|
||||||
float d = length(lightDir_WS);
|
float d = length(lightDir_WS);
|
||||||
float illuminance = max(1 - d / colorRange.w, 0);
|
float illuminance = max(1 - d / colorRange.w, 0);
|
||||||
return illuminance * brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz);
|
return brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool insidePlane(Plane plane)
|
bool insidePlane(Plane plane)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ struct FragmentParameter
|
|||||||
LightingParameter result;
|
LightingParameter result;
|
||||||
result.tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS));
|
result.tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS));
|
||||||
result.position_WS = position_WS;
|
result.position_WS = position_WS;
|
||||||
result.viewDir_WS = viewDir_WS;
|
result.viewDir_WS = normalize(viewDir_WS);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -130,12 +130,8 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
if(obj.is_string())
|
if(obj.is_string())
|
||||||
{
|
{
|
||||||
std::string str = obj.get<std::string>();
|
std::string str = obj.get<std::string>();
|
||||||
if (expressions.find([&str, &expressions](const OShaderExpression& exp) {return exp->key == str; }) != expressions.end())
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
OConstantExpression c = new ConstantExpression(str, ExpressionType::UNKNOWN);
|
OConstantExpression c = new ConstantExpression(str, ExpressionType::UNKNOWN);
|
||||||
std::string name = std::format("Const{0}", auxKey++);
|
std::string name = std::format("const_{0}", auxKey++);
|
||||||
c->key = name;
|
c->key = name;
|
||||||
expressions.add(std::move(c));
|
expressions.add(std::move(c));
|
||||||
return name;
|
return name;
|
||||||
@@ -151,6 +147,14 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
{
|
{
|
||||||
auto& obj = param.value();
|
auto& obj = param.value();
|
||||||
std::string exp = obj["exp"].get<std::string>();
|
std::string exp = obj["exp"].get<std::string>();
|
||||||
|
if (exp.compare("Const") == 0)
|
||||||
|
{
|
||||||
|
OConstantExpression p = new ConstantExpression();
|
||||||
|
std::string name = std::format("{0}", key++);
|
||||||
|
p->key = name;
|
||||||
|
p->expr = obj["value"];
|
||||||
|
expressions.add(std::move(p));
|
||||||
|
}
|
||||||
if(exp.compare("Add") == 0)
|
if(exp.compare("Add") == 0)
|
||||||
{
|
{
|
||||||
OAddExpression p = new AddExpression();
|
OAddExpression p = new AddExpression();
|
||||||
|
|||||||
@@ -48,11 +48,14 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
|
|||||||
{
|
{
|
||||||
aiMaterial* material = scene->mMaterials[i];
|
aiMaterial* material = scene->mMaterials[i];
|
||||||
json matCode;
|
json matCode;
|
||||||
std::string materialName = std::format("{0}{1}{2}", baseName, material->GetName().C_Str(), char(i+'a'));
|
std::string materialName = std::format("{0}{1}{2}", baseName, material->GetName().C_Str(), i);
|
||||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end()); // dots break adding the .asset extension later
|
materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end()); // dots break adding the .asset extension later
|
||||||
matCode["name"] = materialName;
|
matCode["name"] = materialName;
|
||||||
matCode["profile"] = "BlinnPhong"; //TODO: other shading models
|
matCode["profile"] = "BlinnPhong"; //TODO: other shading models
|
||||||
aiString texPath;
|
aiString texPath;
|
||||||
|
uint32 baseColorIndex = 0;
|
||||||
|
uint32 normalIndex = 0;
|
||||||
|
int32 codeIndex = -1;
|
||||||
if(material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS)
|
if(material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS)
|
||||||
{
|
{
|
||||||
auto texFilename = std::filesystem::path(texPath.C_Str()).stem();
|
auto texFilename = std::filesystem::path(texPath.C_Str()).stem();
|
||||||
@@ -60,13 +63,11 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
|
|||||||
{
|
{
|
||||||
matCode["code"].push_back(
|
matCode["code"].push_back(
|
||||||
{
|
{
|
||||||
{ "exp", "BRDF" },
|
{ "exp", "Const" },
|
||||||
{ "profile", "BlinnPhong" },
|
{ "value", "float3(1, 1, 1)"}
|
||||||
{ "values", {
|
|
||||||
{"baseColor", "float3(1, 1, 1)"}
|
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
baseColorIndex = ++codeIndex;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -88,46 +89,100 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
|
|||||||
{ "exp", "Sample" },
|
{ "exp", "Sample" },
|
||||||
{ "texture", "diffuseTexture" },
|
{ "texture", "diffuseTexture" },
|
||||||
{ "sampler", "diffuseSampler" },
|
{ "sampler", "diffuseSampler" },
|
||||||
{ "coords", "input.texCoords[0]"}
|
{ "coords", "input.texCoords"}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
++codeIndex;
|
||||||
matCode["code"].push_back(
|
matCode["code"].push_back(
|
||||||
{
|
{
|
||||||
{ "exp", "Swizzle" },
|
{ "exp", "Swizzle" },
|
||||||
{ "target", 0 },
|
{ "target", codeIndex },
|
||||||
{ "comp", json::array({0, 1, 2}) },
|
{ "comp", json::array({0, 1, 2}) },
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
matCode["code"].push_back(
|
baseColorIndex = ++codeIndex;
|
||||||
{
|
|
||||||
{ "exp", "BRDF" },
|
|
||||||
{ "profile", "BlinnPhong" },
|
|
||||||
{ "values", {
|
|
||||||
{"baseColor", 1}
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
matCode["code"].push_back(
|
matCode["code"].push_back(
|
||||||
{
|
{
|
||||||
{ "exp", "BRDF" },
|
{ "exp", "Const" },
|
||||||
{ "profile", "BlinnPhong" },
|
{ "value", "input.vertexColor.xyz" }
|
||||||
{ "values", {
|
|
||||||
{"baseColor", "input.vertexColor.xyz"}
|
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
baseColorIndex = ++codeIndex;
|
||||||
if(material->GetTexture(aiTextureType_SPECULAR, 0, &texPath) == AI_SUCCESS)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
if(material->GetTexture(aiTextureType_NORMALS, 0, &texPath) == AI_SUCCESS)
|
if(material->GetTexture(aiTextureType_NORMALS, 0, &texPath) == AI_SUCCESS)
|
||||||
{
|
{
|
||||||
|
auto texFilename = std::filesystem::path(texPath.C_Str()).stem();
|
||||||
|
AssetImporter::importTexture(TextureImportArgs{
|
||||||
|
.filePath = meshDirectory / texPath.C_Str(),
|
||||||
|
.importPath = importPath,
|
||||||
|
});
|
||||||
|
matCode["params"]["normalTexture"] =
|
||||||
|
{
|
||||||
|
{"type", "Texture2D"},
|
||||||
|
{"default", texFilename.string()}
|
||||||
|
};
|
||||||
|
matCode["params"]["normalSampler"] =
|
||||||
|
{
|
||||||
|
{"type", "Sampler"}
|
||||||
|
};
|
||||||
|
matCode["code"].push_back(
|
||||||
|
{
|
||||||
|
{ "exp", "Sample" },
|
||||||
|
{ "texture", "normalTexture" },
|
||||||
|
{ "sampler", "normalSampler" },
|
||||||
|
{ "coords", "input.texCoords" }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
++codeIndex;
|
||||||
|
matCode["code"].push_back(
|
||||||
|
{
|
||||||
|
{ "exp", "Swizzle" },
|
||||||
|
{ "target", codeIndex },
|
||||||
|
{ "comp", json::array({0, 1, 2}) },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
++codeIndex;
|
||||||
|
matCode["code"].push_back(
|
||||||
|
{
|
||||||
|
{ "exp", "Mul" },
|
||||||
|
{ "lhs", "2" },
|
||||||
|
{ "rhs", codeIndex },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
++codeIndex;
|
||||||
|
matCode["code"].push_back(
|
||||||
|
{
|
||||||
|
{ "exp", "Sub" },
|
||||||
|
{ "lhs", codeIndex },
|
||||||
|
{ "rhs", "float3(1, 1, 1)"},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
normalIndex = ++codeIndex;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
matCode["code"].push_back(
|
||||||
|
{
|
||||||
|
{ "exp", "Const" },
|
||||||
|
{ "value", "float3(0, 0, 1)" }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
normalIndex = ++codeIndex;
|
||||||
|
}
|
||||||
|
matCode["code"].push_back(
|
||||||
|
{
|
||||||
|
{ "exp", "BRDF" },
|
||||||
|
{ "profile", "BlinnPhong" },
|
||||||
|
{ "values", {
|
||||||
|
{ "baseColor", baseColorIndex },
|
||||||
|
{ "normal", normalIndex },
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
);
|
||||||
std::string outMatFilename = materialName.append(".json");
|
std::string outMatFilename = materialName.append(".json");
|
||||||
std::ofstream outMatFile = std::ofstream(meshDirectory / outMatFilename);
|
std::ofstream outMatFile = std::ofstream(meshDirectory / outMatFilename);
|
||||||
outMatFile << std::setw(4) << matCode;
|
outMatFile << std::setw(4) << matCode;
|
||||||
@@ -181,7 +236,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, const Array<PMaterialIns
|
|||||||
for (uint32 i = 0; i < mesh->mNumVertices; ++i)
|
for (uint32 i = 0; i < mesh->mNumVertices; ++i)
|
||||||
{
|
{
|
||||||
positions[i] = Vector(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
|
positions[i] = Vector(mesh->mVertices[i].x, mesh->mVertices[i].y, mesh->mVertices[i].z);
|
||||||
texCoords[i] = Vector2(mesh->mTextureCoords[0][i].x, mesh->mTextureCoords[0][i].x);
|
texCoords[i] = Vector2(mesh->mTextureCoords[0][i].x, mesh->mTextureCoords[0][i].y);
|
||||||
normals[i] = Vector(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z);
|
normals[i] = Vector(mesh->mNormals[i].x, mesh->mNormals[i].y, mesh->mNormals[i].z);
|
||||||
tangents[i] = Vector(mesh->mTangents[i].x, mesh->mTangents[i].y, mesh->mTangents[i].z);
|
tangents[i] = Vector(mesh->mTangents[i].x, mesh->mTangents[i].y, mesh->mTangents[i].z);
|
||||||
biTangents[i] = Vector(mesh->mBitangents[i].x, mesh->mBitangents[i].y, mesh->mBitangents[i].z);
|
biTangents[i] = Vector(mesh->mBitangents[i].x, mesh->mBitangents[i].y, mesh->mBitangents[i].z);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ struct Camera
|
|||||||
}
|
}
|
||||||
Vector getCameraPosition() const
|
Vector getCameraPosition() const
|
||||||
{
|
{
|
||||||
return cameraPos;
|
return -viewMatrix[3];
|
||||||
}
|
}
|
||||||
void mouseMove(float deltaX, float deltaY);
|
void mouseMove(float deltaX, float deltaY);
|
||||||
void mouseScroll(float x);
|
void mouseScroll(float x);
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public:
|
|||||||
assert(_data != nullptr);
|
assert(_data != nullptr);
|
||||||
for (size_type i = 0; i < size; ++i)
|
for (size_type i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
_data[i] = value;
|
std::allocator_traits<allocator_type>::construct(allocator, &_data[i], value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
constexpr explicit Array(size_type size, const allocator_type& alloc = allocator_type())
|
constexpr explicit Array(size_type size, const allocator_type& alloc = allocator_type())
|
||||||
@@ -147,9 +147,16 @@ public:
|
|||||||
{
|
{
|
||||||
_data = allocateArray(size);
|
_data = allocateArray(size);
|
||||||
assert(_data != nullptr);
|
assert(_data != nullptr);
|
||||||
for (size_type i = 0; i < size; ++i)
|
if constexpr (std::is_integral_v<T> || std::is_floating_point_v<T>)
|
||||||
{
|
{
|
||||||
std::allocator_traits<allocator_type>::construct(allocator, &_data[i]);
|
std::memset(_data, 0, size * sizeof(T));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (size_type i = 0; i < size; ++i)
|
||||||
|
{
|
||||||
|
std::allocator_traits<allocator_type>::construct(allocator, &_data[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
constexpr Array(std::initializer_list<T> init, const allocator_type& alloc = allocator_type())
|
constexpr Array(std::initializer_list<T> init, const allocator_type& alloc = allocator_type())
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet()
|
|||||||
{
|
{
|
||||||
nextAlloc = new DescriptorPool(graphics, layout);
|
nextAlloc = new DescriptorPool(graphics, layout);
|
||||||
}
|
}
|
||||||
std::cout << "Out of descriptors, forwarding" << std::endl;
|
//std::cout << "Out of descriptors, forwarding" << std::endl;
|
||||||
return nextAlloc->allocateDescriptorSet();
|
return nextAlloc->allocateDescriptorSet();
|
||||||
//throw std::logic_error("Out of descriptor sets");
|
//throw std::logic_error("Out of descriptor sets");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ double Gfx::getCurrentFrameDelta()
|
|||||||
|
|
||||||
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier)
|
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier)
|
||||||
{
|
{
|
||||||
|
if (key == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
window->keyPress((KeyCode)key, (InputAction)action, (KeyModifier)modifier);
|
window->keyPress((KeyCode)key, (InputAction)action, (KeyModifier)modifier);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ std::string MulExpression::evaluate(Map<std::string, std::string>& varState) con
|
|||||||
{
|
{
|
||||||
std::string varName = std::format("exp_{}", key);
|
std::string varName = std::format("exp_{}", key);
|
||||||
varState[key] = varName;
|
varState[key] = varName;
|
||||||
return std::format("let {} = mul({}, {});\n", varName, varState[inputs.at("lhs").source], varState[inputs.at("rhs").source]);
|
return std::format("let {} = {} * {};\n", varName, varState[inputs.at("lhs").source], varState[inputs.at("rhs").source]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MulExpression::save(ArchiveBuffer& buffer) const
|
void MulExpression::save(ArchiveBuffer& buffer) const
|
||||||
|
|||||||
Reference in New Issue
Block a user