Compare commits
No commits in common. "main" and "v1.1.0" have entirely different histories.
@ -1,104 +0,0 @@
|
||||
name: Build & Release
|
||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
Windows-AMD64-Build:
|
||||
runs-on: windows-x86_64
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Building/Compiling/Installing Project
|
||||
run: |
|
||||
cd ${{ gitea.workspace }}
|
||||
cmake -A x64 -DCMAKE_BUILD_TYPE=Release --preset=default .
|
||||
cd build
|
||||
cmake --build . --config Release
|
||||
|
||||
- name: Creating Appropriate Directories
|
||||
run: |
|
||||
cd ${{ gitea.workspace }}
|
||||
mv build/Release/Pong.exe .
|
||||
mv build/Release/zlib1.dll .
|
||||
|
||||
- name: Zipping Binaries
|
||||
run: |
|
||||
cd ${{ gitea.workspace }}
|
||||
tar -a -c -f pong-windows-amd64.zip Pong.exe zlib1.dll resources
|
||||
|
||||
- uses: https://github.com/actions/setup-go@v4
|
||||
with:
|
||||
go-version: '>=1.20.1'
|
||||
|
||||
- name: Use Go Action
|
||||
id: use-go-action
|
||||
uses: https://gitea.com/actions/release-action@main
|
||||
with:
|
||||
files: |-
|
||||
pong-windows-amd64.zip
|
||||
api_key: '${{secrets.RELEASE_TOKEN}}'
|
||||
|
||||
Linux-AMD64-Build:
|
||||
runs-on: linux-x86_64
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Installing Dependencies
|
||||
run: |
|
||||
sudo pacman -S --noconfirm zip alsa-lib libxcb xcb-util-cursor vulkan-headers mesa
|
||||
|
||||
- name: Building/Compiling/Installing Project
|
||||
run: |
|
||||
cd ${{ gitea.workspace }}
|
||||
cmake -DCMAKE_BUILD_TYPE=Release .
|
||||
cmake --build . --config Release
|
||||
|
||||
- name: Zipping Binaries
|
||||
run: zip -r pong-linux-amd64.zip Pong resources
|
||||
|
||||
- uses: https://github.com/actions/setup-go@v4
|
||||
with:
|
||||
go-version: '>=1.20.1'
|
||||
|
||||
- name: Use Go Action
|
||||
id: use-go-action
|
||||
uses: https://gitea.com/actions/release-action@main
|
||||
with:
|
||||
files: |-
|
||||
pong-linux-amd64.zip
|
||||
api_key: '${{secrets.RELEASE_TOKEN}}'
|
||||
|
||||
Linux-AARCH64-Build:
|
||||
runs-on: linux-aarch64
|
||||
steps:
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Installing Dependencies
|
||||
run: sudo apt install -y zip libasound2-dev libxcb1-dev libxcb-xinput-dev libxcb-cursor-dev vulkan-headers
|
||||
|
||||
- name: Building/Compiling/Installing Project
|
||||
run: |
|
||||
cd ${{ gitea.workspace }}
|
||||
cmake -DCMAKE_BUILD_TYPE=Release .
|
||||
cmake --build . --config Release
|
||||
|
||||
- name: Zipping Binaries
|
||||
run: zip -r pong-linux-aarch64.zip Pong resources
|
||||
|
||||
- uses: https://github.com/actions/setup-go@v4
|
||||
with:
|
||||
go-version: '>=1.20.1'
|
||||
|
||||
- name: Use Go Action
|
||||
id: use-go-action
|
||||
uses: https://gitea.com/actions/release-action@main
|
||||
with:
|
||||
files: |-
|
||||
pong-linux-aarch64.zip
|
||||
api_key: '${{secrets.RELEASE_TOKEN}}'
|
@ -2,7 +2,7 @@
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ClangTidy" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="clangTidyChecks" value="-*,bugprone-argument-comment,bugprone-assert-side-effect,bugprone-bad-signal-to-kill-thread,bugprone-branch-clone,bugprone-copy-constructor-init,bugprone-dangling-handle,bugprone-dynamic-static-initializers,bugprone-fold-init-type,bugprone-forward-declaration-namespace,bugprone-forwarding-reference-overload,bugprone-inaccurate-erase,bugprone-incorrect-roundings,bugprone-integer-division,bugprone-lambda-function-name,bugprone-macro-parentheses,bugprone-macro-repeated-side-effects,bugprone-misplaced-operator-in-strlen-in-alloc,bugprone-misplaced-pointer-arithmetic-in-alloc,bugprone-misplaced-widening-cast,bugprone-move-forwarding-reference,bugprone-multiple-statement-macro,bugprone-no-escape,bugprone-parent-virtual-call,bugprone-posix-return,bugprone-reserved-identifier,bugprone-sizeof-container,bugprone-sizeof-expression,bugprone-spuriously-wake-up-functions,bugprone-string-constructor,bugprone-string-integer-assignment,bugprone-string-literal-with-embedded-nul,bugprone-suspicious-enum-usage,bugprone-suspicious-include,bugprone-suspicious-memset-usage,bugprone-suspicious-missing-comma,bugprone-suspicious-semicolon,bugprone-suspicious-string-compare,bugprone-suspicious-memory-comparison,bugprone-suspicious-realloc-usage,bugprone-swapped-arguments,bugprone-terminating-continue,bugprone-throw-keyword-missing,bugprone-too-small-loop-variable,bugprone-undefined-memory-manipulation,bugprone-undelegated-constructor,bugprone-unhandled-self-assignment,bugprone-unused-raii,bugprone-unused-return-value,bugprone-use-after-move,bugprone-virtual-near-miss,cert-dcl21-cpp,cert-dcl58-cpp,cert-err34-c,cert-err52-cpp,cert-err60-cpp,cert-flp30-c,cert-msc50-cpp,cert-msc51-cpp,cert-str34-c,cppcoreguidelines-interfaces-global-init,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-slicing,google-default-arguments,google-explicit-constructor,google-runtime-operator,hicpp-exception-baseclass,hicpp-multiway-paths-covered,misc-misplaced-const,misc-new-delete-overloads,misc-no-recursion,misc-non-copyable-objects,misc-throw-by-value-catch-by-reference,misc-unconventional-assign-operator,misc-uniqueptr-reset-release,mpi-buffer-deref,mpi-type-mismatch,openmp-use-default-none,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-string-concatenation,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-trivially-destructible,performance-type-promotion-in-math-fn,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,portability-simd-intrinsics,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-inconsistent-declaration-parameter-name,readability-make-member-function-const,readability-misleading-indentation,readability-misplaced-array-index,readability-non-const-parameter,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-subscript-expr,readability-static-accessed-through-instance,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,readability-use-anyofallof" />
|
||||
<option name="clangTidyChecks" value="-*,bugprone-argument-comment,bugprone-assert-side-effect,bugprone-bad-signal-to-kill-thread,bugprone-branch-clone,bugprone-copy-constructor-init,bugprone-dangling-handle,bugprone-dynamic-static-initializers,bugprone-fold-init-type,bugprone-forward-declaration-namespace,bugprone-forwarding-reference-overload,bugprone-inaccurate-erase,bugprone-incorrect-roundings,bugprone-integer-division,bugprone-lambda-function-name,bugprone-macro-parentheses,bugprone-macro-repeated-side-effects,bugprone-misplaced-operator-in-strlen-in-alloc,bugprone-misplaced-pointer-arithmetic-in-alloc,bugprone-misplaced-widening-cast,bugprone-move-forwarding-reference,bugprone-multiple-statement-macro,bugprone-no-escape,bugprone-parent-virtual-call,bugprone-posix-return,bugprone-reserved-identifier,bugprone-sizeof-container,bugprone-sizeof-expression,bugprone-spuriously-wake-up-functions,bugprone-string-constructor,bugprone-string-integer-assignment,bugprone-string-literal-with-embedded-nul,bugprone-suspicious-enum-usage,bugprone-suspicious-include,bugprone-suspicious-memset-usage,bugprone-suspicious-missing-comma,bugprone-suspicious-semicolon,bugprone-suspicious-string-compare,bugprone-suspicious-memory-comparison,bugprone-suspicious-realloc-usage,bugprone-swapped-arguments,bugprone-terminating-continue,bugprone-throw-keyword-missing,bugprone-too-small-loop-variable,bugprone-undefined-memory-manipulation,bugprone-undelegated-constructor,bugprone-unhandled-self-assignment,bugprone-unused-raii,bugprone-unused-return-value,bugprone-use-after-move,bugprone-virtual-near-miss,cert-dcl21-cpp,cert-dcl58-cpp,cert-err34-c,cert-err52-cpp,cert-err60-cpp,cert-flp30-c,cert-msc50-cpp,cert-msc51-cpp,cert-str34-c,cppcoreguidelines-interfaces-global-init,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-slicing,google-default-arguments,google-explicit-constructor,google-runtime-operator,hicpp-exception-baseclass,hicpp-multiway-paths-covered,misc-misplaced-const,misc-new-delete-overloads,misc-no-recursion,misc-non-copyable-objects,misc-throw-by-value-catch-by-reference,misc-unconventional-assign-operator,misc-uniqueptr-reset-release,mpi-buffer-deref,mpi-type-mismatch,openmp-use-default-none,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-string-concatenation,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-trivially-destructible,performance-type-promotion-in-math-fn,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,portability-simd-intrinsics,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-inconsistent-declaration-parameter-name,readability-make-member-function-const,readability-misleading-indentation,readability-misplaced-array-index,readability-non-const-parameter,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-subscript-expr,readability-static-accessed-through-instance,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,readability-use-anyofallof" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
@ -1,8 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CMakePythonSetting">
|
||||
<option name="pythonIntegrationState" value="YES" />
|
||||
</component>
|
||||
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="ASK" />
|
||||
|
@ -33,55 +33,15 @@ add_executable(Pong
|
||||
Main.cpp
|
||||
)
|
||||
|
||||
find_package(ZLIB REQUIRED)
|
||||
if (ZLIB_FOUND)
|
||||
message(STATUS "ZLIB was found.")
|
||||
else ()
|
||||
message(STATUS "ZLIB was not found.")
|
||||
endif ()
|
||||
|
||||
find_package(OpenSSL REQUIRED)
|
||||
if (OpenSSL_FOUND)
|
||||
message(STATUS "OpenSSL was found.")
|
||||
else ()
|
||||
message(STATUS "OpenSSL was not found.")
|
||||
endif ()
|
||||
|
||||
if (IS_OS_WINDOWS)
|
||||
add_compile_definitions(VK_USE_PLATFORM_WIN32_KHR)
|
||||
|
||||
target_include_directories(Pong PUBLIC ${USER_HOME_DIRECTORY}/EHS/include)
|
||||
target_include_directories(Pong PUBLIC ${USER_HOME_DIRECTORY}/EHE/include)
|
||||
target_include_directories(Pong PUBLIC ${USER_HOME_DIRECTORY}/EHC/include)
|
||||
target_include_directories(Pong PUBLIC ${USER_HOME_DIRECTORY}/LWE/include)
|
||||
target_include_directories(Pong PUBLIC $ENV{VULKAN_SDK}/include)
|
||||
|
||||
message("VK Include Path: $ENV{VULKAN_SDK}/include")
|
||||
|
||||
target_link_directories(Pong PUBLIC "${USER_HOME_DIRECTORY}/EHS/lib")
|
||||
target_link_directories(Pong PUBLIC "${USER_HOME_DIRECTORY}/EHE/lib")
|
||||
target_link_directories(Pong PUBLIC "${USER_HOME_DIRECTORY}/EHC/lib")
|
||||
target_link_directories(Pong PUBLIC "${USER_HOME_DIRECTORY}/LWE/lib")
|
||||
target_link_directories(Pong PUBLIC $ENV{VULKAN_SDK}/lib)
|
||||
|
||||
target_link_libraries(Pong PUBLIC vulkan-1 ws2_32 avrt)
|
||||
|
||||
set(CMAKE_INSTALL_PREFIX "${USER_HOME_DIRECTORY}/LWE")
|
||||
elseif (IS_OS_LINUX)
|
||||
add_compile_definitions(VK_USE_PLATFORM_XCB_KHR EHS_WS_XCB)
|
||||
|
||||
find_package(Vulkan REQUIRED)
|
||||
if (Vulkan_FOUND)
|
||||
message(STATUS "Vulkan was found.")
|
||||
else ()
|
||||
message(STATUS "Vulkan was not found.")
|
||||
endif ()
|
||||
|
||||
target_include_directories(Pong PRIVATE ${USER_HOME_DIRECTORY}/.local/include)
|
||||
|
||||
target_link_directories(Pong PRIVATE "${USER_HOME_DIRECTORY}/.local/lib")
|
||||
|
||||
target_link_libraries(Pong PRIVATE xcb xcb-cursor xcb-xfixes xcb-xinput asound Vulkan::Headers Vulkan::Vulkan)
|
||||
add_compile_definitions(VK_USE_PLATFORM_XCB_KHR)
|
||||
endif()
|
||||
|
||||
target_link_libraries(Pong PRIVATE LWE EHC EHE EHS OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB)
|
||||
target_link_directories(Pong PRIVATE "${USER_HOME_DIRECTORY}/Libraries/LWE/lib")
|
||||
target_include_directories(Pong PRIVATE "${USER_HOME_DIRECTORY}/Libraries/LWE/include")
|
||||
|
||||
find_package(Vulkan REQUIRED)
|
||||
|
||||
target_link_libraries(Pong PRIVATE Vulkan::Headers Vulkan::Vulkan xcb xcb-xfixes xcb-xinput wooting_analog_wrapper LWE z asound)
|
@ -1,12 +0,0 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "default",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"cacheVariables": {
|
||||
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
196
Levels/Game.cpp
@ -1,37 +1,40 @@
|
||||
#include "Game.h"
|
||||
#include "LWE/IO/FontAtlas.h"
|
||||
|
||||
#include <lwe/GameLoop.h>
|
||||
#include <lwe/RenderWindow.h>
|
||||
#include <lwe/systems/AudioSystem.h>
|
||||
#include <lwe/systems/RigidBodySystem.h>
|
||||
#include <lwe/systems/Portrait2DSystem.h>
|
||||
#include <lwe/systems/GuiSystem.h>
|
||||
#include <lwe/coms/AudioSource.h>
|
||||
#include <lwe/coms/AABB2D.h>
|
||||
#include <lwe/coms/Circle.h>
|
||||
#include <lwe/coms/Portrait2D.h>
|
||||
#include <lwe/gpu/GpuFontAtlas.h>
|
||||
#include <lwe/gui/LabelGui.h>
|
||||
#include <ehs/io/audio/Audio.h>
|
||||
#include <ehs/io/hid/Input.h>
|
||||
#include <ehs/io/hid/Keyboard.h>
|
||||
#include <ehs/HRNG.h>
|
||||
#include <ehs/system/CPU.h>
|
||||
#include <LWE/GameLoop.h>
|
||||
#include <LWE/IO/RenderWindow.h>
|
||||
#include <LWE/Systems/AudioSystem.h>
|
||||
#include <LWE/Systems/RigidBodySystem.h>
|
||||
#include <LWE/Systems/Portrait2DSystem.h>
|
||||
#include <LWE/Systems/DynamicsSystem.h>
|
||||
#include <LWE/Systems/GuiSystem.h>
|
||||
#include <LWE/Components/AudioSource.h>
|
||||
#include <LWE/Components/AABB2D.h>
|
||||
#include <LWE/Components/Circle.h>
|
||||
#include <LWE/Components/Portrait2D.h>
|
||||
#include <LWE/Components/Dynamics.h>
|
||||
#include <LWE/Gui/LabelGui.h>
|
||||
#include <LWE/IO/Audio/Audio.h>
|
||||
#include <LWE/IO/HID/Input.h>
|
||||
#include <LWE/IO/HID/GenericInputHandler.h>
|
||||
#include <LWE/IO/HID/Keyboard.h>
|
||||
#include <LWE/HRNG.h>
|
||||
#include <LWE/System/CPU.h>
|
||||
|
||||
const float Game::paddleSpeed = 400.0f;
|
||||
const float Game::ballSpeed = 5000.0f;
|
||||
const float Game::ballSpeed = 15000.0f;
|
||||
|
||||
Game::~Game()
|
||||
{
|
||||
}
|
||||
|
||||
Game::Game()
|
||||
: Level("Game"), plyScore(0), aiScore(0), started(false)
|
||||
: Level("Game"), plyScore(0), aiScore(0)
|
||||
{
|
||||
}
|
||||
|
||||
Game::Game(const Game& lvl)
|
||||
: Level(lvl), plyScore(lvl.plyScore), aiScore(lvl.aiScore), started(lvl.started)
|
||||
: Level(lvl), plyScore(lvl.plyScore), aiScore(lvl.aiScore)
|
||||
{
|
||||
}
|
||||
|
||||
@ -44,34 +47,33 @@ Game& Game::operator=(const Game& lvl)
|
||||
|
||||
plyScore = lvl.plyScore;
|
||||
aiScore = lvl.aiScore;
|
||||
started = lvl.started;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Game::SetupResources(lwe::GpuInterface *inf)
|
||||
void Game::SetupResources()
|
||||
{
|
||||
Level::SetupResources(inf);
|
||||
Level::SetupResources();
|
||||
|
||||
// Setup Resource Code Here
|
||||
AddResource(new lwe::GpuMesh(inf, ehs::portraitGui));
|
||||
AddResource(new lwe::Mesh("PortraitGui", lwe::portraitGuiVerts, lwe::portraitGuiIndices));
|
||||
|
||||
AddResource(new ehs::Audio("resources/audio/Wall.wav", ehs::DataType::FLOAT));
|
||||
AddResource(new ehs::Audio("resources/audio/Paddle.wav", ehs::DataType::FLOAT));
|
||||
AddResource(new ehs::Audio("resources/audio/Score.wav", ehs::DataType::FLOAT));
|
||||
AddResource(lwe::Audio::FromFile_Heap("Resources/Audio/Wall.wav", lwe::DataType::FLOAT));
|
||||
AddResource(lwe::Audio::FromFile_Heap("Resources/Audio/Paddle.wav", lwe::DataType::FLOAT));
|
||||
AddResource(lwe::Audio::FromFile_Heap("Resources/Audio/Score.wav", lwe::DataType::FLOAT));
|
||||
|
||||
constexpr ehs::UInt_8 circleData[] = {255, 255, 255, 255};
|
||||
lwe::GpuImg* circle = new lwe::GpuImg("Circle", inf, 1, 4, {1, 1}, (ehs::Byte*)circleData, lwe::GpuImgAspect::IMG_ASPECT_COLOR);
|
||||
constexpr lwe::UInt_8 circleData[] = {255, 255, 255, 255};
|
||||
lwe::Img* circle = new lwe::Img("Circle", 8, 4, 1, 1, (lwe::Byte*)circleData, lwe::ImgAspect::IMG_ASPECT_COLOR);
|
||||
AddResource(circle);
|
||||
}
|
||||
|
||||
void Game::Setup(lwe::GpuInterface *inf)
|
||||
void Game::Setup()
|
||||
{
|
||||
Level::Setup(inf);
|
||||
Level::Setup();
|
||||
|
||||
// Setup Code Here
|
||||
|
||||
lwe::GameLoop* gl = GetParent();
|
||||
lwe::GameLoop* gl = (lwe::GameLoop*)GetParent("GameLoop");
|
||||
|
||||
lwe::RenderWindow* win = gl->GetWindow();
|
||||
|
||||
@ -79,57 +81,58 @@ void Game::Setup(lwe::GpuInterface *inf)
|
||||
AddSystem(new lwe::AudioSystem());
|
||||
AddSystem(new lwe::Portrait2DSystem());
|
||||
AddSystem(new lwe::RigidBodySystem());
|
||||
AddSystem(new lwe::DynamicsSystem());
|
||||
|
||||
lwe::GuiSystem* gui = new lwe::GuiSystem();
|
||||
gui->AddResource(new lwe::GpuFontAtlas("resources/fonts/Arial_48.ehf", win->GetInterface()));
|
||||
gui->AddResource(new lwe::FontAtlas("Resources/Fonts/Hack-Regular_48.ehf"));
|
||||
AddSystem(gui);
|
||||
|
||||
ehs::Vec2_f scale = win->GetSwapChain()->GetScale();
|
||||
ehs::Vec2_f center = win->GetSwapChain()->GetScale() / 2;
|
||||
lwe::Vec2_f scale = win->GetSwapChain()->GetScale();
|
||||
lwe::Vec2_f center = win->GetSwapChain()->GetScale() / 2;
|
||||
|
||||
// Score Gui
|
||||
lwe::LabelGui* plyScore = new lwe::LabelGui("PlyScore", "Arial_48", "0");
|
||||
plyScore->SetPosition({20.0f, 20.0f, 0.0f});
|
||||
lwe::LabelGui* plyScore = new lwe::LabelGui("PlyScore", "Hack-Regular_48", "0");
|
||||
plyScore->SetPosition({20.0f, 20.0f});
|
||||
gui->AddGui(plyScore);
|
||||
|
||||
lwe::LabelGui* aiScore = new lwe::LabelGui("AiScore", "Arial_48", "0");
|
||||
aiScore->SetPosition({scale.x - 68.0f, 20.0f, 0.0f});
|
||||
lwe::LabelGui* aiScore = new lwe::LabelGui("AiScore", "Hack-Regular_48", "0");
|
||||
aiScore->SetPosition({scale.x - 68.0f, 20.0f});
|
||||
gui->AddGui(aiScore);
|
||||
|
||||
// Bounds Entity
|
||||
lwe::Entity bounds("Bounds");
|
||||
bounds.SetScale({win->GetSwapChain()->GetScale(), 1.0f});
|
||||
lwe::Entity* bounds = new lwe::Entity("Bounds");
|
||||
bounds->SetScale({win->GetSwapChain()->GetScale(), 1.0f});
|
||||
|
||||
lwe::AABB2D* collider = new lwe::AABB2D("BoundsCollider", 0.0f, 0.0f);
|
||||
lwe::AABB2D* collider = new lwe::AABB2D();
|
||||
collider->SetInverted(true);
|
||||
collider->SetStatic(true);
|
||||
bounds.AddComponent(collider);
|
||||
collider->EnableStatic(true);
|
||||
bounds->AddComponent(collider);
|
||||
|
||||
AddEntity(bounds);
|
||||
|
||||
// Field Separator Entity
|
||||
|
||||
lwe::Entity fieldSep("FieldSeparator");
|
||||
fieldSep.SetScale({10.0f, scale.y, 1.0f});
|
||||
fieldSep.SetPos({center.x - 5.0f, 0.0f, 0.0f});
|
||||
lwe::Entity* fieldSep = new lwe::Entity("FieldSeparator");
|
||||
fieldSep->SetScale({10.0f, scale.y, 1.0f});
|
||||
fieldSep->SetPos({center.x - 5.0f, 0.0f, 0.0f});
|
||||
|
||||
lwe::Portrait2D* fieldSepImg = new lwe::Portrait2D("PaddleImg", "Circle");
|
||||
fieldSepImg->SetColor({0.75f});
|
||||
fieldSep.AddComponent(fieldSepImg);
|
||||
fieldSep->AddComponent(fieldSepImg);
|
||||
|
||||
AddEntity(fieldSep);
|
||||
|
||||
// Paddle Entity Template
|
||||
lwe::Entity paddle("Paddle");
|
||||
paddle.SetScale({20.0f, 200.0f, 1.0f});
|
||||
lwe::Entity* paddle = new lwe::Entity("Paddle");
|
||||
paddle->SetScale({20.0f, 200.0f, 1.0f});
|
||||
|
||||
lwe::AABB2D* paddleCollider = new lwe::AABB2D("PaddleCollider", 0.0f, 0.0f);
|
||||
paddleCollider->SetStatic(true);
|
||||
paddle.AddComponent(paddleCollider);
|
||||
lwe::AABB2D* paddleCollider = new lwe::AABB2D("Collider");
|
||||
paddleCollider->EnableStatic(true);
|
||||
paddle->AddComponent(paddleCollider);
|
||||
|
||||
lwe::Portrait2D* paddleImg = new lwe::Portrait2D("PaddleImg", "Circle");
|
||||
paddleImg->SetColor({0.75f});
|
||||
paddle.AddComponent(paddleImg);
|
||||
paddle->AddComponent(paddleImg);
|
||||
|
||||
AddTemplate(paddle);
|
||||
|
||||
@ -142,21 +145,21 @@ void Game::Setup(lwe::GpuInterface *inf)
|
||||
aiPaddle->SetPos({scale.x - 50.0f, center.y - 100.0f, 0.0f});
|
||||
|
||||
// Ball Entity
|
||||
lwe::Entity ball("Ball");
|
||||
ball.SetScale({20.0f, 20.0f, 1.0f});
|
||||
ball.SetPos({center.x - 10.0f, center.y - 10.0f, 0.0f});
|
||||
lwe::Entity* ball = new lwe::Entity("Ball");
|
||||
ball->SetScale({20.0f, 20.0f, 1.0f});
|
||||
ball->SetPos({center.x - 10.0f, center.y - 10.0f, 0.0f});
|
||||
|
||||
lwe::AABB2D* ballCollider = new lwe::AABB2D("BallCollider", 0.5f, 1.1f);
|
||||
lwe::AABB2D* ballCollider = new lwe::AABB2D("Collider");
|
||||
ballCollider->SetCollidedCb([](lwe::RigidBody* a, lwe::RigidBody* b)
|
||||
{
|
||||
lwe::Entity* aOwner = (lwe::Entity*)a->GetEntity();
|
||||
lwe::Entity* bOwner = (lwe::Entity*)b->GetEntity();
|
||||
lwe::Entity* aOwner = (lwe::Entity*)a->GetParent();
|
||||
lwe::Entity* bOwner = (lwe::Entity*)b->GetParent();
|
||||
|
||||
static ehs::UInt_64 id = 0;
|
||||
static lwe::UInt_64 id = 0;
|
||||
|
||||
if (bOwner->GetId() == "Bounds")
|
||||
{
|
||||
lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + ehs::Str_8::FromNum(id++),"Wall");
|
||||
lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + lwe::Str_8::FromNum(id++),"Wall");
|
||||
audio->EnableAutoDelete(true);
|
||||
audio->EnableLoop(false);
|
||||
audio->Play();
|
||||
@ -164,18 +167,21 @@ void Game::Setup(lwe::GpuInterface *inf)
|
||||
}
|
||||
else
|
||||
{
|
||||
lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + ehs::Str_8::FromNum(id++),"Paddle");
|
||||
lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + lwe::Str_8::FromNum(id++),"Paddle");
|
||||
audio->EnableAutoDelete(true);
|
||||
audio->EnableLoop(false);
|
||||
audio->Play();
|
||||
aOwner->AddComponent(audio);
|
||||
}
|
||||
});
|
||||
ball.AddComponent(ballCollider);
|
||||
ball->AddComponent(ballCollider);
|
||||
|
||||
lwe::Dynamics* ballDynamics = new lwe::Dynamics(1.0f, 1.01f);
|
||||
ball->AddComponent(ballDynamics);
|
||||
|
||||
lwe::Portrait2D* ballImg = new lwe::Portrait2D("BallImg", "Circle");
|
||||
ballImg->SetColor({1.0f, 0.0f, 0.0f});
|
||||
ball.AddComponent(ballImg);
|
||||
ball->AddComponent(ballImg);
|
||||
|
||||
AddEntity(ball);
|
||||
}
|
||||
@ -187,78 +193,78 @@ void Game::PostInitialize(lwe::GpuCmdBuffer* cmdBuffer)
|
||||
// Post Initialization Code Here
|
||||
}
|
||||
|
||||
void Game::OnUpdate(lwe::RenderWindow* win, ehs::Input* input, const float delta)
|
||||
void Game::OnUpdate(lwe::Input* input, const float delta)
|
||||
{
|
||||
Level::OnUpdate(win, input, delta);
|
||||
Level::OnUpdate(input, delta);
|
||||
|
||||
// Update Code Here
|
||||
|
||||
const ehs::InputHandler* ih = win->GetInputHandler();
|
||||
const lwe::GenericInputHandler* handler = (lwe::GenericInputHandler*)input->GetHandler("GenericInputHandler");
|
||||
|
||||
const ehs::Keyboard* keyboard = (ehs::Keyboard*)ih->GetDeviceByType(EHS_HID_KEYBOARD);
|
||||
if (!keyboard)
|
||||
return;
|
||||
const lwe::Keyboard* keyboard = handler->GetPrimaryKeyboard();
|
||||
|
||||
lwe::Entity* bounds = GetEntity("Bounds");
|
||||
|
||||
lwe::Entity* ball = GetEntity("Ball");
|
||||
ehs::Vec3_f ballPos = ball->GetPos();
|
||||
ehs::Vec3_f ballScale = ball->GetScale();
|
||||
lwe::Vec3_f ballPos = ball->GetPos();
|
||||
lwe::Vec3_f ballScale = ball->GetScale();
|
||||
|
||||
if (ballPos.x <= bounds->GetPos().x + 10.0f)
|
||||
if (ballPos.x <= bounds->GetPos().x)
|
||||
{
|
||||
aiScore++;
|
||||
|
||||
lwe::GuiSystem* gui = (lwe::GuiSystem*)GetSystem("GuiSystem");
|
||||
lwe::LabelGui* aiScoreLabel = (lwe::LabelGui*)gui->GetGui("AiScore");
|
||||
aiScoreLabel->SetText(ehs::Str_8::FromNum(aiScore));
|
||||
aiScoreLabel->SetText(lwe::Str_8::FromNum(aiScore));
|
||||
|
||||
ResetGame(bounds, ball);
|
||||
}
|
||||
else if (ballPos.x + ballScale.x >= bounds->GetScale().x - 10.0f)
|
||||
else if (ballPos.x + ballScale.x >= bounds->GetScale().x)
|
||||
{
|
||||
plyScore++;
|
||||
|
||||
lwe::GuiSystem* gui = (lwe::GuiSystem*)GetSystem("GuiSystem");
|
||||
lwe::LabelGui* plyScoreLabel = (lwe::LabelGui*)gui->GetGui("PlyScore");
|
||||
plyScoreLabel->SetText(ehs::Str_8::FromNum(plyScore));
|
||||
plyScoreLabel->SetText(lwe::Str_8::FromNum(plyScore));
|
||||
|
||||
ResetGame(bounds, ball);
|
||||
}
|
||||
|
||||
lwe::Entity* plyPaddle = GetEntity("PlyPaddle");
|
||||
|
||||
if (!started && keyboard->IsTouched(ehs::Keyboard::Space))
|
||||
if (!started && keyboard->IsTouched(lwe::Keyboard::Space))
|
||||
{
|
||||
if (!ehs::CPU::HasRDRND())
|
||||
if (!lwe::CPU::HasRDRND())
|
||||
return;
|
||||
|
||||
lwe::AABB2D* ballCollider = (lwe::AABB2D*)ball->GetComponent("AABB2D");
|
||||
lwe::Dynamics* ballDynamics = (lwe::Dynamics*)ball->GetComponent("Dynamics", "");
|
||||
//ballDynamics->ApplyForce({0.0f, ballSpeed, 0.0f});
|
||||
|
||||
if (const ehs::UInt_8 result = ehs::HRNG::Generate_s8(0, 4); result == 0)
|
||||
ballCollider->ApplyForce({ballSpeed, ballSpeed, 0.0f});
|
||||
lwe::UInt_8 result = lwe::HRNG::Generate_s8(0, 4);
|
||||
if (result == 0)
|
||||
ballDynamics->ApplyForce({ballSpeed, ballSpeed, 0.0f});
|
||||
else if (result == 1)
|
||||
ballCollider->ApplyForce({-ballSpeed, ballSpeed, 0.0f});
|
||||
ballDynamics->ApplyForce({-ballSpeed, ballSpeed, 0.0f});
|
||||
else if (result == 2)
|
||||
ballCollider->ApplyForce({ballSpeed, -ballSpeed, 0.0f});
|
||||
ballDynamics->ApplyForce({ballSpeed, -ballSpeed, 0.0f});
|
||||
else if (result == 3)
|
||||
ballCollider->ApplyForce({-ballSpeed, -ballSpeed, 0.0f});
|
||||
ballDynamics->ApplyForce({-ballSpeed, -ballSpeed, 0.0f});
|
||||
|
||||
started = true;
|
||||
}
|
||||
|
||||
if (keyboard->IsDown(ehs::Keyboard::W))
|
||||
if (keyboard->IsDown(lwe::Keyboard::W))
|
||||
{
|
||||
ehs::Vec3_f newPos = plyPaddle->GetPos() - ehs::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
|
||||
lwe::Vec3_f newPos = plyPaddle->GetPos() - lwe::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
|
||||
if (newPos.y <= bounds->GetPos().y)
|
||||
newPos.y = bounds->GetPos().y;
|
||||
|
||||
plyPaddle->SetPos(newPos);
|
||||
}
|
||||
|
||||
if (keyboard->IsDown(ehs::Keyboard::S))
|
||||
if (keyboard->IsDown(lwe::Keyboard::S))
|
||||
{
|
||||
ehs::Vec3_f newPos = plyPaddle->GetPos() + ehs::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
|
||||
lwe::Vec3_f newPos = plyPaddle->GetPos() + lwe::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
|
||||
if (newPos.y + plyPaddle->GetScale().y >= bounds->GetScale().y)
|
||||
newPos.y = bounds->GetScale().y - plyPaddle->GetScale().y;
|
||||
|
||||
@ -266,12 +272,12 @@ void Game::OnUpdate(lwe::RenderWindow* win, ehs::Input* input, const float delta
|
||||
}
|
||||
|
||||
lwe::Entity* aiPaddle = GetEntity("AiPaddle");
|
||||
ehs::Vec3_f aiPaddlePos = aiPaddle->GetPos();
|
||||
ehs::Vec3_f aiPaddleScale = aiPaddle->GetScale();
|
||||
lwe::Vec3_f aiPaddlePos = aiPaddle->GetPos();
|
||||
lwe::Vec3_f aiPaddleScale = aiPaddle->GetScale();
|
||||
|
||||
if (aiPaddlePos.y + aiPaddleScale.y / 2.0f < ballPos.y + ballScale.y / 2.0f)
|
||||
{
|
||||
aiPaddlePos = aiPaddlePos + ehs::Vec3_f(0.0f, paddleSpeed * 2.0f, 0.0f) * delta;
|
||||
aiPaddlePos = aiPaddlePos + lwe::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
|
||||
if (aiPaddlePos.y + aiPaddleScale.y / 2.0f > ballPos.y + ballScale.y / 2.0f)
|
||||
aiPaddlePos.y = ballPos.y + ballScale.y / 2.0f - aiPaddleScale.y / 2.0f;
|
||||
|
||||
@ -282,7 +288,7 @@ void Game::OnUpdate(lwe::RenderWindow* win, ehs::Input* input, const float delta
|
||||
}
|
||||
else
|
||||
{
|
||||
aiPaddlePos = aiPaddlePos - ehs::Vec3_f(0.0f, paddleSpeed * 2.0f, 0.0f) * delta;
|
||||
aiPaddlePos = aiPaddlePos - lwe::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
|
||||
if (aiPaddlePos.y + aiPaddleScale.y / 2.0f < ballPos.y + ballScale.y / 2.0f)
|
||||
aiPaddlePos.y = ballPos.y + ballScale.y / 2.0f - aiPaddleScale.y / 2.0f;
|
||||
|
||||
@ -310,8 +316,8 @@ void Game::ResetGame(const lwe::Entity* bounds, lwe::Entity* ball)
|
||||
|
||||
ball->SetPos(bounds->GetScale() / 2.0f - ball->GetScale() / 2.0f);
|
||||
|
||||
lwe::AABB2D* ballCollider = (lwe::AABB2D*)ball->GetComponent("AABB2D");
|
||||
ballCollider->ResetVelocity();
|
||||
lwe::Dynamics* ballDyn = (lwe::Dynamics*)ball->GetComponent("Dynamics");
|
||||
ballDyn->ResetVelocity();
|
||||
|
||||
started = false;
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <lwe/Level.h>
|
||||
#include <lwe/RenderWindow.h>
|
||||
#include <LWE/LWE.h>
|
||||
#include <LWE/Level.h>
|
||||
|
||||
class Game : public lwe::Level
|
||||
{
|
||||
private:
|
||||
static const float paddleSpeed;
|
||||
static const float ballSpeed;
|
||||
ehs::UInt_64 plyScore;
|
||||
ehs::UInt_64 aiScore;
|
||||
lwe::UInt_64 plyScore;
|
||||
lwe::UInt_64 aiScore;
|
||||
bool started;
|
||||
|
||||
public:
|
||||
@ -21,13 +21,13 @@ public:
|
||||
|
||||
Game& operator=(const Game& lvl);
|
||||
|
||||
void SetupResources(lwe::GpuInterface *inf) override;
|
||||
void SetupResources() override;
|
||||
|
||||
void Setup(lwe::GpuInterface *inf) override;
|
||||
void Setup() override;
|
||||
|
||||
void PostInitialize(lwe::GpuCmdBuffer* cmdBuffer) override;
|
||||
|
||||
void OnUpdate(lwe::RenderWindow* win, ehs::Input* input, const float delta) override;
|
||||
void OnUpdate(lwe::Input* input, const float delta) override;
|
||||
|
||||
void PreRender(lwe::GpuCmdBuffer* cmdBuffer) override;
|
||||
|
||||
|
39
Main.cpp
@ -1,31 +1,37 @@
|
||||
#include <ehs/Log.h>
|
||||
#include <ehs/GC.h>
|
||||
#include <lwe/GameLoop.h>
|
||||
#include <lwe/RenderWindow.h>
|
||||
|
||||
#include <ehs/io/Console.h>
|
||||
#include <LWE/LWE.h>
|
||||
#include <LWE/Log.h>
|
||||
#include <LWE/GarbageCollector.h>
|
||||
#include <LWE/GameLoop.h>
|
||||
#include <LWE/IO/RenderWindow.h>
|
||||
#include <LWE/IO/Console.h>
|
||||
|
||||
#include "Levels/Game.h"
|
||||
#include "LWE/IO/HID/GenericInputHandler.h"
|
||||
|
||||
ehs::SInt_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer)
|
||||
void LogCallback(const lwe::Log& log)
|
||||
{
|
||||
lwe::Console::Write_8(log.ToStr());
|
||||
}
|
||||
|
||||
lwe::SInt_32 Main(lwe::Str_8* appName, lwe::Str_8* appVerId, lwe::Version* appVer)
|
||||
{
|
||||
*appName = "Pong";
|
||||
*appVerId = "Release";
|
||||
*appVer = {1, 0, 0};
|
||||
|
||||
ehs::Log::EnableImmediateMode(true);
|
||||
lwe::Console::Attach();
|
||||
|
||||
ehs::Console::Attach();
|
||||
lwe::Log::SetCallback(LogCallback);
|
||||
|
||||
#if defined(EHS_OS_WINDOWS)
|
||||
#if defined(LWE_OS_WINDOWS)
|
||||
lwe::GpuInstance::AddExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
|
||||
#elif defined(EHS_OS_LINUX)
|
||||
#elif defined(LWE_OS_LINUX)
|
||||
lwe::GpuInstance::AddExtension(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
|
||||
#endif
|
||||
|
||||
lwe::GpuInstance::AddExtension(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
|
||||
lwe::GpuInstance::Initialize(false);
|
||||
lwe::GpuInstance::Initialize(true);
|
||||
|
||||
lwe::GpuDevice primary = lwe::GpuDevice::GetBest();
|
||||
|
||||
@ -40,10 +46,15 @@ ehs::SInt_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVe
|
||||
|
||||
lwe::RenderWindow win(&inf, &queue);
|
||||
win.Create_8(*appName, {0, 0}, {1024, 768});
|
||||
win.Show();
|
||||
|
||||
lwe::GameLoop gl(&win, 6, 0);
|
||||
gl.AddLevel(new Game());
|
||||
gl.GetInput()->AddHandler(new lwe::GenericInputHandler());
|
||||
|
||||
lwe::Frame* mainFrame = new lwe::Frame("Main");
|
||||
|
||||
gl.AddFrame(mainFrame);
|
||||
|
||||
mainFrame->AddLevel(new Game());
|
||||
|
||||
gl.Initialize();
|
||||
gl.Start();
|
||||
|
@ -1,31 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec2 fUv;
|
||||
layout(location = 1) in flat uint fChannels;
|
||||
|
||||
layout(location = 0) out vec4 result;
|
||||
|
||||
layout(binding = 1) uniform Opt
|
||||
{
|
||||
vec4 multiplier;
|
||||
bool preMultiply;
|
||||
} opt;
|
||||
|
||||
layout(binding = 2) uniform sampler2D render;
|
||||
|
||||
void main()
|
||||
{
|
||||
result = opt.multiplier;
|
||||
if (fChannels == 1)
|
||||
result *= vec4(texture(render, fUv).rrr, 1.0f);
|
||||
else if (fChannels == 2)
|
||||
result *= vec4(texture(render, fUv).rrr, texture(render, fUv).g);
|
||||
else if (fChannels == 3)
|
||||
result *= vec4(texture(render, fUv).rgb, 1.0f);
|
||||
else if (fChannels == 4)
|
||||
result *= texture(render, fUv).rgba;
|
||||
|
||||
if (opt.preMultiply)
|
||||
result = vec4(result.rgb * result.a, result.a);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
layout(location = 1) in vec2 vUv;
|
||||
|
||||
layout(location = 0) out vec2 fUv;
|
||||
layout(location = 1) out uint fChannels;
|
||||
|
||||
layout(binding = 0) uniform Transform
|
||||
{
|
||||
mat4 viewProj;
|
||||
vec3 pos;
|
||||
uint channels;
|
||||
vec2 size;
|
||||
} trans;
|
||||
|
||||
mat4 RemoveRotation(mat4 inMat)
|
||||
{
|
||||
inMat[0][0] = 1.0;
|
||||
inMat[0][1] = 0.0;
|
||||
inMat[0][2] = 0.0;
|
||||
inMat[1][0] = 0.0;
|
||||
inMat[1][1] = 1.0;
|
||||
inMat[1][2] = 0.0;
|
||||
inMat[2][0] = 0.0;
|
||||
inMat[2][1] = 0.0;
|
||||
inMat[2][2] = 1.0;
|
||||
|
||||
return inMat;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// The vec4 we will use to set gl_Position
|
||||
vec4 pos = vec4(trans.pos, 1.0f);
|
||||
|
||||
// Adjust the position based on the camera view
|
||||
// Extract the right and up vectors from the view matrix
|
||||
vec3 right = vec3(trans.viewProj[0][0], trans.viewProj[1][0], trans.viewProj[2][0]);
|
||||
vec3 up = vec3(trans.viewProj[0][1], trans.viewProj[1][1], trans.viewProj[2][1]);
|
||||
|
||||
// Adjust the quad vertices to face the camera
|
||||
// The inPosition.xy should be in NDC space, from -1 to 1
|
||||
pos.xyz += (right * vPos.x * trans.size.x) + (up * vPos.y * trans.size.y);
|
||||
|
||||
// Output position
|
||||
gl_Position = trans.viewProj * pos;
|
||||
|
||||
// Pass through the texture coordinates
|
||||
fUv = vUv;
|
||||
fChannels = trans.channels;
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
for file in ./*.vert; do
|
||||
if [ -f "$file" ]; then
|
||||
filename=$(basename -- "$file")
|
||||
|
||||
echo "Compiling vertex shader, ${filename}"
|
||||
|
||||
filename="${filename%.*}"
|
||||
|
||||
glslangValidator -V "${file}" -o "./${filename}_Vert.spv"
|
||||
fi
|
||||
done
|
||||
|
||||
for file in ./*.frag; do
|
||||
if [ -f "$file" ]; then
|
||||
filename=$(basename -- "$file")
|
||||
|
||||
echo "Compiling vertex shader, ${filename}"
|
||||
|
||||
filename="${filename%.*}"
|
||||
|
||||
glslangValidator -V "${file}" -o "./${filename}_Frag.spv"
|
||||
fi
|
||||
done
|
@ -1,22 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec2 fUv;
|
||||
layout(location = 1) in flat uint fChannels;
|
||||
|
||||
layout(location = 0) out vec4 result;
|
||||
|
||||
layout(binding = 1) uniform Opt
|
||||
{
|
||||
vec4 multiplier;
|
||||
} opt;
|
||||
|
||||
layout(binding = 2) uniform sampler2D render;
|
||||
|
||||
void main()
|
||||
{
|
||||
if (fChannels != 1)
|
||||
return;
|
||||
|
||||
result = vec4(texture(render, fUv).rrrr) * opt.multiplier;
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
layout(location = 1) in vec2 vUv;
|
||||
|
||||
layout(location = 0) out vec2 fUv;
|
||||
layout(location = 1) out flat uint fChannels;
|
||||
|
||||
layout(binding = 0) uniform Transform
|
||||
{
|
||||
mat4 proj;
|
||||
mat4 view;
|
||||
mat4 model;
|
||||
int channels;
|
||||
} trans;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = trans.proj * trans.view * trans.model * vec4(vPos, 1.0);
|
||||
|
||||
fUv = vUv;
|
||||
fChannels = trans.channels;
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec2 vUv;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
layout(binding = 1) uniform sampler2D render;
|
||||
|
||||
void main() {
|
||||
outColor = texture(render, vUv);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
layout(location = 1) in vec2 vUv;
|
||||
|
||||
layout(location = 0) out vec2 fUv;
|
||||
|
||||
layout(binding = 0) uniform UniformBufferObject {
|
||||
mat4 mvp;
|
||||
} ubo;
|
||||
|
||||
void main() {
|
||||
gl_Position = ubo.mvp * vec4(vPos, 1.0);
|
||||
|
||||
fUv = vUv;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec2 glyphUV;
|
||||
layout(location = 1) in vec4 glyphColor;
|
||||
|
||||
layout(location = 0) out vec4 result;
|
||||
|
||||
layout(std140, binding = 1) uniform Opt
|
||||
{
|
||||
bool preMultiply;
|
||||
} opt;
|
||||
|
||||
layout(binding = 2) uniform sampler2D atlas;
|
||||
|
||||
void main()
|
||||
{
|
||||
result = vec4(glyphColor.r, glyphColor.g, glyphColor.b, glyphColor.a * texture(atlas, glyphUV).r);
|
||||
if (opt.preMultiply)
|
||||
result = vec4(result.rgb * result.a, result.a);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
layout(location = 1) in vec2 vUv;
|
||||
|
||||
layout(location = 0) out vec2 glyphUV;
|
||||
layout(location = 1) out vec4 glyphColor;
|
||||
|
||||
layout(std140, binding = 0) uniform Data
|
||||
{
|
||||
mat4 proj;
|
||||
mat4 view;
|
||||
mat4 model;
|
||||
vec4 color;
|
||||
} data;
|
||||
|
||||
void main() {
|
||||
gl_Position = data.proj * data.view * data.model * vec4(vPos, 1.0);
|
||||
|
||||
glyphUV = vUv;
|
||||
glyphColor = data.color;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec2 fUv;
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
layout(binding = 1) uniform Material
|
||||
{
|
||||
vec3 lightColor;
|
||||
} material;
|
||||
|
||||
layout(binding = 2) uniform sampler2D render;
|
||||
|
||||
void main() {
|
||||
vec4 result = texture(render, fUv);
|
||||
if (result.rgb == vec3(1.0f, 1.0f, 1.0f))
|
||||
result = vec4(material.lightColor, 1.0f);
|
||||
|
||||
outColor = vec4(result.rgb, 1.0f);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(binding = 0) uniform Transform {
|
||||
mat4 mvp;
|
||||
} transform;
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
layout(location = 1) in vec2 vUv;
|
||||
|
||||
layout(location = 0) out vec2 fUv;
|
||||
|
||||
void main() {
|
||||
gl_Position = transform.mvp * vec4(vPos, 1.0);
|
||||
|
||||
fUv = vUv;
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec2 fUv;
|
||||
|
||||
layout(location = 0) out vec4 result;
|
||||
|
||||
layout(binding = 1) uniform Opt
|
||||
{
|
||||
vec3 color;
|
||||
bool preMultiply;
|
||||
} opt;
|
||||
|
||||
layout(binding = 2) uniform sampler2D render;
|
||||
|
||||
void main()
|
||||
{
|
||||
result = texture(render, fUv).rgba;
|
||||
|
||||
if (result.rgb == vec3(1.0f, 1.0f, 1.0f))
|
||||
result *= vec4(opt.color, 1.0f);
|
||||
|
||||
|
||||
if (opt.preMultiply)
|
||||
result = vec4(result.rgb * result.a, result.a);
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
layout(location = 1) in vec2 vUv;
|
||||
|
||||
layout(location = 0) out vec2 fUv;
|
||||
|
||||
layout(binding = 0) uniform Transform
|
||||
{
|
||||
mat4 viewProj;
|
||||
vec3 pos;
|
||||
vec2 size;
|
||||
} trans;
|
||||
|
||||
mat4 RemoveRotation(mat4 inMat)
|
||||
{
|
||||
inMat[0][0] = 1.0;
|
||||
inMat[0][1] = 0.0;
|
||||
inMat[0][2] = 0.0;
|
||||
inMat[1][0] = 0.0;
|
||||
inMat[1][1] = 1.0;
|
||||
inMat[1][2] = 0.0;
|
||||
inMat[2][0] = 0.0;
|
||||
inMat[2][1] = 0.0;
|
||||
inMat[2][2] = 1.0;
|
||||
|
||||
return inMat;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// The vec4 we will use to set gl_Position
|
||||
vec4 pos = vec4(trans.pos, 1.0f);
|
||||
|
||||
// Adjust the position based on the camera view
|
||||
// Extract the right and up vectors from the view matrix
|
||||
vec3 right = vec3(trans.viewProj[0][0], trans.viewProj[1][0], trans.viewProj[2][0]);
|
||||
vec3 up = vec3(trans.viewProj[0][1], trans.viewProj[1][1], trans.viewProj[2][1]);
|
||||
|
||||
// Adjust the quad vertices to face the camera
|
||||
// The inPosition.xy should be in NDC space, from -1 to 1
|
||||
pos.xyz += (right * vPos.x * trans.size.x) + (up * vPos.y * trans.size.y);
|
||||
|
||||
// Output position
|
||||
gl_Position = trans.viewProj * pos;
|
||||
|
||||
// Pass through the texture coordinates
|
||||
fUv = vUv;
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
|
||||
struct AmbientPointLight
|
||||
{
|
||||
vec3 color;
|
||||
vec3 pos;
|
||||
};
|
||||
|
||||
struct PointLight
|
||||
{
|
||||
vec3 color;
|
||||
float constant;
|
||||
vec3 pos;
|
||||
float linear;
|
||||
float quadratic;
|
||||
};
|
||||
|
||||
struct SpotLight
|
||||
{
|
||||
vec3 color;
|
||||
float innerCutOff;
|
||||
vec3 pos;
|
||||
float outerCutOff;
|
||||
vec3 dir;
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
};
|
||||
|
||||
layout(std140, binding = 2) uniform Data
|
||||
{
|
||||
vec3 ambient;
|
||||
bool preMultiply;
|
||||
vec4 multiplier;
|
||||
uint ambientPointLightCount;
|
||||
uint pointLightCount;
|
||||
uint spotLightCount;
|
||||
AmbientPointLight ambientLights[MAX_LIGHTS];
|
||||
PointLight pointLights[MAX_LIGHTS];
|
||||
SpotLight spotLights[MAX_LIGHTS];
|
||||
} data;
|
||||
|
||||
layout(binding = 3) uniform sampler2D colorMap;
|
||||
layout(binding = 4) uniform sampler2D normalMap;
|
||||
layout(binding = 5) uniform sampler2D specularMap;
|
||||
|
||||
layout(location = 0) in vec4 fVertPos;
|
||||
layout(location = 1) in vec3 fTanPos;
|
||||
layout(location = 2) in vec2 fUV;
|
||||
layout(location = 3) in vec3 fViewPos;
|
||||
layout(location = 4) in mat3 fTBN;
|
||||
|
||||
layout(location = 0) out vec4 result;
|
||||
|
||||
vec3 CalcAmbientPointLight(vec3 normal, vec3 vertexPos, vec3 viewDir, AmbientPointLight light)
|
||||
{
|
||||
vec3 lightDir = normalize(light.pos - vertexPos);
|
||||
|
||||
vec3 diffuse = light.color * max(dot(normal, lightDir), 0.0f);
|
||||
|
||||
vec3 specular = light.color * pow(max(dot(normal, normalize(lightDir + viewDir)), 0.0), texture(specularMap, fUV).r);
|
||||
|
||||
return diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcPointLight(vec3 normal, vec3 vertexPos, vec3 viewDir, PointLight light)
|
||||
{
|
||||
vec3 lightDir = normalize(light.pos - vertexPos);
|
||||
|
||||
float dist = length(light.pos - vertexPos);
|
||||
|
||||
float attenuation = 1.0f / (light.constant + light.linear * dist + light.quadratic * (dist * dist));
|
||||
|
||||
vec3 diffuse = light.color * max(dot(normal, lightDir), 0.0f);
|
||||
|
||||
vec3 specular = light.color * pow(max(dot(normal, normalize(lightDir + viewDir)), 0.0), texture(specularMap, fUV).r);
|
||||
|
||||
return (diffuse + specular) * attenuation;
|
||||
}
|
||||
|
||||
vec3 CalcSpotLight(vec3 normal, vec3 vertexPos, vec3 viewDir, SpotLight light)
|
||||
{
|
||||
vec3 lightDir = normalize(light.pos - vertexPos);
|
||||
|
||||
float dist = length(light.pos - vertexPos);
|
||||
|
||||
float attenuation = 1.0f / (light.constant + light.linear * dist + light.quadratic * (dist * dist));
|
||||
|
||||
float theta = dot(lightDir, normalize(-light.dir));
|
||||
float epsilon = light.innerCutOff - light.outerCutOff;
|
||||
float intensity = clamp((theta - light.outerCutOff) / epsilon, 0.0f, 1.0f);
|
||||
|
||||
vec3 diffuse = light.color * max(dot(normal, lightDir), 0.0f);
|
||||
|
||||
vec3 specular = light.color * pow(max(dot(normal, normalize(lightDir + viewDir)), 0.0), texture(specularMap, fUV).r);
|
||||
|
||||
return (diffuse + specular) * intensity * attenuation;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 viewDir = normalize(fViewPos - fTanPos);
|
||||
vec3 nNorm = normalize(texture(normalMap, fUV).rgb * 2.0f - 1.0f);
|
||||
|
||||
vec3 final = data.ambient;
|
||||
|
||||
//Ambient Point Lights
|
||||
for (uint i = 0; i < data.ambientPointLightCount; ++i)
|
||||
final += CalcAmbientPointLight(nNorm, fVertPos.xyz, viewDir, data.ambientLights[i]);
|
||||
|
||||
//Point Lights
|
||||
for (uint i = 0; i < data.pointLightCount; ++i)
|
||||
final += CalcPointLight(nNorm, fVertPos.xyz, viewDir, data.pointLights[i]);
|
||||
|
||||
//Spot Lights
|
||||
for (uint i = 0; i < data.spotLightCount; ++i)
|
||||
final += CalcSpotLight(nNorm, fVertPos.xyz, viewDir, data.spotLights[i]);
|
||||
|
||||
vec4 tColor = texture(colorMap, fUV);
|
||||
|
||||
result = vec4(tColor.rgb * final * data.multiplier.rgb, tColor.a * data.multiplier.a);
|
||||
|
||||
if (data.preMultiply)
|
||||
result = vec4(result.rgb * result.a, result.a);
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
struct Bone
|
||||
{
|
||||
mat4 trans;
|
||||
};
|
||||
|
||||
layout(std140, binding = 0) uniform Transform
|
||||
{
|
||||
mat4 viewProj;
|
||||
mat4 model;
|
||||
vec3 viewPos;
|
||||
} transform;
|
||||
|
||||
layout(std140, binding = 1) uniform Skin
|
||||
{
|
||||
Bone skeleton[255];
|
||||
} skin;
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
layout(location = 1) in vec3 vNorm;
|
||||
layout(location = 2) in vec2 vUV;
|
||||
layout(location = 3) in vec3 vTan;
|
||||
layout(location = 4) in vec3 vBiTan;
|
||||
layout(location = 5) in uvec4 bones;
|
||||
layout(location = 6) in vec4 weights;
|
||||
|
||||
layout(location = 0) out vec4 fVertPos;
|
||||
layout(location = 1) out vec3 fTanPos;
|
||||
layout(location = 2) out vec2 fUV;
|
||||
layout(location = 3) out vec3 fViewPos;
|
||||
layout(location = 4) out mat3 fTBN;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 totalPos = vec4(0.0f);
|
||||
|
||||
for (uint i = 0; i < 4; ++i)
|
||||
{
|
||||
if (weights[i] == 0.0f)
|
||||
continue;
|
||||
|
||||
totalPos += skin.skeleton[bones[i]].trans * vec4(vPos, 1.0f) * weights[i];
|
||||
}
|
||||
|
||||
fVertPos = transform.model * totalPos;
|
||||
fUV = vUV;
|
||||
|
||||
vec3 T = normalize(vec3(transform.model * vec4(vTan, 0.0f)));
|
||||
vec3 B = normalize(vec3(transform.model * vec4(vBiTan, 0.0f)));
|
||||
vec3 N = normalize(vec3(transform.model * vec4(vNorm, 0.0f)));
|
||||
|
||||
T = normalize(T - dot(T, N) * N);
|
||||
|
||||
fTBN = transpose(mat3(T, B, N));
|
||||
|
||||
fTanPos = fTBN * fVertPos.xyz;
|
||||
fViewPos = fTBN * transform.viewPos;
|
||||
|
||||
gl_Position = transform.viewProj * transform.model * totalPos;
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec2 fUv;
|
||||
layout(location = 1) in flat uint fChannels;
|
||||
|
||||
layout(location = 0) out vec4 result;
|
||||
|
||||
layout(binding = 1) uniform Opt
|
||||
{
|
||||
bool preMultiply;
|
||||
vec4 multiplier;
|
||||
} opt;
|
||||
|
||||
layout(binding = 2) uniform sampler2D render;
|
||||
|
||||
void main()
|
||||
{
|
||||
result = opt.multiplier;
|
||||
if (fChannels == 1)
|
||||
result *= vec4(texture(render, fUv).rrr, 1.0f);
|
||||
else if (fChannels == 2)
|
||||
result *= vec4(texture(render, fUv).rrr, texture(render, fUv).g);
|
||||
else if (fChannels == 3)
|
||||
result *= vec4(texture(render, fUv).rgb, 1.0f);
|
||||
else if (fChannels == 4)
|
||||
result *= texture(render, fUv).rgba;
|
||||
|
||||
if (opt.preMultiply)
|
||||
result = vec4(result.rgb * result.a, result.a);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
layout(location = 1) in vec2 vUv;
|
||||
|
||||
layout(location = 0) out vec2 fUv;
|
||||
layout(location = 1) out flat uint fChannels;
|
||||
|
||||
layout(binding = 0) uniform Transform
|
||||
{
|
||||
mat4 proj;
|
||||
mat4 view;
|
||||
mat4 model;
|
||||
int channels;
|
||||
} trans;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = trans.proj * trans.view * trans.model * vec4(vPos, 1.0);
|
||||
|
||||
fUv = vUv;
|
||||
fChannels = trans.channels;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(std140, binding = 1) uniform Data
|
||||
{
|
||||
vec4 color;
|
||||
} data;
|
||||
|
||||
layout(location = 0) out vec4 result;
|
||||
|
||||
void main()
|
||||
{
|
||||
result = data.color;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(std140, binding = 0) uniform Transform
|
||||
{
|
||||
mat4 viewProj;
|
||||
mat4 model;
|
||||
} transform;
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = transform.viewProj * transform.model * vec4(vPos, 1.0f);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 skyboxUV;
|
||||
|
||||
layout(location = 0) out vec4 result;
|
||||
|
||||
layout(std140, binding = 1) uniform Opt
|
||||
{
|
||||
bool preMultiply;
|
||||
} opt;
|
||||
|
||||
layout(binding = 2) uniform samplerCube skybox;
|
||||
|
||||
void main()
|
||||
{
|
||||
result = texture(skybox, skyboxUV);
|
||||
if (opt.preMultiply)
|
||||
result = vec4(result.rgb * result.a, result.a);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
|
||||
layout(location = 0) out vec3 skyboxUV;
|
||||
|
||||
layout(std140, binding = 0) uniform Data
|
||||
{
|
||||
mat4 viewProj;
|
||||
} data;
|
||||
|
||||
void main()
|
||||
{
|
||||
skyboxUV = vPos;
|
||||
|
||||
vec4 pos = data.viewProj * vec4(vPos, 1.0);
|
||||
|
||||
gl_Position = pos.xyww;
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
|
||||
struct Material
|
||||
{
|
||||
vec4 color;
|
||||
bool diffused;
|
||||
float specular;
|
||||
float shininess;
|
||||
};
|
||||
|
||||
struct AmbientPointLight
|
||||
{
|
||||
vec3 color;
|
||||
vec3 pos;
|
||||
};
|
||||
|
||||
struct PointLight
|
||||
{
|
||||
vec3 color;
|
||||
float constant;
|
||||
vec3 pos;
|
||||
float linear;
|
||||
float quadratic;
|
||||
};
|
||||
|
||||
struct SpotLight
|
||||
{
|
||||
vec3 color;
|
||||
float innerCutOff;
|
||||
vec3 pos;
|
||||
float outerCutOff;
|
||||
vec3 dir;
|
||||
float constant;
|
||||
float linear;
|
||||
float quadratic;
|
||||
};
|
||||
|
||||
layout(std140, binding = 1) uniform Data
|
||||
{
|
||||
vec3 ambient;
|
||||
bool preMultiply;
|
||||
vec3 camPos;
|
||||
Material material;
|
||||
uint ambientPointLightCount;
|
||||
uint pointLightCount;
|
||||
uint spotLightCount;
|
||||
AmbientPointLight ambientLights[MAX_LIGHTS];
|
||||
PointLight pointLights[MAX_LIGHTS];
|
||||
SpotLight spotLights[MAX_LIGHTS];
|
||||
} data;
|
||||
|
||||
layout(location = 1) in vec3 fNorm;
|
||||
layout(location = 0) in vec4 fWorldPos;
|
||||
|
||||
layout(location = 0) out vec4 result;
|
||||
|
||||
vec3 CalcAmbientPointLight(vec3 normal, vec3 vertexPos, vec3 viewDir, Material material, AmbientPointLight light)
|
||||
{
|
||||
vec3 lightDir = normalize(light.pos - vertexPos);
|
||||
|
||||
vec3 diffuse = light.color * max(dot(normal, lightDir), 0.0f);
|
||||
|
||||
vec3 specular = light.color * pow(max(dot(normal, normalize(lightDir + viewDir)), 0.0), material.shininess);
|
||||
|
||||
return diffuse + specular;
|
||||
}
|
||||
|
||||
vec3 CalcPointLight(vec3 normal, vec3 vertexPos, vec3 viewDir, Material material, PointLight light)
|
||||
{
|
||||
vec3 lightDir = normalize(light.pos - vertexPos);
|
||||
|
||||
float dist = length(light.pos - vertexPos);
|
||||
|
||||
float attenuation = 1.0f / (light.constant + light.linear * dist + light.quadratic * (dist * dist));
|
||||
|
||||
vec3 diffuse = light.color * max(dot(normal, lightDir), 0.0f);
|
||||
|
||||
vec3 specular = light.color * pow(max(dot(normal, normalize(lightDir + viewDir)), 0.0), material.shininess);
|
||||
|
||||
return (diffuse + specular) * attenuation;
|
||||
}
|
||||
|
||||
vec3 CalcSpotLight(vec3 normal, vec3 vertexPos, vec3 viewDir, Material material, SpotLight light)
|
||||
{
|
||||
vec3 lightDir = normalize(light.pos - vertexPos);
|
||||
|
||||
float dist = length(light.pos - vertexPos);
|
||||
|
||||
float attenuation = 1.0f / (light.constant + light.linear * dist + light.quadratic * (dist * dist));
|
||||
|
||||
float theta = dot(lightDir, normalize(-light.dir));
|
||||
float epsilon = light.innerCutOff - light.outerCutOff;
|
||||
float intensity = clamp((theta - light.outerCutOff) / epsilon, 0.0f, 1.0f);
|
||||
|
||||
vec3 diffuse = light.color * max(dot(normal, lightDir), 0.0f);
|
||||
|
||||
vec3 specular = light.color * pow(max(dot(normal, normalize(lightDir + viewDir)), 0.0), material.shininess);
|
||||
|
||||
return (diffuse + specular) * intensity * attenuation;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
if (data.material.diffused == true)
|
||||
{
|
||||
vec3 viewDir = normalize(data.camPos - fWorldPos.xyz);
|
||||
vec3 nNorm = normalize(fNorm);
|
||||
|
||||
vec3 final = data.ambient;
|
||||
|
||||
//Ambient Point Lights
|
||||
for (uint i = 0; i < data.ambientPointLightCount; ++i)
|
||||
final += CalcAmbientPointLight(nNorm, fWorldPos.xyz, viewDir, data.material, data.ambientLights[i]);
|
||||
|
||||
//Point Lights
|
||||
for (uint i = 0; i < data.pointLightCount; ++i)
|
||||
final += CalcPointLight(nNorm, fWorldPos.xyz, viewDir, data.material, data.pointLights[i]);
|
||||
|
||||
//Spot Lights
|
||||
for (uint i = 0; i < data.spotLightCount; ++i)
|
||||
final += CalcSpotLight(nNorm, fWorldPos.xyz, viewDir, data.material, data.spotLights[i]);
|
||||
|
||||
//outColor = vec4(data.spotLights[0].quadratic, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
result = vec4(data.material.color.rgb * final, data.material.color.a);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = data.material.color;
|
||||
}
|
||||
|
||||
if (data.preMultiply)
|
||||
result = vec4(result.rgb * result.a, result.a);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(std140, binding = 0) uniform Transform
|
||||
{
|
||||
mat4 viewProj;
|
||||
mat4 model;
|
||||
} transform;
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
layout(location = 1) in vec3 vNorm;
|
||||
|
||||
layout(location = 1) out vec3 fNorm;
|
||||
layout(location = 0) out vec4 fWorldPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
fNorm = (transform.model * vec4(vNorm, 0.0f)).xyz;
|
||||
fWorldPos = transform.model * vec4(vPos, 1.0f);
|
||||
|
||||
gl_Position = transform.viewProj * fWorldPos;
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
layout(binding = 1) uniform Shading
|
||||
{
|
||||
vec4 color;
|
||||
bool preMultiply;
|
||||
} shading;
|
||||
|
||||
layout(binding = 1) uniform sampler2D render;
|
||||
|
||||
void main()
|
||||
{
|
||||
outColor = shading.color;
|
||||
|
||||
if (shading.preMultiply)
|
||||
outColor = vec4(outColor.rgb * outColor.a, outColor.a);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
|
||||
layout(binding = 0) uniform UniformBufferObject
|
||||
{
|
||||
mat4 viewProj;
|
||||
mat4 model;
|
||||
} ubo;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = ubo.viewProj * ubo.model * vec4(vPos, 1.0);
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#version 450
|
||||
|
||||
#extension GL_EXT_scalar_block_layout : enable
|
||||
|
||||
#define MAX_WEIGHTS 3
|
||||
#define MAX_BONES 50
|
||||
|
||||
layout(binding = 0) uniform Transform
|
||||
{
|
||||
mat4 viewProj;
|
||||
mat4 model;
|
||||
mat4 bones[MAX_BONES];
|
||||
} transform;
|
||||
|
||||
layout(location = 0) in vec3 vNorm;
|
||||
layout(location = 1) in vec3 vPos;
|
||||
layout(location = 2) in uvec3 vBoneIndices;
|
||||
layout(location = 3) in vec3 vWeights;
|
||||
|
||||
layout(location = 0) out vec3 fNorm;
|
||||
layout(location = 1) out vec4 fWorldPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 totalLocalPos = vec4(0.0f);
|
||||
vec4 totalNormal = vec4(0.0f);
|
||||
|
||||
for (int i = 0; i < MAX_WEIGHTS; ++i)
|
||||
{
|
||||
totalLocalPos += transform.bones[vBoneIndices[i]] * vec4(vPos, 1.0f) * vWeights[i];
|
||||
totalNormal += transform.bones[vBoneIndices[i]] * vec4(vNorm, 0.0f) * vWeights[i];
|
||||
}
|
||||
|
||||
fNorm = (transform.model * totalNormal).xyz;
|
||||
fWorldPos = transform.model * totalLocalPos;
|
||||
|
||||
gl_Position = transform.viewProj * fWorldPos;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec2 vUv;
|
||||
|
||||
layout(location = 0) out vec4 result;
|
||||
|
||||
layout(binding = 1) uniform Opt
|
||||
{
|
||||
bool preMultiply;
|
||||
vec4 multiplier;
|
||||
} opt;
|
||||
|
||||
layout(binding = 2) uniform sampler2D render;
|
||||
|
||||
void main()
|
||||
{
|
||||
result = opt.multiplier * texture(render, vUv);
|
||||
if (opt.preMultiply)
|
||||
result = vec4(result.rgb * result.a, result.a);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(location = 0) in vec3 vPos;
|
||||
layout(location = 1) in vec2 vUv;
|
||||
|
||||
layout(location = 0) out vec2 fUv;
|
||||
|
||||
layout(binding = 0) uniform Transform
|
||||
{
|
||||
mat4 proj;
|
||||
mat4 view;
|
||||
mat4 model;
|
||||
} trans;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = trans.proj * trans.view * trans.model * vec4(vPos, 1.0);
|
||||
|
||||
fUv = vUv;
|
||||
}
|
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 481 KiB |
Before Width: | Height: | Size: 558 KiB |
Before Width: | Height: | Size: 209 KiB |
Before Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 127 B |
Before Width: | Height: | Size: 134 B |
Before Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 186 KiB |
Before Width: | Height: | Size: 143 B |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 131 B |