Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua Scripting Support #50

Merged
merged 39 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
829cd39
Added initial lua scripting component using sol2 library
gruco0002 Feb 11, 2024
c8642b7
Added external file script support with hot reload
tippesi Feb 11, 2024
073c070
Improved scripting, added serialization for scripts
gruco0002 Feb 11, 2024
8d23146
Added exported property support for lua scripts
gruco0002 Feb 13, 2024
7b74a84
Merge branch 'major-rework' into feature/lua-scripting
tippesi Feb 18, 2024
799dcc0
Should fix the resulting merge issues
tippesi Feb 18, 2024
6e0ff49
Merge branch 'major-rework' into feature/lua-scripting
tippesi Feb 25, 2024
a8a34b1
Moved lua state into LuaScriptManager
gruco0002 Feb 25, 2024
6c44a17
Script properties are now serialized
gruco0002 Feb 25, 2024
0ba5a4a
More bindings and fixes
tippesi Feb 25, 2024
aa8eca6
Push script as well
tippesi Feb 25, 2024
b009166
More script bindings
tippesi Feb 25, 2024
a856977
Attempt to fix build issues
tippesi Feb 25, 2024
18b1998
Many bug fixes related to/uncovered by scripting
tippesi Feb 26, 2024
375ce08
Fixed a bunch of issues + no more autosave
tippesi Feb 27, 2024
e1ff73a
Many adjustments
tippesi Feb 28, 2024
bc6e612
Update thirdparty license file
tippesi Feb 28, 2024
83277c7
Smaller fixes
tippesi Feb 28, 2024
d770d93
Smaller adjustments
tippesi Feb 29, 2024
a4f18f3
Update build.yml
tippesi Mar 5, 2024
c6a0a62
Some improvements
tippesi Mar 5, 2024
9fd3871
Merge branch 'feature/lua-scripting' of https://github.com/tippesi/At…
tippesi Mar 5, 2024
ba62ada
Fixed the import of a scene from mesh
tippesi Mar 6, 2024
eb2d8b7
Improved CPU performance for scenes with many meshes
tippesi Mar 6, 2024
3fcc7dd
More performance improvements
tippesi Mar 6, 2024
8cc88a9
Graphics queue submission can now be done async
tippesi Mar 7, 2024
e62e6fa
Merge branch 'major-rework' into feature/lua-scripting
tippesi Mar 7, 2024
0db1bd0
Fixed the pipeline again + more improvements
tippesi Mar 8, 2024
5f75b5e
Fixed many issues
tippesi Mar 9, 2024
8e776e2
Keyboard bindings for lua
tippesi Mar 9, 2024
613c2a1
Fix code smells and scene
tippesi Mar 9, 2024
b3673f8
More changes and an ongoing investigation into Vulkan queues
tippesi Mar 10, 2024
0c8c414
Fixed some synchronization/threading issues
tippesi Mar 11, 2024
51ba3b9
Even more fixes
tippesi Mar 11, 2024
76a780b
Many fixes and improvements
tippesi Mar 15, 2024
710bae7
Trying to find out why artifacts won't run
tippesi Mar 17, 2024
2ef1a74
Fix build pipeline issue
tippesi Mar 20, 2024
4b448de
Final updates
tippesi Mar 23, 2024
c2566ea
More fixes
tippesi Mar 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading