277 Commits

Author SHA1 Message Date
antopilo
6d7a3a09b1 Better far volumetric handling with sky color 2025-04-25 21:20:36 -04:00
antopilo
67916d0307 Added normal maapping + material preview widget 2025-04-25 20:22:41 -04:00
antopilo
30b5ccc339 Volumetric upscaling + support for other types of lights + CSM 2025-04-24 23:18:14 -04:00
antopilo
4f24372a2f Rendering volumetric at quarter res 2025-04-24 19:56:11 -04:00
antopilo
08be51fc2d Merge branch 'vulkan-dev' of https://github.com/antopilo/Nuake into vulkan-dev
# Conflicts:
#	Nuake/Source/Nuake/Modules/QuakeModule/Module.lua
2025-04-24 18:14:27 -04:00
antopilo
eac8c7aab0 Fixed quake module typo 2025-04-24 18:14:10 -04:00
Antoine Pilote
a82e3dec04 Fixed compilation warning 2025-04-24 12:25:45 -04:00
Antoine Pilote
e8c4af6e5c Merge branch 'vulkan-dev' of https://github.com/antopilo/nuake into vulkan-dev
# Conflicts:
#	Nuake/Source/Nuake/Rendering/Vulkan/VulkanRenderer.cpp
2025-04-24 12:16:14 -04:00
Antoine Pilote
b73caaf8b7 GPU validation 2025-04-24 12:13:05 -04:00
antopilo
aeac3a4e47 Added back volumetric 2025-04-23 20:11:42 -04:00
antopilo
e18298a8cb Editor animations/optimization 2025-04-23 00:47:18 -04:00
antopilo
bef8e3d204 Added escape to unselect 2025-04-21 22:59:59 -04:00
antopilo
8b7bdf6376 Added quake BSP importer module 2025-04-21 11:37:56 -04:00
antopilo
23cf27b120 Re-enabled mesh colliders 2025-04-21 11:36:42 -04:00
antopilo
163c3887ac Cleanup code 2025-04-21 11:36:34 -04:00
antopilo
85062d4de5 Live reloading 2025-04-21 11:36:26 -04:00
antopilo
ce89e8b466 Improved filebrowser 2025-04-21 11:35:42 -04:00
antopilo
4052c14567 Better splash screen 2025-04-17 23:18:11 -04:00
antopilo
5c5289ee73 No more random textures when resizing viewport 2025-04-17 22:50:02 -04:00
antopilo
9a3919d633 Fixed crashen when closing window 2025-04-17 22:33:03 -04:00
antopilo
0c4252be5e Manual GPU resource deletion in desctructor 2025-04-17 22:32:53 -04:00
antopilo
e2fd0644e4 Removed test gizmo drawing 2025-04-17 22:32:40 -04:00
antopilo
54b7c4143f Fixed material being wrongly serialized when baking an asset 2025-04-17 22:23:00 -04:00
antopilo
217a4fbcb6 Fixed weird splash screen when loading a project 2025-04-17 22:22:47 -04:00
antopilo
8125d24926 Fixed crash when resizing viewport 2025-04-17 22:13:57 -04:00
antopilo
d276e875a8 Fixed albedo not working when first importing asset 2025-04-17 20:58:38 -04:00
antopilo
5da09282d0 Added PCF smooth shadows 2025-04-17 20:17:31 -04:00
antopilo
a8c38a5a4e Fixed GPU memory leak when stopping starting + disabled tracy by default 2025-04-17 18:39:24 -04:00
antopilo
a809c5a568 Added color in output window 2025-04-17 18:38:58 -04:00
antopilo
d891762b3f Added GPU resource info count 2025-04-17 18:38:49 -04:00
antopilo
d2b9ef97da GPU Cleanup 2025-04-15 23:34:33 -04:00
antopilo
62fe4b360d Logger now outputs color 2025-04-15 19:34:08 -04:00
antopilo
7f65a80ad0 Removed unsused code 2025-04-15 19:34:01 -04:00
antopilo
a46ee129f0 Fixed most vulkan validation layers 2025-04-15 19:33:46 -04:00
antopilo
710d63ad98 Added mouse picking 2025-04-14 21:11:26 -04:00
antopilo
b8bedd6cb2 Selection now works for all gizmos 2025-04-14 17:43:54 -04:00
antopilo
1af791293d Better outline 2025-04-14 17:29:39 -04:00
antopilo
57564645f2 better outline + gizmo interaction 2025-04-14 17:29:23 -04:00
antopilo
5ce9fb6093 Finished outline selection shader 2025-04-14 14:34:26 -04:00
antopilo
804d147492 Progress towards working selection outline 2025-04-14 13:51:14 -04:00
antopilo
cf80cd3471 Gizmo drawing mode 2025-04-14 13:50:30 -04:00
antopilo
153d7e423e Added option to chose gizmo visiblity during gameplay or not 2025-04-14 13:50:20 -04:00
antopilo
f4fd6e78f3 Added spotlight gizmo + yellow gizmo when selected 2025-04-14 10:38:53 -04:00
antopilo
1f219ba8bc Game viewport now resizing 2025-04-13 20:29:45 -04:00
antopilo
e656c01bda Prevent gizmo shortcut when controlling camera 2025-04-13 20:14:00 -04:00
antopilo
ef29123dec Added back viewport overlay + bold fonts on primary buttons 2025-04-13 20:12:26 -04:00
antopilo
3ceeb3e272 Tabbing 2025-04-13 18:18:28 -04:00
antopilo
54eff5f454 Tabbing in scene render pipeline 2025-04-13 18:17:19 -04:00
antopilo
b2510a4365 Finished SSAO and debug lines rendering 2025-04-13 18:16:12 -04:00
antopilo
ad581b1d4e Fixed double gizmo bug in viewport 2025-04-13 16:37:27 -04:00
antopilo
b959d4abc0 Added blur + clamping to ssao 2025-04-13 12:39:03 -04:00
antopilo
dc8d4c54ee Improved ssao 2025-04-13 12:26:08 -04:00
antopilo
7921723d72 Simplified widget drawer 2025-04-13 10:44:48 -04:00
antopilo
193b64e177 Added back SSAO 2025-04-12 17:57:02 -04:00
antopilo
6037d48210 Added support for modules to specifiy DLLs and Libs to be used by the engine 2025-04-05 16:38:15 -04:00
antopilo
5bb4303eff Now bindings works automatically and is smoooth, aslo strings work now 2025-04-04 19:01:01 -04:00
antopilo
a516f09cf5 Added generator to work with prebuild steps 2025-04-04 17:21:08 -04:00
antopilo
bff8ca2be1 Now bindings between coral and and generatedC# correctly working 2025-04-04 17:11:48 -04:00
antopilo
1668363c4e Turned off vulkan validation by default 2025-04-04 16:10:50 -04:00
antopilo
00367c37c9 Added basics for automatic C# -> C++ Bindings 2025-04-04 00:17:07 -04:00
antopilo
2908429b68 C# generator now working with bindings.json 2025-04-03 23:06:54 -04:00
antopilo
c9dfe2706e Dumping bindings.json on load 2025-04-03 21:27:23 -04:00
antopilo
41dd201128 Added generate bindings.json function 2025-04-03 21:27:15 -04:00
antopilo
709633dce6 Added default widget drawer 2025-04-03 21:26:54 -04:00
antopilo
2df8cdf150 Added component registering to modules 2025-04-03 12:37:20 -04:00
antopilo
d6d9c380c4 Merge branch 'vulkan-dev' of https://github.com/antopilo/Nuake into vulkan-dev 2025-04-03 10:02:15 -04:00
Antoine Pilote
06c6aab24e Now using module param volume 2025-04-02 16:57:07 -04:00
Antoine Pilote
2876ee701b Removed audio from core engine and moved to module only 2025-04-02 16:49:53 -04:00
Antoine Pilote
fff6997dd4 Nowcalling module events 2025-04-02 16:49:28 -04:00
Antoine Pilote
ef70a04da9 Added basic events for modules to register to
OnUpdate, OnFixedUpdate, OnSceneLoad, OnGameStateChanged
2025-04-02 16:27:06 -04:00
Antoine Pilote
729ae9050d Moved game state into its own header 2025-04-02 16:26:33 -04:00
Antoine Pilote
0f7a9ebfba Added widget drawer for module settings 2025-04-02 13:19:30 -04:00
antopilo
13dd209424 Cleaned up project settings window.cpp 2025-04-02 00:47:49 -04:00
antopilo
3037813cf4 Merge branch 'vulkan-dev' of https://github.com/antopilo/Nuake into vulkan-dev 2025-04-02 00:23:49 -04:00
antopilo
5ae981db06 Now drawing registred module settings in project settings 2025-04-02 00:23:40 -04:00
antopilo
a99d793b39 Display a message box when the GPU doesnt support required extensions 2025-03-30 20:00:49 -04:00
antopilo
9dba0d2f4b Added OS API to display message boxes 2025-03-30 20:00:29 -04:00
antopilo
68519dc28b Aded function reflection API 2025-03-26 08:59:51 -04:00
antopilo
e81da93173 Started generic class reflection system 2025-03-25 01:15:24 -04:00
antopilo
155c9a8551 More progress on adding invokation API 2025-03-24 23:49:22 -04:00
antopilo
87ba90a6a0 Module reflection system 2025-03-24 22:55:40 -04:00
antopilo
c2d6a12aa5 Added line rasterization mode 2025-03-23 23:05:49 -04:00
antopilo
6b7a19b5b6 Added Stippled line and debug line API and rendering 2025-03-23 22:50:59 -04:00
antopilo
b30f3192b6 Now properly clearing depth textures 2025-03-23 16:56:57 -04:00
antopilo
e8fda9c544 Added LoadOP to render pass 2025-03-23 01:03:42 -04:00
antopilo
58c2193356 Removed debug gizmo quad 2025-03-23 00:08:40 -04:00
antopilo
eb33b8b241 Added back all icon gizmos for all components type 2025-03-23 00:07:11 -04:00
antopilo
1e0d79e0eb Added textured quad to gizmo api 2025-03-23 00:06:54 -04:00
antopilo
8d41c47a93 Now using alpha blending for gizmo 2025-03-23 00:06:25 -04:00
antopilo
9252264154 Removed Z offset from quad mesh + draw a quad for each light 2025-03-22 23:25:05 -04:00
antopilo
85f0eb2c02 Gizmo api now working with a simple quad in the world 2025-03-22 23:17:25 -04:00
antopilo
0243ef83cb Added Gizmo pass and a OnDebugDraw render pipeline pass 2025-03-22 21:56:07 -04:00
antopilo
e232d06ed3 Minor code cleanup 2025-03-22 19:35:46 -04:00
antopilo
ff50932aa4 Fix crash when closing and reopening the same scene editor. Keep cache of previously created dockspaces 2025-03-22 19:16:47 -04:00
antopilo
c065f12801 Fixed title bar appearing when loading a scene 2025-03-22 18:46:50 -04:00
antopilo
994a5843cf Removed useless namespace 2025-03-03 08:58:46 -05:00
antopilo
f3e0267623 Reusing the same code 2025-03-01 12:27:18 -05:00
antopilo
f491f51d7b Viewport now call onResize on game cameras 2025-02-08 18:46:35 -05:00
antopilo
f0d762b8a1 Camera switching between playmode/editor mode now working properly 2025-02-08 18:38:53 -05:00
antopilo
d0c8e84f50 Improved material parsing 2025-02-08 18:38:28 -05:00
antopilo
7182f4c09b Removed commented opengl code 2025-02-08 18:37:59 -05:00
antopilo
151d0be0f1 Fixed inverted embedded image dumping 2025-02-08 18:37:48 -05:00
antopilo
cede05a309 Viewport now resets to the correct camera after changing scene 2025-02-08 18:32:02 -05:00
antopilo
e09dbb671a GLTFBaker Now works with embedded textures 2025-02-08 14:49:29 -05:00
antopilo
809aea6974 Started handling embedded textures 2025-02-06 12:40:31 -05:00
antopilo
ea503a1c85 Fixed imguizmo aspect ratio 2025-02-06 12:40:21 -05:00
antopilo
ee36f98cdd Added back environment clear color 2025-02-02 21:50:13 -05:00
antopilo
6c3debff41 Started work to reenable play mode 2025-02-02 21:49:54 -05:00
antopilo
b10e437e35 When opening a project without any default scene, open a new one on project load 2025-02-02 13:47:25 -05:00
antopilo
5cc18788f7 Silenced a warning 2025-02-02 13:41:30 -05:00
antopilo
d1523f1b17 Fixed nuake.net not loading 2025-02-02 13:39:35 -05:00
antopilo
80aa334bbc Renabled subprocess 2025-02-02 12:52:33 -05:00
antopilo
4335d0ac9c Fixed editor assimp errors 2025-02-02 12:22:01 -05:00
antopilo
3635e1195c Open a new scene when all scene editors are closed 2025-02-02 12:16:29 -05:00
antopilo
41c05f52a1 Fixed new scene button 2025-02-02 12:12:18 -05:00
antopilo
caa94aeff7 Merge branch 'vulkan-dev' of https://github.com/antopilo/Nuake into vulkan-dev 2025-02-02 12:07:13 -05:00
antopilo
d9c495d0fd Made GBuffer pipeline non static 2025-02-02 12:06:57 -05:00
Antoine Pilote
ce2b29ec1c Added assimp config 2025-02-02 11:58:59 -05:00
antopilo
8d92f68cc6 Added a mapping of viewport -> scene renderer 2025-02-02 10:47:29 -05:00
antopilo
e95787824c Reordered headers in VulkanRenderer.h 2025-02-02 10:34:56 -05:00
antopilo
21647c27cf Reimplemented scene editor window caching to fix crash when closing one during iteration 2025-02-02 10:31:08 -05:00
antopilo
bb7d7aafbc Reverted to tonemapped output 2025-02-02 10:22:53 -05:00
antopilo
e99c8423a6 Started reflection based component serialization 2025-02-01 22:17:15 -05:00
antopilo
c13bd36a78 Made light component use reflection 2025-02-01 22:16:58 -05:00
antopilo
4dd5d2516e Started porting outline pass 2025-02-01 22:16:50 -05:00
antopilo
403446b45d Started reflection based component serialization 2025-02-01 13:22:27 -05:00
antopilo
f3b738758d Added comments to module example 2025-02-01 13:22:15 -05:00
antopilo
17f96f5af2 SceneSystemDB now working properly 2025-02-01 12:06:03 -05:00
antopilo
447fa3cdad Fixed gizmo not working properly 2025-02-01 12:05:22 -05:00
antopilo
d2f36082a9 Moved assimp into its own module 2025-02-01 10:53:37 -05:00
antopilo
2ffe62ee01 Removed debug logging 2025-02-01 10:37:56 -05:00
antopilo
bda0043ede Added example C++ module 2025-02-01 10:37:47 -05:00
antopilo
02c05cf0c1 Removed useless cache copy of scene editors when iterating over them to draw 2025-02-01 01:30:05 -05:00
antopilo
a278d960d1 Removed debug testing window for docking 2025-02-01 01:15:14 -05:00
antopilo
680e5f1651 Automatically dock new scene editors + fixed upside down images in filebrowser widget 2025-02-01 01:02:04 -05:00
antopilo
11490f0f57 Fixed static resources generator with new folder structure 2025-02-01 00:38:33 -05:00
antopilo
9d30f160ba Added per frame in flight deletion queue 2025-01-31 23:30:40 -05:00
antopilo
b51a6b1ccb Fixed aspect ratio of editor camera 2025-01-31 23:30:16 -05:00
antopilo
c28b27f38e Fixed default path of new scene editor filebrowser widget 2025-01-31 23:30:09 -05:00
antopilo
f1e6a10cb1 Fixed swapchain not clearing 2025-01-31 22:53:14 -05:00
antopilo
64edf33622 Editor camera now working again in viewport 2025-01-31 22:49:48 -05:00
antopilo
cd6eb2a682 Added GPUManged interface for resource deletion 2025-01-31 20:56:58 -05:00
antopilo
f54fe85d09 Fixed duplicated static images loading 2025-01-31 19:41:06 -05:00
antopilo
edc4b16ffe Fixed assimp compilation 2025-01-31 18:24:25 -05:00
antopilo
f4a36c9a16 Updated submodules URL to new path 2025-01-31 18:14:20 -05:00
antopilo
25185255cc Removed empty folder 2025-01-31 18:10:22 -05:00
antopilo
74fee28303 Updated readme to point towards Data/ 2025-01-31 18:09:04 -05:00
antopilo
1f3a5e02af Refactored folder structure 2025-01-31 18:04:43 -05:00
antopilo
a4e7e7d530 Removed extra files 2025-01-30 22:49:01 -05:00
antopilo
07f93c0509 Renamed to build scripts 2025-01-30 22:44:19 -05:00
antopilo
16e7819ad8 Fixed compilation issue 2025-01-30 22:43:03 -05:00
antopilo
916d7cf1b4 Removed subprocess 2025-01-30 22:41:55 -05:00
antopilo
92a64f19ea Reworked file structure 2025-01-30 22:41:17 -05:00
antopilo
e8a84c98ec Merge branch 'vulkan-dev' of https://github.com/antopilo/Nuake into vulkan-dev 2025-01-30 19:43:55 -05:00
Antoine Pilote
9cceec7035 Updated readme 2025-01-30 13:26:11 -05:00
Antoine Pilote
85eaa46ee3 Set editor as startup project 2025-01-30 13:23:58 -05:00
Antoine Pilote
e4d276974c Added action to copy deps 2025-01-30 13:19:29 -05:00
Antoine Pilote
3650041051 Added VMA manually 2025-01-30 13:05:45 -05:00
Antoine Pilote
292031dbc2 Bye bye vma 2025-01-30 13:04:52 -05:00
Antoine Pilote
475aceed9b vma 2025-01-30 13:04:10 -05:00
Antoine Pilote
31da43228b Removed VMA submodule 2025-01-30 13:03:07 -05:00
antopilo
f6dd41ed9a Started Vulkan Waster management 🗑️ 2025-01-29 23:20:56 -05:00
antopilo
7d0af312ef Cleaned up a lot of old code 2025-01-29 21:33:17 -05:00
antopilo
ea136b729c Can now render 2 scene at once 2025-01-29 19:43:21 -05:00
antopilo
e5fc760938 Fixed viewport rendering behavior, no longer a black screen. Was missing models in pipeline 2025-01-29 17:57:35 -05:00
antopilo
4d316fe280 Drawing multiple scenes, only need to copy to viewport render targets 2025-01-28 23:08:35 -05:00
antopilo
5347fab0ed Fixed viewport leaks + compilation issues 2025-01-27 21:30:18 -05:00
antopilo
83de729716 Started abstraction for scene viewports 2025-01-27 21:12:25 -05:00
antopilo
faf86c05a7 Request to close window 2025-01-26 21:23:44 -05:00
antopilo
c4e79c61ed Multi-scene editing refactor 2025-01-26 20:21:04 -05:00
antopilo
387b82d385 Reorganized folder structure + using template concepts for security 2025-01-26 11:49:37 -05:00
antopilo
a3dc799692 Started editor windows refactor 2025-01-26 00:07:15 -05:00
antopilo
7a2218824d Added debug draw event 2025-01-25 19:19:01 -05:00
antopilo
b70211ee86 Cleaned up VulkanRenderer 2025-01-25 17:10:31 -05:00
antopilo
81bf61221b Better asset baking + manifest scaning on project load 2025-01-25 17:10:20 -05:00
antopilo
cf8e4cad4d Added onSceneLoaded delegate 2025-01-25 17:09:58 -05:00
Antoine Pilote
8831407da0 Resolve ID 2025-01-23 16:13:45 -05:00
antopilo
ec9cbcf18b Fixed runtime compilation + GLTF material baking 2025-01-22 22:18:12 -05:00
antopilo
8faaef0ec6 Asset bakers now support multiple extensions if necessary 2025-01-21 00:47:18 -05:00
antopilo
1728b20cda Finished basic GLTF asset baking thread safe 2025-01-20 23:31:35 -05:00
antopilo
148a792902 Started path for baking assets 2025-01-19 22:22:03 -05:00
antopilo
ebaf70dfbd Started asset baker abstraction 2025-01-18 19:51:10 -05:00
antopilo
745c6a1f32 Added missing texture 2025-01-18 18:49:13 -05:00
antopilo
89ebc5d012 Resource management refactor - added custom file resolver + RID 2025-01-18 17:51:49 -05:00
antopilo
ab534fe929 Some fixes with coral 2025-01-17 17:59:17 -05:00
antopilo
6b53ab6f8f Fixed some of the crashes with new coral 2025-01-16 21:34:08 -05:00
antopilo
51038f4579 Fixed C# premake scripts 2025-01-16 20:19:27 -05:00
antopilo
6dc7765c70 Updated premake4 to latest 2025-01-16 19:58:36 -05:00
antopilo
476a1d6d95 Bumped coral to latest 2025-01-16 19:57:47 -05:00
antopilo
cae58d8bf5 Started bloom pass 2025-01-16 01:02:03 -05:00
antopilo
333ea73d3a Added tonemapping pass 2025-01-13 20:23:55 -05:00
antopilo
9573eba60b Done with CSM for now 2025-01-13 19:08:43 -05:00
antopilo
d5e987a89d Fix render pass not clearing 2025-01-13 01:45:11 -05:00
antopilo
21150ba091 Deleted old pipeline 2025-01-12 23:05:47 -05:00
antopilo
0ed6e06924 Fixed shading pass with new architecture 2025-01-12 22:54:41 -05:00
antopilo
37fd764248 Switched to bool in shader while sending ints! 2025-01-12 22:34:25 -05:00
antopilo
8c592ba87b Fixed wrong camera being used + materials 2025-01-12 22:33:13 -05:00
antopilo
e52bc15eaa More cleanup with scene renderer 2025-01-12 22:14:30 -05:00
antopilo
c0f8e68daf Made some commandbuffer method const 2025-01-12 22:14:10 -05:00
antopilo
1340d71799 Refactoring 2025-01-12 21:46:19 -05:00
antopilo
64d3cb6e01 Cleaned more 2025-01-12 21:27:02 -05:00
antopilo
0725cafbf3 More cleanup 2025-01-12 21:23:22 -05:00
antopilo
e717cbe68b Major code cleanup 2025-01-12 21:11:10 -05:00
antopilo
28e902b176 moved all descriptor to GPU resource + fixed all validation errors 2025-01-12 20:24:31 -05:00
antopilo
2e95d7d2ad compilation fix with static pipeline object 2025-01-12 12:36:35 -05:00
antopilo
8b3f8aefe9 Continued abstracting command buffer 2025-01-12 12:22:52 -05:00
antopilo
3a97be84b4 Added vulkan shader manager 2025-01-12 11:01:47 -05:00
antopilo
95b0e01f0e Started refactor of the scene renderpipeline to support multiple attachments as inputs 2025-01-12 10:44:38 -05:00
antopilo
e203ac5bd8 Started working towards supporting all the splits 2025-01-12 00:02:56 -05:00
antopilo
890b1c44b2 CSM first cascade working 2025-01-11 21:23:49 -05:00
antopilo
3193ebd062 Starting point for CSM projectiong matrix debugging 2025-01-11 00:12:21 -05:00
antopilo
72440a362d Fixed camera view array 2025-01-10 23:36:25 -05:00
antopilo
d419d6019f Bindless Camera views 2025-01-10 21:12:59 -05:00
antopilo
da6b23cb07 work 2025-01-10 19:44:37 -05:00
Antoine Pilote
2c8de739bd Copy camera 2025-01-10 16:44:38 -05:00
Antoine Pilote
996c3e6e16 Push previous work 2025-01-10 16:09:45 -05:00
Antoine Pilote
7e5a45de52 Manually tracking image layout transitions 2025-01-10 13:20:22 -05:00
Antoine Pilote
c0182293ec bump vma 2025-01-10 12:15:59 -05:00
antopilo
13730be45c Started shadow pipeline 2025-01-10 08:24:14 -05:00
antopilo
95e1c38e0b Point, spot and directional lights now working 2025-01-09 23:14:49 -05:00
antopilo
5a0686bd17 Now PBR directional 2025-01-09 22:40:16 -05:00
antopilo
194b81e114 PBR Directional light working 2025-01-09 19:37:55 -05:00
antopilo
8e8fa1cd6d Fixed color attachments not working 2025-01-09 19:21:53 -05:00
antopilo
a197ab62a6 Started shading pass 2025-01-09 19:08:04 -05:00
antopilo
e5671fd47b Fixed errors with descriptors input 2025-01-08 22:18:46 -05:00
antopilo
b40b0045b9 Started automatic sync + transition for render pass 2025-01-08 21:19:23 -05:00
antopilo
49f9f3bbe0 Bindless textures now working 2025-01-08 20:01:24 -05:00
antopilo
f0325e1ce9 Bindless texture buffer now working 2025-01-08 19:23:40 -05:00
antopilo
e60c114acf Started input system 2025-01-08 00:19:09 -05:00
antopilo
3e92a6c7f4 Started pipeline renderpass inputs 2025-01-07 23:25:16 -05:00
antopilo
d2cd2a542c Deleted old GBuffer 2025-01-07 22:00:20 -05:00
antopilo
2bad2b600a Gbuffer now uses new render pass abstraction + deleted all old rendering code 2025-01-07 21:57:42 -05:00
antopilo
bb4b882ed4 Added attachment resizing + viewport scissoring 2025-01-07 19:49:58 -05:00
antopilo
d69c56bed8 Now render passes have execution order and building process 2025-01-07 19:19:17 -05:00
antopilo
0f5172eb04 Progress on render pipeline and render pass abstraction 2025-01-06 14:53:13 -05:00
antopilo
ab09f8efb5 Started RenderPipeline Absraction 2025-01-05 22:45:37 -05:00
antopilo
0dfa62988b render pipeline stuff 2025-01-05 01:53:26 -05:00
antopilo
3d5ad2e131 Fixed normal TBN matrix 2025-01-04 21:39:46 -05:00
antopilo
1471c2849d All material data now works 2025-01-04 20:37:24 -05:00
antopilo
f3486bc316 Now passing material index + buffer 2025-01-04 20:33:29 -05:00
antopilo
3f6de89262 Now rendering to multiple render target 2025-01-04 18:51:11 -05:00
antopilo
c67b9f18e5 Now renders albedo 2025-01-04 15:13:04 -05:00
antopilo
2d07e3777e Added image GPU resource handling + missing texture 2025-01-04 12:02:39 -05:00
antopilo
8d7f587d7e Display buffer names instead in GPU Resources explorer 2025-01-04 11:24:50 -05:00
antopilo
55901f8603 Fixed imguizmo with reverse-z 2025-01-04 11:07:25 -05:00
antopilo
8548fc8133 vma 2025-01-04 03:51:59 -05:00
antopilo
604da83051 Fixed audio file icon causing editor to crash 2025-01-04 03:38:40 -05:00
antopilo
97ba783644 Filebrowser icons done 2025-01-04 03:31:27 -05:00
antopilo
3e10ee032c Fixed mesh deserialization 2025-01-04 03:17:11 -05:00
antopilo
342513e2e5 Fixed size of minimize button 2025-01-04 03:12:48 -05:00
antopilo
0efc76bfaa Reenabled custom titlebar for Vulkan 2025-01-04 03:07:28 -05:00
antopilo
5f39899981 Added images back to the editor 2025-01-04 03:03:17 -05:00
antopilo
e8ad4be39d Icons are back + Texture can now be created from data 2025-01-04 01:54:13 -05:00
antopilo
90c6652074 Now rendering scene models at correct positions + reverse-z 2025-01-03 23:35:05 -05:00
antopilo
1164bd4b0f Cleaned up pipeline builder code 2024-12-25 17:47:06 -05:00
antopilo
3bf57200af Now using GPUResource manager and updated VkVertex to match real vertex struct 2024-12-25 17:01:37 -05:00
antopilo
1a5a8608fc Moved to VkMesh 2024-12-25 16:36:42 -05:00
antopilo
724459e0dd Started abstraction for VkBuffers 2024-12-25 15:43:34 -05:00
antopilo
34bee233e2 Added missing dxc bin files 2024-12-25 13:14:40 -05:00
antopilo
4ea582ddf7 bump vma 2024-12-25 13:08:08 -05:00
antopilo
679eaa456a Removed vulkan module and modified premake 2024-12-25 13:07:23 -05:00
antopilo
519d54df9b update 2024-12-22 11:59:40 -05:00
antopilo
4897c8fb2c Added 3D camera perspective 2024-12-21 15:11:19 -05:00
antopilo
57c767d659 Fixes for descriptor sets 2024-12-21 14:16:50 -05:00
antopilo
8680107227 Added camera descriptor 2024-12-21 13:15:27 -05:00
antopilo
d40144b9e7 Added DXC error reporting 2024-12-21 13:15:12 -05:00
antopilo
002795d29d Started camera buffer 2024-12-21 11:51:30 -05:00
antopilo
24c41f778e Now drawing quad with vertex pulling 2024-12-21 11:02:38 -05:00
antopilo
dfc5b6fa69 Now using vertex pulling with mesh buffers 2024-12-08 00:30:33 -05:00
antopilo
29130dde7f Triangle in render texture 2024-12-07 21:48:59 -05:00
antopilo
cd2e603733 Added VkImages 2024-12-07 13:28:01 -05:00
antopilo
39a0273595 now displaying viewport texture 2024-12-07 00:59:58 -05:00
antopilo
b2d749244f Editor now displaying in Vulkan 2024-12-04 15:25:08 -05:00
antopilo
5ba897ed46 Vulkan compute shaders 2024-12-04 13:26:03 -05:00
antopilo
fb677f8fe6 Added VMA 2024-12-03 00:54:07 -05:00
antopilo
e5c252629b Added delition queue + removed OGL code 2024-12-02 22:24:31 -05:00
antopilo
84a7d5e248 Now vulkan renderer is clearing the screen 2024-12-02 22:09:54 -05:00
2490 changed files with 485102 additions and 42030 deletions

44
.gitmodules vendored
View File

@@ -1,33 +1,33 @@
[submodule "Nuake/dependencies/assimp"]
path = Nuake/dependencies/assimp
[submodule "Nuake/Thirdparty/assimp"]
path = Nuake/Thirdparty/assimp
url = https://github.com/assimp/assimp.git
[submodule "Nuake/dependencies/JoltPhysics"]
path = Nuake/dependencies/JoltPhysics
[submodule "Nuake/Thirdparty/JoltPhysics"]
path = Nuake/Thirdparty/JoltPhysics
url = https://github.com/antopilo/JoltPhysics.git
[submodule "Nuake/dependencies/soloud"]
path = Nuake/dependencies/soloud
[submodule "Nuake/Thirdparty/soloud"]
path = Nuake/Thirdparty/soloud
url = https://github.com/antopilo/soloud.git
[submodule "Nuake/dependencies/Coral"]
path = Nuake/dependencies/Coral
[submodule "Nuake/Thirdparty/Coral"]
path = Nuake/Thirdparty/Coral
url = https://github.com/antopilo/Coral.git
[submodule "Nuake/dependencies/recastnavigation"]
path = Nuake/dependencies/recastnavigation
[submodule "Nuake/Thirdparty/recastnavigation"]
path = Nuake/Thirdparty/recastnavigation
url = https://github.com/antopilo/recastnavigation.git
[submodule "Nuake/dependencies/tracy"]
path = Nuake/dependencies/tracy
[submodule "Nuake/Thirdparty/tracy"]
path = Nuake/Thirdparty/tracy
url = https://github.com/wolfpld/tracy.git
[submodule "Nuake/dependencies/msdf-atlas-gen"]
path = Nuake/dependencies/msdf-atlas-gen
[submodule "Nuake/Thirdparty/msdf-atlas-gen"]
path = Nuake/Thirdparty/msdf-atlas-gen
url = https://github.com/antopilo/msdf-atlas-gen.git
[submodule "Nuake/dependencies/yoga"]
path = Nuake/dependencies/yoga
[submodule "Nuake/Thirdparty/yoga"]
path = Nuake/Thirdparty/yoga
url = https://github.com/facebook/yoga.git
[submodule "Nuake/dependencies/freetype"]
path = Nuake/dependencies/freetype
[submodule "Nuake/Thirdparty/freetype"]
path = Nuake/Thirdparty/freetype
url = https://github.com/freetype/freetype.git
[submodule "Nuake/dependencies/entt"]
path = Nuake/dependencies/entt
[submodule "Nuake/Thirdparty/entt"]
path = Nuake/Thirdparty/entt
url = https://github.com/skypjack/entt.git
[submodule "Nuake/dependencies/glfw"]
path = Nuake/dependencies/glfw
[submodule "Nuake/Thirdparty/glfw"]
path = Nuake/Thirdparty/glfw
url = https://github.com/antopilo/glfw.git

30
BuildScripts/build.bat Normal file
View File

@@ -0,0 +1,30 @@
@echo off
REM Set default values for configuration and platform
set CONFIG=Debug
set PLATFORM=
REM Get solution file path
set SOLUTION=Nuake.sln
REM Check if Configuration is provided
if not "%~2"=="" (
set CONFIG=%~2
)
REM Check if Platform is provided
if not "%~3"=="" (
set PLATFORM=%~3
)
REM Build the solution
echo Building solution "%SOLUTION%" with Configuration=%CONFIG% and Platform=%PLATFORM%...
"C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\MSBuild.exe" "Nuake.sln" -verbosity:minimal
PAUSE
REM Check if build succeeded
if %ERRORLEVEL%==0 (
echo Build succeeded.
) else (
echo Build failed.
exit /b 1
)

View File

@@ -1,2 +1,3 @@
cd ..
premake5 vs2022
pause

File diff suppressed because it is too large Load Diff

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

Before

Width:  |  Height:  |  Size: 988 B

After

Width:  |  Height:  |  Size: 988 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 223 B

After

Width:  |  Height:  |  Size: 223 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 849 B

After

Width:  |  Height:  |  Size: 849 B

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 468 B

After

Width:  |  Height:  |  Size: 468 B

View File

Before

Width:  |  Height:  |  Size: 985 B

After

Width:  |  Height:  |  Size: 985 B

View File

Before

Width:  |  Height:  |  Size: 792 B

After

Width:  |  Height:  |  Size: 792 B

View File

Before

Width:  |  Height:  |  Size: 281 B

After

Width:  |  Height:  |  Size: 281 B

View File

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 205 B

After

Width:  |  Height:  |  Size: 205 B

View File

Before

Width:  |  Height:  |  Size: 168 B

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 572 B

After

Width:  |  Height:  |  Size: 572 B

View File

Before

Width:  |  Height:  |  Size: 240 B

After

Width:  |  Height:  |  Size: 240 B

View File

Before

Width:  |  Height:  |  Size: 626 B

After

Width:  |  Height:  |  Size: 626 B

View File

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

Before

Width:  |  Height:  |  Size: 901 B

After

Width:  |  Height:  |  Size: 901 B

View File

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
Data/Images/splash.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

View File

Before

Width:  |  Height:  |  Size: 546 B

After

Width:  |  Height:  |  Size: 546 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -0,0 +1,28 @@
// HLSL version for Shader Model 6.1
RWTexture2D<float4> image : register(u0);
// Define the size of a thread group
[numthreads(16, 16, 1)]
void main(
uint3 dispatchThreadID : SV_DispatchThreadID,
uint3 groupThreadID : SV_GroupThreadID,
uint3 groupID : SV_GroupID
) {
// Get the size of the image
uint2 size;
image.GetDimensions(size.x, size.y);
// Current texel coordinates
uint2 texelCoord = dispatchThreadID.xy;
if (texelCoord.x < size.x && texelCoord.y < size.y) {
float4 color = float4(0.0, 0.0, 0.0, 1.0);
if (groupThreadID.x != 0 && groupThreadID.y != 0) {
color.x = float(texelCoord.x) / float(size.x);
color.y = float(texelCoord.y) / float(size.y);
}
image[texelCoord] = color;
}
}

View File

@@ -0,0 +1,127 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
[[vk::binding(0, 7)]]
StructuredBuffer<float3> ssaoKernels;
struct PSInput {
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
struct PSOutput {
float4 oColor0 : SV_TARGET;
};
struct BlurConstant
{
int blurSourceID;
float2 sourceSize;
};
[[vk::push_constant]]
BlurConstant pushConstants;
float3 SampleTexture(int textureId, float2 uv)
{
return textures[textureId].Sample(mySampler, uv).rgb;
}
PSOutput main(PSInput input)
{
float2 texelSize = 1.0 / pushConstants.sourceSize;
float3 result = 0.0;
for (int x = -2; x < 2; x++)
{
for (int y = -2; y < 2; y++)
{
float2 offset = float2(x, y) * texelSize;
result += SampleTexture(pushConstants.blurSourceID, input.UV + offset);
}
}
result = result / (4.0 * 4.0);
PSOutput output;
output.oColor0 = float4(result.rgb, 1.0f);
return output;
}

View File

@@ -0,0 +1,110 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
[[vk::binding(0, 7)]]
StructuredBuffer<float3> ssaoKernels;
struct BlurConstant
{
int blurSourceID;
};
[[vk::push_constant]]
BlurConstant pushConstants;
// Outputs
struct VSOutput {
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
Vertex v = vertexBuffer[vertexIndex];
output.UV = float2(v.uv_x, v.uv_y);
output.Position = float4(v.position, 1.0f);
return output;
}

View File

@@ -0,0 +1,124 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct PSInput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
struct PSOutput {
float4 oColor0 : SV_TARGET;
};
struct CopyPushConstant
{
int SourceTextureID;
int Source2TextureID;
int Mode;
};
[[vk::push_constant]]
CopyPushConstant pushConstants;
PSOutput main(PSInput input)
{
PSOutput output;
int sourceTextureID = pushConstants.SourceTextureID;
int source2TextureID = pushConstants.Source2TextureID;
float2 uv = input.UV;
float4 sampleValue = textures[sourceTextureID].Sample(mySampler, input.UV);
float4 sampleValue2 = textures[source2TextureID].Sample(mySampler, input.UV);
if(pushConstants.Mode == 0)
{
output.oColor0 = lerp(sampleValue, sampleValue2, 1.0 - sampleValue.a);
}
else if(pushConstants.Mode == 1)
{
output.oColor0 = sampleValue;
output.oColor0 = sampleValue + sampleValue2;
}
return output;
}

View File

@@ -0,0 +1,110 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct CopyPushConstant
{
int SourceTextureID;
int Source2TextureID;
int Mode;
};
[[vk::push_constant]]
CopyPushConstant pushConstants;
// Outputs
struct VSOutput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
Vertex v = vertexBuffer[vertexIndex];
output.UV = float2(v.uv_x, v.uv_y);
output.Position = float4(v.position, 1.0f);
return output;
}

View File

@@ -0,0 +1,160 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct PSInput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
struct PSOutput {
float4 oColor0 : SV_TARGET;
};
struct DepthAwareBlurConstant
{
int DepthTextureID;
int VolumetricTextureID;
};
[[vk::push_constant]]
DepthAwareBlurConstant pushConstants;
float2 GetTextureSize(Texture2D tex)
{
uint width, height;
tex.GetDimensions(width, height);
return float2(width, height);
}
float PixelToUV(float2 uv, Texture2D tex)
{
float2 texSize = GetTextureSize(tex);
return uv / texSize;
}
PSOutput main(PSInput input)
{
int depthTexture = pushConstants.DepthTextureID;
float upSampledDepth = textures[depthTexture].Sample(mySampler, input.UV).r;
float3 upSampledColor = textures[pushConstants.VolumetricTextureID].Sample(mySampler, input.UV).rgb;
float3 color = 0.0f.xxx;
float totalWeight = 0.0f;
int2 screenCoordinates = int2(input.Position.xy);
int xOffset = (screenCoordinates.x % 2 == 0) ? -1 : 1;
int yOffset = (screenCoordinates.y % 2 == 0) ? -1 : 1;
int2 offsets[] = {int2(0, 0),
int2(0, yOffset),
int2(xOffset, 0),
int2(xOffset, yOffset)};
for (int i = 0; i < 4; i ++)
{
float2 uvOffset = float2(offsets[i].x * 4.0, offsets[i].y * 4.0) ;
uvOffset = PixelToUV(uvOffset, textures[pushConstants.DepthTextureID]);
float3 downscaledColor = textures[pushConstants.VolumetricTextureID].Sample(mySampler, input.UV + uvOffset).rgb;
float downscaledDepth = textures[pushConstants.DepthTextureID].Sample(mySampler, input.UV + uvOffset).r;
float currentWeight = 1.0f;
if(abs(upSampledDepth - downscaledDepth) > 0.0001)
{
//color = float3(1, 0, 0);
currentWeight *= 0.0f;
}
//currentWeight *= max(0.0f, 1.0f - abs(upSampledDepth - downscaledDepth));
color += downscaledColor * currentWeight;
totalWeight += currentWeight;
}
float3 volumetricLight;
const float epsilon = 0.0001f;
volumetricLight.xyz = color / (totalWeight + epsilon);
PSOutput output;
output.oColor0 = float4(volumetricLight.x, volumetricLight.y, volumetricLight.z, 1.0f);
//output.oColor0 = float4(upSampledColor.x, upSampledColor.y, upSampledColor.z, 1.0f);
return output;
}

View File

@@ -0,0 +1,109 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct DepthAwareBlurConstant
{
int DepthTextureID;
int VolumetricTextureID;
};
[[vk::push_constant]]
DepthAwareBlurConstant pushConstants;
// Outputs
struct VSOutput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
Vertex v = vertexBuffer[vertexIndex];
output.UV = float2(v.uv_x, v.uv_y);
output.Position = float4(v.position, 1.0f);
return output;
}

View File

@@ -0,0 +1,146 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct PSInput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
struct PSOutput
{
float4 oColor0 : SV_TARGET;
float4 oEntityID : SV_TARGET1;
};
struct DebugConstant
{
float4 Color;
float4x4 Transform;
int TextureID;
float EntityID;
};
[[vk::push_constant]]
DebugConstant pushConstants;
PSOutput main(PSInput input)
{
PSOutput output;
if(pushConstants.TextureID < 0)
{
output.oColor0 = float4(input.UV.x, input.UV.y, 0, 1);
}
else
{
float2 uv = input.UV;
float4 textureSample = textures[pushConstants.TextureID].Sample(mySampler, uv);
// Alpha scisorring
if(textureSample.a < 0.1)
{
//discard;
}
output.oColor0 = textureSample * pushConstants.Color;
if(pushConstants.EntityID != 0.0f)
{
float2 center = float2(0.5, 0.5);
float dist = distance(uv, center);
float radius = 0.5; // You can adjust this as needed
if (dist <= radius)
{
output.oEntityID = float4(pushConstants.EntityID, 0, 0, 1.0f);
}
else
{
output.oEntityID = float4(0, 0, 0, 0); // Or leave it unassigned if default is zero
discard;
}
}
}
return output;
}

View File

@@ -0,0 +1,111 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct DebugConstant
{
float4 Color;
float4x4 Transform;
int TextureID;
float EntityID;
};
[[vk::push_constant]]
DebugConstant pushConstants;
// Outputs
struct VSOutput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
Vertex v = vertexBuffer[vertexIndex];
output.UV = float2(v.uv_x, v.uv_y);
output.Position = mul(pushConstants.Transform, float4(v.position, 1.0f));
return output;
}

View File

@@ -0,0 +1,110 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct PSInput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
struct PSOutput
{
float4 oColor0 : SV_TARGET;
};
struct LineConstant
{
float4x4 Transform;
float4 Color;
};
[[vk::push_constant]]
LineConstant pushConstants;
PSOutput main(PSInput input)
{
PSOutput output;
output.oColor0 = pushConstants.Color;
return output;
}

View File

@@ -0,0 +1,109 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct LineConstant
{
float4x4 Transform;
float4 Color;
};
[[vk::push_constant]]
LineConstant pushConstants;
// Outputs
struct VSOutput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
Vertex v = vertexBuffer[vertexIndex];
output.UV = float2(v.uv_x, v.uv_y);
output.Position = mul(pushConstants.Transform, float4(v.position, 1.0f));
return output;
}

View File

@@ -0,0 +1,186 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct PSInput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
struct PSOutput {
float4 oColor0 : SV_TARGET;
};
struct OutlinePushConstant
{
float4 Color;
float Thickness;
int SourceTextureID;
int EntityIDTextureID;
int DepthTextureID;
float SelectedEntity;
};
[[vk::push_constant]]
OutlinePushConstant pushConstants;
float2 GetTexelSize(Texture2D tex)
{
uint width, height;
tex.GetDimensions(width, height);
return 1.0 / float2(width, height);
}
float LinearizeDepth(float depth, float nearPlane, float farPlane)
{
return (2.0 * nearPlane) / (farPlane + nearPlane - (1.0 - depth) * (farPlane - nearPlane));
}
PSOutput main(PSInput input)
{
PSOutput output;
float4 outlineColor = pushConstants.Color;
float target = pushConstants.SelectedEntity;
float radius = pushConstants.Thickness;
float2 uv = input.UV;
int entityIDTextureID = pushConstants.EntityIDTextureID;
float hasHit = 0.0f;
float sampleValue = textures[entityIDTextureID].Sample(mySampler, uv).r;
float depth = textures[pushConstants.DepthTextureID].Sample(mySampler, uv).r;
float4 fragColor = float4(0, 0, 0, 0);
const float TAU = 6.28318530;
const float steps = 64.0;
for(float i = 0.0f; i < TAU; i += TAU / steps)
{
float2 uvOffset = float2(cos(i), sin(i)) * (GetTexelSize(textures[entityIDTextureID])) * radius;
float2 sampleUV = uv + uvOffset;
sampleUV.x = clamp(sampleUV.x, 0.0, 0.999);
sampleUV.y = clamp(sampleUV.y, 0.0, 0.999);
float sample = textures[entityIDTextureID].Sample(mySampler, sampleUV).r;
float sampleDepth = textures[pushConstants.DepthTextureID].Sample(mySampler, sampleUV).r;
//sampleDepth = LinearizeDepth(sampleDepth, 0.1f, 200.0f);
//depth = LinearizeDepth(depth, 0.1f, 200.0f);
bool passDepthTest = (sampleDepth > depth);
if(sample == target && passDepthTest)
{
hasHit = 1.0f;
if(passDepthTest && sampleValue == target)
{
//hasHit = 0.0f;
}
}
float alpha = smoothstep(0.1, 0.9, hasHit);
float4 outputColor = float4(
lerp(fragColor.r, outlineColor.r, alpha),
lerp(fragColor.g, outlineColor.g, alpha),
lerp(fragColor.b, outlineColor.b, alpha),
lerp(fragColor.a, outlineColor.a, alpha)
);
fragColor = outputColor;
}
if(fragColor.a > 0.1)
{
fragColor.a = 1.0f;
}
float3 sourceTexture = textures[pushConstants.SourceTextureID].Sample(mySampler, uv).rgb;
float ratio = float(sampleValue != target && hasHit > 0.0f);
float4 finalColor = float4(
lerp(sourceTexture.r, fragColor.r, ratio),
lerp(sourceTexture.g, fragColor.g, ratio),
lerp(sourceTexture.b, fragColor.b, ratio),
lerp(1.0f, fragColor.a, ratio)
);
output.oColor0 = finalColor;
return output;
}

View File

@@ -0,0 +1,113 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct OutlinePushConstant
{
float4 Color;
float Thickness;
int SourceTextureID;
int EntityIDTextureID;
int DepthTextureID;
float SelectedEntity;
};
[[vk::push_constant]]
OutlinePushConstant pushConstants;
// Outputs
struct VSOutput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
Vertex v = vertexBuffer[vertexIndex];
output.UV = float2(v.uv_x, v.uv_y);
output.Position = float4(v.position, 1.0f);
return output;
}

View File

@@ -0,0 +1,399 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct PSInput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
struct PSOutput {
float4 oColor0 : SV_TARGET;
};
struct ShadingPushConstant
{
int AlbedoInputTextureId;
int DepthInputTextureId;
int NormalInputTextureId;
int MaterialInputTextureId;
int LightCount;
int CameraID;
float cascadeDepth[4];
float AmbientTerm;
int SSAOTextureId;
};
[[vk::push_constant]]
ShadingPushConstant pushConstants;
float3 WorldPosFromDepth(float depth, float2 uv, float4x4 invProj, float4x4 invView)
{
float z = depth;
float4 clipSpacePosition = float4(uv.x * 2.0 - 1.0, (uv.y * 2.0 - 1.0), z, 1.0f);
float4 viewSpacePosition = mul(invProj, clipSpacePosition);
viewSpacePosition /= viewSpacePosition.w;
float4 worldSpacePosition = mul(invView, viewSpacePosition);
return worldSpacePosition.xyz;
}
float LinearizeDepth(float depth, float nearPlane, float farPlane, bool reverseDepth)
{
if (reverseDepth)
{
// Reverse depth (near plane = 1.0, far plane = 0.0)
return nearPlane * farPlane / lerp(farPlane, nearPlane, depth);
}
else
{
// Standard depth (near plane = 0.0, far plane = 1.0)
return (2.0 * nearPlane * farPlane) / (farPlane + nearPlane - depth * (farPlane - nearPlane));
}
}
float DistributionGGX(float3 N, float3 H, float a)
{
float PI = 3.141592653589793f;
float a2 = a * a;
float NdotH = max(dot(N, H), 0.0);
float NdotH2 = NdotH * NdotH;
float nom = a2;
float denom = (NdotH2 * (a2 - 1.0) + 1.0);
denom = PI * denom * denom;
return nom / denom;
}
float GeometrySchlickGGX(float NdotV, float k)
{
float nom = NdotV;
float denom = NdotV * (1.0 - k) + k;
return nom / denom;
}
float GeometrySmith(float3 N, float3 V, float3 L, float k)
{
float NdotV = max(dot(N, V), 0.0);
float NdotL = max(dot(N, L), 0.0);
float ggx1 = GeometrySchlickGGX(NdotV, k);
float ggx2 = GeometrySchlickGGX(NdotL, k);
return ggx1 * ggx2;
}
float3 fresnelSchlick(float cosTheta, float3 F0)
{
return F0 + (1.0 - F0) * pow(max(1.0 - cosTheta, 0.0), 5.0);
}
float3 fresnelSchlickRoughness(float cosTheta, float3 F0, float roughness)
{
float roughnessTerm = 1.0f - roughness;
return F0 + (max(float3(roughnessTerm, roughnessTerm, roughnessTerm), F0) - F0) * pow(max(1.0 - cosTheta, 0.0), 5.0);
}
float linearDepth(float z, float near, float far) {
return near * far / (far - z * (far - near));
}
int GetCSMSplit(float depth)
{
for(int i = 0; i < 4; i++)
{
float csmSplitDepth = pushConstants.cascadeDepth[i];
if(depth < csmSplitDepth + 0.000001)
{
return i;
}
}
return 0;
}
float SampleShadowMap(int textureId, float2 coords, float compare)
{
return compare > textures[textureId].Sample(mySampler, coords.xy).r;
}
float SampleShadowMapLinear(int textureId, float2 coords, float compare, float2 texelSize)
{
float2 pixelPos = coords / texelSize + float2(0.5f, 0.5f);
float2 fracPart = frac(pixelPos);
float2 startTexel = (pixelPos - fracPart) * texelSize;
float blTexel = SampleShadowMap(textureId, startTexel, compare);
float brTexel = SampleShadowMap(textureId, startTexel + float2(texelSize.x, 0.0), compare);
float tlTexel = SampleShadowMap(textureId, startTexel + float2(0.0, texelSize.y), compare);
float trTexel = SampleShadowMap(textureId, startTexel + texelSize, compare);
float mixA = lerp(blTexel, tlTexel, fracPart.y);
float mixB = lerp(brTexel, trTexel, fracPart.y);
return lerp(mixA, mixB, fracPart.x);
}
float ShadowCalculation(Light light, float3 fragPos, float3 normal)
{
// Find correct CSM splits from depth
CameraView camView = cameras[pushConstants.CameraID];
float depth = length(fragPos - camView.Position);
int splitIndex = GetCSMSplit(depth);
// Calculate shadows for found split
CameraView lightView = cameras[light.transformId[splitIndex]];
int shadowMap = light.shadowMapTextureId[0];
float4 fragLightSpace = mul(lightView.Projection, mul(lightView.View, float4(fragPos, 1.0)));
float3 projCoords = fragLightSpace.xyz / fragLightSpace.w;
projCoords.xy = projCoords.xy * 0.5 + 0.5;
if (projCoords.x < 0.0 || projCoords.x > 1.0 || projCoords.y < 0.0 || projCoords.y > 1.0) {
return 1.0;
}
//projCoords.y = 1.0 - projCoords.y;
float currentDepth = projCoords.z;
float bias = max(0.005 * (1.0 - dot(normal, light.direction)), 0.0005);
if(splitIndex < 2)
{
const float NUM_SAMPLES = 4.0f;
const float SAMPLES_START = (NUM_SAMPLES - 1.0f) / 2.0f;
const float NUM_SAMPLES_SQUARED = NUM_SAMPLES * NUM_SAMPLES;
float2 texelSize = 1.0f / float2(4096, 4096);
float result = 0.0f;
for(float y = -SAMPLES_START; y <= SAMPLES_START; y += 1.0f)
{
for (float x = -SAMPLES_START; x <= SAMPLES_START; x += 1.0f)
{
float2 coordsOffset = float2(x, y) * texelSize;
result += SampleShadowMapLinear(light.shadowMapTextureId[splitIndex], projCoords.xy + coordsOffset, currentDepth, texelSize);
}
}
return result /= NUM_SAMPLES_SQUARED;
}
float shadowMapDepth = textures[light.shadowMapTextureId[splitIndex]].Sample(mySampler, projCoords.xy).r;
return (currentDepth > shadowMapDepth);//> 0.0 ? 1.0 : 0.0;
}
PSOutput main(PSInput input)
{
PSOutput output;
CameraView camView = cameras[pushConstants.CameraID];
int depthTexture = pushConstants.DepthInputTextureId;
float depth = textures[depthTexture].Sample(mySampler, input.UV).r;
if(depth == 0.0f)
{
discard;
}
float3 worldPos = WorldPosFromDepth(depth, input.UV, camView.InverseProjection, camView.InverseView);
int albedoTextureId = pushConstants.AlbedoInputTextureId;
float3 albedo = textures[albedoTextureId].Sample(mySampler, input.UV).xyz;
float3 normal = textures[pushConstants.NormalInputTextureId].Sample(mySampler, input.UV).rgb;
normal = normal * 2.0f - 1.0f;
float4 materialSample = textures[pushConstants.MaterialInputTextureId].Sample(mySampler, input.UV);
float metallic = materialSample.r;
float ao = materialSample.g;
float roughness = materialSample.b;
float ssao = textures[pushConstants.SSAOTextureId].Sample(mySampler, input.UV);
float3 N = normal;
float3 V = normalize(camView.Position - worldPos);
float3 R = reflect(-V, N);
float3 F0 = float3(0.04, 0.04, 0.04);
F0 = lerp(F0, albedo, metallic);
Light directionalLight;
bool foundDirectional = false;
for(int i = 0; i < pushConstants.LightCount; i++)
{
Light light = lights[i];
if(light.type == 0)
{
directionalLight = light;
foundDirectional = true;
break;
}
}
const float PI = 3.141592653589793f;
float3 Lo = float3(0.0, 0.0, 0.0);
float shadow = 1.0f;
if(foundDirectional == false)
{
shadow = 1.0f;
}
//Directional
if(foundDirectional)
{
Light light = directionalLight;
float3 L = normalize(light.direction);
float attenuation = 1.0f;
if(light.castShadow == true)
{
shadow *= ShadowCalculation(light, worldPos, N);
//output.oColor0 = float4(albedo * 0.1 + float3(shadow, shadow, shadow), 1);
//return output;
}
// TODO: Shadow
float3 radiance = light.color.rgb * attenuation;
float3 H = normalize(V + L);
float NDF = DistributionGGX(N, H, roughness);
float G = GeometrySmith(N, V, L, roughness);
float3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
float3 nominator = NDF * G * F;
float denominator = 4 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001; // 0.001 to prevent divide by zero.
float3 specular = nominator / denominator;
float3 kS = F;
float3 kD = float3(1.0, 1.0, 1.0) - kS;
kD *= 1.0 - metallic;
float NdotL = max(dot(N, L), 0.0);
Lo += (kD * albedo / PI + specular) * radiance * NdotL * shadow;
}
// other lights
for(int i = 0; i < pushConstants.LightCount; i++)
{
Light light = lights[i];
float3 L = normalize(light.position - worldPos);
float distance = length(light.position - worldPos);
float attenuation = 1.0 / (distance * distance);
float3 radiance = float3(0, 0, 0);
if(light.type == 1) // point light
{
radiance = light.color * attenuation;
}
else if(light.type == 2)
{
float theta = dot(L, normalize(-light.direction));
float epsilon = light.innerConeAngle - light.outerConeAngle;
float intensity = clamp((theta - light.outerConeAngle) / epsilon, 0.0, 1.0);
radiance = light.color * intensity * attenuation;
}
float3 H = normalize(V + L);
float NDF = DistributionGGX(N, H, roughness);
float G = GeometrySmith(N, V, L, roughness);
float3 F = fresnelSchlick(max(dot(H, V), 0.0), F0);
float3 nominator = NDF * G * F;
float denominator = 4 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001; // 0.001 to prevent divide by zero.
float3 specular = nominator / denominator;
float3 kS = F;
float3 kD = float3(1.0, 1.0, 1.0) - kS;
kD *= 1.0 - metallic;
float NdotL = max(dot(N, L), 0.0);
Lo += (kD * albedo / PI + specular) * radiance * NdotL;
}
float3 F = fresnelSchlickRoughness(max(dot(N, V), 0.0), F0, roughness);
float3 kS = F;
float3 kD = 1.0 - kS;
kD *= 1.0 - metallic;
float3 ambient = (albedo) * ao * ssao * pushConstants.AmbientTerm;
float3 color = (ambient) + Lo;
output.oColor0 = float4(color, 1);
return output;
}

View File

@@ -0,0 +1,117 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct ShadingPushConstant
{
int AlbedoInputTextureId;
int DepthInputTextureId;
int NormalInputTextureId;
int MaterialInputTextureId;
int LightCount;
int CameraID;
float cascadeDepth[4];
float AmbientTerm;
int SSAOTextureId;
};
[[vk::push_constant]]
ShadingPushConstant pushConstants;
// Outputs
struct VSOutput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
Vertex v = vertexBuffer[vertexIndex];
output.UV = float2(v.uv_x, v.uv_y);
output.Position = float4(v.position, 1.0f);
return output;
}

View File

@@ -0,0 +1,100 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct PSInput
{
float4 Position : SV_Position;
};
struct ModelPushConstant
{
int modelIndex; // Push constant data
int materialIndex;
int cameraID;
};
[[vk::push_constant]]
ModelPushConstant pushConstants;
void main(PSInput input)
{
}

View File

@@ -0,0 +1,129 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
float hasAlbedo;
float3 albedo;
int hasNormal;
int hasMetalness;
int hasRoughness;
int hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct ModelPushConstant
{
int modelIndex; // Push constant data
int materialIndex;
int cameraID;
};
[[vk::push_constant]]
ModelPushConstant pushConstants;
// Outputs
struct VSOutput
{
float4 Position : SV_Position;
};
float LinearizeDepth(float depth, float nearPlane, float farPlane, bool reverseDepth)
{
if (reverseDepth)
{
// Reverse depth (near plane = 1.0, far plane = 0.0)
return nearPlane * farPlane / lerp(farPlane, nearPlane, depth);
}
else
{
// Standard depth (near plane = 0.0, far plane = 1.0)
return (2.0 * nearPlane * farPlane) / (farPlane + nearPlane - depth * (farPlane - nearPlane));
}
}
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
ModelData modelData = model[pushConstants.modelIndex];
CameraView camView = cameras[pushConstants.cameraID];
// Load vertex data from the buffer
Vertex v = vertexBuffer[vertexIndex];
// Output the position of each vertex
output.Position = mul(camView.Projection, mul(camView.View,mul(modelData.model, float4(v.position, 1.0f))));
//output.Position.z = LinearizeDepth(output.Position.z, camView.Near, camView.Far, false);
return output;
}

View File

@@ -0,0 +1,223 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
[[vk::binding(0, 7)]]
StructuredBuffer<float3> ssaoKernels;
struct PSInput {
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
struct PSOutput {
float4 oColor0 : SV_TARGET;
};
struct SSAOConstant
{
int noiseTextureID;
int normalTextureID;
int depthTextureID;
int camViewID;
float radius;
float bias;
float2 noiseScale;
float power;
};
[[vk::push_constant]]
SSAOConstant pushConstants;
float3 ViewPosFromDepth(float depth, float2 uv, float4x4 invProj)
{
float z = depth;
float4 clipSpacePosition = float4(uv.x * 2.0 - 1.0, (uv.y * 2.0 - 1.0), z, 1.0f);
float4 viewSpacePosition = mul(invProj, clipSpacePosition);
viewSpacePosition /= viewSpacePosition.w;
return viewSpacePosition.xyz;
}
float3 WorldPosFromDepth(float depth, float2 uv, CameraView camera)
{
float z = depth;
float4 clipSpacePosition = float4(uv.x * 2.0 - 1.0, (uv.y * 2.0 - 1.0), z, 1.0f);
float4 viewSpacePosition = mul(camera.InverseProjection, clipSpacePosition);
viewSpacePosition /= viewSpacePosition.w;
float4 worldSpacePosition = mul(camera.InverseView, viewSpacePosition);
worldSpacePosition /= worldSpacePosition.w;
return worldSpacePosition.xyz;
}
float3 SampleTexture(int textureId, float2 uv)
{
return textures[textureId].Sample(mySampler, uv).rgb;
}
float SampleDepth(float2 uv)
{
return textures[pushConstants.depthTextureID].Sample(mySampler, uv).r;
}
float3x3 Inverse3x3(float3x3 m)
{
float3 r0 = cross(m[1], m[2]);
float3 r1 = cross(m[2], m[0]);
float3 r2 = cross(m[0], m[1]);
float det = dot(r2, m[2]);
float invDet = 1.0 / det;
return float3x3(
r0 * invDet,
r1 * invDet,
r2 * invDet
);
}
PSOutput main(PSInput input)
{
CameraView camera = cameras[pushConstants.camViewID];
float depth = SampleDepth(input.UV);
// Discard the sky
if(depth < 0.00001)
{
discard;
}
// Calculate TBN
float3x3 normalMatrix = (float3x3)camera.View;
//normalMatrix[0] *= -1.0; // Flip the Z basis vector
float3 normal = SampleTexture(pushConstants.normalTextureID, input.UV).xyz * 2.0 - 1.0;
normal = mul(normalMatrix, normal);
float2 randomVecSample = SampleTexture(pushConstants.noiseTextureID, input.UV * pushConstants.noiseScale).xy * 2.0 - 1.0;
float3 randomVec = float3(randomVecSample.x, -randomVecSample.y, 0);
//randomVec = float3(0, 1, 0);
float3 tangent = normalize(randomVec - normal * dot(randomVec, normal));
float3 bitangent = cross(normal, tangent);
float3x3 TBN = float3x3(tangent, bitangent, normal);
float3 fragPos = ViewPosFromDepth(depth, input.UV, camera.InverseProjection);
// Fix from: https://github.com/JoeyDeVries/LearnOpenGL/issues/364
float4 fragWorldPos = mul(camera.InverseView, float4(fragPos, 1.0));
fragWorldPos.xyz /= fragWorldPos.w;
PSOutput output;
float occlusion = 0.0f;
for(int i = 0; i < 64; i++)
{
float3 samplePos = mul(ssaoKernels[i], TBN);
samplePos = fragPos + samplePos * pushConstants.radius;
//samplePos = fragWorldPos + samplePos * pushConstants.radius;
//return output;
// Fix from: https://github.com/JoeyDeVries/LearnOpenGL/issues/364
float4 worldSamplePos = mul(camera.View, float4(samplePos, 1.0));
worldSamplePos.xyz /= worldSamplePos.w;
//samplePos = worldSamplePos.xyz;
float4 offset = float4(samplePos, 1.0f);
offset = mul(camera.Projection, offset);
offset.xyz /= offset.w;
offset.xyz = offset.xyz * 0.5 + 0.5;
offset.x = clamp(offset.x, 0.00001, 0.999);
offset.y = clamp(offset.y, 0.00001, 0.999);
float sampleDepth = ViewPosFromDepth(SampleDepth(offset.xy), offset.xy, camera.InverseProjection).z;
float rangeCheck = smoothstep(0.0, 1.0, pushConstants.radius / abs(sampleDepth - fragPos.z));
occlusion += (sampleDepth - pushConstants.bias >= samplePos.z ? 1.0 : 0.0) * rangeCheck;
}
occlusion = 1.0 - (occlusion / 64.0);
occlusion = pow(occlusion, pushConstants.power);
output.oColor0 = float4(occlusion, occlusion, occlusion, 1.0f);
return output;
}

View File

@@ -0,0 +1,116 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
[[vk::binding(0, 7)]]
StructuredBuffer<float3> ssaoKernels;
struct SSAOConstant
{
int noiseTextureID;
int normalTextureID;
int depthTextureID;
float radius;
float bias;
float2 noiseScale;
float power;
};
[[vk::push_constant]]
SSAOConstant pushConstants;
// Outputs
struct VSOutput {
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
Vertex v = vertexBuffer[vertexIndex];
output.UV = float2(v.uv_x, v.uv_y);
output.Position = float4(v.position, 1.0f);
return output;
}

View File

@@ -0,0 +1,28 @@
struct VSInput
{
[[vk::location(0)]] float3 Position : POSITION0;
[[vk::location(1)]] float3 Color : COLOR0;
};
struct UBO
{
float4x4 projectionMatrix;
float4x4 modelMatrix;
float4x4 viewMatrix;
};
cbuffer ubo : register(b0, space0) { UBO ubo; }
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 Color : COLOR0;
};
VSOutput main(VSInput input, uint VertexIndex : SV_VertexID)
{
VSOutput output = (VSOutput)0;
output.Color = input.Color * float(VertexIndex);
output.Pos = mul(ubo.projectionMatrix, mul(ubo.viewMatrix, mul(ubo.modelMatrix, float4(input.Position.xyz, 1.0))));
return output;
}

View File

@@ -0,0 +1,132 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct PSInput {
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
struct PSOutput {
float4 oColor0 : SV_TARGET;
};
struct TonemapPushConstant
{
float Exposure;
float Gamma;
int SourceTextureID;
};
[[vk::push_constant]]
TonemapPushConstant pushConstants;
float3 PBRNeutralToneMapping(float3 color)
{
const float startCompression = 0.8 - 0.04;
const float desaturation = 0.15;
float x = min(color.r, min(color.g, color.b));
float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
color -= offset;
float peak = max(color.r, max(color.g, color.b));
if (peak < startCompression) return color;
const float d = 1. - startCompression;
float newPeak = 1. - d * d / (peak + d - startCompression);
color *= newPeak / peak;
float g = 1. - 1. / (desaturation * (peak - newPeak) + 1.);
return lerp(color, newPeak * float3(1, 1, 1), g);
}
PSOutput main(PSInput input)
{
PSOutput output;
float3 color = textures[pushConstants.SourceTextureID].Sample(mySampler, input.UV).rgb;
float3 mapped = float3(1.0, 1.0, 1.0) - exp(-color * pushConstants.Exposure);
color = pow(mapped, float3(pushConstants.Gamma, pushConstants.Gamma, pushConstants.Gamma));
output.oColor0 = float4(color, 1);
return output;
}

View File

@@ -0,0 +1,110 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct TonemapPushConstant
{
float Exposure;
float Gamma;
int SourceTextureID;
};
[[vk::push_constant]]
TonemapPushConstant pushConstants;
// Outputs
struct VSOutput {
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
Vertex v = vertexBuffer[vertexIndex];
output.UV = float2(v.uv_x, v.uv_y);
output.Position = float4(v.position, 1.0f);
return output;
}

View File

@@ -0,0 +1,186 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float4 tangent;
float4 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct PSInput
{
float4 Position : SV_Position;
float3 Color : TEXCOORD0;
float2 UV : TEXCOORD1;
float3 Normal : TEXCOORD2;
float3 Tangent : TEXCOORD3;
float3 Bitangent : TEXCOORD4;
};
struct PSOutput {
float4 oColor0 : SV_TARGET;
float4 oNormal : SV_TARGET1;
float4 oMaterial : SV_TARGET2;
float4 oEntityID : SV_TARGET3;
};
struct ModelPushConstant
{
int modelIndex; // Push constant data
int materialIndex;
int cameraID;
float entityID;
};
[[vk::push_constant]]
ModelPushConstant pushConstants;
PSOutput main(PSInput input)
{
PSOutput output;
Material inMaterial = material[pushConstants.materialIndex];
// NORMAL
// TODO use TBN matrix
float3 T = input.Tangent.xyz;
float3 B = input.Bitangent.xyz;
float3 N = input.Normal.xyz;
float3x3 TBN = float3x3(T, B, N);
float3 normal = float3(0.0, 0.0, 1.0);
if(inMaterial.hasNormal == 1)
{
normal = textures[inMaterial.normalTextureId].Sample(mySampler, input.UV).rgb;
normal.xyz = normal.zxy;
normal = normal * 2.0f - 1.0f;
}
else
{
normal = normal;
}
//normal = input.Normal;
normal = mul(transpose(TBN), normal);
normal = normal / 2.0f + 0.5f;
output.oNormal = float4(normal, 1.0f);
// MATERIAL
// ALBEDO COLOR
float4 albedoColor = float4(inMaterial.albedo.xyz, 1.0f);
if(inMaterial.hasAlbedo == 1)
{
float4 albedoSample = textures[inMaterial.albedoTextureId].Sample(mySampler, input.UV);
// Alpha cutout?
if(albedoSample.a < 0.001f)
{
discard;
}
albedoColor.xyz = albedoSample.xyz;
}
output.oColor0 = albedoColor;
// MATERIAL PROPERTIES
float metalnessValue = inMaterial.metalnessValue;
if(inMaterial.hasMetalness == 1)
{
// TODO: Sample from metal texture
}
float aoValue = inMaterial.aoValue;
if(inMaterial.hasAO == 1)
{
// TODO: Sample from AO texture
}
float roughnessValue = inMaterial.roughnessValue;
if(inMaterial.hasRoughness == 1)
{
// TODO: Sample from roughness texture
}
float3 materialOuput = float3(inMaterial.metalnessValue, inMaterial.aoValue, inMaterial.roughnessValue);
output.oMaterial = float4(materialOuput, 1.0f);
output.oEntityID = float4(pushConstants.entityID, 0.0f, 0.0f, 1.0f);
return output;
}

View File

@@ -0,0 +1,154 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float4 tangent;
float4 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct ModelPushConstant
{
int modelIndex; // Push constant data
int materialIndex;
int cameraID;
float entityID;
};
[[vk::push_constant]]
ModelPushConstant pushConstants;
// Outputs
struct VSOutput
{
float4 Position : SV_Position;
float3 Color : TEXCOORD0;
float2 UV : TEXCOORD1;
float3 Normal : TEXCOORD2;
float3 Tangent : TEXCOORD3;
float3 Bitangent : TEXCOORD4;
};
float3x3 invert(float3x3 m)
{
float3 a = m[0];
float3 b = m[1];
float3 c = m[2];
float3 r0 = cross(b, c);
float3 r1 = cross(c, a);
float3 r2 = cross(a, b);
float det = dot(r2, c);
// Return identity if not invertible (optional fallback)
if (abs(det) < 1e-6)
return float3x3(1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0);
float invDet = 1.0 / det;
return float3x3(r0 * invDet,
r1 * invDet,
r2 * invDet);
}
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
CameraView camView = cameras[pushConstants.cameraID];
ModelData modelData = model[pushConstants.modelIndex];
// Load vertex data from the buffer
Vertex v = vertexBuffer[vertexIndex];
// Output the position of each vertex
output.Position = mul(camView.Projection, mul(camView.View, mul(modelData.model, float4(v.position, 1.0f))));
output.Color = normalize(float3(v.position.xyz));
output.UV = float2(v.uv_x, v.uv_y);
float3x3 upper3x3 = (float3x3)modelData.model;
float3x3 normalMatrix = transpose(invert(upper3x3));
output.Bitangent = mul(normalMatrix, normalize(v.bitangent.xyz));
output.Normal = mul(normalMatrix, normalize(v.normal.xyz));
output.Tangent = mul(normalMatrix, normalize(v.tangent.xyz));
//output.Normal = v.normal.xyz;
return output;
}

View File

@@ -0,0 +1,347 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct PSInput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
struct PSOutput {
float4 oColor0 : SV_TARGET;
};
struct VolumetricConstant
{
int DepthTextureID;
int StepCount;
float FogAmount;
float Exponant;
int CamViewID;
int LightCount;
float Ambient;
float Time;
float NoiseSpeed;
float NoiseScale;
float NoiseStrength;
float CSMSplits[4];
};
[[vk::push_constant]]
VolumetricConstant pushConstants;
float2 GetTexelSize(Texture2D tex)
{
uint width, height;
tex.GetDimensions(width, height);
return 1.0 / float2(width, height);
}
float LinearizeDepth(float depth, float nearPlane, float farPlane)
{
return (2.0 * nearPlane) / (farPlane + nearPlane - (1.0 - depth) * (farPlane - nearPlane));
}
float ComputeScattering(float lightDotView)
{
float PI = 3.141592653589793f;
float result = 1.0f - pushConstants.FogAmount;
result /= (4.0f * PI * pow(1.0f + pushConstants.FogAmount * pushConstants.FogAmount - (1.0f * pushConstants.FogAmount) * lightDotView, 1.5f));
return result;
}
float3 WorldPosFromDepth(float depth, float2 uv, float4x4 invProj, float4x4 invView)
{
float z = depth;
float4 clipSpacePosition = float4(uv.x * 2.0 - 1.0, (uv.y * 2.0 - 1.0), z, 1.0f);
float4 viewSpacePosition = mul(invProj, clipSpacePosition);
viewSpacePosition /= viewSpacePosition.w;
float4 worldSpacePosition = mul(invView, viewSpacePosition);
return worldSpacePosition.xyz;
}
// Simplex 3D Noise
float mod289(float x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
float3 mod289(float3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
float4 mod289(float4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
float4 permute(float4 x) { return mod289(((x*34.0)+1.0)*x); }
float4 taylorInvSqrt(float4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
float snoise(float3 v)
{
const float2 C = float2(1.0/6.0, 1.0/3.0) ;
const float4 D = float4(0.0, 0.5, 1.0, 2.0);
// First corner
float3 i = floor(v + dot(v, C.yyy));
float3 x0 = v - i + dot(i, C.xxx);
// Other corners
float3 g = step(x0.yzx, x0.xyz);
float3 l = 1.0 - g;
float3 i1 = min(g.xyz, l.zxy);
float3 i2 = max(g.xyz, l.zxy);
// x0 = x0 - 0.0 + 0.0 * C.xxx;
float3 x1 = x0 - i1 + C.xxx;
float3 x2 = x0 - i2 + C.yyy;
float3 x3 = x0 - 1.0 + 3.0 * C.xxx;
// Permutations
i = mod289(i);
float4 p = permute(permute(permute(
i.z + float4(0.0, i1.z, i2.z, 1.0))
+ i.y + float4(0.0, i1.y, i2.y, 1.0))
+ i.x + float4(0.0, i1.x, i2.x, 1.0));
// Gradients: 7x7 points over a cube, mapped onto a unit sphere
float4 j = p - 49.0 * floor(p * (1.0 / 49.0)); // mod(p,7*7)
float4 x_ = floor(j * (1.0 / 7.0));
float4 y_ = floor(j - 7.0 * x_); // mod(j,7)
float4 x = (x_ * 2.0 + 0.5) / 7.0 - 1.0;
float4 y = (y_ * 2.0 + 0.5) / 7.0 - 1.0;
float4 h = 1.0 - abs(x) - abs(y);
float4 b0 = float4(x.xy, y.xy);
float4 b1 = float4(x.zw, y.zw);
float4 s0 = floor(b0) * 2.0 + 1.0;
float4 s1 = floor(b1) * 2.0 + 1.0;
float4 sh = -step(h, 0.0);
float4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;
float4 a1 = b1.xzyw + s1.xzyw * sh.zzww;
float3 g0 = float3(a0.xy, h.x);
float3 g1 = float3(a0.zw, h.y);
float3 g2 = float3(a1.xy, h.z);
float3 g3 = float3(a1.zw, h.w);
// Normalize gradients
float4 norm = taylorInvSqrt(float4(dot(g0,g0), dot(g1,g1), dot(g2,g2), dot(g3,g3)));
g0 *= norm.x;
g1 *= norm.y;
g2 *= norm.z;
g3 *= norm.w;
// Mix final noise value
float4 m = max(0.6 - float4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
m = m * m;
return 42.0 * dot(m*m, float4(dot(g0,x0), dot(g1,x1), dot(g2,x2), dot(g3,x3)));
}
int GetCSMSplit(float depth)
{
for(int i = 0; i < 4; i++)
{
float csmSplitDepth = pushConstants.CSMSplits[i];
if(depth < csmSplitDepth + 0.000001)
{
return i;
}
}
return -1;
}
PSOutput main(PSInput input)
{
float ditherPattern[4][4] = { { 0.0f, 0.5f, 0.125f, 0.625f},
{ 0.75f, 0.22f, 0.875f, 0.375f},
{ 0.1875f, 0.6875f, 0.0625f, 0.5625},
{ 0.9375f, 0.4375f, 0.8125f, 0.3125} };
CameraView camView = cameras[pushConstants.CamViewID];
float3 startPosition = camView.Position;
int depthTexture = pushConstants.DepthTextureID;
float depth = textures[depthTexture].Sample(mySampler, input.UV).r;
float3 worldPos = WorldPosFromDepth(depth, input.UV, camView.InverseProjection, camView.InverseView);
float3 rayVector = worldPos - startPosition;
float rayLength = length(rayVector);
PSOutput output;
if(rayLength > 1000.0)
{
output.oColor0 = float4(0.0f, 0.0f, 0, 0.0f);
//return output;
}
float stepLength = rayLength / pushConstants.StepCount;
float3 rayDirection = rayVector / rayLength;
float3 step = rayDirection * stepLength;
float3 accumFog = float3(0, 0, 0);
float3 currentPosition = startPosition;
for(int i = 0; i < pushConstants.StepCount; i++)
{
for(int l = 0; l < pushConstants.LightCount; l++)
{
Light light = lights[l];
if(light.type == 0)
{
float lightDepth = length(worldPos - camView.Position);
int splitIndex = GetCSMSplit(lightDepth);
if(splitIndex == -1)
{
accumFog += (ComputeScattering(dot(rayDirection, light.direction)).rrr * light.color.xyz) * pushConstants.Exponant;
}
else
{
CameraView lightView = cameras[light.transformId[splitIndex]];
float4 fragPosLightSpace = mul(lightView.Projection, mul(lightView.View, float4(currentPosition, 1.0)));
float3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
projCoords.xy = projCoords.xy * 0.5 + 0.5;
float currentDepth = projCoords.z;
float closestDepth = textures[light.shadowMapTextureId[splitIndex]].Sample(mySampler, projCoords.xy).r;
float3 noiseOffset = float3(pushConstants.NoiseSpeed * pushConstants.Time, pushConstants.NoiseSpeed * pushConstants.Time, pushConstants.NoiseSpeed * pushConstants.Time);
float3 noiseSamplePos = (currentPosition + noiseOffset) * pushConstants.NoiseScale;
if(closestDepth < currentDepth)
{
accumFog += (ComputeScattering(dot(rayDirection, light.direction)).rrr * light.color.xyz) * pushConstants.Exponant * ((snoise(noiseSamplePos.xyz) + 1.0) / 2.0);
}
else
{
accumFog += (ComputeScattering(dot(rayDirection, light.direction)).rrr * light.color.xyz) * pushConstants.Ambient * ((snoise(noiseSamplePos.xyz) + 1.0) / 2.0);
}
}
}
else if(light.type == 1)
{
float3 lightToFrag = currentPosition - light.position;
float distance = length(lightToFrag);
float3 lightDir = normalize(-lightToFrag);
float attenuation = 1.0 / (distance * distance);
attenuation = 1.0 - smoothstep(0.0, 3.0f, distance);
float3 noiseOffset = float3(pushConstants.NoiseSpeed * pushConstants.Time, pushConstants.NoiseSpeed * pushConstants.Time, pushConstants.NoiseSpeed * pushConstants.Time);
float3 noiseSamplePos = (currentPosition + noiseOffset) * pushConstants.NoiseScale;
float lightScatter = (snoise(noiseSamplePos.xyz) + 1.0) * 0.5;
float3 scatterTerm = ComputeScattering(dot(rayDirection, lightDir)).rrr * light.color.xyz;
accumFog += scatterTerm * lightScatter * pushConstants.Exponant * attenuation;
}
else if(light.type == 2)
{
float3 lightToFrag = currentPosition - light.position;
float distance = length(lightToFrag);
float3 lightDir = normalize(-lightToFrag);
float attenuation = 1.0 / (distance * distance);
attenuation = 1.0 - smoothstep(0.0, 6.0f, distance);
float3 noiseOffset = float3(pushConstants.NoiseSpeed * pushConstants.Time, pushConstants.NoiseSpeed * pushConstants.Time, pushConstants.NoiseSpeed * pushConstants.Time);
float3 noiseSamplePos = (currentPosition + noiseOffset) * pushConstants.NoiseScale;
float lightScatter = (snoise(noiseSamplePos.xyz) + 1.0) * 0.5;
float theta = dot(lightDir, normalize(-light.direction));
float epsilon = light.innerConeAngle - light.outerConeAngle;
float intensity = clamp((theta - light.outerConeAngle) / epsilon, 0.0, 1.0);
float3 scatterTerm = ComputeScattering(dot(rayDirection, lightDir)).rrr * light.color.xyz;
accumFog += scatterTerm * lightScatter * pushConstants.Exponant * attenuation * intensity;
}
}
currentPosition += step ;
}
accumFog /= pushConstants.StepCount;
output.oColor0 = float4(accumFog.x, accumFog.y, accumFog.z, 1.0f);
return output;
}

View File

@@ -0,0 +1,119 @@
// Transforms
struct ModelData
{
float4x4 model;
};
[[vk::binding(0, 0)]]
StructuredBuffer<ModelData> model : register(t1);
// Vertex
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float3 tangent;
float3 bitangent;
};
[[vk::binding(0, 1)]]
StructuredBuffer<Vertex> vertexBuffer : register(t2);
// Samplers
[[vk::binding(0, 2)]]
SamplerState mySampler : register(s0);
// Materials
struct Material
{
bool hasAlbedo;
float3 albedo;
bool hasNormal;
bool hasMetalness;
bool hasRoughness;
bool hasAO;
float metalnessValue;
float roughnessValue;
float aoValue;
int albedoTextureId;
int normalTextureId;
int metalnessTextureId;
int roughnessTextureId;
int aoTextureId;
};
[[vk::binding(0, 3)]]
StructuredBuffer<Material> material;
// Textures
[[vk::binding(0, 4)]]
Texture2D textures[];
// Lights
struct Light
{
float3 position;
int type;
float4 color;
float3 direction;
float outerConeAngle;
float innerConeAngle;
bool castShadow;
int shadowMapTextureId[4];
int transformId[4];
};
[[vk::binding(0, 5)]]
StructuredBuffer<Light> lights;
// Cameras
struct CameraView {
float4x4 View;
float4x4 Projection;
float4x4 ViewProjection;
float4x4 InverseView;
float4x4 InverseProjection;
float3 Position;
float Near;
float Far;
};
[[vk::binding(0, 6)]]
StructuredBuffer<CameraView> cameras;
struct VolumetricConstant
{
int DepthTextureID;
int StepCount;
float FogAmount;
float Exponant;
int CamViewID;
int LightCount;
float Ambient;
float Time;
float NoiseSpeed;
float NoiseScale;
float NoiseStrength;
float CSMSplits[4];
};
[[vk::push_constant]]
VolumetricConstant pushConstants;
// Outputs
struct VSOutput
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID)
{
VSOutput output;
Vertex v = vertexBuffer[vertexIndex];
output.UV = float2(v.uv_x, v.uv_y);
output.Position = float4(v.position, 1.0f);
return output;
}

Some files were not shown because too many files have changed in this diff Show More