Skip to content

Commit

Permalink
Lua Scripting Support (#50)
Browse files Browse the repository at this point in the history
* Added initial lua scripting component using sol2 library

* Added external file script support with hot reload

* Improved scripting, added serialization for scripts

* Added exported property support for lua scripts

* Should fix the resulting merge issues

* Moved lua state into LuaScriptManager

* Script properties are now serialized

* More bindings and fixes

* Push script as well

* More script bindings

* Attempt to fix build issues

* Many bug fixes related to/uncovered by scripting

* Fixed a bunch of issues + no more autosave

* Many adjustments

* Update thirdparty license file

* Smaller fixes

* Smaller adjustments

* Update build.yml

* Some improvements

* Fixed the import of a scene from mesh

* Improved CPU performance for scenes with many meshes

* More performance improvements

* Graphics queue submission can now be done async

* Fixed the pipeline again + more improvements

* Fixed many issues

* Keyboard bindings for lua

* Fix code smells and scene

* More changes and an ongoing investigation into Vulkan queues

* Fixed some synchronization/threading issues

* Even more fixes

* Many fixes and improvements

* Trying to find out why artifacts won't run

* Fix build pipeline issue

* Final updates

* More fixes

---------

Co-authored-by: Simon Tippe <[email protected]>
  • Loading branch information
gruco0002 and tippesi committed Mar 24, 2024
1 parent dd9f50f commit 6820993
Show file tree
Hide file tree
Showing 185 changed files with 4,701 additions and 1,527 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
cc: "cl"
cxx: "cl"
configure-options: -DCMAKE_TOOLCHAIN_FILE='${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake'
-DATLAS_TESTS=ON -DATLAS_BINDLESS=OFF -DATLAS_HEADLESS=ON -G Ninja
-DATLAS_TESTS=ON -DATLAS_BINDLESS=OFF -DATLAS_EDITOR=OFF -DATLAS_HEADLESS=ON -G Ninja
parallel: 16
build-type: ${{ matrix.build-type }}

Expand Down Expand Up @@ -256,7 +256,7 @@ jobs:
cc: "gcc"
cxx: "g++"
configure-options: -DCMAKE_TOOLCHAIN_FILE='${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake'
-DATLAS_TESTS=ON -DATLAS_BINDLESS=OFF -DATLAS_HEADLESS=ON -G Ninja
-DATLAS_TESTS=ON -DATLAS_BINDLESS=OFF -DATLAS_EDITOR=OFF -DATLAS_HEADLESS=ON -G Ninja
parallel: 16
build-type: ${{ matrix.build-type }}

Expand Down Expand Up @@ -385,7 +385,7 @@ jobs:
cc: "clang"
cxx: "clang++"
configure-options: -DCMAKE_TOOLCHAIN_FILE='${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake'
-DATLAS_TESTS=ON -DATLAS_BINDLESS=OFF -DATLAS_HEADLESS=ON -G Ninja
-DATLAS_TESTS=ON -DATLAS_BINDLESS=OFF -DATLAS_EDITOR=OFF -DATLAS_HEADLESS=ON -G Ninja
parallel: 16
build-type: ${{ matrix.build-type }}

Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ jobs:
with:
committish: 5786fcb0cb5eb08d1931a230dad9701e7a6c37f0

- name: Delete MSVC tool version
shell: pwsh
# Add additional scripting steps here
run: |
cd 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build'
Get-ChildItem -Recurse *
Remove-Item * -Include 'Microsoft.VCToolsVersion.v143.default.props','Microsoft.VCToolsVersion.v143.default.txt' -Force | Out-Null
Get-ChildItem -Recurse *
- name: Setup Microsoft Visual C++ CLI
uses: ilammy/msvc-dev-cmd@v1

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ data/emissive mesh
data/flying world
data/living room
data/mis
data/ancient
data/farm
data/town
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

if (CYGWIN OR MINGW)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -O3 -std=gnu++11" )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -O3 -std=gnu++20" )
endif()

if (ANDROID)
Expand Down Expand Up @@ -91,6 +91,8 @@ find_package(glslang CONFIG REQUIRED)
find_package(SPIRV-Tools-opt CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(unofficial-joltphysics CONFIG REQUIRED)
find_package(Lua REQUIRED)
find_package(sol2 CONFIG REQUIRED)

if (ATLAS_TESTS)
find_package(GTest CONFIG REQUIRED)
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
![GI scene](wiki/images/intel_sponza.gif) <br/>*Realtime Sponza scene with raytraced GI, AO and reflections (model from [Intel Graphics Research Sample Library](https://www.intel.com/content/www/us/en/developer/topic-technology/graphics-research/samples.html))* <br/>
## Introduction
This is a cross platform toy engine developed in my spare time that is available on Linux, Windows and MacOS.
>**Note:**
>The current version (0.2.0) contains many API changes and is still an active WIP
## Requirements
- Vulkan SDK
- C++20 compatible compiler
Expand All @@ -22,8 +24,6 @@ or while doing the build configuration with CMake. To use vcpkg together with CM
### Compiling the demo application
Run CMake with the option ATLAS_DEMO=ON to include the demo application in the project. For easier use, the vsbuild.bat does exactly
that and launches Visual Studio afterwards. After launching the IDE, set AtlasEngineDemo as your target.
>**Note:**
>In order to start the application properly you might need to change the asset directory in the [demo source file](https://github.com/tippesi/Atlas-Engine/blob/master/src/demo/App.cpp).
### Including the library into your own project
It is possible to compile the engine either as a shared or static library. Set the ATLAS_BUILD_SHARED option accordingly. To make
the library work with its dependencies, the root CMakeLists.txt of this repository has to be added as a subdirectory. As an entry
Expand Down Expand Up @@ -66,10 +66,14 @@ in the LICENSE.md file in the dependency directory.
>The files in the data folder (except the shaders) use a different license.
## Code Example
For a code example have a look at the [demo application](https://github.com/tippesi/Atlas-Engine/tree/master/src/demo).
## Latest executables
The latest non-release executables can be found in the latest run of the [build pipeline](https://github.com/tippesi/Atlas-Engine/actions/workflows/build.yml?query=branch%3Amaster). They contain both the demo application and the editor.
## Screenshots
![Example scene](wiki/images/sponza_rasterized.png) <br/>
*Rasterized image using real time global illumination* <br/>
![Editor](wiki/images/editor.png)
*Sponza demo scene opened in the editor*
![Example scene](wiki/images/sponza_rasterized.png)
*Rasterized image using real time global illumination*
![Example scene](wiki/images/sponza_pathtraced.png)
*Path traced scene*
![Island scene](wiki/images/island.gif) <br/>
*Island demo scene using the terrain and ocean systems* <br/>
![Island scene](wiki/images/island.gif)
*Island demo scene using the terrain and ocean systems*
32 changes: 32 additions & 0 deletions THIRDPARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,38 @@ nlohmann-json
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Lua
---------------------------------------------------------------------------------
Copyright © 1994–2016 Lua.org, PUC-Rio.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sol2
---------------------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2013-2022 Rapptz, ThePhD, and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

JoltPhysics
---------------------------------------------------------------------------------
Copyright 2021 Jorrit Rouwe
Expand Down
2 changes: 1 addition & 1 deletion data/scenes/sponza.aescene

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions data/scripts/cameraAnimation.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- This is a comment

ScriptProperties = {
animationLength = { type = "double", value = 30.0 },
animationActive = { type = "boolean", value = false }
}

animationTime = 0.0

function Update(delta)

local entity = GetThisEntity()
local scene = GetThisScene()

if scene:HasMainCamera() ~= true or ScriptProperties.animationActive.value ~= true then
return
end

local camera = scene:GetMainCamera()
local hierarchy = entity:GetHierarchyComponent()

local children = hierarchy:GetChildren()

if children == nil then
return
end

if #children <= 1 then
return
end

animationTime = animationTime + Atlas.Clock.GetDelta()

local animationProgress = animationTime / ScriptProperties.animationLength.value
if animationProgress >= 1.0 then
return
end

local childProgress = animationProgress * (#children - 1.0)

local lowerChildIndex = math.floor(childProgress)
local upperChildIndex = math.ceil(childProgress)
local childFraction = childProgress - lowerChildIndex

local lowerChildEntity = children[lowerChildIndex + 1]
local upperChildEntity = children[upperChildIndex + 1]

local lowerChildCamera = lowerChildEntity:GetCameraComponent()
local upperChildCamera = upperChildEntity:GetCameraComponent()

camera.location = Glm.Mix(lowerChildCamera:GetLocation(), upperChildCamera:GetLocation(), childFraction)
camera.rotation = Glm.Mix(lowerChildCamera.rotation, upperChildCamera.rotation, childFraction)

end
61 changes: 61 additions & 0 deletions data/scripts/entitySpawner.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-- This is a comment

ScriptProperties = {
spawnEntityName = { type = "string", value = "" },
spawnRate = { type = "double", value = 1.0 }
}

lastSpawn = 0.0

function Update(delta)

local entity = GetThisEntity()
local scene = GetThisScene()
local spawnEntity = scene:GetEntityByName(ScriptProperties.spawnEntityName.value)

if not spawnEntity:IsValid() then
return
end

transform = entity:GetTransformComponent()

spawnTransform = spawnEntity:GetTransformComponent()
spawnRigidBody = spawnEntity:GetRigidBodyComponent()

if spawnTransform == nil or spawnRigidBody == nil or transform == nil then
return
end

local time = Atlas.Clock.Get()
local spawnFraction = 1.0 / ScriptProperties.spawnRate.value

if time - lastSpawn > spawnFraction then
local decomp = Atlas.MatrixDecomposition(transform.globalMatrix)

local spawnCenter = decomp.translation

local deg = math.random(0.0, 1.0) * 2.0 * 3.14159
local dist = math.random(0.0, 1.0) + math.random(0.0, 1.0)

if dist > 1.0 then
dist = 2.0 - dist
end

local dir = Glm.Vec3(math.cos(deg), 0.0, math.sin(deg)) * dist * 5.0

local spawnPoint = dir + spawnCenter
local matrix = Glm.Translate(spawnPoint)

local newEntity = scene:DuplicateEntity(spawnEntity)

local newTransform = newEntity:GetTransformComponent()
local newRigidBody = newEntity:GetRigidBodyComponent()

newRigidBody:SetLinearVelocity(dir)
newTransform:Set(matrix)

lastSpawn = time

Atlas.Log.Warning("New spawn")
end
end
27 changes: 27 additions & 0 deletions data/scripts/example.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- This is a comment

ScriptProperties = {
duplicateEntityName = { type = "string", value = "" }
}

function Update(delta)
entity = GetThisEntity()

transform = entity:GetTransformComponent()
rigidBody = entity:GetRigidBodyComponent()

local time = Atlas.Clock.Get()

local offset = Glm.Vec3(0.0, math.sin(time), 0.0) + Glm.Vec3(0.0, 5.0, 0.0)
local matrix = Glm.Translate(offset)

Atlas.Log.Warning(tostring(offset.y))

transform:Set(matrix)

-- ~= is equal to != in most other languages
if rigidBody ~= nil then
rigidBody:SetLinearVelocity(Glm.Vec3(0.0))
rigidBody:SetAngularVelocity(Glm.Vec3(0.0))
end
end
34 changes: 34 additions & 0 deletions data/scripts/thirdPersonPlayer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- This is a comment

ScriptProperties = {
spawnEntityName = { type = "string", value = "" },
spawnRate = { type = "double", value = 1.0 }
}

lastSpawn = 0.0

function Update(delta)

-- Only update the player rotation if there is input
local playerInput = (Atlas.KeyboardMap.IsKeyPressed(Atlas.Keycode.KeyW, true) or
Atlas.KeyboardMap.IsKeyPressed(Atlas.Keycode.KeyA, true) or
Atlas.KeyboardMap.IsKeyPressed(Atlas.Keycode.KeyS, true) or
Atlas.KeyboardMap.IsKeyPressed(Atlas.Keycode.KeyD, true))

if playerInput ~= true then
return
end

local entity = GetThisEntity()
local scene = GetThisScene()

local camera = entity:GetCameraComponent()
local transform = entity:GetTransformComponent()
local player = entity:GetPlayerComponent()

local rotationMatrix = Glm.Rotate(Glm.Mat4(1.0), camera.rotation.x, Glm.Vec3(0.0, 1.0, 0.0))
local recomposed = Atlas.MatrixDecomposition(rotationMatrix)

player:SetRotation(Glm.Quat(recomposed.rotation))

end
2 changes: 1 addition & 1 deletion data/shader/deferred/direct.csh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void main() {
// for transmissive materials
vec3 shadowNormal = surface.material.transmissive ? dot(-uniforms.light.direction.xyz, geometryNormal) < 0.0 ?
-geometryNormal : geometryNormal : geometryNormal;
shadowFactor = CalculateCascadedShadow(uniforms.light.shadow, cascadeMaps, surface.P,
shadowFactor = CalculateCascadedShadow(uniforms.light.shadow, cascadeMaps, surface.P, vec3(vec2(pixel) + 0.5, 0.0),
shadowNormal, saturate(dot(-uniforms.light.direction.xyz, shadowNormal)));
#endif
#ifdef SCREEN_SPACE_SHADOWS
Expand Down
4 changes: 0 additions & 4 deletions data/shader/fsr2/ffx_fsr2_upsample.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ FfxFloat32x4 ComputeUpsampledColorAndWeight(const AccumulationPassCommonParams p
Deringing(clippingBox, fColorAndWeight.xyz);
}

#if FFX_FSR2_OPTION_UPSAMPLE_SAMPLERS_USE_DATA_HALF && FFX_HALF
#include "ffx_fsr2_force16_end.h"
#endif

return fColorAndWeight;
}

Expand Down
2 changes: 1 addition & 1 deletion data/shader/pathtracer/temporal.csh
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ void main() {
historyRadiance, currentRadiance);
float adjClipBlend = clamp(clipBlend, 0.0, pushConstants.historyClipMax);
currentRadiance = clamp(currentRadiance, currentNeighbourhoodMin, currentNeighbourhoodMax);
//historyRadiance = mix(historyRadiance, currentRadiance, adjClipBlend);
// historyRadiance = mix(historyRadiance, currentRadiance, adjClipBlend);
historyRadiance = YCoCgToRGB(historyRadiance);
currentRadiance = YCoCgToRGB(currentRadiance);
Expand Down
6 changes: 4 additions & 2 deletions data/shader/postprocessing.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ layout(set = 3, binding = 4) uniform UniformBuffer {
float vignettePower;
float vignetteStrength;
vec4 vignetteColor;

vec4 tintColor;
} Uniforms;

const float gamma = 1.0 / 2.2;
Expand Down Expand Up @@ -65,7 +65,7 @@ float ToneMap(float luminance) {

vec3 saturate(vec3 color, float factor) {
const vec3 luma = vec3(0.299, 0.587, 0.114);
vec3 pixelLuminance = vec3(dot(color, luma));
vec3 pixelLuminance = max(vec3(dot(color, luma)), vec3(0.0));
return mix(pixelLuminance, color, factor);
}

Expand Down Expand Up @@ -180,6 +180,8 @@ void main() {
#endif
#endif

color = color * Uniforms.tintColor.rgb;

color = clamp(saturate(color, Uniforms.saturation), vec3(0.0), vec3(1.0));

color = ((color - 0.5) * max(Uniforms.contrast, 0.0)) + 0.5;
Expand Down
Loading

0 comments on commit 6820993

Please sign in to comment.