diff --git a/res/shaders/lib/BRDF.slang b/res/shaders/lib/BRDF.slang index bed7578..0da07b3 100644 --- a/res/shaders/lib/BRDF.slang +++ b/res/shaders/lib/BRDF.slang @@ -34,7 +34,7 @@ struct Phong : IBRDF float3 r = 2 * (nDotL) * normal_WS - lightDir_WS; float rDotV = dot(r, viewDir_WS); - return lightColor * (baseColor * max(nDotL, 0.0));// + specular * pow(max(rDotV, 0.0), max(shininess, 1))); + return lightColor * (baseColor * max(nDotL, 0.0)) + specular * pow(max(rDotV, 0.0), max(shininess, 1)); } float3 evaluateAmbient() @@ -77,7 +77,7 @@ struct BlinnPhong : IBRDF float3 h = normalize(lightDir_WS + viewDir_WS); float specular = pow(saturate(dot(normal_WS, h)), shininess); - return (baseColor * diffuse * lightColor) + (specularColor * specular); + return (baseColor * diffuse * lightColor);// + (specularColor * specular); } float3 evaluateAmbient() diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index 12b9211..9f3567d 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -14,7 +14,7 @@ struct DirectionalLight : ILightEnv float3 illuminate(LightingParameter params, B brdf) { - float3 dir_WS = normalize(direction.xyz); + float3 dir_WS = -normalize(direction.xyz); return brdf.evaluate(params.tangentToWorld, params.viewDir_WS, dir_WS, color.xyz); } }; diff --git a/res/shaders/lib/MaterialParameter.slang b/res/shaders/lib/MaterialParameter.slang index c7cff0a..b390d81 100644 --- a/res/shaders/lib/MaterialParameter.slang +++ b/res/shaders/lib/MaterialParameter.slang @@ -12,6 +12,7 @@ struct LightingParameter float3x3 tangentToWorld; float3 viewDir_WS; float3 position_WS; + float3 normal_WS; } @@ -91,12 +92,15 @@ struct FragmentParameter result.tangentToWorld = getTangentToWorld(); result.viewDir_WS = normalize(pViewParams.cameraPosition_WS.xyz - position_WS); result.position_WS = position_WS; + result.normal_WS = normalize(normal_WS); return result; } float3x3 getTangentToWorld() { - return float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS)); + // in theory, transposing would make this a world-to-tangent matrix, but because we are building the matrix ourselves + // and something with matrix layouts is working the opposite direction, we need to transpose here + return transpose(float3x3(tangent_WS, biTangent_WS, normal_WS)); } #endif static FragmentParameter interpolate(FragmentParameter f0, FragmentParameter f1, FragmentParameter f2, float3 barycentricCoords) @@ -138,10 +142,9 @@ struct VertexAttributes FragmentParameter result; result.position_CS = clipPos; #ifndef POS_ONLY - float3x3 normalMatrix = transpose(float3x3(inverseTransformMatrix)); - result.tangent_WS = mul(normalMatrix, tangent_MS); - result.biTangent_WS = mul(normalMatrix, biTangent_MS); - result.normal_WS = mul(normalMatrix, normal_MS); + result.tangent_WS = normalize(mul(transformMatrix, float4(tangent_MS, 0)).xyz); + result.biTangent_WS = normalize(mul(transformMatrix, float4(biTangent_MS, 0)).xyz); + result.normal_WS = normalize(mul(transformMatrix, float4(normal_MS, 0)).xyz); result.vertexColor = vertexColor; result.position_WS = worldPos.xyz; result.texCoords0 = float4(texCoords[0], texCoords[1]); diff --git a/res/shaders/lib/SkinnedMeshVertexData.slang b/res/shaders/lib/SkinnedMeshVertexData.slang index 7ad4c59..93878c7 100644 --- a/res/shaders/lib/SkinnedMeshVertexData.slang +++ b/res/shaders/lib/SkinnedMeshVertexData.slang @@ -1,10 +1,11 @@ import VertexData; import Common; import Scene; +import MaterialParameter; -struct SkinnedMeshVertexData : VertexData +struct SkinnedMeshVertexData { - SkinnedMeshVertexAttributes getAttributes(uint index, float4x4 transform) + VertexInput getAttributes(uint index, float4x4 transform) { StaticMeshVertexAttributes attr; float4x4 boneTransform = float4x4(1.0f); diff --git a/src/Editor/Asset/MeshLoader.cpp b/src/Editor/Asset/MeshLoader.cpp index 57e64d9..1869a50 100644 --- a/src/Editor/Asset/MeshLoader.cpp +++ b/src/Editor/Asset/MeshLoader.cpp @@ -372,12 +372,6 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array& aiShadingMode mode; material->Get(AI_MATKEY_SHADING_MODEL, mode); switch (mode) { - case aiShadingMode_Blinn: - brdf.profile = "BlinnPhong"; - brdf.variables["specularColor"] = outputSpecular; - brdf.variables["ambient"] = outputAmbient; - brdf.variables["shininess"] = outputShininess; - break; case aiShadingMode_Phong: brdf.profile = "Phong"; brdf.variables["specular"] = outputSpecular; @@ -387,7 +381,6 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array& case aiShadingMode_Toon: brdf.profile = "CelShading"; break; - default: case aiShadingMode_CookTorrance: brdf.profile = "CookTorrance"; brdf.variables["roughness"] = outputRoughness; @@ -396,6 +389,13 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array& brdf.variables["ambientOcclusion"] = outputAmbient; } break; + default: + case aiShadingMode_Blinn: + brdf.profile = "BlinnPhong"; + brdf.variables["specularColor"] = outputSpecular; + brdf.variables["ambient"] = outputAmbient; + brdf.variables["shininess"] = outputShininess; + break; }; uint32 twoSided = false; float opacity = 1.0f; diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index b7e5c3b..6234590 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -96,13 +96,6 @@ int main() { .filePath = sourcePath / "import/textures/skybox.jpg", .type = TextureImportType::TEXTURE_CUBEMAP, }); - AssetImporter::importTexture(TextureImportArgs{ - .filePath = sourcePath / "import/textures/brickwall.jpg", - }); - AssetImporter::importTexture(TextureImportArgs{ - .filePath = sourcePath / "import/textures/brickwall_normal.jpg", - .type = TextureImportType::TEXTURE_NORMAL, - }); // AssetImporter::importMesh(MeshImportArgs{ // .filePath = sourcePath / "import/models/ship.fbx", // .importPath = "ship", diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index e0c8dd0..bb9eb17 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -196,7 +196,7 @@ void BasePass::render() { }, .rasterizationState = { - .cullMode = Gfx::SE_CULL_MODE_NONE, + .cullMode = Gfx::SE_CULL_MODE_BACK_BIT, }, .colorBlend = { diff --git a/src/Engine/Graphics/VertexData.h b/src/Engine/Graphics/VertexData.h index 724c096..b2cad79 100644 --- a/src/Engine/Graphics/VertexData.h +++ b/src/Engine/Graphics/VertexData.h @@ -77,7 +77,10 @@ class VertexData { const Array& getTransparentData() const { return transparentData; } const Array& getRayTracingData() const { return rayTracingScene; } const MeshData& getMeshData(MeshId id) const { return meshData[id]; } - void registerBottomLevelAccelerationStructure(Gfx::PBottomLevelAS blas) { dataToBuild.add(blas); } + void registerBottomLevelAccelerationStructure(Gfx::PBottomLevelAS blas) { + assert(blas != nullptr); + dataToBuild.add(blas); + } uint64 getIndicesOffset(uint32 meshletIndex) { return meshlets[meshletIndex].indicesOffset; } uint64 getNumInstances() const { return instanceData.size(); } static List getList(); diff --git a/src/Engine/Graphics/slang-compile.cpp b/src/Engine/Graphics/slang-compile.cpp index a7453d5..202feb2 100644 --- a/src/Engine/Graphics/slang-compile.cpp +++ b/src/Engine/Graphics/slang-compile.cpp @@ -142,7 +142,7 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg for (size_t i = 0; i < signature->getParameterCount(); ++i) { auto param = signature->getParameterByIndex(i); layout->addMapping(param->getName(), param->getBindingIndex()); - std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl; + //std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl; } // workaround