diff --git a/CMakeSettings.json b/CMakeSettings.json index 38f2e2c..a95c7d1 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -5,7 +5,7 @@ "buildCommandArgs": "", "ctestCommandArgs": "", "configurationType": "Debug", - "generator": "Ninja Multi-Config", + "generator": "Ninja", "intelliSenseMode": "windows-msvc-x64", "inheritEnvironments": [ "msvc_x64" ], "cmakeCommandArgs": "-DCMAKE_DEBUG_POSTFIX=\"\" -DCMAKE_PLATFORM=x64", diff --git a/MinecraftClone/Assets/arial.asset b/MinecraftClone/Assets/arial.asset deleted file mode 100644 index 2a8a2bd..0000000 Binary files a/MinecraftClone/Assets/arial.asset and /dev/null differ diff --git a/res/shaders/TextPass.slang b/res/shaders/TextPass.slang index a3144b0..cd2642f 100644 --- a/res/shaders/TextPass.slang +++ b/res/shaders/TextPass.slang @@ -1,23 +1,5 @@ import Common; -struct GlyphInstanceData -{ - float x; - float y; - float z; - float width; - float height; - uint glyphIndex; -}; - -struct TextData -{ - StructuredBuffer glyphs; - SamplerState glyphSampler; - Texture2D glyphTextures[]; -}; -ParameterBlock pText; - struct VertexInput { uint vertexId : SV_VertexID; @@ -31,6 +13,24 @@ struct VertexOutput uint glyphIndex : GLYPHINDEX; }; +struct GlyphInstanceData +{ + float x; + float y; + float z; + float width; + float height; + uint glyphIndex; +}; +struct TextData +{ + StructuredBuffer glyphs; + SamplerState glyphSampler; + Texture2D glyphTextures[]; +}; +ParameterBlock pText; + + [shader("vertex")] VertexOutput vertexMain(VertexInput input) { diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index ae2fdcf..dd8fd7d 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -70,6 +70,10 @@ struct LightEnv layout(set=3) ParameterBlock pLightEnv; +[Differentiable] +float polynomial(float a, float b, float c, float x) { + return a * x * x + b * x + c; +} interface IBRDF { diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index a527235..2fa89f7 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -50,6 +50,8 @@ int main() { AssetImporter::importEnvironmentMap(EnvironmentImportArgs{ .filePath = sourcePath / "import" / "textures" / "newport_loft.hdr", }); + AssetImporter::importTexture(TextureImportArgs{.filePath = sourcePath / "import" / "texture" / "Dirt.png", .importPath = ""}); + getThreadPool().waitIdle(); vd->commitMeshes(); diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index 1ffd5f9..9cc43ab 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -157,8 +157,7 @@ void BasePass::render() { vertexData->getInstanceDataSet()->updateBuffer(VertexData::CULLINGDATA_NAME, 0, cullingBuffer); vertexData->getInstanceDataSet()->writeChanges(); permutation.setVertexData(vertexData->getTypeName()); - const auto& materials = vertexData->getMaterialData(); - for (const auto& materialData : materials) { + for (const auto& materialData : vertexData->getMaterialData()) { // material not used for any active meshes, skip if (materialData.instances.size() == 0) continue; diff --git a/src/Engine/Graphics/slang-compile.cpp b/src/Engine/Graphics/slang-compile.cpp index 06d23f2..dd355e2 100644 --- a/src/Engine/Graphics/slang-compile.cpp +++ b/src/Engine/Graphics/slang-compile.cpp @@ -139,11 +139,9 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef()); CHECK_DIAGNOSTICS(); - //std::cout << info.name << std::endl; for (uint32 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; } // workaround diff --git a/src/Engine/Material/ShaderExpression.h b/src/Engine/Material/ShaderExpression.h index 4dc81bf..f79232c 100644 --- a/src/Engine/Material/ShaderExpression.h +++ b/src/Engine/Material/ShaderExpression.h @@ -4,7 +4,6 @@ #include "Math/Math.h" #include "MinimalEngine.h" - namespace Seele { enum class ExpressionType { UNKNOWN, @@ -184,6 +183,9 @@ struct SwizzleExpression : public ShaderExpression { StaticArray comp = {-1, -1, -1, -1}; SwizzleExpression() {} SwizzleExpression(StaticArray comp) : comp(std::move(comp)) {} + SwizzleExpression(std::string key, std::string target, StaticArray comp) : ShaderExpression(key) { + inputs["target"].source = target; + } virtual ~SwizzleExpression() {} virtual uint64 getIdentifier() const override { return IDENTIFIER; } virtual std::string evaluate(Map& varState) const override; @@ -194,6 +196,11 @@ DEFINE_REF(SwizzleExpression) struct SampleExpression : public ShaderExpression { static constexpr uint64 IDENTIFIER = 0x16; SampleExpression() {} + SampleExpression(std::string key, std::string texture, std::string sampler, std::string texCoords) : ShaderExpression(key) { + inputs["texture"].source = texture; + inputs["sampler"].source = sampler; + inputs["texCoords"].source = texCoords; + } virtual ~SampleExpression() {} virtual uint64 getIdentifier() const override { return IDENTIFIER; } virtual std::string evaluate(Map& varState) const override; @@ -205,8 +212,6 @@ DEFINE_REF(SampleExpression) struct MaterialNode { std::string profile; Map variables; - MaterialNode() {} - ~MaterialNode() {} void save(ArchiveBuffer& buffer) const; void load(ArchiveBuffer& buffer); }; diff --git a/src/Engine/System/MeshUpdater.cpp b/src/Engine/System/MeshUpdater.cpp index 748fea0..ea716e6 100644 --- a/src/Engine/System/MeshUpdater.cpp +++ b/src/Engine/System/MeshUpdater.cpp @@ -9,7 +9,8 @@ MeshUpdater::MeshUpdater(PScene scene) : ComponentSystemaccessComponent(id); if (comp.meshletOffsets.empty()) { for (uint32 i = 0; i < comp.asset->meshes.size(); ++i) { comp.meshletOffsets.add(comp.asset->meshes[i]->vertexData->addCullingMapping(comp.asset->meshes[i]->id)); diff --git a/test.py b/test.py index ae7340f..353c3da 100644 --- a/test.py +++ b/test.py @@ -16,3 +16,11 @@ print(positions) print(indices) +# Create a tensor with attached grads from a numpy array +# Note: We pass zero=True to initialize the grads to zero on allocation +x = spy.Tensor.numpy(device, np.array([1, 2, 3, 4], dtype=np.float32)).with_grads(zero=True) + +# Evaluate the polynomial and ask for a tensor back +# Expecting result = 2x^2 + 8x - 1 +result: spy.Tensor = module.polynomial(a=2, b=8, c=-1, x=x, _result='tensor') +print(result.to_numpy()) \ No newline at end of file