diff --git a/.gitignore b/.gitignore
index 845c64ce0..0dbc751f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,12 +6,15 @@ build-win/
cmake_build/
dependencies/
CMakeFiles/
+stk-editor/
.config/
supertuxkart-64
+data/editor
data/karts
data/library
+data/models
data/music
data/sfx
data/textures
diff --git a/.travis.yml b/.travis.yml
index 86a203378..06ef93281 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -15,8 +15,9 @@ before_install:
- sudo apt-get update -qq
# Install dependencies
- sudo apt-get install build-essential cmake libogg-dev libvorbis-dev libopenal-dev libxxf86vm-dev libcurl4-openssl-dev libfribidi-dev libbluetooth-dev
- # Install mesa from an other repo (a newer version is required)
- - sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu quantal main restricted"
+ # Install mesa from an other repo (a newer version is required). Quantal is not supported anymore, saucy is only supported till July 2014,
+ # so we try to use trusty (precise which is what traiv uses a too old mesa version which doesn't link)
+ - sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu trusty main restricted"
- sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32
- sudo apt-get update -qq
- sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 725de1145..966c5efe6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -124,9 +124,9 @@ if(UNIX AND USE_XRANDR)
endif()
if(UNIX)
- if(USE_CPP2011)
- add_definitions("-std=c++0x")
- endif()
+# if(USE_CPP2011)
+ add_definitions("-std=gnu++0x")
+# endif()
endif()
# OpenGL
diff --git a/data/gui/custom_video_settings.stkgui b/data/gui/custom_video_settings.stkgui
index 2942c4312..e5383347b 100644
--- a/data/gui/custom_video_settings.stkgui
+++ b/data/gui/custom_video_settings.stkgui
@@ -70,27 +70,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -136,9 +140,9 @@
-
+
-
+
diff --git a/data/models/Hammer.jpg b/data/models/Hammer.jpg
deleted file mode 100644
index 23936c89c..000000000
Binary files a/data/models/Hammer.jpg and /dev/null differ
diff --git a/data/models/License.txt b/data/models/License.txt
deleted file mode 100644
index 7c0365972..000000000
--- a/data/models/License.txt
+++ /dev/null
@@ -1,82 +0,0 @@
-* plunger model, cake model, bomb model, anchor model
- created by MiniBjorn (c) 2008
- released under Creative Commons Attribution-Share Alike 3.0
- [http://creativecommons.org/licenses/by-sa/3.0/]
-
-* bubblegum model, nitrotank-big model, nitrotank-small model, giftbox model
- created by MiniBjorn (c) 2008
- released under Creative Commons Attribution-Share Alike 3.0
- [http://creativecommons.org/licenses/by-sa/3.0/]
-
-* banana.ac
- created by horace aka thomas oppl (toppl@fh-sbg.ac.at) (c) 2008
- released under Creative Commons Attribution-Share Alike 3.0
- [http://creativecommons.org/licenses/by-sa/3.0/]
-
-* chest*
- by MiniBjorn (c) 2010
- released under Creative Commons Attribution-Share Alike 3.0
- [http://creativecommons.org/licenses/by-sa/3.0/]
-
-* gplose
- released under CC-BY-SA 3.0 [http://creativecommons.org/licenses/by-sa/3.0/]
- oak by Julius Krischan Makowka, released un CC-BY-SA 3.0
- Tires by Thomas Oppl, released under CC-BY-SA 3.0
- scene and finishing touches by Marianne Gagnon
-
-* Hammer.jpg
- by Marianne Gagnon, released under CC-BY-SA 3.0
- Incorporates image by Philipp Zinger, released under CCBY 3.0
- image by Louise Price, released under CC-BY 2.0 (considered a derivate work thus allowing to upgrade the license version),
- image by Smoth 007, released under CC-BY-SA 2.0 (considered a derivate work thus allowing to upgrade the license version),
- image by Juangonzalez64 released under the public domain
-
-* swatter, christmas_hat
- released under CC-BY-SA 3.0
- by Funto
-
-* tire
- based on work by Thomas Oppl, released under CC-BY-SA 3.0
- with modifications by Marianne Gagnon
-
-* tnt-bomb
- by Fraang, released under CC-BY-SA 3.0
-
-* village
- released under CC-BY-SA 3.0 [http://creativecommons.org/licenses/by-sa/3.0/]
- oak by Julius Krischan Makowka, released un CC-BY-SA 3.0
- mushrooms by pfunked, with modifications by Marianne Gagnon, released under CC-BY-SA 3.0
- pinos by Moser Juan José, with minor modifications by Marianne Gagnon, released under CC-BY-SA 3.0
- scene and finishing touches by Marianne Gagnon
-
-* shroom_color* textures by Julius Krischan Makowka, released un CC-BY-SA 3.0
-
-* door.png by Marianne Gagnon, released under CC-BY-SA 3.0, based on a public domain image
- from BurningWell.
-
-* zipper_collect
- by Connor, released as Public Domain
-
-* rubber_ball and jump-bomb.jpg
- by Samuncle, released under CC-BY-SA
-
-* thunderbird model
- by Funto & Kinsu, released under CC-BY-SA 3.0
-
-* thunderbird texture, easter egg, bomb texture
- by Fraag, released under CC-BY-SA 3.0
-
-* swatter-icon
- by Totoplus62, released under CC-0
-
-* balldimpleddark
- by Hero, released under CC-BY-SA 3.0
-
-* rubber_ball-icon, plunger icon, easter egg icon, cake icon, bowling ball texture and icon
- by Totoplus62, released under CC-BY-SA 3.0
-
-* shield-icon
- by tuxfan, release under CC-BY-SA 3.0
-
-
-Others are GPL, by the original (super)TuxKart team
diff --git a/data/models/anchor-attach-icon.png b/data/models/anchor-attach-icon.png
deleted file mode 100644
index 1b053fa5e..000000000
Binary files a/data/models/anchor-attach-icon.png and /dev/null differ
diff --git a/data/models/anchor-icon.png b/data/models/anchor-icon.png
deleted file mode 100644
index 3ac70ee99..000000000
Binary files a/data/models/anchor-icon.png and /dev/null differ
diff --git a/data/models/anchor.b3d b/data/models/anchor.b3d
deleted file mode 100644
index 2142f7761..000000000
Binary files a/data/models/anchor.b3d and /dev/null differ
diff --git a/data/models/anchor.png b/data/models/anchor.png
deleted file mode 100644
index 58b517fbd..000000000
Binary files a/data/models/anchor.png and /dev/null differ
diff --git a/data/models/ball.jpg b/data/models/ball.jpg
deleted file mode 100644
index 9d073a029..000000000
Binary files a/data/models/ball.jpg and /dev/null differ
diff --git a/data/models/balldimpleddark.jpg b/data/models/balldimpleddark.jpg
deleted file mode 100644
index 991f58b5b..000000000
Binary files a/data/models/balldimpleddark.jpg and /dev/null differ
diff --git a/data/models/banana-low.b3d b/data/models/banana-low.b3d
deleted file mode 100644
index ec6ee3cae..000000000
Binary files a/data/models/banana-low.b3d and /dev/null differ
diff --git a/data/models/banana.b3d b/data/models/banana.b3d
deleted file mode 100644
index 90888d701..000000000
Binary files a/data/models/banana.b3d and /dev/null differ
diff --git a/data/models/banana.png b/data/models/banana.png
deleted file mode 100644
index f7dd34ec1..000000000
Binary files a/data/models/banana.png and /dev/null differ
diff --git a/data/models/bomb-attach-icon.png b/data/models/bomb-attach-icon.png
deleted file mode 100644
index d015e8ef7..000000000
Binary files a/data/models/bomb-attach-icon.png and /dev/null differ
diff --git a/data/models/bomb.b3d b/data/models/bomb.b3d
deleted file mode 100644
index b1da4b322..000000000
Binary files a/data/models/bomb.b3d and /dev/null differ
diff --git a/data/models/bonusblock1.png b/data/models/bonusblock1.png
deleted file mode 100644
index 9b451414a..000000000
Binary files a/data/models/bonusblock1.png and /dev/null differ
diff --git a/data/models/bonusblock2.b3d b/data/models/bonusblock2.b3d
deleted file mode 100644
index 16354c0ba..000000000
Binary files a/data/models/bonusblock2.b3d and /dev/null differ
diff --git a/data/models/bowling-icon.png b/data/models/bowling-icon.png
deleted file mode 100644
index 2109251ee..000000000
Binary files a/data/models/bowling-icon.png and /dev/null differ
diff --git a/data/models/bowling.b3d b/data/models/bowling.b3d
deleted file mode 100644
index 3de5eac90..000000000
Binary files a/data/models/bowling.b3d and /dev/null differ
diff --git a/data/models/bowling.png b/data/models/bowling.png
deleted file mode 100644
index 6bfbe2b82..000000000
Binary files a/data/models/bowling.png and /dev/null differ
diff --git a/data/models/bronze.png b/data/models/bronze.png
deleted file mode 100644
index 32a63334e..000000000
Binary files a/data/models/bronze.png and /dev/null differ
diff --git a/data/models/bubblegum-icon.png b/data/models/bubblegum-icon.png
deleted file mode 100644
index 637d532d3..000000000
Binary files a/data/models/bubblegum-icon.png and /dev/null differ
diff --git a/data/models/bubblegum-low.b3d b/data/models/bubblegum-low.b3d
deleted file mode 100644
index 4fd60cd40..000000000
Binary files a/data/models/bubblegum-low.b3d and /dev/null differ
diff --git a/data/models/bubblegum-nolok-low.b3d b/data/models/bubblegum-nolok-low.b3d
deleted file mode 100644
index 220b7d141..000000000
Binary files a/data/models/bubblegum-nolok-low.b3d and /dev/null differ
diff --git a/data/models/bubblegum-nolok.b3d b/data/models/bubblegum-nolok.b3d
deleted file mode 100644
index 474fe8353..000000000
Binary files a/data/models/bubblegum-nolok.b3d and /dev/null differ
diff --git a/data/models/bubblegum.b3d b/data/models/bubblegum.b3d
deleted file mode 100644
index f5d7201bc..000000000
Binary files a/data/models/bubblegum.b3d and /dev/null differ
diff --git a/data/models/bubblegum.png b/data/models/bubblegum.png
deleted file mode 100644
index f9eaee268..000000000
Binary files a/data/models/bubblegum.png and /dev/null differ
diff --git a/data/models/bubblegum_nolok.jpg b/data/models/bubblegum_nolok.jpg
deleted file mode 100644
index f34b78589..000000000
Binary files a/data/models/bubblegum_nolok.jpg and /dev/null differ
diff --git a/data/models/bubblegum_shield.b3d b/data/models/bubblegum_shield.b3d
deleted file mode 100644
index 00b3d5d42..000000000
Binary files a/data/models/bubblegum_shield.b3d and /dev/null differ
diff --git a/data/models/bubblegum_shield.png b/data/models/bubblegum_shield.png
deleted file mode 100644
index 2ebe7913c..000000000
Binary files a/data/models/bubblegum_shield.png and /dev/null differ
diff --git a/data/models/bubblegum_shield_nolok.b3d b/data/models/bubblegum_shield_nolok.b3d
deleted file mode 100644
index a498e97f0..000000000
Binary files a/data/models/bubblegum_shield_nolok.b3d and /dev/null differ
diff --git a/data/models/bubblegum_shield_nolok.png b/data/models/bubblegum_shield_nolok.png
deleted file mode 100644
index 1dde72a9d..000000000
Binary files a/data/models/bubblegum_shield_nolok.png and /dev/null differ
diff --git a/data/models/cake-icon.png b/data/models/cake-icon.png
deleted file mode 100644
index 86b0f5b2d..000000000
Binary files a/data/models/cake-icon.png and /dev/null differ
diff --git a/data/models/cake.b3d b/data/models/cake.b3d
deleted file mode 100644
index ccb7271bf..000000000
Binary files a/data/models/cake.b3d and /dev/null differ
diff --git a/data/models/cake.png b/data/models/cake.png
deleted file mode 100644
index c4459bf99..000000000
Binary files a/data/models/cake.png and /dev/null differ
diff --git a/data/models/candy_stripe.png b/data/models/candy_stripe.png
deleted file mode 100644
index 9033d5292..000000000
Binary files a/data/models/candy_stripe.png and /dev/null differ
diff --git a/data/models/chest.b3d b/data/models/chest.b3d
deleted file mode 100644
index 6dfc67d17..000000000
Binary files a/data/models/chest.b3d and /dev/null differ
diff --git a/data/models/chest.jpg b/data/models/chest.jpg
deleted file mode 100644
index f44596033..000000000
Binary files a/data/models/chest.jpg and /dev/null differ
diff --git a/data/models/christmas_hat.b3d b/data/models/christmas_hat.b3d
deleted file mode 100644
index 261209589..000000000
Binary files a/data/models/christmas_hat.b3d and /dev/null differ
diff --git a/data/models/christmas_hat.png b/data/models/christmas_hat.png
deleted file mode 100644
index 227b61076..000000000
Binary files a/data/models/christmas_hat.png and /dev/null differ
diff --git a/data/models/easter_egg-icon.png b/data/models/easter_egg-icon.png
deleted file mode 100644
index b3ed0fe91..000000000
Binary files a/data/models/easter_egg-icon.png and /dev/null differ
diff --git a/data/models/easter_egg.b3d b/data/models/easter_egg.b3d
deleted file mode 100644
index e2fd13a6a..000000000
Binary files a/data/models/easter_egg.b3d and /dev/null differ
diff --git a/data/models/easter_egg_3.png b/data/models/easter_egg_3.png
deleted file mode 100644
index a388e7e9a..000000000
Binary files a/data/models/easter_egg_3.png and /dev/null differ
diff --git a/data/models/gift-box-low.b3d b/data/models/gift-box-low.b3d
deleted file mode 100644
index c435fea23..000000000
Binary files a/data/models/gift-box-low.b3d and /dev/null differ
diff --git a/data/models/gift-box.b3d b/data/models/gift-box.b3d
deleted file mode 100644
index aa89d7c56..000000000
Binary files a/data/models/gift-box.b3d and /dev/null differ
diff --git a/data/models/gift-box.png b/data/models/gift-box.png
deleted file mode 100644
index 46dff7c9b..000000000
Binary files a/data/models/gift-box.png and /dev/null differ
diff --git a/data/models/gift-loop.png b/data/models/gift-loop.png
deleted file mode 100644
index 3971225fa..000000000
Binary files a/data/models/gift-loop.png and /dev/null differ
diff --git a/data/models/gold.png b/data/models/gold.png
deleted file mode 100644
index 72d47c3b3..000000000
Binary files a/data/models/gold.png and /dev/null differ
diff --git a/data/models/jump-bomb.jpg b/data/models/jump-bomb.jpg
deleted file mode 100644
index 273419d36..000000000
Binary files a/data/models/jump-bomb.jpg and /dev/null differ
diff --git a/data/models/materials.xml b/data/models/materials.xml
deleted file mode 100644
index 4a7f9bf9e..000000000
--- a/data/models/materials.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/data/models/nitrotank-big-low.b3d b/data/models/nitrotank-big-low.b3d
deleted file mode 100644
index 9009158bb..000000000
Binary files a/data/models/nitrotank-big-low.b3d and /dev/null differ
diff --git a/data/models/nitrotank-big.b3d b/data/models/nitrotank-big.b3d
deleted file mode 100644
index 53b8032bf..000000000
Binary files a/data/models/nitrotank-big.b3d and /dev/null differ
diff --git a/data/models/nitrotank-small-low.b3d b/data/models/nitrotank-small-low.b3d
deleted file mode 100644
index 568bccfd8..000000000
Binary files a/data/models/nitrotank-small-low.b3d and /dev/null differ
diff --git a/data/models/nitrotank-small.b3d b/data/models/nitrotank-small.b3d
deleted file mode 100644
index 1afb4eead..000000000
Binary files a/data/models/nitrotank-small.b3d and /dev/null differ
diff --git a/data/models/parachute-attach-icon.png b/data/models/parachute-attach-icon.png
deleted file mode 100644
index cfab603ae..000000000
Binary files a/data/models/parachute-attach-icon.png and /dev/null differ
diff --git a/data/models/parachute-icon.png b/data/models/parachute-icon.png
deleted file mode 100644
index 10fea95a6..000000000
Binary files a/data/models/parachute-icon.png and /dev/null differ
diff --git a/data/models/parachute.b3d b/data/models/parachute.b3d
deleted file mode 100644
index 511f8ac42..000000000
Binary files a/data/models/parachute.b3d and /dev/null differ
diff --git a/data/models/parachute.png b/data/models/parachute.png
deleted file mode 100644
index a5aad3ed9..000000000
Binary files a/data/models/parachute.png and /dev/null differ
diff --git a/data/models/plunger-icon.png b/data/models/plunger-icon.png
deleted file mode 100644
index 382d2d4fe..000000000
Binary files a/data/models/plunger-icon.png and /dev/null differ
diff --git a/data/models/plunger.b3d b/data/models/plunger.b3d
deleted file mode 100644
index ce461508f..000000000
Binary files a/data/models/plunger.b3d and /dev/null differ
diff --git a/data/models/plunger.png b/data/models/plunger.png
deleted file mode 100644
index 4b6d928b4..000000000
Binary files a/data/models/plunger.png and /dev/null differ
diff --git a/data/models/referee.xml b/data/models/referee.xml
deleted file mode 100644
index 35472ebc8..000000000
--- a/data/models/referee.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
diff --git a/data/models/reset-attach-icon.png b/data/models/reset-attach-icon.png
deleted file mode 100644
index 767c978f2..000000000
Binary files a/data/models/reset-attach-icon.png and /dev/null differ
diff --git a/data/models/reset-button.b3d b/data/models/reset-button.b3d
deleted file mode 100644
index 31093dea8..000000000
Binary files a/data/models/reset-button.b3d and /dev/null differ
diff --git a/data/models/reset-button.png b/data/models/reset-button.png
deleted file mode 100644
index 8d2df1ae5..000000000
Binary files a/data/models/reset-button.png and /dev/null differ
diff --git a/data/models/rubber_ball-icon.png b/data/models/rubber_ball-icon.png
deleted file mode 100644
index a5aee7add..000000000
Binary files a/data/models/rubber_ball-icon.png and /dev/null differ
diff --git a/data/models/rubber_ball.b3d b/data/models/rubber_ball.b3d
deleted file mode 100644
index 59dd3b7a8..000000000
Binary files a/data/models/rubber_ball.b3d and /dev/null differ
diff --git a/data/models/shield-icon.png b/data/models/shield-icon.png
deleted file mode 100644
index 41e27bc21..000000000
Binary files a/data/models/shield-icon.png and /dev/null differ
diff --git a/data/models/shroom_color2.png b/data/models/shroom_color2.png
deleted file mode 100644
index d217b282e..000000000
Binary files a/data/models/shroom_color2.png and /dev/null differ
diff --git a/data/models/shroom_color_a.png b/data/models/shroom_color_a.png
deleted file mode 100644
index bbacb578d..000000000
Binary files a/data/models/shroom_color_a.png and /dev/null differ
diff --git a/data/models/silver.png b/data/models/silver.png
deleted file mode 100644
index 9ec5d8d0f..000000000
Binary files a/data/models/silver.png and /dev/null differ
diff --git a/data/models/stk_mod_nitroBarrel.png b/data/models/stk_mod_nitroBarrel.png
deleted file mode 100644
index 5d29a7f5f..000000000
Binary files a/data/models/stk_mod_nitroBarrel.png and /dev/null differ
diff --git a/data/models/stk_mod_nitroBottle.png b/data/models/stk_mod_nitroBottle.png
deleted file mode 100644
index c996eef59..000000000
Binary files a/data/models/stk_mod_nitroBottle.png and /dev/null differ
diff --git a/data/models/stk_mod_nitroLogo.png b/data/models/stk_mod_nitroLogo.png
deleted file mode 100644
index 4dae47fbf..000000000
Binary files a/data/models/stk_mod_nitroLogo.png and /dev/null differ
diff --git a/data/models/swap-icon.png b/data/models/swap-icon.png
deleted file mode 100644
index 8a02cbb64..000000000
Binary files a/data/models/swap-icon.png and /dev/null differ
diff --git a/data/models/swatter-icon.png b/data/models/swatter-icon.png
deleted file mode 100644
index c3ff719a5..000000000
Binary files a/data/models/swatter-icon.png and /dev/null differ
diff --git a/data/models/swatter.b3d b/data/models/swatter.b3d
deleted file mode 100644
index 4e638c74f..000000000
Binary files a/data/models/swatter.b3d and /dev/null differ
diff --git a/data/models/swatter.png b/data/models/swatter.png
deleted file mode 100644
index 3782c851a..000000000
Binary files a/data/models/swatter.png and /dev/null differ
diff --git a/data/models/swatter_anim2.b3d b/data/models/swatter_anim2.b3d
deleted file mode 100644
index ce2995290..000000000
Binary files a/data/models/swatter_anim2.b3d and /dev/null differ
diff --git a/data/models/swatter_nolok.b3d b/data/models/swatter_nolok.b3d
deleted file mode 100644
index 995897fcb..000000000
Binary files a/data/models/swatter_nolok.b3d and /dev/null differ
diff --git a/data/models/thunderbird.b3d b/data/models/thunderbird.b3d
deleted file mode 100644
index 0dee65d10..000000000
Binary files a/data/models/thunderbird.b3d and /dev/null differ
diff --git a/data/models/thunderbird.png b/data/models/thunderbird.png
deleted file mode 100644
index 8b5b8439b..000000000
Binary files a/data/models/thunderbird.png and /dev/null differ
diff --git a/data/models/tire.b3d b/data/models/tire.b3d
deleted file mode 100644
index c18b26df7..000000000
Binary files a/data/models/tire.b3d and /dev/null differ
diff --git a/data/models/tnt-bomb.png b/data/models/tnt-bomb.png
deleted file mode 100644
index 15b08f261..000000000
Binary files a/data/models/tnt-bomb.png and /dev/null differ
diff --git a/data/models/traffic_light_green.jpg b/data/models/traffic_light_green.jpg
deleted file mode 100644
index a66b07ba4..000000000
Binary files a/data/models/traffic_light_green.jpg and /dev/null differ
diff --git a/data/models/traffic_light_red.jpg b/data/models/traffic_light_red.jpg
deleted file mode 100644
index bfb59316f..000000000
Binary files a/data/models/traffic_light_red.jpg and /dev/null differ
diff --git a/data/models/traffic_light_yellow.jpg b/data/models/traffic_light_yellow.jpg
deleted file mode 100644
index c2e7bcd54..000000000
Binary files a/data/models/traffic_light_yellow.jpg and /dev/null differ
diff --git a/data/models/trophy_bronze.b3d b/data/models/trophy_bronze.b3d
deleted file mode 100644
index fe5d3c29c..000000000
Binary files a/data/models/trophy_bronze.b3d and /dev/null differ
diff --git a/data/models/trophy_gold.b3d b/data/models/trophy_gold.b3d
deleted file mode 100644
index 88039ce82..000000000
Binary files a/data/models/trophy_gold.b3d and /dev/null differ
diff --git a/data/models/trophy_silver.b3d b/data/models/trophy_silver.b3d
deleted file mode 100644
index b57585d26..000000000
Binary files a/data/models/trophy_silver.b3d and /dev/null differ
diff --git a/data/models/warning.b3d b/data/models/warning.b3d
deleted file mode 100644
index 0364480cf..000000000
Binary files a/data/models/warning.b3d and /dev/null differ
diff --git a/data/models/warning.png b/data/models/warning.png
deleted file mode 100644
index fcc25de1c..000000000
Binary files a/data/models/warning.png and /dev/null differ
diff --git a/data/models/zipper.b3d b/data/models/zipper.b3d
deleted file mode 100644
index ed7e7ac82..000000000
Binary files a/data/models/zipper.b3d and /dev/null differ
diff --git a/data/models/zipper.png b/data/models/zipper.png
deleted file mode 100644
index de30dbfe8..000000000
Binary files a/data/models/zipper.png and /dev/null differ
diff --git a/data/models/zipper_collect.png b/data/models/zipper_collect.png
deleted file mode 100644
index d5e4f3c96..000000000
Binary files a/data/models/zipper_collect.png and /dev/null differ
diff --git a/data/shaders/displace.frag b/data/shaders/displace.frag
index 84fe29b60..eca0e7189 100644
--- a/data/shaders/displace.frag
+++ b/data/shaders/displace.frag
@@ -42,14 +42,6 @@ void main()
// Fade according to distance to cam
float fade = 1.0 - smoothstep(1.0, 100.0, camdist);
- // Fade according to distance from the edges
- const float mindist = 0.1;
- fade *= smoothstep(0.0, mindist, uv_bis.x) * smoothstep(0.0, mindist, uv_bis.y) *
- (1.0 - smoothstep(1.0 - mindist, 1.0, uv_bis.x)) *
- (1.0 - smoothstep(1.0 - mindist, 1.0, uv_bis.y));
-
- offset *= 50.0 * fade * maxlen;
-
vec4 shiftval;
shiftval.r = step(offset.x, 0.0) * -offset.x;
shiftval.g = step(0.0, offset.x) * offset.x;
diff --git a/data/shaders/grass_pass.vert b/data/shaders/grass_pass.vert
index fa52d4c7f..fc3e83ed7 100644
--- a/data/shaders/grass_pass.vert
+++ b/data/shaders/grass_pass.vert
@@ -1,7 +1,23 @@
-uniform vec3 windDir;
-uniform mat4 ModelViewProjectionMatrix;
-uniform mat4 TransposeInverseModelView;
+#ifdef UBO_DISABLED
+uniform mat4 ViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform mat4 InverseViewMatrix;
+uniform mat4 InverseProjectionMatrix;
+#else
+layout (std140) uniform MatrixesData
+{
+ mat4 ViewMatrix;
+ mat4 ProjectionMatrix;
+ mat4 InverseViewMatrix;
+ mat4 InverseProjectionMatrix;
+ mat4 ShadowViewProjMatrixes[4];
+ vec2 screen;
+};
+#endif
+uniform vec3 windDir;
+uniform mat4 ModelMatrix;
+uniform mat4 InverseModelMatrix;
#if __VERSION__ >= 330
layout(location = 0) in vec3 Position;
@@ -20,7 +36,9 @@ out vec2 uv;
void main()
{
- uv = Texcoord;
- nor = (TransposeInverseModelView * vec4(Normal, 1.)).xyz;
- gl_Position = ModelViewProjectionMatrix * vec4(Position + windDir * Color.r, 1.);
+ uv = Texcoord;
+ mat4 ModelViewProjectionMatrix = ProjectionMatrix * ViewMatrix * ModelMatrix;
+ mat4 TransposeInverseModelView = transpose(InverseModelMatrix * InverseViewMatrix);
+ nor = (TransposeInverseModelView * vec4(Normal, 1.)).xyz;
+ gl_Position = ModelViewProjectionMatrix * vec4(Position + windDir * Color.r, 1.);
}
diff --git a/data/shaders/grass_pass2.frag b/data/shaders/grass_pass2.frag
index 0ad58609a..55aeecf59 100644
--- a/data/shaders/grass_pass2.frag
+++ b/data/shaders/grass_pass2.frag
@@ -1,8 +1,24 @@
+#ifdef UBO_DISABLED
+uniform mat4 ViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform mat4 InverseViewMatrix;
+uniform mat4 InverseProjectionMatrix;
+uniform vec2 screen;
+#else
+layout (std140) uniform MatrixesData
+{
+ mat4 ViewMatrix;
+ mat4 ProjectionMatrix;
+ mat4 InverseViewMatrix;
+ mat4 InverseProjectionMatrix;
+ mat4 ShadowViewProjMatrixes[4];
+ vec2 screen;
+};
+#endif
+
uniform sampler2D Albedo;
uniform vec3 SunDir;
-uniform mat4 invproj;
uniform sampler2D dtex;
-uniform vec2 screen;
in vec3 nor;
in vec2 uv;
@@ -16,7 +32,7 @@ void main(void)
float z = texture(dtex, texc).x;
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
- xpos = invproj * xpos;
+ xpos = InverseProjectionMatrix * xpos;
xpos /= xpos.w;
vec3 eyedir = normalize(xpos.xyz);
diff --git a/data/shaders/instanciedgrassshadow.vert b/data/shaders/instanciedgrassshadow.vert
new file mode 100644
index 000000000..92c21af65
--- /dev/null
+++ b/data/shaders/instanciedgrassshadow.vert
@@ -0,0 +1,50 @@
+layout (std140) uniform MatrixesData
+{
+ mat4 ViewMatrix;
+ mat4 ProjectionMatrix;
+ mat4 InverseViewMatrix;
+ mat4 InverseProjectionMatrix;
+ mat4 ShadowViewProjMatrixes[4];
+};
+uniform vec3 windDir;
+#if __VERSION__ >= 330
+layout(location = 0) in vec3 Position;
+layout(location = 2) in vec4 Color;
+layout(location = 3) in vec2 Texcoord;
+
+layout(location = 7) in vec3 Origin;
+layout(location = 8) in vec3 Orientation;
+layout(location = 9) in vec3 Scale;
+#else
+in vec3 Position;
+in vec4 Color;
+in vec2 Texcoord;
+
+in vec3 Origin;
+in vec3 Orientation;
+in vec3 Scale;
+#endif
+
+#ifdef VSLayer
+out vec2 uv;
+#else
+out vec2 tc;
+out int layerId;
+#endif
+
+mat4 getWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
+mat4 getInverseWorldMatrix(vec3 translation, vec3 rotation, vec3 scale);
+
+void main(void)
+{
+ mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale);
+#ifdef VSLayer
+ gl_Layer = gl_InstanceID & 3;
+ gl_Position = ShadowViewProjMatrixes[gl_Layer] * ModelMatrix * vec4(Position + windDir * Color.r, 1.);
+ uv = Texcoord;
+#else
+ layerId = gl_InstanceID & 3;
+ gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * vec4(Position + windDir * Color.r, 1.);
+ tc = Texcoord;
+#endif
+}
\ No newline at end of file
diff --git a/data/shaders/rh.frag b/data/shaders/rh.frag
index 6b1a45c16..ed760b4ab 100644
--- a/data/shaders/rh.frag
+++ b/data/shaders/rh.frag
@@ -60,7 +60,7 @@ void main(void)
vec2 uv = RHuv + offset * 0.01;
// Get world position and normal from the RSM sample
- float depth = texture2D(dtex, uv).z;
+ float depth = texture(dtex, uv).z;
vec4 RSMPos = inverse(RSMMatrix) * (2. * vec4(uv, depth, 1.) - 1.);
RSMPos /= RSMPos.w;
vec3 RSMAlbedo = texture(ctex, uv).xyz;
diff --git a/data/shaders/rsm.vert b/data/shaders/rsm.vert
index 5ed3b9ad4..69846d811 100644
--- a/data/shaders/rsm.vert
+++ b/data/shaders/rsm.vert
@@ -8,11 +8,17 @@ uniform mat4 TextureMatrix =
0., 0., 1., 0.,
0., 0., 0., 1.);
-
+#if __VERSION__ >= 330
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
layout(location = 2) in vec4 Color;
layout(location = 3) in vec2 Texcoord;
+#else
+in vec3 Position;
+in vec3 Normal;
+in vec4 Color;
+in vec2 Texcoord;
+#endif
out vec3 nor;
out vec2 uv;
diff --git a/data/shaders/shadow.vert b/data/shaders/shadow.vert
index d1212e7ea..d7f6316e6 100644
--- a/data/shaders/shadow.vert
+++ b/data/shaders/shadow.vert
@@ -9,8 +9,13 @@ layout (std140) uniform MatrixesData
uniform mat4 ModelMatrix;
+#if __VERSION__ >= 330
layout(location = 0) in vec3 Position;
layout(location = 3) in vec2 Texcoord;
+#else
+in vec3 Position;
+in vec2 Texcoord;
+#endif
#ifdef VSLayer
out vec2 uv;
diff --git a/data/shaders/shadow_grass.vert b/data/shaders/shadow_grass.vert
new file mode 100644
index 000000000..7b1ce0caf
--- /dev/null
+++ b/data/shaders/shadow_grass.vert
@@ -0,0 +1,41 @@
+layout (std140) uniform MatrixesData
+{
+ mat4 ViewMatrix;
+ mat4 ProjectionMatrix;
+ mat4 InverseViewMatrix;
+ mat4 InverseProjectionMatrix;
+ mat4 ShadowViewProjMatrixes[4];
+};
+
+uniform mat4 ModelMatrix;
+uniform vec3 windDir;
+
+#if __VERSION__ >= 330
+layout(location = 0) in vec3 Position;
+layout(location = 2) in vec4 Color;
+layout(location = 3) in vec2 Texcoord;
+#else
+in vec3 Position;
+in vec4 Color;
+in vec2 Texcoord;
+#endif
+
+#ifdef VSLayer
+out vec2 uv;
+#else
+out vec2 tc;
+out int layerId;
+#endif
+
+void main(void)
+{
+#ifdef VSLayer
+ gl_Layer = gl_InstanceID & 3;
+ uv = Texcoord;
+ gl_Position = ShadowViewProjMatrixes[gl_Layer] * ModelMatrix * vec4(Position + windDir * Color.r, 1.);
+#else
+ layerId = gl_InstanceID & 3;
+ tc = Texcoord;
+ gl_Position = ShadowViewProjMatrixes[layerId] * ModelMatrix * vec4(Position + windDir * Color.r, 1.);
+#endif
+}
diff --git a/data/shaders/splatting.frag b/data/shaders/splatting.frag
index 8fb96d066..ede2b6a47 100644
--- a/data/shaders/splatting.frag
+++ b/data/shaders/splatting.frag
@@ -41,7 +41,7 @@ void main() {
vec4 splatted = splatting.r * detail0 +
splatting.g * detail1 +
splatting.b * detail2 +
- (1.0 - splatting.r - splatting.g - splatting.b) * detail3;
+ max(0., (1.0 - splatting.r - splatting.g - splatting.b)) * detail3;
vec2 tc = gl_FragCoord.xy / screen;
vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz;
diff --git a/data/shaders/ssao.frag b/data/shaders/ssao.frag
index 445de5388..c31e34f0b 100644
--- a/data/shaders/ssao.frag
+++ b/data/shaders/ssao.frag
@@ -26,7 +26,7 @@ out float AO;
const float sigma = 1.;
const float tau = 7.;
-const float beta = 0.001;
+const float beta = 0.002;
const float epsilon = .00001;
const float radius = 1.;
const float k = 1.5;
@@ -38,8 +38,8 @@ const float invSamples = 1. / SAMPLES;
vec3 getXcYcZc(int x, int y, float zC)
{
// We use perspective symetric projection matrix hence P(0,2) = P(1, 2) = 0
- float xC= (1. - 2 * (float(x) + 0.5) / screen.x) * zC / ProjectionMatrix[0][0];
- float yC= (1. + 2 * (float(y) + 0.5) / screen.y) * zC / ProjectionMatrix[1][1];
+ float xC= (2 * (float(x)) / screen.x - 1.) * zC / ProjectionMatrix[0][0];
+ float yC= (2 * (float(y)) / screen.y - 1.) * zC / ProjectionMatrix[1][1];
return vec3(xC, yC, zC);
}
@@ -53,7 +53,7 @@ void main(void)
// get the normal of current fragment
vec3 ddx = dFdx(FragPos);
vec3 ddy = dFdy(FragPos);
- vec3 norm = -normalize(cross(ddy, ddx));
+ vec3 norm = normalize(cross(ddy, ddx));
float r = radius / FragPos.z;
float phi = 3. * (x ^ y) + x * y;
diff --git a/src/config/device_config.cpp b/src/config/device_config.cpp
index 32db91569..488550389 100644
--- a/src/config/device_config.cpp
+++ b/src/config/device_config.cpp
@@ -19,6 +19,7 @@
#include
#include "config/device_config.hpp"
+#include "utils/log.hpp"
#include
using namespace irr;
@@ -226,7 +227,7 @@ bool DeviceConfig::deserializeAction(irr::io::IrrXMLReader* xml)
// Never hurts to check ;)
if (xml == NULL)
{
- fprintf(stderr, "Error: null pointer (DeviceConfig::deserializeAction)\n");
+ Log::error("DeviceConfig", "Null pointer (DeviceConfig::deserializeAction)");
return false;
}
@@ -243,8 +244,8 @@ bool DeviceConfig::deserializeAction(irr::io::IrrXMLReader* xml)
}
if(binding_id==-1)
{
- printf("WARNING: DeviceConfig::deserializeAction : action '%s' is unknown\n",
- name_string);
+ Log::warn("DeviceConfig", "DeviceConfig::deserializeAction : action '%s' is unknown.",
+ name_string);
return false;
}
@@ -349,23 +350,15 @@ GamepadConfig::GamepadConfig(irr::io::IrrXMLReader* xml) : DeviceConfig( DEVICE_
{
const char* name_string = xml->getAttributeValue("name");
if(name_string == NULL)
- {
- printf("ERROR: Unnamed joystick in config file\n");
- }
+ Log::error("DeviceConfig", "Unnamed joystick in config file.");
else
- {
m_name = name_string;
- }
const char* enabled_string = xml->getAttributeValue("enabled");
if (enabled_string != NULL)
- {
m_enabled = (strcmp(enabled_string, "true") == 0);
- }
else
- {
m_enabled = true;
- }
m_plugged = 0;
setDefaultBinds();
diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp
index 3cf9171cb..5294ef234 100644
--- a/src/config/user_config.cpp
+++ b/src/config/user_config.cpp
@@ -713,8 +713,8 @@ bool UserConfig::loadConfig()
// add back the code previously there that upgraded the config file to the new
// format instead of overwriting it.
- GUIEngine::showMessage( _("Your config file was too old, so it was deleted and a new one will be created."), 10.0f);
- printf("Your config file was too old, so it was deleted and a new one will be created.");
+ GUIEngine::showMessage(_("Your config file was too old, so it was deleted and a new one will be created."), 10.0f);
+ Log::info("UserConfig", "Your config file was too old, so it was deleted and a new one will be created.");
delete root;
return false;
diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp
index 70a57c36f..2ebed145a 100644
--- a/src/graphics/camera.cpp
+++ b/src/graphics/camera.cpp
@@ -205,8 +205,8 @@ void Camera::setupCamera()
break;
default:
if(UserConfigParams::logMisc())
- fprintf(stderr, "Incorrect number of players: '%d' - assuming 1.\n",
- race_manager->getNumLocalPlayers());
+ Log::warn("Camera", "Incorrect number of players: '%d' - assuming 1.",
+ race_manager->getNumLocalPlayers());
m_viewport = core::recti(0, 0,
UserConfigParams::m_width,
UserConfigParams::m_height);
diff --git a/src/graphics/camera.hpp b/src/graphics/camera.hpp
index e9555ea7f..125bc439f 100644
--- a/src/graphics/camera.hpp
+++ b/src/graphics/camera.hpp
@@ -155,10 +155,9 @@ private:
m_type = EC_AHEAD_OF_KART;
else
{
- fprintf(stderr,
- "Invalid camera type '%s' - camera is ignored.\n",
- s.c_str());
- return false;
+ Log::warn("Camera", "Invalid camera type '%s' - camera is ignored.",
+ s.c_str());
+ return false;
}
node.get("xyz", &m_position);
node.get("distance", &m_distance2);
diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp
index d83c5c3ea..7b82dcb97 100644
--- a/src/graphics/irr_driver.cpp
+++ b/src/graphics/irr_driver.cpp
@@ -1932,8 +1932,9 @@ void IrrDriver::update(float dt)
// =================================
if (!m_device->run())
{
- GUIEngine::cleanUp();
- GUIEngine::deallocate();
+ // Don't bother cleaning up GUI, has no use and may result in crashes
+ //GUIEngine::cleanUp();
+ //GUIEngine::deallocate();
main_loop->abort();
return;
}
diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp
index 29baf0534..69909bce2 100644
--- a/src/graphics/irr_driver.hpp
+++ b/src/graphics/irr_driver.hpp
@@ -70,7 +70,6 @@ enum STKRenderingPass
SOLID_LIT_PASS,
TRANSPARENT_PASS,
GLOW_PASS,
- DISPLACEMENT_PASS,
SHADOW_PASS,
PASS_COUNT,
};
@@ -353,8 +352,6 @@ private:
std::vector m_forcedbloom;
- std::vector m_displacing;
-
std::vector m_background;
STKRenderingPass m_phase;
@@ -380,7 +377,6 @@ private:
void renderGlow(std::vector& glows);
void renderSSAO();
void renderLights(unsigned pointlightCount);
- void renderDisplacement();
void renderShadowsDebug();
void doScreenShot();
public:
@@ -668,12 +664,6 @@ public:
// ------------------------------------------------------------------------
const std::vector &getForcedBloom() const { return m_forcedbloom; }
// ------------------------------------------------------------------------
- void clearDisplacingNodes() { m_displacing.clear(); }
- // ------------------------------------------------------------------------
- const std::vector &getDisplacingNodes() const { return m_displacing; }
- // ------------------------------------------------------------------------
- void addDisplacingNode(scene::ISceneNode * const n) { m_displacing.push_back(n); }
- // ------------------------------------------------------------------------
void clearBackgroundNodes() { m_background.clear(); }
// ------------------------------------------------------------------------
void addBackgroundNode(scene::ISceneNode * const n) { m_background.push_back(n); }
diff --git a/src/graphics/material_manager.cpp b/src/graphics/material_manager.cpp
index a5fea5f95..544cf635a 100644
--- a/src/graphics/material_manager.cpp
+++ b/src/graphics/material_manager.cpp
@@ -239,7 +239,7 @@ bool MaterialManager::pushTempMaterial(const XMLNode *root,
if(!node)
{
// We don't have access to the filename at this stage anymore :(
- fprintf(stderr, "Unknown node in material.xml file\n");
+ Log::warn("MaterialManager", "Unknown node in material.xml file.");
continue;
}
try
@@ -249,7 +249,7 @@ bool MaterialManager::pushTempMaterial(const XMLNode *root,
catch(std::exception& e)
{
// The message contains a '%s' for the filename
- fprintf(stderr, e.what(), filename.c_str());
+ Log::warn("MaterialManager", e.what(), filename.c_str());
}
} // for igetNumNodes)(
return true;
diff --git a/src/graphics/particle_emitter.cpp b/src/graphics/particle_emitter.cpp
index bfc66d6b3..8bf4d0ada 100644
--- a/src/graphics/particle_emitter.cpp
+++ b/src/graphics/particle_emitter.cpp
@@ -581,7 +581,7 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
}
default:
{
- fprintf(stderr, "[ParticleEmitter] Unknown shape\n");
+ Log::error("ParticleEmitter", "Unknown shape");
return;
}
}
diff --git a/src/graphics/particle_kind.cpp b/src/graphics/particle_kind.cpp
index e23b4e92e..d332ceacf 100644
--- a/src/graphics/particle_kind.cpp
+++ b/src/graphics/particle_kind.cpp
@@ -100,7 +100,7 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
}
else
{
- fprintf(stderr, "[ParticleKind] main node has unknown value for attribute 'emitter'\n");
+ Log::warn("ParticleKind", " main node has unknown value for attribute 'emitter'.");
m_shape = EMITTER_POINT;
}
@@ -254,8 +254,8 @@ Material* ParticleKind::getMaterial() const
}
else
{
- fprintf(stderr, "[ParticleKind] WARNING: particle image '%s' does not appear in the list of "
- "currently known materials\n", m_material_file.c_str());
+ Log::warn("ParticleKind", "Particle image '%s' does not appear in the list of "
+ "currently known materials.", m_material_file.c_str());
return NULL;
}
}
diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp
index 9993087d8..90bf81d42 100644
--- a/src/graphics/render.cpp
+++ b/src/graphics/render.cpp
@@ -266,10 +266,6 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po
{
glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO);
- PROFILER_PUSH_CPU_MARKER("- Solid Pass 1", 0xFF, 0x00, 0x00);
- renderSolidFirstPass();
- PROFILER_POP_CPU_MARKER();
-
// Shadows
{
PROFILER_PUSH_CPU_MARKER("- Shadow", 0x30, 0x6F, 0x90);
@@ -283,6 +279,12 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po
PROFILER_POP_CPU_MARKER();
}
+ PROFILER_PUSH_CPU_MARKER("- Solid Pass 1", 0xFF, 0x00, 0x00);
+ renderSolidFirstPass();
+ PROFILER_POP_CPU_MARKER();
+
+
+
// Lights
{
PROFILER_PUSH_CPU_MARKER("- Light", 0x00, 0xFF, 0x00);
@@ -319,8 +321,7 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po
}
PROFILER_PUSH_CPU_MARKER("- Skybox", 0xFF, 0x00, 0xFF);
- if (!SkyboxTextures.empty())
- renderSkybox(camnode);
+ renderSkybox(camnode);
PROFILER_POP_CPU_MARKER();
if (getRH())
@@ -379,13 +380,6 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po
return;
}
- // Render displacement
- {
- PROFILER_PUSH_CPU_MARKER("- Displacement", 0x00, 0x00, 0xFF);
- ScopedGPUTimer Timer(getGPUTimer(Q_DISPLACEMENT));
- renderDisplacement();
- PROFILER_POP_CPU_MARKER();
- }
// Ensure that no object will be drawn after that by using invalid pass
irr_driver->setPhase(PASS_COUNT);
}
@@ -504,363 +498,6 @@ void IrrDriver::computeSunVisibility()
}
}
-void IrrDriver::renderSolidFirstPass()
-{
- m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind();
- glClearColor(0., 0., 0., 0.);
- glDepthMask(GL_TRUE);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-
- glDepthFunc(GL_LEQUAL);
- glEnable(GL_DEPTH_TEST);
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_BLEND);
- glEnable(GL_CULL_FACE);
- irr_driver->setPhase(SOLID_NORMAL_AND_DEPTH_PASS);
- GroupedFPSM::reset();
- GroupedFPSM::reset();
- GroupedFPSM::reset();
- GroupedFPSM::reset();
- m_scene_manager->drawAll(scene::ESNRP_SOLID);
-
- if (!UserConfigParams::m_dynamic_lights)
- return;
-
- {
- ScopedGPUTimer Timer(getGPUTimer(Q_SOLID_PASS1));
- glUseProgram(MeshShader::ObjectPass1Shader::Program);
- glBindVertexArray(getVAO(video::EVT_STANDARD));
- for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i)
- {
- GLMesh &mesh = *GroupedFPSM::MeshSet[i];
- if (!mesh.textures[0])
- mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
- compressTexture(mesh.textures[0], true);
- setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- draw(mesh, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], 0);
- }
-
- glBindVertexArray(getVAO(video::EVT_2TCOORDS));
- for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i)
- {
- GLMesh &mesh = *GroupedFPSM::MeshSet[i];
- if (!mesh.textures[0])
- mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
- compressTexture(mesh.textures[0], true);
- setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- draw(mesh, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], 0);
- }
-
- glUseProgram(MeshShader::ObjectRefPass1Shader::Program);
- glBindVertexArray(getVAO(EVT_STANDARD));
- for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i)
- {
- const GLMesh &mesh = *GroupedFPSM::MeshSet[i];
- if (mesh.VAOType != video::EVT_STANDARD)
- {
-#ifdef DEBUG
- Log::error("Materials", "Wrong vertex Type associed to alpha ref pass 1 (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
-#endif
- continue;
- }
- compressTexture(mesh.textures[0], true);
- setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
-
- draw(mesh, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], GroupedFPSM::MeshSet[i]->TextureMatrix, 0);
- }
- glUseProgram(MeshShader::NormalMapShader::Program);
- glBindVertexArray(getVAO(EVT_TANGENTS));
- for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i)
- {
- const GLMesh &mesh = *GroupedFPSM::MeshSet[i];
- assert(mesh.VAOType == video::EVT_TANGENTS);
- assert(mesh.textures[1]);
- compressTexture(mesh.textures[1], false);
- setTexture(0, getTextureGLuint(mesh.textures[1]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- compressTexture(mesh.textures[0], true);
- setTexture(1, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
-
- draw(mesh, GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], 0, 1);
- }
- }
-}
-
-template
-void renderMeshes2ndPass(std::vector &meshes, const std::vector &MVPMatrixes)
-{
- glUseProgram(Shader::Program);
- glBindVertexArray(getVAO(VertexType));
- for (unsigned i = 0; i < meshes.size(); i++)
- {
- GLMesh &mesh = *meshes[i];
- if (!mesh.textures[0])
- mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
- if (mesh.VAOType != VertexType)
- {
-#ifdef DEBUG
- Log::error("Materials", "Wrong vertex Type associed to pass 2 (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
-#endif
- continue;
- }
- compressTexture(mesh.textures[0], true);
- setTexture(MeshShader::ObjectPass2Shader::TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- if (irr_driver->getLightViz())
- {
- GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
- }
- else
- {
- GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
- }
- draw(mesh, MVPMatrixes[i], mesh.TextureMatrix);
- }
-}
-
-void IrrDriver::renderSolidSecondPass()
-{
- SColor clearColor(0, 150, 150, 150);
- if (World::getWorld() != NULL)
- clearColor = World::getWorld()->getClearColor();
-
- glClearColor(clearColor.getRed() / 255.f, clearColor.getGreen() / 255.f,
- clearColor.getBlue() / 255.f, clearColor.getAlpha() / 255.f);
- glClear(GL_COLOR_BUFFER_BIT);
-
- if (UserConfigParams::m_dynamic_lights)
- glDepthMask(GL_FALSE);
- else
- {
- glDepthMask(GL_TRUE);
- glClear(GL_DEPTH_BUFFER_BIT);
- }
-
- irr_driver->setPhase(SOLID_LIT_PASS);
- glEnable(GL_DEPTH_TEST);
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_BLEND);
- GroupedSM::reset();
- GroupedSM::reset();
- GroupedSM::reset();
- GroupedSM::reset();
- GroupedSM::reset();
- GroupedSM::reset();
- GroupedSM::reset();
- setTexture(0, m_rtts->getRenderTarget(RTT_TMP1), GL_NEAREST, GL_NEAREST);
- setTexture(1, m_rtts->getRenderTarget(RTT_TMP2), GL_NEAREST, GL_NEAREST);
- setTexture(2, m_rtts->getRenderTarget(RTT_HALF1_R), GL_LINEAR, GL_LINEAR);
-
- {
- ScopedGPUTimer Timer(getGPUTimer(Q_SOLID_PASS2));
-
- m_scene_manager->drawAll(scene::ESNRP_SOLID);
-
- renderMeshes2ndPass(GroupedSM::MeshSet, GroupedSM::MVPSet);
- renderMeshes2ndPass(GroupedSM::MeshSet, GroupedSM::MVPSet);
- renderMeshes2ndPass(GroupedSM::MeshSet, GroupedSM::MVPSet);
-
- glUseProgram(MeshShader::SphereMapShader::Program);
- glBindVertexArray(getVAO(EVT_STANDARD));
- for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++)
- {
- const GLMesh &mesh = *GroupedSM::MeshSet[i];
- assert(mesh.VAOType == EVT_STANDARD);
- compressTexture(mesh.textures[0], true);
- if (irr_driver->getLightViz())
- {
- GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
- }
- else
- {
- GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
- }
- setTexture(MeshShader::SphereMapShader::TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- draw(mesh, GroupedSM::MVPSet[i], GroupedSM::TIMVSet[i], irr_driver->getSceneManager()->getAmbientLight());
- }
-
- glUseProgram(MeshShader::SplattingShader::Program);
- glBindVertexArray(getVAO(EVT_2TCOORDS));
- for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++)
- drawSplatting(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i]);
-
- glUseProgram(MeshShader::ObjectUnlitShader::Program);
- glBindVertexArray(getVAO(EVT_STANDARD));
- for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++)
- {
- const GLMesh &mesh = *GroupedSM::MeshSet[i];
- assert(mesh.VAOType == EVT_STANDARD);
- compressTexture(mesh.textures[0], true);
- setTexture(MeshShader::ObjectUnlitShader::TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- if (irr_driver->getLightViz())
- {
- GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
- }
- else
- {
- GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
- }
- draw(mesh, GroupedSM::MVPSet[i]);
- }
-
- glUseProgram(MeshShader::DetailledObjectPass2Shader::Program);
- glBindVertexArray(getVAO(EVT_2TCOORDS));
- for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++)
- {
- GLMesh &mesh = *GroupedSM::MeshSet[i];
- assert(mesh.VAOType == EVT_2TCOORDS);
- compressTexture(mesh.textures[0], true);
- setTexture(MeshShader::DetailledObjectPass2Shader::TU_Albedo, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- if (irr_driver->getLightViz())
- {
- GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
- }
- else
- {
- GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
- }
- if (!mesh.textures[1])
- {
-#ifdef DEBUG
- Log::error("Materials", "No detail/lightmap texture provided for detail/lightmap material.");
-#endif
- mesh.textures[1] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
- }
- compressTexture(mesh.textures[1], true);
- setTexture(MeshShader::DetailledObjectPass2Shader::TU_detail, getTextureGLuint(mesh.textures[1]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- draw(mesh, GroupedSM::MVPSet[i]);
- }
- }
-}
-
-void IrrDriver::renderTransparent()
-{
- irr_driver->setPhase(TRANSPARENT_PASS);
- glEnable(GL_DEPTH_TEST);
- glDisable(GL_ALPHA_TEST);
- glDepthMask(GL_FALSE);
- glEnable(GL_BLEND);
- glBlendEquation(GL_FUNC_ADD);
- glDisable(GL_CULL_FACE);
- TransparentMeshes::reset();
- TransparentMeshes::reset();
- m_scene_manager->drawAll(scene::ESNRP_TRANSPARENT);
-
- glBindVertexArray(getVAO(EVT_STANDARD));
-
- if (World::getWorld() && World::getWorld()->isFogEnabled())
- {
- const Track * const track = World::getWorld()->getTrack();
-
- // This function is only called once per frame - thus no need for setters.
- const float fogmax = track->getFogMax();
- const float startH = track->getFogStartHeight();
- const float endH = track->getFogEndHeight();
- const float start = track->getFogStart();
- const float end = track->getFogEnd();
- const video::SColor tmpcol = track->getFogColor();
-
- core::vector3df col(tmpcol.getRed() / 255.0f,
- tmpcol.getGreen() / 255.0f,
- tmpcol.getBlue() / 255.0f);
-
- glUseProgram(MeshShader::TransparentFogShader::Program);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- for (unsigned i = 0; i < TransparentMeshes::MeshSet.size(); i++)
- {
- GLMesh &mesh = *TransparentMeshes::MeshSet[i];
- if (mesh.VAOType != EVT_STANDARD)
- {
-#ifdef DEBUG
- Log::error("Materials", "Wrong vertex Type associed to fog + transparent blend (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
-#endif
- glBindVertexArray(getVAO(mesh.VAOType));
- }
-
-
- if (!mesh.textures[0])
- mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
- compressTexture(mesh.textures[0], true);
- setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
-
- draw(mesh, TransparentMeshes::MVPSet[i], TransparentMeshes::MeshSet[i]->TextureMatrix, fogmax, startH, endH, start, end, col, Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition(), 0);
- if (mesh.VAOType != EVT_STANDARD)
- glBindVertexArray(getVAO(EVT_STANDARD));
- }
- glBlendFunc(GL_ONE, GL_ONE);
- for (unsigned i = 0; i < TransparentMeshes::MeshSet.size(); i++)
- {
- GLMesh &mesh = *TransparentMeshes::MeshSet[i];
- if (mesh.VAOType != EVT_STANDARD)
- {
-#ifdef DEBUG
- Log::error("Materials", "Wrong vertex Type associed to fog + transparent additive (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
-#endif
- glBindVertexArray(getVAO(mesh.VAOType));
- }
- glBindVertexArray(getVAO(mesh.VAOType));
-
- if (!mesh.textures[0])
- mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
- compressTexture(mesh.textures[0], true);
- setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
-
- draw(mesh, TransparentMeshes::MVPSet[i], TransparentMeshes::MeshSet[i]->TextureMatrix, fogmax, startH, endH, start, end, col, Camera::getCamera(0)->getCameraSceneNode()->getAbsolutePosition(), 0);
- if (mesh.VAOType != EVT_STANDARD)
- glBindVertexArray(getVAO(EVT_STANDARD));
- }
- }
- else
- {
- glUseProgram(MeshShader::TransparentShader::Program);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- for (unsigned i = 0; i < TransparentMeshes::MeshSet.size(); i++)
- {
- GLMesh &mesh = *TransparentMeshes::MeshSet[i];
- if (mesh.VAOType != EVT_STANDARD)
- {
-#ifdef DEBUG
- Log::error("Materials", "Wrong vertex Type associed to fog + transparent additive (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
-#endif
- glBindVertexArray(getVAO(mesh.VAOType));
- }
- glBindVertexArray(getVAO(mesh.VAOType));
- if (!mesh.textures[0])
- mesh.textures[0] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
- compressTexture(mesh.textures[0], true);
- setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- draw(mesh, TransparentMeshes::MVPSet[i], TransparentMeshes::MeshSet[i]->TextureMatrix, 0);
- if (mesh.VAOType != EVT_STANDARD)
- glBindVertexArray(getVAO(EVT_STANDARD));
- }
-
- glBlendFunc(GL_ONE, GL_ONE);
- for (unsigned i = 0; i < TransparentMeshes::MeshSet.size(); i++)
- {
- const GLMesh &mesh = *TransparentMeshes::MeshSet[i];
- if (mesh.VAOType != EVT_STANDARD)
- {
-#ifdef DEBUG
- Log::error("Materials", "Wrong vertex Type associed to fog + transparent additive (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
-#endif
- glBindVertexArray(getVAO(mesh.VAOType));
- }
- glBindVertexArray(getVAO(mesh.VAOType));
- compressTexture(mesh.textures[0], true);
- setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- draw(mesh, TransparentMeshes::MVPSet[i], TransparentMeshes::MeshSet[i]->TextureMatrix, 0);
- if (mesh.VAOType != EVT_STANDARD)
- glBindVertexArray(getVAO(EVT_STANDARD));
- }
- }
-}
-
void IrrDriver::renderParticles()
{
glDepthMask(GL_FALSE);
@@ -1063,66 +700,7 @@ void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, siz
delete []tmp;
}
-void IrrDriver::renderShadows()
-{
- irr_driver->setPhase(SHADOW_PASS);
- glDisable(GL_BLEND);
- glEnable(GL_POLYGON_OFFSET_FILL);
- glPolygonOffset(1.5, 0.);
- m_rtts->getShadowFBO().Bind();
- glClear(GL_DEPTH_BUFFER_BIT);
- glDrawBuffer(GL_NONE);
- glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO);
-
- m_scene_manager->drawAll(scene::ESNRP_SOLID);
-
- glUseProgram(MeshShader::ShadowShader::Program);
- glBindVertexArray(getVAO(EVT_STANDARD));
- for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i)
- drawShadow(*GroupedFPSM::MeshSet[i], GroupedFPSM::MVPSet[i]);
- glBindVertexArray(getVAO(EVT_2TCOORDS));
- for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i)
- drawShadow(*GroupedFPSM::MeshSet[i], GroupedFPSM::MVPSet[i]);
- glBindVertexArray(getVAO(EVT_TANGENTS));
- for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i)
- drawShadow(*GroupedFPSM::MeshSet[i], GroupedFPSM::MVPSet[i]);
-
- glUseProgram(MeshShader::RefShadowShader::Program);
- glBindVertexArray(getVAO(EVT_STANDARD));
- for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i)
- drawShadowRef(*GroupedFPSM::MeshSet[i], GroupedFPSM::MVPSet[i]);
-
- glDisable(GL_POLYGON_OFFSET_FILL);
-
- if (!UserConfigParams::m_gi)
- return;
-
- m_rtts->getRSM().Bind();
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glUseProgram(MeshShader::RSMShader::Program);
- glBindVertexArray(getVAO(EVT_STANDARD));
- for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i)
- {
- const GLMesh mesh = *GroupedFPSM::MeshSet[i];
- if (!mesh.textures[0])
- continue;
- compressTexture(mesh.textures[0], true);
- setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- draw(mesh, rsm_matrix, GroupedFPSM::MVPSet[i], 0);
- }
- glBindVertexArray(getVAO(EVT_2TCOORDS));
- for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i)
- {
- const GLMesh mesh = *GroupedFPSM::MeshSet[i];
- if (!mesh.textures[0])
- continue;
- compressTexture(mesh.textures[0], true);
- setTexture(0, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
- draw(mesh, rsm_matrix, GroupedFPSM::MVPSet[i], 0);
- }
-}
static void renderWireFrameFrustrum(float *tmp, unsigned i)
{
@@ -1211,704 +789,4 @@ void IrrDriver::renderGlow(std::vector& glows)
m_rtts->getFBO(FBO_COLORS).Bind();
m_post_processing->renderGlow(m_rtts->getRenderTarget(RTT_QUARTER1));
glDisable(GL_STENCIL_TEST);
-}
-
-// ----------------------------------------------------------------------------
-
-static LightShader::PointLightInfo PointLightsInfo[MAXLIGHT];
-
-static void renderPointLights(unsigned count)
-{
- glEnable(GL_BLEND);
- glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_ONE, GL_ONE);
- glEnable(GL_DEPTH_TEST);
- glDepthMask(GL_FALSE);
-
- glUseProgram(LightShader::PointLightShader::Program);
- glBindVertexArray(LightShader::PointLightShader::vao);
- glBindBuffer(GL_ARRAY_BUFFER, LightShader::PointLightShader::vbo);
- glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(LightShader::PointLightInfo), PointLightsInfo);
-
- setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST);
- setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
- LightShader::PointLightShader
- ::setUniforms(core::vector2df(float(UserConfigParams::m_width),
- float(UserConfigParams::m_height) ),
- 200, 0, 1);
-
- glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
-}
-
-unsigned IrrDriver::UpdateLightsInfo(scene::ICameraSceneNode * const camnode, float dt)
-{
- const u32 lightcount = m_lights.size();
- const core::vector3df &campos = camnode->getAbsolutePosition();
-
- std::vector BucketedLN[15];
- for (unsigned int i = 0; i < lightcount; i++)
- {
- if (!m_lights[i]->isPointLight())
- {
- m_lights[i]->render();
- continue;
- }
- const core::vector3df &lightpos = (m_lights[i]->getAbsolutePosition() - campos);
- unsigned idx = (unsigned)(lightpos.getLength() / 10);
- if (idx > 14)
- idx = 14;
- BucketedLN[idx].push_back(m_lights[i]);
- }
-
- unsigned lightnum = 0;
-
- for (unsigned i = 0; i < 15; i++)
- {
- for (unsigned j = 0; j < BucketedLN[i].size(); j++)
- {
- if (++lightnum >= MAXLIGHT)
- {
- LightNode* light_node = BucketedLN[i].at(j);
- light_node->setEnergyMultiplier(0.0f);
- }
- else
- {
- LightNode* light_node = BucketedLN[i].at(j);
-
- float em = light_node->getEnergyMultiplier();
- if (em < 1.0f)
- {
- light_node->setEnergyMultiplier(std::min(1.0f, em + dt));
- }
-
- const core::vector3df &pos = light_node->getAbsolutePosition();
- PointLightsInfo[lightnum].posX = pos.X;
- PointLightsInfo[lightnum].posY = pos.Y;
- PointLightsInfo[lightnum].posZ = pos.Z;
-
- PointLightsInfo[lightnum].energy = light_node->getEffectiveEnergy();
-
- const core::vector3df &col = light_node->getColor();
- PointLightsInfo[lightnum].red = col.X;
- PointLightsInfo[lightnum].green = col.Y;
- PointLightsInfo[lightnum].blue = col.Z;
-
- // Light radius
- PointLightsInfo[lightnum].radius = light_node->getRadius();
- }
- }
- if (lightnum > MAXLIGHT)
- {
- irr_driver->setLastLightBucketDistance(i * 10);
- break;
- }
- }
-
- lightnum++;
- return lightnum;
-}
-
-void IrrDriver::renderLights(unsigned pointlightcount)
-{
- //RH
- if (UserConfigParams::m_gi)
- {
- ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_RH));
- glDisable(GL_BLEND);
- m_rtts->getRH().Bind();
- glUseProgram(FullScreenShader::RadianceHintsConstructionShader::Program);
- glBindVertexArray(FullScreenShader::RadianceHintsConstructionShader::vao);
- setTexture(0, m_rtts->getRSM().getRTT()[0], GL_LINEAR, GL_LINEAR);
- setTexture(1, m_rtts->getRSM().getRTT()[1], GL_LINEAR, GL_LINEAR);
- setTexture(2, m_rtts->getRSM().getDepthTexture(), GL_LINEAR, GL_LINEAR);
- FullScreenShader::RadianceHintsConstructionShader::setUniforms(rsm_matrix, rh_matrix, rh_extend, 0, 1, 2);
- glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 32);
- }
-
- for (unsigned i = 0; i < sun_ortho_matrix.size(); i++)
- sun_ortho_matrix[i] *= getInvViewMatrix();
- m_rtts->getFBO(FBO_COMBINED_TMP1_TMP2).Bind();
- if (!UserConfigParams::m_dynamic_lights)
- glClearColor(.5, .5, .5, .5);
- glClear(GL_COLOR_BUFFER_BIT);
- if (!UserConfigParams::m_dynamic_lights)
- return;
-
- m_rtts->getFBO(FBO_TMP1_WITH_DS).Bind();
- if (UserConfigParams::m_gi)
- {
- ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_GI));
- m_post_processing->renderGI(rh_matrix, rh_extend, m_rtts->getRH().getRTT()[0], m_rtts->getRH().getRTT()[1], m_rtts->getRH().getRTT()[2]);
- }
-
- if (SkyboxCubeMap)
- {
- ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_ENVMAP));
- m_post_processing->renderDiffuseEnvMap(blueSHCoeff, greenSHCoeff, redSHCoeff);
- }
- m_rtts->getFBO(FBO_COMBINED_TMP1_TMP2).Bind();
-
- if (World::getWorld() && World::getWorld()->getTrack()->hasShadows() && SkyboxCubeMap)
- irr_driver->getSceneManager()->setAmbientLight(SColor(0, 0, 0, 0));
-
- // Render sunlight if and only if track supports shadow
- if (!World::getWorld() || World::getWorld()->getTrack()->hasShadows())
- {
- ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_SUN));
- if (World::getWorld() && UserConfigParams::m_shadows)
- m_post_processing->renderShadowedSunlight(sun_ortho_matrix, m_rtts->getShadowDepthTex());
- else
- m_post_processing->renderSunlight();
- }
- {
- ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_POINTLIGHTS));
- renderPointLights(MIN2(pointlightcount, MAXLIGHT));
- }
-}
-
-void IrrDriver::renderSSAO()
-{
- m_rtts->getFBO(FBO_SSAO).Bind();
- glClearColor(1., 1., 1., 1.);
- glClear(GL_COLOR_BUFFER_BIT);
- m_post_processing->renderSSAO();
- // Blur it to reduce noise.
- FrameBuffer::Blit(m_rtts->getFBO(FBO_SSAO), m_rtts->getFBO(FBO_HALF1_R), GL_COLOR_BUFFER_BIT, GL_LINEAR);
- m_post_processing->renderGaussian17TapBlur(irr_driver->getFBO(FBO_HALF1_R), irr_driver->getFBO(FBO_HALF2_R));
-
-}
-
-static void getXYZ(GLenum face, float i, float j, float &x, float &y, float &z)
-{
- switch (face)
- {
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- x = 1.;
- y = -i;
- z = -j;
- break;
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- x = -1.;
- y = -i;
- z = j;
- break;
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- x = j;
- y = 1.;
- z = i;
- break;
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- x = j;
- y = -1;
- z = -i;
- break;
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- x = j;
- y = -i;
- z = 1;
- break;
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
- x = -j;
- y = -i;
- z = -1;
- break;
- }
-
- float norm = sqrt(x * x + y * y + z * z);
- x /= norm, y /= norm, z /= norm;
- return;
-}
-
-static void getYml(GLenum face, size_t width, size_t height,
- float *Y00,
- float *Y1minus1, float *Y10, float *Y11,
- float *Y2minus2, float *Y2minus1, float *Y20, float *Y21, float *Y22)
-{
- for (unsigned i = 0; i < width; i++)
- {
- for (unsigned j = 0; j < height; j++)
- {
- float x, y, z;
- float fi = float(i), fj = float(j);
- fi /= width, fj /= height;
- fi = 2 * fi - 1, fj = 2 * fj - 1;
- getXYZ(face, fi, fj, x, y, z);
-
- // constant part of Ylm
- float c00 = 0.282095f;
- float c1minus1 = 0.488603f;
- float c10 = 0.488603f;
- float c11 = 0.488603f;
- float c2minus2 = 1.092548f;
- float c2minus1 = 1.092548f;
- float c21 = 1.092548f;
- float c20 = 0.315392f;
- float c22 = 0.546274f;
-
- size_t idx = i * height + j;
-
- Y00[idx] = c00;
- Y1minus1[idx] = c1minus1 * y;
- Y10[idx] = c10 * z;
- Y11[idx] = c11 * x;
- Y2minus2[idx] = c2minus2 * x * y;
- Y2minus1[idx] = c2minus1 * y * z;
- Y21[idx] = c21 * x * z;
- Y20[idx] = c20 * (3 * z * z - 1);
- Y22[idx] = c22 * (x * x - y * y);
- }
- }
-}
-
-static float getTexelValue(unsigned i, unsigned j, size_t width, size_t height, float *Coeff, float *Y00, float *Y1minus1, float *Y10, float *Y11,
- float *Y2minus2, float * Y2minus1, float * Y20, float *Y21, float *Y22)
-{
- float d = sqrt((float)(i * i + j * j + 1));
- float solidangle = 1.;
- size_t idx = i * height + j;
- float reconstructedVal = Y00[idx] * Coeff[0];
- reconstructedVal += Y1minus1[i * height + j] * Coeff[1] + Y10[i * height + j] * Coeff[2] + Y11[i * height + j] * Coeff[3];
- reconstructedVal += Y2minus2[idx] * Coeff[4] + Y2minus1[idx] * Coeff[5] + Y20[idx] * Coeff[6] + Y21[idx] * Coeff[7] + Y22[idx] * Coeff[8];
- reconstructedVal /= solidangle;
- return MAX2(255.0f * reconstructedVal, 0.f);
-}
-
-static void unprojectSH(float *output[], size_t width, size_t height,
- float *Y00[],
- float *Y1minus1[], float *Y10[], float *Y11[],
- float *Y2minus2[], float *Y2minus1[], float * Y20[],float *Y21[], float *Y22[],
- float *blueSHCoeff, float *greenSHCoeff, float *redSHCoeff)
-{
- for (unsigned face = 0; face < 6; face++)
- {
- for (unsigned i = 0; i < width; i++)
- {
- for (unsigned j = 0; j < height; j++)
- {
- float fi = float(i), fj = float(j);
- fi /= width, fj /= height;
- fi = 2 * fi - 1, fj = 2 * fj - 1;
-
- output[face][4 * height * i + 4 * j + 2] = getTexelValue(i, j, width, height,
- redSHCoeff,
- Y00[face], Y1minus1[face], Y10[face], Y11[face], Y2minus2[face], Y2minus1[face], Y20[face], Y21[face], Y22[face]);
- output[face][4 * height * i + 4 * j + 1] = getTexelValue(i, j, width, height,
- greenSHCoeff,
- Y00[face], Y1minus1[face], Y10[face], Y11[face], Y2minus2[face], Y2minus1[face], Y20[face], Y21[face], Y22[face]);
- output[face][4 * height * i + 4 * j] = getTexelValue(i, j, width, height,
- blueSHCoeff,
- Y00[face], Y1minus1[face], Y10[face], Y11[face], Y2minus2[face], Y2minus1[face], Y20[face], Y21[face], Y22[face]);
- }
- }
- }
-}
-
-static void projectSH(float *color[], size_t width, size_t height,
- float *Y00[],
- float *Y1minus1[], float *Y10[], float *Y11[],
- float *Y2minus2[], float *Y2minus1[], float * Y20[], float *Y21[], float *Y22[],
- float *blueSHCoeff, float *greenSHCoeff, float *redSHCoeff
- )
-{
- for (unsigned i = 0; i < 9; i++)
- {
- blueSHCoeff[i] = 0;
- greenSHCoeff[i] = 0;
- redSHCoeff[i] = 0;
- }
- float wh = float(width * height);
- for (unsigned face = 0; face < 6; face++)
- {
- for (unsigned i = 0; i < width; i++)
- {
- for (unsigned j = 0; j < height; j++)
- {
- size_t idx = i * height + j;
- float fi = float(i), fj = float(j);
- fi /= width, fj /= height;
- fi = 2 * fi - 1, fj = 2 * fj - 1;
-
-
- float d = sqrt(fi * fi + fj * fj + 1);
-
- // Constant obtained by projecting unprojected ref values
- float solidangle = 2.75f / (wh * pow(d, 1.5f));
- // pow(., 2.2) to convert from srgb
- float b = pow(color[face][4 * height * i + 4 * j ] / 255.f, 2.2f);
- float g = pow(color[face][4 * height * i + 4 * j + 1] / 255.f, 2.2f);
- float r = pow(color[face][4 * height * i + 4 * j + 2] / 255.f, 2.2f);
-
- assert(b >= 0.);
-
- blueSHCoeff[0] += b * Y00[face][idx] * solidangle;
- blueSHCoeff[1] += b * Y1minus1[face][idx] * solidangle;
- blueSHCoeff[2] += b * Y10[face][idx] * solidangle;
- blueSHCoeff[3] += b * Y11[face][idx] * solidangle;
- blueSHCoeff[4] += b * Y2minus2[face][idx] * solidangle;
- blueSHCoeff[5] += b * Y2minus1[face][idx] * solidangle;
- blueSHCoeff[6] += b * Y20[face][idx] * solidangle;
- blueSHCoeff[7] += b * Y21[face][idx] * solidangle;
- blueSHCoeff[8] += b * Y22[face][idx] * solidangle;
-
- greenSHCoeff[0] += g * Y00[face][idx] * solidangle;
- greenSHCoeff[1] += g * Y1minus1[face][idx] * solidangle;
- greenSHCoeff[2] += g * Y10[face][idx] * solidangle;
- greenSHCoeff[3] += g * Y11[face][idx] * solidangle;
- greenSHCoeff[4] += g * Y2minus2[face][idx] * solidangle;
- greenSHCoeff[5] += g * Y2minus1[face][idx] * solidangle;
- greenSHCoeff[6] += g * Y20[face][idx] * solidangle;
- greenSHCoeff[7] += g * Y21[face][idx] * solidangle;
- greenSHCoeff[8] += g * Y22[face][idx] * solidangle;
-
-
- redSHCoeff[0] += r * Y00[face][idx] * solidangle;
- redSHCoeff[1] += r * Y1minus1[face][idx] * solidangle;
- redSHCoeff[2] += r * Y10[face][idx] * solidangle;
- redSHCoeff[3] += r * Y11[face][idx] * solidangle;
- redSHCoeff[4] += r * Y2minus2[face][idx] * solidangle;
- redSHCoeff[5] += r * Y2minus1[face][idx] * solidangle;
- redSHCoeff[6] += r * Y20[face][idx] * solidangle;
- redSHCoeff[7] += r * Y21[face][idx] * solidangle;
- redSHCoeff[8] += r * Y22[face][idx] * solidangle;
- }
- }
- }
-}
-
-static void displayCoeff(float *SHCoeff)
-{
- printf("L00:%f\n", SHCoeff[0]);
- printf("L1-1:%f, L10:%f, L11:%f\n", SHCoeff[1], SHCoeff[2], SHCoeff[3]);
- printf("L2-2:%f, L2-1:%f, L20:%f, L21:%f, L22:%f\n", SHCoeff[4], SHCoeff[5], SHCoeff[6], SHCoeff[7], SHCoeff[8]);
-}
-
-// Only for 9 coefficients
-static void testSH(unsigned char *color[6], size_t width, size_t height,
- float *blueSHCoeff, float *greenSHCoeff, float *redSHCoeff)
-{
- float *Y00[6];
- float *Y1minus1[6];
- float *Y10[6];
- float *Y11[6];
- float *Y2minus2[6];
- float *Y2minus1[6];
- float *Y20[6];
- float *Y21[6];
- float *Y22[6];
-
- float *testoutput[6];
- for (unsigned i = 0; i < 6; i++)
- {
- testoutput[i] = new float[width * height * 4];
- for (unsigned j = 0; j < width * height; j++)
- {
- testoutput[i][4 * j ] = float(0xFF & color[i][4 * j]);
- testoutput[i][4 * j + 1] = float(0xFF & color[i][4 * j + 1]);
- testoutput[i][4 * j + 2] = float(0xFF & color[i][4 * j + 2]);
- }
- }
-
- for (unsigned face = 0; face < 6; face++)
- {
- Y00[face] = new float[width * height];
- Y1minus1[face] = new float[width * height];
- Y10[face] = new float[width * height];
- Y11[face] = new float[width * height];
- Y2minus2[face] = new float[width * height];
- Y2minus1[face] = new float[width * height];
- Y20[face] = new float[width * height];
- Y21[face] = new float[width * height];
- Y22[face] = new float[width * height];
-
- getYml(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, width, height, Y00[face], Y1minus1[face], Y10[face], Y11[face], Y2minus2[face], Y2minus1[face], Y20[face], Y21[face], Y22[face]);
- }
-
-/* blueSHCoeff[0] = 0.54,
- blueSHCoeff[1] = .6, blueSHCoeff[2] = -.27, blueSHCoeff[3] = .01,
- blueSHCoeff[4] = -.12, blueSHCoeff[5] = -.47, blueSHCoeff[6] = -.15, blueSHCoeff[7] = .14, blueSHCoeff[8] = -.3;
- greenSHCoeff[0] = .44,
- greenSHCoeff[1] = .35, greenSHCoeff[2] = -.18, greenSHCoeff[3] = -.06,
- greenSHCoeff[4] = -.05, greenSHCoeff[5] = -.22, greenSHCoeff[6] = -.09, greenSHCoeff[7] = .21, greenSHCoeff[8] = -.05;
- redSHCoeff[0] = .79,
- redSHCoeff[1] = .39, redSHCoeff[2] = -.34, redSHCoeff[3] = -.29,
- redSHCoeff[4] = -.11, redSHCoeff[5] = -.26, redSHCoeff[6] = -.16, redSHCoeff[7] = .56, redSHCoeff[8] = .21;
-
- printf("Blue:\n");
- displayCoeff(blueSHCoeff);
- printf("Green:\n");
- displayCoeff(greenSHCoeff);
- printf("Red:\n");
- displayCoeff(redSHCoeff);*/
-
- projectSH(testoutput, width, height,
- Y00,
- Y1minus1, Y10, Y11,
- Y2minus2, Y2minus1, Y20, Y21, Y22,
- blueSHCoeff, greenSHCoeff, redSHCoeff
- );
-
- //printf("Blue:\n");
- //displayCoeff(blueSHCoeff);
- //printf("Green:\n");
- //displayCoeff(greenSHCoeff);
- //printf("Red:\n");
- //displayCoeff(redSHCoeff);
-
-
-
- // Convolute in frequency space
-/* float A0 = 3.141593;
- float A1 = 2.094395;
- float A2 = 0.785398;
- blueSHCoeff[0] *= A0;
- greenSHCoeff[0] *= A0;
- redSHCoeff[0] *= A0;
- for (unsigned i = 0; i < 3; i++)
- {
- blueSHCoeff[1 + i] *= A1;
- greenSHCoeff[1 + i] *= A1;
- redSHCoeff[1 + i] *= A1;
- }
- for (unsigned i = 0; i < 5; i++)
- {
- blueSHCoeff[4 + i] *= A2;
- greenSHCoeff[4 + i] *= A2;
- redSHCoeff[4 + i] *= A2;
- }
-
-
- unprojectSH(testoutput, width, height,
- Y00,
- Y1minus1, Y10, Y11,
- Y2minus2, Y2minus1, Y20, Y21, Y22,
- blueSHCoeff, greenSHCoeff, redSHCoeff
- );*/
-
-
-/* printf("Blue:\n");
- displayCoeff(blueSHCoeff);
- printf("Green:\n");
- displayCoeff(greenSHCoeff);
- printf("Red:\n");
- displayCoeff(redSHCoeff);
-
- printf("\nAfter projection\n\n");*/
-
-
-
- for (unsigned i = 0; i < 6; i++)
- {
- for (unsigned j = 0; j < width * height; j++)
- {
- color[i][4 * j ] = char(MIN2(testoutput[i][4 * j], 255));
- color[i][4 * j + 1] = char(MIN2(testoutput[i][4 * j + 1], 255));
- color[i][4 * j + 2] = char(MIN2(testoutput[i][4 * j + 2], 255));
- }
- }
-
- for (unsigned face = 0; face < 6; face++)
- {
- delete[] testoutput[face];
- delete[] Y00[face];
- delete[] Y1minus1[face];
- delete[] Y10[face];
- delete[] Y11[face];
- }
-}
-
-/** Generate an opengl cubemap texture from 6 2d textures.
- Out of legacy the sequence of textures maps to :
- - 1st texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_Y
- - 2nd texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
- - 3rd texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_X
- - 4th texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_X
- - 5th texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
- - 6th texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_Z
-* \param textures sequence of 6 textures.
-*/
-GLuint generateCubeMapFromTextures(const std::vector &textures)
-{
- GLuint result;
- glGenTextures(1, &result);
-
- unsigned w = 0, h = 0;
- for (unsigned i = 0; i < 6; i++)
- {
- w = MAX2(w, textures[i]->getOriginalSize().Width);
- h = MAX2(h, textures[i]->getOriginalSize().Height);
- }
-
- const unsigned texture_permutation[] = { 2, 3, 0, 1, 5, 4 };
- char *rgba[6];
- for (unsigned i = 0; i < 6; i++)
- rgba[i] = new char[w * h * 4];
- for (unsigned i = 0; i < 6; i++)
- {
- unsigned idx = texture_permutation[i];
-
- video::IImage* image = irr_driver->getVideoDriver()->createImageFromData(
- textures[idx]->getColorFormat(),
- textures[idx]->getSize(),
- textures[idx]->lock(),
- false
- );
- textures[idx]->unlock();
-
- image->copyToScaling(rgba[i], w, h);
- image->drop();
-
- glBindTexture(GL_TEXTURE_CUBE_MAP, result);
- if (UserConfigParams::m_texture_compression)
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_COMPRESSED_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
- else
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
- }
- for (unsigned i = 0; i < 6; i++)
- delete[] rgba[i];
- return result;
-}
-
-void IrrDriver::generateSkyboxCubemap()
-{
- glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
-
- SkyboxCubeMap = generateCubeMapFromTextures(SkyboxTextures);
- const unsigned texture_permutation[] = { 2, 3, 0, 1, 5, 4 };
-
- if (SphericalHarmonicsTextures.size() == 6)
- {
- unsigned sh_w = 0, sh_h = 0;
- for (unsigned i = 0; i < 6; i++)
- {
- sh_w = MAX2(sh_w, SphericalHarmonicsTextures[i]->getOriginalSize().Width);
- sh_h = MAX2(sh_h, SphericalHarmonicsTextures[i]->getOriginalSize().Height);
- }
-
- unsigned char *sh_rgba[6];
- for (unsigned i = 0; i < 6; i++)
- sh_rgba[i] = new unsigned char[sh_w * sh_h * 4];
- for (unsigned i = 0; i < 6; i++)
- {
- unsigned idx = texture_permutation[i];
-
- video::IImage* image = getVideoDriver()->createImageFromData(
- SphericalHarmonicsTextures[idx]->getColorFormat(),
- SphericalHarmonicsTextures[idx]->getSize(),
- SphericalHarmonicsTextures[idx]->lock(),
- false
- );
- SphericalHarmonicsTextures[idx]->unlock();
-
- image->copyToScaling(sh_rgba[i], sh_w, sh_h);
- image->drop();
- }
-
- testSH(sh_rgba, sh_w, sh_h, blueSHCoeff, greenSHCoeff, redSHCoeff);
-
- for (unsigned i = 0; i < 6; i++)
- delete[] sh_rgba[i];
- }
- else
- {
- int sh_w = 16;
- int sh_h = 16;
-
- const video::SColorf& ambientf = irr_driver->getSceneManager()->getAmbientLight();
- video::SColor ambient = ambientf.toSColor();
-
- unsigned char *sh_rgba[6];
- for (unsigned i = 0; i < 6; i++)
- {
- sh_rgba[i] = new unsigned char[sh_w * sh_h * 4];
-
- for (int j = 0; j < sh_w * sh_h * 4; j+=4)
- {
- sh_rgba[i][j] = ambient.getBlue();
- sh_rgba[i][j + 1] = ambient.getGreen();
- sh_rgba[i][j + 2] = ambient.getRed();
- sh_rgba[i][j + 3] = 255;
- }
- }
-
- testSH(sh_rgba, sh_w, sh_h, blueSHCoeff, greenSHCoeff, redSHCoeff);
-
- for (unsigned i = 0; i < 6; i++)
- delete[] sh_rgba[i];
- }
-
- /*for (unsigned i = 0; i < 6; i++)
- {
- glBindTexture(GL_TEXTURE_CUBE_MAP, ConvolutedSkyboxCubeMap);
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
- }
-
- glBindTexture(GL_TEXTURE_CUBE_MAP, 0);*/
-}
-
-void IrrDriver::renderSkybox(const scene::ICameraSceneNode *camera)
-{
- if (!SkyboxCubeMap)
- generateSkyboxCubemap();
- glBindVertexArray(MeshShader::SkyboxShader::cubevao);
- glDisable(GL_CULL_FACE);
- assert(SkyboxTextures.size() == 6);
-
- core::matrix4 translate;
- translate.setTranslation(camera->getAbsolutePosition());
-
- // Draw the sky box between the near and far clip plane
- const f32 viewDistance = (camera->getNearValue() + camera->getFarValue()) * 0.5f;
- core::matrix4 scale;
- scale.setScale(core::vector3df(viewDistance, viewDistance, viewDistance));
- core::matrix4 transform = translate * scale;
- core::matrix4 invtransform;
- transform.getInverse(invtransform);
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_CUBE_MAP, SkyboxCubeMap);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glUseProgram(MeshShader::SkyboxShader::Program);
- MeshShader::SkyboxShader::setUniforms(transform,
- core::vector2df(float(UserConfigParams::m_width),
- float(UserConfigParams::m_height)),
- 0);
- glDrawElements(GL_TRIANGLES, 6 * 6, GL_UNSIGNED_INT, 0);
- glBindVertexArray(0);
-}
-
-// ----------------------------------------------------------------------------
-
-void IrrDriver::renderDisplacement()
-{
- irr_driver->getFBO(FBO_TMP1_WITH_DS).Bind();
- glClear(GL_COLOR_BUFFER_BIT);
- irr_driver->getFBO(FBO_DISPLACE).Bind();
- glClear(GL_COLOR_BUFFER_BIT);
-
- DisplaceProvider * const cb = (DisplaceProvider *)irr_driver->getCallback(ES_DISPLACE);
- cb->update();
-
- const int displacingcount = m_displacing.size();
- irr_driver->setPhase(DISPLACEMENT_PASS);
- glEnable(GL_DEPTH_TEST);
- glDisable(GL_ALPHA_TEST);
- glDepthMask(GL_FALSE);
- glDisable(GL_BLEND);
- glClear(GL_STENCIL_BUFFER_BIT);
- glEnable(GL_STENCIL_TEST);
- glStencilFunc(GL_ALWAYS, 1, 0xFF);
- glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
-
- glBindVertexArray(getVAO(EVT_2TCOORDS));
- for (int i = 0; i < displacingcount; i++)
- {
- m_scene_manager->setCurrentRendertime(scene::ESNRP_TRANSPARENT);
- m_displacing[i]->render();
- }
-
- irr_driver->getFBO(FBO_COLORS).Bind();
- glStencilFunc(GL_EQUAL, 1, 0xFF);
- m_post_processing->renderPassThrough(m_rtts->getRenderTarget(RTT_DISPLACE));
- glDisable(GL_STENCIL_TEST);
-}
+}
\ No newline at end of file
diff --git a/src/graphics/render_geometry.cpp b/src/graphics/render_geometry.cpp
new file mode 100644
index 000000000..20ee1d760
--- /dev/null
+++ b/src/graphics/render_geometry.cpp
@@ -0,0 +1,486 @@
+#include "graphics/irr_driver.hpp"
+
+#include "config/user_config.hpp"
+#include "graphics/callbacks.hpp"
+#include "graphics/camera.hpp"
+#include "graphics/glwrap.hpp"
+#include "graphics/lens_flare.hpp"
+#include "graphics/light.hpp"
+#include "graphics/lod_node.hpp"
+#include "graphics/material_manager.hpp"
+#include "graphics/particle_kind_manager.hpp"
+#include "graphics/per_camera_node.hpp"
+#include "graphics/post_processing.hpp"
+#include "graphics/referee.hpp"
+#include "graphics/rtts.hpp"
+#include "graphics/screenquad.hpp"
+#include "graphics/shaders.hpp"
+#include "graphics/stkmeshscenenode.hpp"
+#include "graphics/stkinstancedscenenode.hpp"
+#include "graphics/wind.hpp"
+#include "io/file_manager.hpp"
+#include "items/item.hpp"
+#include "items/item_manager.hpp"
+#include "modes/world.hpp"
+#include "physics/physics.hpp"
+#include "tracks/track.hpp"
+#include "utils/constants.hpp"
+#include "utils/helpers.hpp"
+#include "utils/log.hpp"
+#include "utils/profiler.hpp"
+
+#include
+
+
+template
+void draw(const GLMesh *mesh, uniforms... Args)
+{
+ irr_driver->IncreaseObjectCount();
+ GLenum ptype = mesh->PrimitiveType;
+ GLenum itype = mesh->IndexType;
+ size_t count = mesh->IndexCount;
+
+ Shader::setUniforms(Args...);
+ glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, mesh->vaoBaseVertex);
+}
+
+
+template
+void draw(const T *Shader, const GLMesh *mesh, uniforms... Args)
+{
+ irr_driver->IncreaseObjectCount();
+ GLenum ptype = mesh->PrimitiveType;
+ GLenum itype = mesh->IndexType;
+ size_t count = mesh->IndexCount;
+
+ Shader->setUniforms(Args...);
+ glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, mesh->vaoBaseVertex);
+}
+
+template
+struct unroll_args_instance
+{
+ template
+ static void exec(const T *Shader, const std::tuple &t, Args... args)
+ {
+ unroll_args_instance::template exec(Shader, t, std::get(t), args...);
+ }
+};
+
+template<>
+struct unroll_args_instance<0>
+{
+ template
+ static void exec(const T *Shader, const std::tuple &t, Args... args)
+ {
+ draw(Shader, args...);
+ }
+};
+
+template
+void apply_instance(const T *Shader, const std::tuple &arg)
+{
+ unroll_args_instance >::value >::template exec(Shader, arg);
+}
+
+template
+struct custom_unroll_args;
+
+template<>
+struct custom_unroll_args<>
+{
+ template
+ static void exec(const T *Shader, const std::tuple &t, Args... args)
+ {
+ draw(Shader, std::get<0>(t), args...);
+ }
+};
+
+template
+struct custom_unroll_args
+{
+ template
+ static void exec(const T *Shader, const std::tuple &t, Args... args)
+ {
+ custom_unroll_args::template exec(Shader, t, std::get(t), args...);
+ }
+};
+
+
+template
+void renderMeshes1stPass(const std::vector > &TexUnits, std::vector > &meshes)
+{
+ glUseProgram(Shader::getInstance()->Program);
+ glBindVertexArray(getVAO(VertexType));
+ for (unsigned i = 0; i < meshes.size(); i++)
+ {
+ GLMesh &mesh = *(std::get<0>(meshes[i]));
+ for (unsigned j = 0; j < TexUnits.size(); j++)
+ {
+ if (!mesh.textures[j])
+ mesh.textures[j] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
+ compressTexture(mesh.textures[j], TexUnits[j].second);
+ setTexture(TexUnits[j].first, getTextureGLuint(mesh.textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
+ }
+ if (mesh.VAOType != VertexType)
+ {
+#ifdef DEBUG
+ Log::error("Materials", "Wrong vertex Type associed to pass 1 (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
+#endif
+ continue;
+ }
+ custom_unroll_args::template exec(Shader::getInstance(), meshes[i]);
+ }
+}
+
+void IrrDriver::renderSolidFirstPass()
+{
+ m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind();
+ glClearColor(0., 0., 0., 0.);
+ glDepthMask(GL_TRUE);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+
+ glDepthFunc(GL_LEQUAL);
+ glEnable(GL_DEPTH_TEST);
+ glDisable(GL_ALPHA_TEST);
+ glDisable(GL_BLEND);
+ glEnable(GL_CULL_FACE);
+ irr_driver->setPhase(SOLID_NORMAL_AND_DEPTH_PASS);
+ ListMatDefault::Arguments.clear();
+ ListMatAlphaRef::Arguments.clear();
+ ListMatSphereMap::Arguments.clear();
+ ListMatDetails::Arguments.clear();
+ ListMatUnlit::Arguments.clear();
+ ListMatNormalMap::Arguments.clear();
+ ListMatGrass::Arguments.clear();
+ ListMatSplatting::Arguments.clear();
+ m_scene_manager->drawAll(scene::ESNRP_SOLID);
+
+ if (!UserConfigParams::m_dynamic_lights)
+ return;
+
+ {
+ ScopedGPUTimer Timer(getGPUTimer(Q_SOLID_PASS1));
+ renderMeshes1stPass({ { MeshShader::ObjectPass1Shader::getInstance()->TU_tex, true } }, ListMatDefault::Arguments);
+ renderMeshes1stPass({ { MeshShader::ObjectPass1Shader::getInstance()->TU_tex, true } }, ListMatSphereMap::Arguments);
+ renderMeshes1stPass({ { MeshShader::ObjectPass1Shader::getInstance()->TU_tex, true } }, ListMatUnlit::Arguments);
+ renderMeshes1stPass({ { MeshShader::ObjectPass1Shader::getInstance()->TU_tex, true } }, ListMatDetails::Arguments);
+ renderMeshes1stPass({ { MeshShader::ObjectPass1Shader::getInstance()->TU_tex, true } }, ListMatSplatting::Arguments);
+ renderMeshes1stPass({ { MeshShader::ObjectRefPass1Shader::getInstance()->TU_tex, true } }, ListMatAlphaRef::Arguments);
+ renderMeshes1stPass({ { MeshShader::GrassPass1Shader::getInstance()->TU_tex, true } }, ListMatGrass::Arguments);
+ renderMeshes1stPass({ { MeshShader::NormalMapShader::getInstance()->TU_glossy, true }, { MeshShader::NormalMapShader::getInstance()->TU_normalmap, false } }, ListMatNormalMap::Arguments);
+ }
+}
+
+template
+void renderMeshes2ndPass(const std::vector > &TexUnits, std::vector > &meshes)
+{
+ glUseProgram(Shader::getInstance()->Program);
+ glBindVertexArray(getVAO(VertexType));
+ for (unsigned i = 0; i < meshes.size(); i++)
+ {
+ GLMesh &mesh = *(std::get<0>(meshes[i]));
+ for (unsigned j = 0; j < TexUnits.size(); j++)
+ {
+ if (!mesh.textures[j])
+ mesh.textures[j] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
+ compressTexture(mesh.textures[j], TexUnits[j].second);
+ setTexture(TexUnits[j].first, getTextureGLuint(mesh.textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
+ if (irr_driver->getLightViz())
+ {
+ GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
+ glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
+ }
+ else
+ {
+ GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
+ glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
+ }
+ }
+
+ if (mesh.VAOType != VertexType)
+ {
+#ifdef DEBUG
+ Log::error("Materials", "Wrong vertex Type associed to pass 2 (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
+#endif
+ continue;
+ }
+ custom_unroll_args::template exec(Shader::getInstance(), meshes[i]);
+ }
+}
+
+void IrrDriver::renderSolidSecondPass()
+{
+ SColor clearColor(0, 150, 150, 150);
+ if (World::getWorld() != NULL)
+ clearColor = World::getWorld()->getClearColor();
+
+ glClearColor(clearColor.getRed() / 255.f, clearColor.getGreen() / 255.f,
+ clearColor.getBlue() / 255.f, clearColor.getAlpha() / 255.f);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ if (UserConfigParams::m_dynamic_lights)
+ glDepthMask(GL_FALSE);
+ else
+ {
+ glDepthMask(GL_TRUE);
+ glClear(GL_DEPTH_BUFFER_BIT);
+ }
+
+ irr_driver->setPhase(SOLID_LIT_PASS);
+ glEnable(GL_DEPTH_TEST);
+ glDisable(GL_ALPHA_TEST);
+ glDisable(GL_BLEND);
+ setTexture(0, m_rtts->getRenderTarget(RTT_TMP1), GL_NEAREST, GL_NEAREST);
+ setTexture(1, m_rtts->getRenderTarget(RTT_TMP2), GL_NEAREST, GL_NEAREST);
+ setTexture(2, m_rtts->getRenderTarget(RTT_HALF1_R), GL_LINEAR, GL_LINEAR);
+
+ {
+ ScopedGPUTimer Timer(getGPUTimer(Q_SOLID_PASS2));
+
+ m_scene_manager->drawAll(scene::ESNRP_SOLID);
+
+ renderMeshes2ndPass({ { MeshShader::ObjectPass2Shader::getInstance()->TU_Albedo, true } }, ListMatDefault::Arguments);
+ renderMeshes2ndPass({ { MeshShader::ObjectRefPass2Shader::getInstance()->TU_Albedo, true } }, ListMatAlphaRef::Arguments);
+ renderMeshes2ndPass({ { MeshShader::SphereMapShader::getInstance()->TU_tex, true } }, ListMatSphereMap::Arguments);
+ renderMeshes2ndPass({ { MeshShader::DetailledObjectPass2Shader::getInstance()->TU_Albedo, true }, { MeshShader::DetailledObjectPass2Shader::getInstance()->TU_detail, true } }, ListMatDetails::Arguments);
+ renderMeshes2ndPass({ { MeshShader::GrassPass2Shader::getInstance()->TU_Albedo, true } }, ListMatGrass::Arguments);
+ renderMeshes2ndPass({ { MeshShader::ObjectUnlitShader::getInstance()->TU_tex, true } }, ListMatUnlit::Arguments);
+ renderMeshes2ndPass({ { 8, true }, { MeshShader::SplattingShader::getInstance()->TU_tex_layout, false }, { MeshShader::SplattingShader::getInstance()->TU_tex_detail0, true }, { MeshShader::SplattingShader::getInstance()->TU_tex_detail1, true }, { MeshShader::SplattingShader::getInstance()->TU_tex_detail2, true }, { MeshShader::SplattingShader::getInstance()->TU_tex_detail3, true } }, ListMatSplatting::Arguments);
+ renderMeshes2ndPass({ { MeshShader::ObjectPass2Shader::getInstance()->TU_Albedo, true } }, ListMatNormalMap::Arguments);
+ }
+}
+
+static video::ITexture *displaceTex = 0;
+
+void IrrDriver::renderTransparent()
+{
+ irr_driver->setPhase(TRANSPARENT_PASS);
+ glEnable(GL_DEPTH_TEST);
+ glDisable(GL_ALPHA_TEST);
+ glDepthMask(GL_FALSE);
+ glEnable(GL_BLEND);
+ glBlendEquation(GL_FUNC_ADD);
+ glDisable(GL_CULL_FACE);
+ ListBlendTransparent::Arguments.clear();
+ ListAdditiveTransparent::Arguments.clear();
+ ListBlendTransparentFog::Arguments.clear();
+ ListAdditiveTransparentFog::Arguments.clear();
+ ListDisplacement::Arguments.clear();
+ m_scene_manager->drawAll(scene::ESNRP_TRANSPARENT);
+
+ glBindVertexArray(getVAO(EVT_STANDARD));
+
+ if (World::getWorld() && World::getWorld()->isFogEnabled())
+ {
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ renderMeshes2ndPass({ { MeshShader::TransparentFogShader::getInstance()->TU_tex, true } }, ListBlendTransparentFog::Arguments);
+ glBlendFunc(GL_ONE, GL_ONE);
+ renderMeshes2ndPass({ { MeshShader::TransparentFogShader::getInstance()->TU_tex, true } }, ListAdditiveTransparentFog::Arguments);
+ }
+ else
+ {
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ renderMeshes2ndPass({ { MeshShader::TransparentShader::getInstance()->TU_tex, true } }, ListBlendTransparent::Arguments);
+ glBlendFunc(GL_ONE, GL_ONE);
+ renderMeshes2ndPass({ { MeshShader::TransparentShader::getInstance()->TU_tex, true } }, ListAdditiveTransparent::Arguments);
+ }
+
+ if (!UserConfigParams::m_dynamic_lights)
+ return;
+
+ // Render displacement nodes
+ irr_driver->getFBO(FBO_TMP1_WITH_DS).Bind();
+ glClear(GL_COLOR_BUFFER_BIT);
+ irr_driver->getFBO(FBO_DISPLACE).Bind();
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ DisplaceProvider * const cb = (DisplaceProvider *)irr_driver->getCallback(ES_DISPLACE);
+ cb->update();
+
+ glEnable(GL_DEPTH_TEST);
+ glDisable(GL_ALPHA_TEST);
+ glDepthMask(GL_FALSE);
+ glDisable(GL_BLEND);
+ glClear(GL_STENCIL_BUFFER_BIT);
+ glEnable(GL_STENCIL_TEST);
+ glStencilFunc(GL_ALWAYS, 1, 0xFF);
+ glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
+
+ glBindVertexArray(getVAO(EVT_2TCOORDS));
+ // Generate displace mask
+ // Use RTT_TMP4 as displace mask
+ irr_driver->getFBO(FBO_TMP1_WITH_DS).Bind();
+ for (unsigned i = 0; i < ListDisplacement::Arguments.size(); i++)
+ {
+ const GLMesh &mesh = *(std::get<0>(ListDisplacement::Arguments[i]));
+ const core::matrix4 &AbsoluteTransformation = std::get<1>(ListDisplacement::Arguments[i]);
+ if (mesh.VAOType != video::EVT_2TCOORDS)
+ {
+#ifdef DEBUG
+ Log::error("Materials", "Displacement has wrong vertex type");
+#endif
+ continue;
+ }
+
+ GLenum ptype = mesh.PrimitiveType;
+ GLenum itype = mesh.IndexType;
+ size_t count = mesh.IndexCount;
+
+ glUseProgram(MeshShader::DisplaceMaskShaderInstance->Program);
+ MeshShader::DisplaceMaskShaderInstance->setUniforms(AbsoluteTransformation);
+ glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex);
+ }
+
+ irr_driver->getFBO(FBO_DISPLACE).Bind();
+ if (!displaceTex)
+ displaceTex = irr_driver->getTexture(FileManager::TEXTURE, "displace.png");
+ for (unsigned i = 0; i < ListDisplacement::Arguments.size(); i++)
+ {
+ const GLMesh &mesh = *(std::get<0>(ListDisplacement::Arguments[i]));
+ const core::matrix4 &AbsoluteTransformation = std::get<1>(ListDisplacement::Arguments[i]);
+ if (mesh.VAOType != video::EVT_2TCOORDS)
+ continue;
+
+ GLenum ptype = mesh.PrimitiveType;
+ GLenum itype = mesh.IndexType;
+ size_t count = mesh.IndexCount;
+ // Render the effect
+ setTexture(MeshShader::DisplaceShaderInstance->TU_displacement_tex, getTextureGLuint(displaceTex), GL_LINEAR, GL_LINEAR, true);
+ setTexture(MeshShader::DisplaceShaderInstance->TU_mask_tex, irr_driver->getRenderTargetTexture(RTT_TMP1), GL_LINEAR, GL_LINEAR, true);
+ setTexture(MeshShader::DisplaceShaderInstance->TU_color_tex, irr_driver->getRenderTargetTexture(RTT_COLOR), GL_LINEAR, GL_LINEAR, true);
+ setTexture(MeshShader::DisplaceShaderInstance->TU_tex, getTextureGLuint(mesh.textures[0]), GL_LINEAR, GL_LINEAR, true);
+ glUseProgram(MeshShader::DisplaceShaderInstance->Program);
+ MeshShader::DisplaceShaderInstance->setUniforms(AbsoluteTransformation,
+ core::vector2df(cb->getDirX(), cb->getDirY()),
+ core::vector2df(cb->getDir2X(), cb->getDir2Y()));
+
+ glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex);
+ }
+
+ irr_driver->getFBO(FBO_COLORS).Bind();
+ glStencilFunc(GL_EQUAL, 1, 0xFF);
+ m_post_processing->renderPassThrough(m_rtts->getRenderTarget(RTT_DISPLACE));
+ glDisable(GL_STENCIL_TEST);
+
+}
+
+template
+void drawShadow(const T *Shader, const GLMesh *mesh, uniforms... Args)
+{
+ irr_driver->IncreaseObjectCount();
+ GLenum ptype = mesh->PrimitiveType;
+ GLenum itype = mesh->IndexType;
+ size_t count = mesh->IndexCount;
+
+ Shader->setUniforms(Args...);
+ glDrawElementsInstancedBaseVertex(ptype, count, itype, (GLvoid *)mesh->vaoOffset, 4, mesh->vaoBaseVertex);
+}
+
+template
+struct shadow_custom_unroll_args;
+
+template<>
+struct shadow_custom_unroll_args<>
+{
+ template
+ static void exec(const T *Shader, const std::tuple &t, Args... args)
+ {
+ drawShadow(Shader, std::get<0>(t), args...);
+ }
+};
+
+template
+struct shadow_custom_unroll_args
+{
+ template
+ static void exec(const T *Shader, const std::tuple &t, Args... args)
+ {
+ shadow_custom_unroll_args::template exec(Shader, t, std::get(t), args...);
+ }
+};
+
+template
+void renderShadow(const T *Shader, const std::vector TextureUnits, const std::vector >&t)
+{
+ glUseProgram(Shader->Program);
+ glBindVertexArray(getVAO(VertexType));
+ for (unsigned i = 0; i < t.size(); i++)
+ {
+ const GLMesh *mesh = std::get<0>(t[i]);
+ for (unsigned j = 0; j < TextureUnits.size(); j++)
+ {
+ compressTexture(mesh->textures[j], true);
+ setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
+ }
+
+ shadow_custom_unroll_args::template exec(Shader, t[i]);
+ }
+}
+
+template
+void drawRSM(const core::matrix4 & rsm_matrix, const std::vector TextureUnits, const std::vector >&t)
+{
+ glUseProgram(MeshShader::RSMShader::Program);
+ glBindVertexArray(getVAO(VertexType));
+ for (unsigned i = 0; i < t.size(); i++)
+ {
+ GLMesh *mesh = std::get<0>(t[i]);
+ for (unsigned j = 0; j < TextureUnits.size(); j++)
+ {
+ if (!mesh->textures[j])
+ mesh->textures[j] = getUnicolorTexture(video::SColor(255, 255, 255, 255));
+ compressTexture(mesh->textures[j], true);
+ setTexture(TextureUnits[j], getTextureGLuint(mesh->textures[j]), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
+ }
+ draw(mesh, rsm_matrix, std::get<1>(t[i]));
+ }
+}
+
+void IrrDriver::renderShadows()
+{
+ glDepthFunc(GL_LEQUAL);
+ glDepthMask(GL_TRUE);
+ glEnable(GL_DEPTH_TEST);
+ glDisable(GL_BLEND);
+ glDisable(GL_ALPHA_TEST);
+ glEnable(GL_POLYGON_OFFSET_FILL);
+ glPolygonOffset(1.5, 0.);
+ m_rtts->getShadowFBO().Bind();
+ glClear(GL_DEPTH_BUFFER_BIT);
+ glDrawBuffer(GL_NONE);
+
+ irr_driver->setPhase(SHADOW_PASS);
+ ListMatDefault::Arguments.clear();
+ ListMatAlphaRef::Arguments.clear();
+ ListMatSphereMap::Arguments.clear();
+ ListMatDetails::Arguments.clear();
+ ListMatUnlit::Arguments.clear();
+ ListMatNormalMap::Arguments.clear();
+ ListMatGrass::Arguments.clear();
+ ListMatSplatting::Arguments.clear();
+ m_scene_manager->drawAll(scene::ESNRP_SOLID);
+
+ renderShadow(MeshShader::ShadowShaderInstance, {}, ListMatDefault::Arguments);
+ renderShadow(MeshShader::ShadowShaderInstance, {}, ListMatSphereMap::Arguments);
+ renderShadow(MeshShader::ShadowShaderInstance, {}, ListMatUnlit::Arguments);
+ renderShadow(MeshShader::ShadowShaderInstance, {}, ListMatDetails::Arguments);
+ renderShadow(MeshShader::ShadowShaderInstance, {}, ListMatSplatting::Arguments);
+ renderShadow(MeshShader::ShadowShaderInstance, {}, ListMatNormalMap::Arguments);
+ renderShadow(MeshShader::RefShadowShaderInstance, { MeshShader::RefShadowShaderInstance->TU_tex }, ListMatAlphaRef::Arguments);
+ renderShadow(MeshShader::GrassShadowShaderInstance, { MeshShader::GrassShadowShaderInstance->TU_tex }, ListMatGrass::Arguments);
+
+ glDisable(GL_POLYGON_OFFSET_FILL);
+
+ if (!UserConfigParams::m_gi)
+ return;
+
+ m_rtts->getRSM().Bind();
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ drawRSM(rsm_matrix, { MeshShader::RSMShader::TU_tex }, ListMatDefault::Arguments);
+ drawRSM(rsm_matrix, { MeshShader::RSMShader::TU_tex }, ListMatSphereMap::Arguments);
+ drawRSM(rsm_matrix, { MeshShader::RSMShader::TU_tex }, ListMatUnlit::Arguments);
+ drawRSM(rsm_matrix, { MeshShader::RSMShader::TU_tex }, ListMatDetails::Arguments);
+ drawRSM(rsm_matrix, { MeshShader::RSMShader::TU_tex }, ListMatSplatting::Arguments);
+}
diff --git a/src/graphics/render_lighting.cpp b/src/graphics/render_lighting.cpp
new file mode 100644
index 000000000..c74e57a2b
--- /dev/null
+++ b/src/graphics/render_lighting.cpp
@@ -0,0 +1,199 @@
+#include "graphics/irr_driver.hpp"
+
+#include "config/user_config.hpp"
+#include "graphics/callbacks.hpp"
+#include "graphics/camera.hpp"
+#include "graphics/glwrap.hpp"
+#include "graphics/lens_flare.hpp"
+#include "graphics/light.hpp"
+#include "graphics/lod_node.hpp"
+#include "graphics/material_manager.hpp"
+#include "graphics/particle_kind_manager.hpp"
+#include "graphics/per_camera_node.hpp"
+#include "graphics/post_processing.hpp"
+#include "graphics/referee.hpp"
+#include "graphics/rtts.hpp"
+#include "graphics/screenquad.hpp"
+#include "graphics/shaders.hpp"
+#include "graphics/stkmeshscenenode.hpp"
+#include "graphics/stkinstancedscenenode.hpp"
+#include "graphics/wind.hpp"
+#include "io/file_manager.hpp"
+#include "items/item.hpp"
+#include "items/item_manager.hpp"
+#include "modes/world.hpp"
+#include "physics/physics.hpp"
+#include "tracks/track.hpp"
+#include "utils/constants.hpp"
+#include "utils/helpers.hpp"
+#include "utils/log.hpp"
+#include "utils/profiler.hpp"
+
+#include
+#include
+
+#define MAX2(a, b) ((a) > (b) ? (a) : (b))
+#define MIN2(a, b) ((a) > (b) ? (b) : (a))
+
+static LightShader::PointLightInfo PointLightsInfo[MAXLIGHT];
+
+static void renderPointLights(unsigned count)
+{
+ glEnable(GL_BLEND);
+ glBlendEquation(GL_FUNC_ADD);
+ glBlendFunc(GL_ONE, GL_ONE);
+ glEnable(GL_DEPTH_TEST);
+ glDepthMask(GL_FALSE);
+
+ glUseProgram(LightShader::PointLightShader::Program);
+ glBindVertexArray(LightShader::PointLightShader::vao);
+ glBindBuffer(GL_ARRAY_BUFFER, LightShader::PointLightShader::vbo);
+ glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(LightShader::PointLightInfo), PointLightsInfo);
+
+ setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST);
+ setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
+ LightShader::PointLightShader
+ ::setUniforms(core::vector2df(float(UserConfigParams::m_width),
+ float(UserConfigParams::m_height)),
+ 200, 0, 1);
+
+ glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
+}
+
+unsigned IrrDriver::UpdateLightsInfo(scene::ICameraSceneNode * const camnode, float dt)
+{
+ const u32 lightcount = m_lights.size();
+ const core::vector3df &campos = camnode->getAbsolutePosition();
+
+ std::vector BucketedLN[15];
+ for (unsigned int i = 0; i < lightcount; i++)
+ {
+ if (!m_lights[i]->isPointLight())
+ {
+ m_lights[i]->render();
+ continue;
+ }
+ const core::vector3df &lightpos = (m_lights[i]->getAbsolutePosition() - campos);
+ unsigned idx = (unsigned)(lightpos.getLength() / 10);
+ if (idx > 14)
+ idx = 14;
+ BucketedLN[idx].push_back(m_lights[i]);
+ }
+
+ unsigned lightnum = 0;
+
+ for (unsigned i = 0; i < 15; i++)
+ {
+ for (unsigned j = 0; j < BucketedLN[i].size(); j++)
+ {
+ if (++lightnum >= MAXLIGHT)
+ {
+ LightNode* light_node = BucketedLN[i].at(j);
+ light_node->setEnergyMultiplier(0.0f);
+ }
+ else
+ {
+ LightNode* light_node = BucketedLN[i].at(j);
+
+ float em = light_node->getEnergyMultiplier();
+ if (em < 1.0f)
+ {
+ light_node->setEnergyMultiplier(std::min(1.0f, em + dt));
+ }
+
+ const core::vector3df &pos = light_node->getAbsolutePosition();
+ PointLightsInfo[lightnum].posX = pos.X;
+ PointLightsInfo[lightnum].posY = pos.Y;
+ PointLightsInfo[lightnum].posZ = pos.Z;
+
+ PointLightsInfo[lightnum].energy = light_node->getEffectiveEnergy();
+
+ const core::vector3df &col = light_node->getColor();
+ PointLightsInfo[lightnum].red = col.X;
+ PointLightsInfo[lightnum].green = col.Y;
+ PointLightsInfo[lightnum].blue = col.Z;
+
+ // Light radius
+ PointLightsInfo[lightnum].radius = light_node->getRadius();
+ }
+ }
+ if (lightnum > MAXLIGHT)
+ {
+ irr_driver->setLastLightBucketDistance(i * 10);
+ break;
+ }
+ }
+
+ lightnum++;
+ return lightnum;
+}
+
+void IrrDriver::renderLights(unsigned pointlightcount)
+{
+ //RH
+ if (UserConfigParams::m_gi)
+ {
+ ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_RH));
+ glDisable(GL_BLEND);
+ m_rtts->getRH().Bind();
+ glUseProgram(FullScreenShader::RadianceHintsConstructionShader::Program);
+ glBindVertexArray(FullScreenShader::RadianceHintsConstructionShader::vao);
+ setTexture(0, m_rtts->getRSM().getRTT()[0], GL_LINEAR, GL_LINEAR);
+ setTexture(1, m_rtts->getRSM().getRTT()[1], GL_LINEAR, GL_LINEAR);
+ setTexture(2, m_rtts->getRSM().getDepthTexture(), GL_LINEAR, GL_LINEAR);
+ FullScreenShader::RadianceHintsConstructionShader::setUniforms(rsm_matrix, rh_matrix, rh_extend, 0, 1, 2);
+ glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 32);
+ }
+
+ for (unsigned i = 0; i < sun_ortho_matrix.size(); i++)
+ sun_ortho_matrix[i] *= getInvViewMatrix();
+ m_rtts->getFBO(FBO_COMBINED_TMP1_TMP2).Bind();
+ if (!UserConfigParams::m_dynamic_lights)
+ glClearColor(.5, .5, .5, .5);
+ glClear(GL_COLOR_BUFFER_BIT);
+ if (!UserConfigParams::m_dynamic_lights)
+ return;
+
+ m_rtts->getFBO(FBO_TMP1_WITH_DS).Bind();
+ if (UserConfigParams::m_gi)
+ {
+ ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_GI));
+ m_post_processing->renderGI(rh_matrix, rh_extend, m_rtts->getRH().getRTT()[0], m_rtts->getRH().getRTT()[1], m_rtts->getRH().getRTT()[2]);
+ }
+
+ if (SkyboxCubeMap)
+ {
+ ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_ENVMAP));
+ m_post_processing->renderDiffuseEnvMap(blueSHCoeff, greenSHCoeff, redSHCoeff);
+ }
+ m_rtts->getFBO(FBO_COMBINED_TMP1_TMP2).Bind();
+
+ if (World::getWorld() && World::getWorld()->getTrack()->hasShadows() && SkyboxCubeMap)
+ irr_driver->getSceneManager()->setAmbientLight(SColor(0, 0, 0, 0));
+
+ // Render sunlight if and only if track supports shadow
+ if (!World::getWorld() || World::getWorld()->getTrack()->hasShadows())
+ {
+ ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_SUN));
+ if (World::getWorld() && UserConfigParams::m_shadows)
+ m_post_processing->renderShadowedSunlight(sun_ortho_matrix, m_rtts->getShadowDepthTex());
+ else
+ m_post_processing->renderSunlight();
+ }
+ {
+ ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_POINTLIGHTS));
+ renderPointLights(MIN2(pointlightcount, MAXLIGHT));
+ }
+}
+
+void IrrDriver::renderSSAO()
+{
+ m_rtts->getFBO(FBO_SSAO).Bind();
+ glClearColor(1., 1., 1., 1.);
+ glClear(GL_COLOR_BUFFER_BIT);
+ m_post_processing->renderSSAO();
+ // Blur it to reduce noise.
+ FrameBuffer::Blit(m_rtts->getFBO(FBO_SSAO), m_rtts->getFBO(FBO_HALF1_R), GL_COLOR_BUFFER_BIT, GL_LINEAR);
+ m_post_processing->renderGaussian17TapBlur(irr_driver->getFBO(FBO_HALF1_R), irr_driver->getFBO(FBO_HALF2_R));
+
+}
\ No newline at end of file
diff --git a/src/graphics/render_skybox.cpp b/src/graphics/render_skybox.cpp
new file mode 100644
index 000000000..f628065c4
--- /dev/null
+++ b/src/graphics/render_skybox.cpp
@@ -0,0 +1,540 @@
+#include "graphics/irr_driver.hpp"
+
+#include "config/user_config.hpp"
+#include "graphics/callbacks.hpp"
+#include "graphics/camera.hpp"
+#include "graphics/glwrap.hpp"
+#include "graphics/lens_flare.hpp"
+#include "graphics/light.hpp"
+#include "graphics/lod_node.hpp"
+#include "graphics/material_manager.hpp"
+#include "graphics/particle_kind_manager.hpp"
+#include "graphics/per_camera_node.hpp"
+#include "graphics/post_processing.hpp"
+#include "graphics/referee.hpp"
+#include "graphics/rtts.hpp"
+#include "graphics/screenquad.hpp"
+#include "graphics/shaders.hpp"
+#include "graphics/stkmeshscenenode.hpp"
+#include "graphics/stkinstancedscenenode.hpp"
+#include "graphics/wind.hpp"
+#include "io/file_manager.hpp"
+#include "items/item.hpp"
+#include "items/item_manager.hpp"
+#include "modes/world.hpp"
+#include "physics/physics.hpp"
+#include "tracks/track.hpp"
+#include "utils/constants.hpp"
+#include "utils/helpers.hpp"
+#include "utils/log.hpp"
+#include "utils/profiler.hpp"
+
+#include
+#include
+
+#define MAX2(a, b) ((a) > (b) ? (a) : (b))
+#define MIN2(a, b) ((a) > (b) ? (b) : (a))
+
+static void getXYZ(GLenum face, float i, float j, float &x, float &y, float &z)
+{
+ switch (face)
+ {
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+ x = 1.;
+ y = -i;
+ z = -j;
+ break;
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+ x = -1.;
+ y = -i;
+ z = j;
+ break;
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+ x = j;
+ y = 1.;
+ z = i;
+ break;
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+ x = j;
+ y = -1;
+ z = -i;
+ break;
+ case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+ x = j;
+ y = -i;
+ z = 1;
+ break;
+ case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ x = -j;
+ y = -i;
+ z = -1;
+ break;
+ }
+
+ float norm = sqrt(x * x + y * y + z * z);
+ x /= norm, y /= norm, z /= norm;
+ return;
+}
+
+static void getYml(GLenum face, size_t width, size_t height,
+ float *Y00,
+ float *Y1minus1, float *Y10, float *Y11,
+ float *Y2minus2, float *Y2minus1, float *Y20, float *Y21, float *Y22)
+{
+ for (unsigned i = 0; i < width; i++)
+ {
+ for (unsigned j = 0; j < height; j++)
+ {
+ float x, y, z;
+ float fi = float(i), fj = float(j);
+ fi /= width, fj /= height;
+ fi = 2 * fi - 1, fj = 2 * fj - 1;
+ getXYZ(face, fi, fj, x, y, z);
+
+ // constant part of Ylm
+ float c00 = 0.282095f;
+ float c1minus1 = 0.488603f;
+ float c10 = 0.488603f;
+ float c11 = 0.488603f;
+ float c2minus2 = 1.092548f;
+ float c2minus1 = 1.092548f;
+ float c21 = 1.092548f;
+ float c20 = 0.315392f;
+ float c22 = 0.546274f;
+
+ size_t idx = i * height + j;
+
+ Y00[idx] = c00;
+ Y1minus1[idx] = c1minus1 * y;
+ Y10[idx] = c10 * z;
+ Y11[idx] = c11 * x;
+ Y2minus2[idx] = c2minus2 * x * y;
+ Y2minus1[idx] = c2minus1 * y * z;
+ Y21[idx] = c21 * x * z;
+ Y20[idx] = c20 * (3 * z * z - 1);
+ Y22[idx] = c22 * (x * x - y * y);
+ }
+ }
+}
+
+static float getTexelValue(unsigned i, unsigned j, size_t width, size_t height, float *Coeff, float *Y00, float *Y1minus1, float *Y10, float *Y11,
+ float *Y2minus2, float * Y2minus1, float * Y20, float *Y21, float *Y22)
+{
+ float d = sqrt((float)(i * i + j * j + 1));
+ float solidangle = 1.;
+ size_t idx = i * height + j;
+ float reconstructedVal = Y00[idx] * Coeff[0];
+ reconstructedVal += Y1minus1[i * height + j] * Coeff[1] + Y10[i * height + j] * Coeff[2] + Y11[i * height + j] * Coeff[3];
+ reconstructedVal += Y2minus2[idx] * Coeff[4] + Y2minus1[idx] * Coeff[5] + Y20[idx] * Coeff[6] + Y21[idx] * Coeff[7] + Y22[idx] * Coeff[8];
+ reconstructedVal /= solidangle;
+ return MAX2(255.0f * reconstructedVal, 0.f);
+}
+
+static void unprojectSH(float *output[], size_t width, size_t height,
+ float *Y00[],
+ float *Y1minus1[], float *Y10[], float *Y11[],
+ float *Y2minus2[], float *Y2minus1[], float * Y20[], float *Y21[], float *Y22[],
+ float *blueSHCoeff, float *greenSHCoeff, float *redSHCoeff)
+{
+ for (unsigned face = 0; face < 6; face++)
+ {
+ for (unsigned i = 0; i < width; i++)
+ {
+ for (unsigned j = 0; j < height; j++)
+ {
+ float fi = float(i), fj = float(j);
+ fi /= width, fj /= height;
+ fi = 2 * fi - 1, fj = 2 * fj - 1;
+
+ output[face][4 * height * i + 4 * j + 2] = getTexelValue(i, j, width, height,
+ redSHCoeff,
+ Y00[face], Y1minus1[face], Y10[face], Y11[face], Y2minus2[face], Y2minus1[face], Y20[face], Y21[face], Y22[face]);
+ output[face][4 * height * i + 4 * j + 1] = getTexelValue(i, j, width, height,
+ greenSHCoeff,
+ Y00[face], Y1minus1[face], Y10[face], Y11[face], Y2minus2[face], Y2minus1[face], Y20[face], Y21[face], Y22[face]);
+ output[face][4 * height * i + 4 * j] = getTexelValue(i, j, width, height,
+ blueSHCoeff,
+ Y00[face], Y1minus1[face], Y10[face], Y11[face], Y2minus2[face], Y2minus1[face], Y20[face], Y21[face], Y22[face]);
+ }
+ }
+ }
+}
+
+static void projectSH(float *color[], size_t width, size_t height,
+ float *Y00[],
+ float *Y1minus1[], float *Y10[], float *Y11[],
+ float *Y2minus2[], float *Y2minus1[], float * Y20[], float *Y21[], float *Y22[],
+ float *blueSHCoeff, float *greenSHCoeff, float *redSHCoeff
+ )
+{
+ for (unsigned i = 0; i < 9; i++)
+ {
+ blueSHCoeff[i] = 0;
+ greenSHCoeff[i] = 0;
+ redSHCoeff[i] = 0;
+ }
+ float wh = float(width * height);
+ for (unsigned face = 0; face < 6; face++)
+ {
+ for (unsigned i = 0; i < width; i++)
+ {
+ for (unsigned j = 0; j < height; j++)
+ {
+ size_t idx = i * height + j;
+ float fi = float(i), fj = float(j);
+ fi /= width, fj /= height;
+ fi = 2 * fi - 1, fj = 2 * fj - 1;
+
+
+ float d = sqrt(fi * fi + fj * fj + 1);
+
+ // Constant obtained by projecting unprojected ref values
+ float solidangle = 2.75f / (wh * pow(d, 1.5f));
+ // pow(., 2.2) to convert from srgb
+ float b = pow(color[face][4 * height * i + 4 * j] / 255.f, 2.2f);
+ float g = pow(color[face][4 * height * i + 4 * j + 1] / 255.f, 2.2f);
+ float r = pow(color[face][4 * height * i + 4 * j + 2] / 255.f, 2.2f);
+
+ assert(b >= 0.);
+
+ blueSHCoeff[0] += b * Y00[face][idx] * solidangle;
+ blueSHCoeff[1] += b * Y1minus1[face][idx] * solidangle;
+ blueSHCoeff[2] += b * Y10[face][idx] * solidangle;
+ blueSHCoeff[3] += b * Y11[face][idx] * solidangle;
+ blueSHCoeff[4] += b * Y2minus2[face][idx] * solidangle;
+ blueSHCoeff[5] += b * Y2minus1[face][idx] * solidangle;
+ blueSHCoeff[6] += b * Y20[face][idx] * solidangle;
+ blueSHCoeff[7] += b * Y21[face][idx] * solidangle;
+ blueSHCoeff[8] += b * Y22[face][idx] * solidangle;
+
+ greenSHCoeff[0] += g * Y00[face][idx] * solidangle;
+ greenSHCoeff[1] += g * Y1minus1[face][idx] * solidangle;
+ greenSHCoeff[2] += g * Y10[face][idx] * solidangle;
+ greenSHCoeff[3] += g * Y11[face][idx] * solidangle;
+ greenSHCoeff[4] += g * Y2minus2[face][idx] * solidangle;
+ greenSHCoeff[5] += g * Y2minus1[face][idx] * solidangle;
+ greenSHCoeff[6] += g * Y20[face][idx] * solidangle;
+ greenSHCoeff[7] += g * Y21[face][idx] * solidangle;
+ greenSHCoeff[8] += g * Y22[face][idx] * solidangle;
+
+
+ redSHCoeff[0] += r * Y00[face][idx] * solidangle;
+ redSHCoeff[1] += r * Y1minus1[face][idx] * solidangle;
+ redSHCoeff[2] += r * Y10[face][idx] * solidangle;
+ redSHCoeff[3] += r * Y11[face][idx] * solidangle;
+ redSHCoeff[4] += r * Y2minus2[face][idx] * solidangle;
+ redSHCoeff[5] += r * Y2minus1[face][idx] * solidangle;
+ redSHCoeff[6] += r * Y20[face][idx] * solidangle;
+ redSHCoeff[7] += r * Y21[face][idx] * solidangle;
+ redSHCoeff[8] += r * Y22[face][idx] * solidangle;
+ }
+ }
+ }
+}
+
+static void displayCoeff(float *SHCoeff)
+{
+ printf("L00:%f\n", SHCoeff[0]);
+ printf("L1-1:%f, L10:%f, L11:%f\n", SHCoeff[1], SHCoeff[2], SHCoeff[3]);
+ printf("L2-2:%f, L2-1:%f, L20:%f, L21:%f, L22:%f\n", SHCoeff[4], SHCoeff[5], SHCoeff[6], SHCoeff[7], SHCoeff[8]);
+}
+
+// Only for 9 coefficients
+static void testSH(unsigned char *color[6], size_t width, size_t height,
+ float *blueSHCoeff, float *greenSHCoeff, float *redSHCoeff)
+{
+ float *Y00[6];
+ float *Y1minus1[6];
+ float *Y10[6];
+ float *Y11[6];
+ float *Y2minus2[6];
+ float *Y2minus1[6];
+ float *Y20[6];
+ float *Y21[6];
+ float *Y22[6];
+
+ float *testoutput[6];
+ for (unsigned i = 0; i < 6; i++)
+ {
+ testoutput[i] = new float[width * height * 4];
+ for (unsigned j = 0; j < width * height; j++)
+ {
+ testoutput[i][4 * j] = float(0xFF & color[i][4 * j]);
+ testoutput[i][4 * j + 1] = float(0xFF & color[i][4 * j + 1]);
+ testoutput[i][4 * j + 2] = float(0xFF & color[i][4 * j + 2]);
+ }
+ }
+
+ for (unsigned face = 0; face < 6; face++)
+ {
+ Y00[face] = new float[width * height];
+ Y1minus1[face] = new float[width * height];
+ Y10[face] = new float[width * height];
+ Y11[face] = new float[width * height];
+ Y2minus2[face] = new float[width * height];
+ Y2minus1[face] = new float[width * height];
+ Y20[face] = new float[width * height];
+ Y21[face] = new float[width * height];
+ Y22[face] = new float[width * height];
+
+ getYml(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, width, height, Y00[face], Y1minus1[face], Y10[face], Y11[face], Y2minus2[face], Y2minus1[face], Y20[face], Y21[face], Y22[face]);
+ }
+
+ /* blueSHCoeff[0] = 0.54,
+ blueSHCoeff[1] = .6, blueSHCoeff[2] = -.27, blueSHCoeff[3] = .01,
+ blueSHCoeff[4] = -.12, blueSHCoeff[5] = -.47, blueSHCoeff[6] = -.15, blueSHCoeff[7] = .14, blueSHCoeff[8] = -.3;
+ greenSHCoeff[0] = .44,
+ greenSHCoeff[1] = .35, greenSHCoeff[2] = -.18, greenSHCoeff[3] = -.06,
+ greenSHCoeff[4] = -.05, greenSHCoeff[5] = -.22, greenSHCoeff[6] = -.09, greenSHCoeff[7] = .21, greenSHCoeff[8] = -.05;
+ redSHCoeff[0] = .79,
+ redSHCoeff[1] = .39, redSHCoeff[2] = -.34, redSHCoeff[3] = -.29,
+ redSHCoeff[4] = -.11, redSHCoeff[5] = -.26, redSHCoeff[6] = -.16, redSHCoeff[7] = .56, redSHCoeff[8] = .21;
+
+ printf("Blue:\n");
+ displayCoeff(blueSHCoeff);
+ printf("Green:\n");
+ displayCoeff(greenSHCoeff);
+ printf("Red:\n");
+ displayCoeff(redSHCoeff);*/
+
+ projectSH(testoutput, width, height,
+ Y00,
+ Y1minus1, Y10, Y11,
+ Y2minus2, Y2minus1, Y20, Y21, Y22,
+ blueSHCoeff, greenSHCoeff, redSHCoeff
+ );
+
+ //printf("Blue:\n");
+ //displayCoeff(blueSHCoeff);
+ //printf("Green:\n");
+ //displayCoeff(greenSHCoeff);
+ //printf("Red:\n");
+ //displayCoeff(redSHCoeff);
+
+
+
+ // Convolute in frequency space
+ /* float A0 = 3.141593;
+ float A1 = 2.094395;
+ float A2 = 0.785398;
+ blueSHCoeff[0] *= A0;
+ greenSHCoeff[0] *= A0;
+ redSHCoeff[0] *= A0;
+ for (unsigned i = 0; i < 3; i++)
+ {
+ blueSHCoeff[1 + i] *= A1;
+ greenSHCoeff[1 + i] *= A1;
+ redSHCoeff[1 + i] *= A1;
+ }
+ for (unsigned i = 0; i < 5; i++)
+ {
+ blueSHCoeff[4 + i] *= A2;
+ greenSHCoeff[4 + i] *= A2;
+ redSHCoeff[4 + i] *= A2;
+ }
+
+
+ unprojectSH(testoutput, width, height,
+ Y00,
+ Y1minus1, Y10, Y11,
+ Y2minus2, Y2minus1, Y20, Y21, Y22,
+ blueSHCoeff, greenSHCoeff, redSHCoeff
+ );*/
+
+
+ /* printf("Blue:\n");
+ displayCoeff(blueSHCoeff);
+ printf("Green:\n");
+ displayCoeff(greenSHCoeff);
+ printf("Red:\n");
+ displayCoeff(redSHCoeff);
+
+ printf("\nAfter projection\n\n");*/
+
+
+
+ for (unsigned i = 0; i < 6; i++)
+ {
+ for (unsigned j = 0; j < width * height; j++)
+ {
+ color[i][4 * j] = char(MIN2(testoutput[i][4 * j], 255));
+ color[i][4 * j + 1] = char(MIN2(testoutput[i][4 * j + 1], 255));
+ color[i][4 * j + 2] = char(MIN2(testoutput[i][4 * j + 2], 255));
+ }
+ }
+
+ for (unsigned face = 0; face < 6; face++)
+ {
+ delete[] testoutput[face];
+ delete[] Y00[face];
+ delete[] Y1minus1[face];
+ delete[] Y10[face];
+ delete[] Y11[face];
+ }
+}
+
+/** Generate an opengl cubemap texture from 6 2d textures.
+Out of legacy the sequence of textures maps to :
+- 1st texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_Y
+- 2nd texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
+- 3rd texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_X
+- 4th texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_X
+- 5th texture maps to GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
+- 6th texture maps to GL_TEXTURE_CUBE_MAP_POSITIVE_Z
+* \param textures sequence of 6 textures.
+*/
+GLuint generateCubeMapFromTextures(const std::vector &textures)
+{
+ assert(textures.size() == 6);
+
+ GLuint result;
+ glGenTextures(1, &result);
+
+ unsigned w = 0, h = 0;
+ for (unsigned i = 0; i < 6; i++)
+ {
+ w = MAX2(w, textures[i]->getOriginalSize().Width);
+ h = MAX2(h, textures[i]->getOriginalSize().Height);
+ }
+
+ const unsigned texture_permutation[] = { 2, 3, 0, 1, 5, 4 };
+ char *rgba[6];
+ for (unsigned i = 0; i < 6; i++)
+ rgba[i] = new char[w * h * 4];
+ for (unsigned i = 0; i < 6; i++)
+ {
+ unsigned idx = texture_permutation[i];
+
+ video::IImage* image = irr_driver->getVideoDriver()->createImageFromData(
+ textures[idx]->getColorFormat(),
+ textures[idx]->getSize(),
+ textures[idx]->lock(),
+ false
+ );
+ textures[idx]->unlock();
+
+ image->copyToScaling(rgba[i], w, h);
+ image->drop();
+
+ glBindTexture(GL_TEXTURE_CUBE_MAP, result);
+ if (UserConfigParams::m_texture_compression)
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_COMPRESSED_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
+ else
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
+ }
+ for (unsigned i = 0; i < 6; i++)
+ delete[] rgba[i];
+ return result;
+}
+
+void IrrDriver::generateSkyboxCubemap()
+{
+ glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
+
+ assert(SkyboxTextures.size() == 6);
+ SkyboxCubeMap = generateCubeMapFromTextures(SkyboxTextures);
+ const unsigned texture_permutation[] = { 2, 3, 0, 1, 5, 4 };
+
+ if (SphericalHarmonicsTextures.size() == 6)
+ {
+ unsigned sh_w = 0, sh_h = 0;
+ for (unsigned i = 0; i < 6; i++)
+ {
+ sh_w = MAX2(sh_w, SphericalHarmonicsTextures[i]->getOriginalSize().Width);
+ sh_h = MAX2(sh_h, SphericalHarmonicsTextures[i]->getOriginalSize().Height);
+ }
+
+ unsigned char *sh_rgba[6];
+ for (unsigned i = 0; i < 6; i++)
+ sh_rgba[i] = new unsigned char[sh_w * sh_h * 4];
+ for (unsigned i = 0; i < 6; i++)
+ {
+ unsigned idx = texture_permutation[i];
+
+ video::IImage* image = getVideoDriver()->createImageFromData(
+ SphericalHarmonicsTextures[idx]->getColorFormat(),
+ SphericalHarmonicsTextures[idx]->getSize(),
+ SphericalHarmonicsTextures[idx]->lock(),
+ false
+ );
+ SphericalHarmonicsTextures[idx]->unlock();
+
+ image->copyToScaling(sh_rgba[i], sh_w, sh_h);
+ image->drop();
+ }
+
+ testSH(sh_rgba, sh_w, sh_h, blueSHCoeff, greenSHCoeff, redSHCoeff);
+
+ for (unsigned i = 0; i < 6; i++)
+ delete[] sh_rgba[i];
+ }
+ else
+ {
+ int sh_w = 16;
+ int sh_h = 16;
+
+ const video::SColorf& ambientf = irr_driver->getSceneManager()->getAmbientLight();
+ video::SColor ambient = ambientf.toSColor();
+
+ unsigned char *sh_rgba[6];
+ for (unsigned i = 0; i < 6; i++)
+ {
+ sh_rgba[i] = new unsigned char[sh_w * sh_h * 4];
+
+ for (int j = 0; j < sh_w * sh_h * 4; j += 4)
+ {
+ sh_rgba[i][j] = ambient.getBlue();
+ sh_rgba[i][j + 1] = ambient.getGreen();
+ sh_rgba[i][j + 2] = ambient.getRed();
+ sh_rgba[i][j + 3] = 255;
+ }
+ }
+
+ testSH(sh_rgba, sh_w, sh_h, blueSHCoeff, greenSHCoeff, redSHCoeff);
+
+ for (unsigned i = 0; i < 6; i++)
+ delete[] sh_rgba[i];
+ }
+
+ /*for (unsigned i = 0; i < 6; i++)
+ {
+ glBindTexture(GL_TEXTURE_CUBE_MAP, ConvolutedSkyboxCubeMap);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_SRGB_ALPHA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)rgba[i]);
+ }
+
+ glBindTexture(GL_TEXTURE_CUBE_MAP, 0);*/
+}
+
+void IrrDriver::renderSkybox(const scene::ICameraSceneNode *camera)
+{
+ if (SkyboxTextures.empty())
+ return;
+ if (!SkyboxCubeMap)
+ generateSkyboxCubemap();
+ glBindVertexArray(MeshShader::SkyboxShader::cubevao);
+ glDisable(GL_CULL_FACE);
+ assert(SkyboxTextures.size() == 6);
+
+ core::matrix4 translate;
+ translate.setTranslation(camera->getAbsolutePosition());
+
+ // Draw the sky box between the near and far clip plane
+ const f32 viewDistance = (camera->getNearValue() + camera->getFarValue()) * 0.5f;
+ core::matrix4 scale;
+ scale.setScale(core::vector3df(viewDistance, viewDistance, viewDistance));
+ core::matrix4 transform = translate * scale;
+ core::matrix4 invtransform;
+ transform.getInverse(invtransform);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, SkyboxCubeMap);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glUseProgram(MeshShader::SkyboxShader::Program);
+ MeshShader::SkyboxShader::setUniforms(transform,
+ core::vector2df(float(UserConfigParams::m_width),
+ float(UserConfigParams::m_height)),
+ 0);
+ glDrawElements(GL_TRIANGLES, 6 * 6, GL_UNSIGNED_INT, 0);
+ glBindVertexArray(0);
+}
\ No newline at end of file
diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp
index 1be223a12..43f1e2c87 100644
--- a/src/graphics/shaders.cpp
+++ b/src/graphics/shaders.cpp
@@ -258,8 +258,8 @@ void Shaders::loadShaders()
m_shaders[ES_SUNLIGHT] = glsl_noinput(dir + "pass.vert", dir + "pass.frag");
- m_shaders[ES_DISPLACE] = glsl(dir + "pass.vert", dir + "pass.frag",
- m_callbacks[ES_DISPLACE]);
+ m_shaders[ES_DISPLACE] = glslmat(dir + "pass.vert", dir + "pass.frag",
+ m_callbacks[ES_DISPLACE], EMT_TRANSPARENT_ALPHA_CHANNEL);
m_shaders[ES_PASSFAR] = glsl(dir + "pass.vert", dir + "pass.frag",
m_callbacks[ES_COLORIZE]);
@@ -325,37 +325,24 @@ void Shaders::loadShaders()
FullScreenShader::MLAABlendWeightSHader::init();
FullScreenShader::MLAAGatherSHader::init();
MeshShader::ColorizeShader::init();
- MeshShader::NormalMapShader::init();
- MeshShader::ObjectPass1Shader::init();
- MeshShader::ObjectRefPass1Shader::init();
- MeshShader::InstancedObjectPass1Shader::init();
- MeshShader::InstancedObjectRefPass1Shader::init();
- MeshShader::InstancedGrassPass1Shader::init();
- MeshShader::ObjectPass2Shader::init();
- MeshShader::InstancedObjectPass2Shader::init();
- MeshShader::InstancedObjectRefPass2Shader::init();
- MeshShader::InstancedGrassPass2Shader::init();
- MeshShader::DetailledObjectPass2Shader::init();
- MeshShader::UntexturedObjectShader::init();
- MeshShader::ObjectRefPass2Shader::init();
- MeshShader::ObjectUnlitShader::init();
- MeshShader::SphereMapShader::init();
- MeshShader::SplattingShader::init();
- MeshShader::GrassPass1Shader::init();
- MeshShader::GrassPass2Shader::init();
+ MeshShader::InstancedObjectPass1ShaderInstance = new MeshShader::InstancedObjectPass1Shader();
+ MeshShader::InstancedObjectRefPass1ShaderInstance = new MeshShader::InstancedObjectRefPass1Shader();
+ MeshShader::InstancedGrassPass1ShaderInstance = new MeshShader::InstancedGrassPass1Shader();
+ MeshShader::InstancedObjectPass2ShaderInstance = new MeshShader::InstancedObjectPass2Shader();
+ MeshShader::InstancedObjectRefPass2ShaderInstance = new MeshShader::InstancedObjectRefPass2Shader();
+ MeshShader::InstancedGrassPass2ShaderInstance = new MeshShader::InstancedGrassPass2Shader();
MeshShader::BubbleShader::init();
- MeshShader::TransparentShader::init();
- MeshShader::TransparentFogShader::init();
MeshShader::BillboardShader::init();
LightShader::PointLightShader::init();
- MeshShader::DisplaceShader::init();
- MeshShader::DisplaceMaskShader::init();
- MeshShader::ShadowShader::init();
+ MeshShader::DisplaceShaderInstance = new MeshShader::DisplaceShader();
+ MeshShader::DisplaceMaskShaderInstance = new MeshShader::DisplaceMaskShader();
+ MeshShader::ShadowShaderInstance = new MeshShader::ShadowShader();
MeshShader::RSMShader::init();
- MeshShader::InstancedShadowShader::init();
- MeshShader::RefShadowShader::init();
- MeshShader::InstancedRefShadowShader::init();
- MeshShader::GrassShadowShader::init();
+ MeshShader::InstancedShadowShaderInstance = new MeshShader::InstancedShadowShader();
+ MeshShader::RefShadowShaderInstance = new MeshShader::RefShadowShader();
+ MeshShader::InstancedRefShadowShaderInstance = new MeshShader::InstancedRefShadowShader();
+ MeshShader::GrassShadowShaderInstance = new MeshShader::GrassShadowShader();
+ MeshShader::InstancedGrassShadowShaderInstance = new MeshShader::InstancedGrassShadowShader();
MeshShader::SkyboxShader::init();
MeshShader::ViewFrustrumShader::init();
ParticleShader::FlipParticleRender::init();
@@ -395,7 +382,7 @@ void Shaders::check(const int num) const
}
}
-static void bypassUBO(GLint Program)
+void bypassUBO(GLuint Program)
{
GLint VM = glGetUniformLocation(Program, "ViewMatrix");
glUniformMatrix4fv(VM, 1, GL_FALSE, irr_driver->getViewMatrix().pointer());
@@ -444,143 +431,120 @@ namespace UtilShader
}
}
+static void
+AssignTextureUnit(GLuint Program, const std::vector > assoc)
+{
+ glUseProgram(Program);
+ for (unsigned i = 0; i < assoc.size(); i++)
+ {
+ GLuint uniform = glGetUniformLocation(Program, assoc[i].second);
+ glUniform1i(uniform, assoc[i].first);
+ }
+ glUseProgram(0);
+}
+
+static void
+AssignUniforms(GLuint Program, std::vector &uniforms, const std::vector &name)
+{
+ for (unsigned i = 0; i < name.size(); i++)
+ {
+ uniforms.push_back(glGetUniformLocation(Program, name[i]));
+ }
+}
+
+void glUniformMatrix4fvWraper(GLuint a, size_t b, unsigned c, const float *d)
+{
+ glUniformMatrix4fv(a, b, c, d);
+}
+
+void glUniform3fWraper(GLuint a, float b, float c, float d)
+{
+ glUniform3f(a, b, c, d);
+}
+
+void glUniform2fWraper(GLuint a, float b, float c)
+{
+ glUniform2f(a, b, c);
+}
+
+void glUniform1fWrapper(GLuint a, float b)
+{
+ glUniform1f(a, b);
+}
+
namespace MeshShader
{
// Solid Normal and depth pass shaders
- GLuint ObjectPass1Shader::Program;
- GLuint ObjectPass1Shader::uniform_MM;
- GLuint ObjectPass1Shader::uniform_IMM;
- GLuint ObjectPass1Shader::uniform_tex;
-
- void ObjectPass1Shader::init()
+ ObjectPass1Shader::ObjectPass1Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass1.frag").c_str());
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
- uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix");
- uniform_tex = glGetUniformLocation(Program, "tex");
+ AssignUniforms(Program, uniforms, {"ModelMatrix", "InverseModelMatrix"});
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
+ TU_tex = 0;
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
}
- void ObjectPass1Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_tex)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer());
- glUniform1i(uniform_tex, TU_tex);
- }
-
- GLuint ObjectRefPass1Shader::Program;
- GLuint ObjectRefPass1Shader::uniform_MM;
- GLuint ObjectRefPass1Shader::uniform_IMM;
- GLuint ObjectRefPass1Shader::uniform_TM;
- GLuint ObjectRefPass1Shader::uniform_tex;
-
- void ObjectRefPass1Shader::init()
+ ObjectRefPass1Shader::ObjectRefPass1Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
- uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix");
- uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
- uniform_tex = glGetUniformLocation(Program, "tex");
+ AssignUniforms(Program, uniforms, { "ModelMatrix", "InverseModelMatrix", "TextureMatrix" });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
+ TU_tex = 0;
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
}
- void ObjectRefPass1Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
- glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer());
- glUniform1i(uniform_tex, TU_tex);
- }
-
- GLuint GrassPass1Shader::Program;
- GLuint GrassPass1Shader::uniform_MVP;
- GLuint GrassPass1Shader::uniform_TIMV;
- GLuint GrassPass1Shader::uniform_tex;
- GLuint GrassPass1Shader::uniform_windDir;
-
- void GrassPass1Shader::init()
+ GrassPass1Shader::GrassPass1Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
- uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
- uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView");
- uniform_tex = glGetUniformLocation(Program, "tex");
- uniform_windDir = glGetUniformLocation(Program, "windDir");
+ AssignUniforms(Program, uniforms, { "ModelMatrix", "InverseModelMatrix", "windDir" });
+ TU_tex = 0;
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
}
- void GrassPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::vector3df &windDirection, unsigned TU_tex)
- {
- glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
- glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer());
- glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z);
- glUniform1i(uniform_tex, TU_tex);
- }
-
- GLuint NormalMapShader::Program;
- GLuint NormalMapShader::uniform_MM;
- GLuint NormalMapShader::uniform_IMM;
- GLuint NormalMapShader::uniform_normalMap;
- GLuint NormalMapShader::uniform_DiffuseForAlpha;
-
- void NormalMapShader::init()
+ NormalMapShader::NormalMapShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/normalmap.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/normalmap.frag").c_str());
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
- uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix");
- uniform_normalMap = glGetUniformLocation(Program, "normalMap");
- uniform_DiffuseForAlpha = glGetUniformLocation(Program, "DiffuseForAlpha");
+ AssignUniforms(Program, uniforms, {"ModelMatrix", "InverseModelMatrix"});
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
+ TU_normalmap = 1;
+ TU_glossy = 0;
+ AssignTextureUnit(Program, { { TU_normalmap, "normalMap" }, { TU_glossy, "DiffuseForAlpha" } });
}
- void NormalMapShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_normalMap, unsigned TU_uniform_DiffuseForAlpha)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer());
- glUniform1i(uniform_normalMap, TU_normalMap);
- glUniform1i(uniform_DiffuseForAlpha, TU_uniform_DiffuseForAlpha);
- }
-
- GLuint InstancedObjectPass1Shader::Program;
- GLuint InstancedObjectPass1Shader::uniform_tex;
-
- void InstancedObjectPass1Shader::init()
+ InstancedObjectPass1Shader::InstancedObjectPass1Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass1.frag").c_str());
- uniform_tex = glGetUniformLocation(Program, "tex");
+ TU_tex = 0;
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
@@ -588,24 +552,17 @@ namespace MeshShader
}
}
- void InstancedObjectPass1Shader::setUniforms(unsigned TU_tex)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniform1i(uniform_tex, TU_tex);
- }
+ InstancedObjectPass1Shader *InstancedObjectPass1ShaderInstance;
- GLuint InstancedObjectRefPass1Shader::Program;
- GLuint InstancedObjectRefPass1Shader::uniform_tex;
-
- void InstancedObjectRefPass1Shader::init()
+ InstancedObjectRefPass1Shader::InstancedObjectRefPass1Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
- uniform_tex = glGetUniformLocation(Program, "tex");
+ TU_tex = 0;
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
@@ -613,26 +570,18 @@ namespace MeshShader
}
}
- void InstancedObjectRefPass1Shader::setUniforms(unsigned TU_tex)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniform1i(uniform_tex, TU_tex);
- }
+ InstancedObjectRefPass1Shader *InstancedObjectRefPass1ShaderInstance;
- GLuint InstancedGrassPass1Shader::Program;
- GLuint InstancedGrassPass1Shader::uniform_windDir;
- GLuint InstancedGrassPass1Shader::uniform_tex;
-
- void InstancedGrassPass1Shader::init()
+ InstancedGrassPass1Shader::InstancedGrassPass1Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_grass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
- uniform_windDir = glGetUniformLocation(Program, "windDir");
- uniform_tex = glGetUniformLocation(Program, "tex");
+ AssignUniforms(Program, uniforms, { "windDir" });
+ TU_tex = 0;
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
@@ -640,35 +589,16 @@ namespace MeshShader
}
}
- void InstancedGrassPass1Shader::setUniforms(const core::vector3df &windDir, unsigned TU_tex)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniform3f(uniform_windDir, windDir.X, windDir.Y, windDir.Z);
- glUniform1i(uniform_tex, TU_tex);
- }
+ InstancedGrassPass1Shader *InstancedGrassPass1ShaderInstance;
// Solid Lit pass shaders
-
- GLuint ObjectPass2Shader::Program;
- GLuint ObjectPass2Shader::uniform_MM;
- GLuint ObjectPass2Shader::uniform_TM;
- GLuint ObjectPass2Shader::uniform_ambient;
- GLuint ObjectPass2Shader::TU_Albedo;
-
- void ObjectPass2Shader::init()
+ ObjectPass2Shader::ObjectPass2Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass2.frag").c_str());
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
- uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
- GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo");
- GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
- GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
- GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
- uniform_ambient = glGetUniformLocation(Program, "ambient");
+ AssignUniforms(Program, uniforms, { "ModelMatrix", "TextureMatrix", "ambient" });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
@@ -676,52 +606,22 @@ namespace MeshShader
}
TU_Albedo = 3;
- glUseProgram(Program);
- glUniform1i(uniform_DiffuseMap, 0);
- glUniform1i(uniform_SpecularMap, 1);
- glUniform1i(uniform_SSAO, 2);
- glUniform1i(uniform_Albedo, TU_Albedo);
- glUseProgram(0);
+ AssignTextureUnit(Program, { { 0, "DiffuseMap" }, { 1, "SpecularMap" }, { 2, "SSAO" }, { TU_Albedo, "Albedo" } });
}
- void ObjectPass2Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
- const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
- glUniform3f(uniform_ambient, s.r, s.g, s.b);
- }
+ ObjectPass2Shader *ObjectPass2ShaderInstance;
- GLuint InstancedObjectPass2Shader::Program;
- GLuint InstancedObjectPass2Shader::uniform_VP;
- GLuint InstancedObjectPass2Shader::uniform_TM;
- GLuint InstancedObjectPass2Shader::uniform_ambient;
- GLuint InstancedObjectPass2Shader::TU_Albedo;
-
- void InstancedObjectPass2Shader::init()
+ InstancedObjectPass2Shader::InstancedObjectPass2Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass2.frag").c_str());
- uniform_VP = glGetUniformLocation(Program, "ViewProjectionMatrix");
- uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
- GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo");
- GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
- GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
- GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
- uniform_ambient = glGetUniformLocation(Program, "ambient");
+ AssignUniforms(Program, uniforms, { "ambient" });
TU_Albedo = 3;
- glUseProgram(Program);
- glUniform1i(uniform_DiffuseMap, 0);
- glUniform1i(uniform_SpecularMap, 1);
- glUniform1i(uniform_SSAO, 2);
- glUniform1i(uniform_Albedo, TU_Albedo);
- glUseProgram(0);
+ AssignTextureUnit(Program, { { 0, "DiffuseMap" }, { 1, "SpecularMap" }, { 2, "SSAO" }, { TU_Albedo, "Albedo" } });
if (!UserConfigParams::m_ubo_disabled)
{
@@ -730,112 +630,49 @@ namespace MeshShader
}
}
- void InstancedObjectPass2Shader::setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &TextureMatrix)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_VP, 1, GL_FALSE, ViewProjectionMatrix.pointer());
- glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
- const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
- glUniform3f(uniform_ambient, s.r, s.g, s.b);
- }
+ InstancedObjectPass2Shader *InstancedObjectPass2ShaderInstance;
- GLuint InstancedObjectRefPass2Shader::Program;
- GLuint InstancedObjectRefPass2Shader::uniform_VP;
- GLuint InstancedObjectRefPass2Shader::uniform_TM;
- GLuint InstancedObjectRefPass2Shader::uniform_ambient;
- GLuint InstancedObjectRefPass2Shader::TU_Albedo;
-
- void InstancedObjectRefPass2Shader::init()
+ InstancedObjectRefPass2Shader::InstancedObjectRefPass2Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str());
- uniform_VP = glGetUniformLocation(Program, "ViewProjectionMatrix");
- uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
- GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo");
- GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
- GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
- GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
- uniform_ambient = glGetUniformLocation(Program, "ambient");
+ AssignUniforms(Program, uniforms, { "ambient" });
TU_Albedo = 3;
- glUseProgram(Program);
- glUniform1i(uniform_DiffuseMap, 0);
- glUniform1i(uniform_SpecularMap, 1);
- glUniform1i(uniform_SSAO, 2);
- glUniform1i(uniform_Albedo, TU_Albedo);
- glUseProgram(0);
+ AssignTextureUnit(Program, { { 0, "DiffuseMap" }, { 1, "SpecularMap" }, { 2, "SSAO" }, { TU_Albedo, "Albedo" } });
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
- void InstancedObjectRefPass2Shader::setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &TextureMatrix)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_VP, 1, GL_FALSE, ViewProjectionMatrix.pointer());
- glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
- const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
- glUniform3f(uniform_ambient, s.r, s.g, s.b);
- }
+ InstancedObjectRefPass2Shader *InstancedObjectRefPass2ShaderInstance;
- GLuint DetailledObjectPass2Shader::Program;
- GLuint DetailledObjectPass2Shader::uniform_MM;
- GLuint DetailledObjectPass2Shader::uniform_ambient;
- GLuint DetailledObjectPass2Shader::TU_Albedo;
- GLuint DetailledObjectPass2Shader::TU_detail;
-
- void DetailledObjectPass2Shader::init()
+ DetailledObjectPass2Shader::DetailledObjectPass2Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/detailledobject_pass2.frag").c_str());
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
- GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo");
- GLuint uniform_Detail = glGetUniformLocation(Program, "Detail");
- GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
- GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
- GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
- uniform_ambient = glGetUniformLocation(Program, "ambient");
+ AssignUniforms(Program, uniforms, { "ModelMatrix", "ambient" });
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
TU_Albedo = 3;
TU_detail = 4;
- glUseProgram(Program);
- glUniform1i(uniform_DiffuseMap, 0);
- glUniform1i(uniform_SpecularMap, 1);
- glUniform1i(uniform_SSAO, 2);
- glUniform1i(uniform_Albedo, TU_Albedo);
- glUniform1i(uniform_Detail, TU_detail);
- glUseProgram(0);
+ AssignTextureUnit(Program, { { 0, "DiffuseMap" }, { 1, "SpecularMap" }, { 2, "SSAO" }, { TU_Albedo, "Albedo" }, { TU_detail, "Detail" } });
}
- void DetailledObjectPass2Shader::setUniforms(const core::matrix4 &ModelMatrix)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
- glUniform3f(uniform_ambient, s.r, s.g, s.b);
- }
+ DetailledObjectPass2Shader *DetailledObjectPass2ShaderInstance;
- GLuint ObjectUnlitShader::Program;
- GLuint ObjectUnlitShader::uniform_MM;
- GLuint ObjectUnlitShader::TU_tex;
-
- void ObjectUnlitShader::init()
+ ObjectUnlitShader::ObjectUnlitShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
- GLuint uniform_tex = glGetUniformLocation(Program, "tex");
+ AssignUniforms(Program, uniforms, { "ModelMatrix" });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
@@ -843,76 +680,18 @@ namespace MeshShader
}
TU_tex = 3;
- glUseProgram(Program);
- glUniform1i(uniform_tex, TU_tex);
- glUseProgram(0);
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
}
- void ObjectUnlitShader::setUniforms(const core::matrix4 &ModelMatrix)
+ ObjectUnlitShader *ObjectUnlitShaderInstance;
+
+ ObjectRefPass2Shader::ObjectRefPass2Shader()
{
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- }
-
- GLuint UntexturedObjectShader::Program;
- GLuint UntexturedObjectShader::uniform_MM;
- GLuint UntexturedObjectShader::uniform_ambient;
-
- void UntexturedObjectShader::init()
- {
- Program = LoadProgram(
- GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
- GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
- GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/untextured_object.frag").c_str());
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
- GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
- GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
- GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
- uniform_ambient = glGetUniformLocation(Program, "ambient");
- if (!UserConfigParams::m_ubo_disabled)
- {
- GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
- glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
- }
-
- glUseProgram(Program);
- glUniform1i(uniform_DiffuseMap, 0);
- glUniform1i(uniform_SpecularMap, 1);
- glUniform1i(uniform_SSAO, 2);
- glUseProgram(0);
- }
-
- void UntexturedObjectShader::setUniforms(const core::matrix4 &ModelMatrix)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
- glUniform3f(uniform_ambient, s.r, s.g, s.b);
- }
-
-
- GLuint ObjectRefPass2Shader::Program;
- GLuint ObjectRefPass2Shader::uniform_MM;
- GLuint ObjectRefPass2Shader::uniform_TM;
- GLuint ObjectRefPass2Shader::uniform_ambient;
- GLuint ObjectRefPass2Shader::TU_Albedo;
-
- void ObjectRefPass2Shader::init()
- {
- initGL();
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str());
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
- uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
- GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo");
- GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
- GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
- GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
- uniform_ambient = glGetUniformLocation(Program, "ambient");
+ AssignUniforms(Program, uniforms, { "ModelMatrix", "TextureMatrix", "ambient" });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
@@ -920,139 +699,52 @@ namespace MeshShader
}
TU_Albedo = 3;
- glUseProgram(Program);
- glUniform1i(uniform_DiffuseMap, 0);
- glUniform1i(uniform_SpecularMap, 1);
- glUniform1i(uniform_SSAO, 2);
- glUniform1i(uniform_Albedo, TU_Albedo);
- glUseProgram(0);
+ AssignTextureUnit(Program, { { 0, "DiffuseMap" }, { 1, "SpecularMap" }, { 2, "SSAO" }, { TU_Albedo, "Albedo" } });
}
- void ObjectRefPass2Shader::setUniforms(const core::matrix4 &ModelMatrix,
- const core::matrix4 &TextureMatrix)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
- const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
- glUniform3f(uniform_ambient, s.r, s.g, s.b);
- }
+ ObjectRefPass2Shader *ObjectRefPass2ShaderInstance;
- GLuint GrassPass2Shader::Program;
- GLuint GrassPass2Shader::uniform_MVP;
- GLuint GrassPass2Shader::uniform_ambient;
- GLuint GrassPass2Shader::uniform_windDir;
- GLuint GrassPass2Shader::TU_Albedo;
-
- void GrassPass2Shader::init()
+ GrassPass2Shader::GrassPass2Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/grass_pass2.frag").c_str());
- uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
- GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo");
- GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
- GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
- GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
- uniform_ambient = glGetUniformLocation(Program, "ambient");
- uniform_windDir = glGetUniformLocation(Program, "windDir");
+ AssignUniforms(Program, uniforms, { "ModelMatrix", "windDir", "ambient" });
TU_Albedo = 3;
- glUseProgram(Program);
- glUniform1i(uniform_DiffuseMap, 0);
- glUniform1i(uniform_SpecularMap, 1);
- glUniform1i(uniform_SSAO, 2);
- glUniform1i(uniform_Albedo, TU_Albedo);
- glUseProgram(0);
+ AssignTextureUnit(Program, { { 0, "DiffuseMap" }, { 1, "SpecularMap" }, { 2, "SSAO" }, { TU_Albedo, "Albedo" } });
}
- void GrassPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix,
- const core::vector3df &windDirection)
- {
- glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
- const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
- glUniform3f(uniform_ambient, s.r, s.g, s.b);
- glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z);
- }
+ GrassPass2Shader *GrassPass2ShaderInstance;
- GLuint InstancedGrassPass2Shader::Program;
- GLuint InstancedGrassPass2Shader::uniform_VP;
- GLuint InstancedGrassPass2Shader::uniform_ambient;
- GLuint InstancedGrassPass2Shader::uniform_windDir;
- GLuint InstancedGrassPass2Shader::uniform_invproj;
- GLuint InstancedGrassPass2Shader::uniform_IVM;
- GLuint InstancedGrassPass2Shader::uniform_SunDir;
- GLuint InstancedGrassPass2Shader::TU_Albedo;
- GLuint InstancedGrassPass2Shader::TU_dtex;
-
- void InstancedGrassPass2Shader::init()
+ InstancedGrassPass2Shader::InstancedGrassPass2Shader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanced_grass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/grass_pass2.frag").c_str());
- uniform_VP = glGetUniformLocation(Program, "ViewProjectionMatrix");
- GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo");
- GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
- GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
- GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
- GLuint uniform_dtex = glGetUniformLocation(Program, "dtex");
- uniform_ambient = glGetUniformLocation(Program, "ambient");
- uniform_windDir = glGetUniformLocation(Program, "windDir");
- uniform_invproj = glGetUniformLocation(Program, "invproj");
- uniform_IVM = glGetUniformLocation(Program, "InverseViewMatrix");
- uniform_SunDir = glGetUniformLocation(Program, "SunDir");
+ AssignUniforms(Program, uniforms, { "windDir", "SunDir", "ambient" });
TU_Albedo = 3;
TU_dtex = 4;
- glUseProgram(Program);
- glUniform1i(uniform_DiffuseMap, 0);
- glUniform1i(uniform_SpecularMap, 1);
- glUniform1i(uniform_SSAO, 2);
- glUniform1i(uniform_Albedo, TU_Albedo);
- glUniform1i(uniform_dtex, TU_dtex);
- glUseProgram(0);
+ AssignTextureUnit(Program, { { 0, "DiffuseMap" }, { 1, "SpecularMap" }, { 2, "SSAO" }, { TU_Albedo, "Albedo" }, { TU_dtex, "dtex" } });
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
- void InstancedGrassPass2Shader::setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &InverseViewMatrix, const core::matrix4 &invproj, const core::vector3df &windDirection, const core::vector3df &SunDir)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_VP, 1, GL_FALSE, ViewProjectionMatrix.pointer());
- glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, invproj.pointer());
- glUniformMatrix4fv(uniform_IVM, 1, GL_FALSE, InverseViewMatrix.pointer());
- glUniform3f(uniform_SunDir, SunDir.X, SunDir.Y, SunDir.Z);
- const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
- glUniform3f(uniform_ambient, s.r, s.g, s.b);
- glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z);
- }
+ InstancedGrassPass2Shader *InstancedGrassPass2ShaderInstance;
- GLuint SphereMapShader::Program;
- GLuint SphereMapShader::uniform_MM;
- GLuint SphereMapShader::uniform_IMM;
- GLuint SphereMapShader::uniform_ambient;
- GLuint SphereMapShader::TU_tex;
-
- void SphereMapShader::init()
+ SphereMapShader::SphereMapShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectpass_spheremap.frag").c_str());
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
- uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix");
- uniform_ambient = glGetUniformLocation(Program, "ambient");
- GLuint uniform_tex = glGetUniformLocation(Program, "tex");
- GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
- GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
- GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
+ AssignUniforms(Program, uniforms, { "ModelMatrix", "InverseModelMatrix", "ambient" });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
@@ -1060,71 +752,28 @@ namespace MeshShader
}
TU_tex = 3;
- glUseProgram(Program);
- glUniform1i(uniform_DiffuseMap, 0);
- glUniform1i(uniform_SpecularMap, 1);
- glUniform1i(uniform_SSAO, 2);
- glUniform1i(uniform_tex, TU_tex);
- glUseProgram(0);
+ AssignTextureUnit(Program, { { 0, "DiffuseMap" }, { 1, "SpecularMap" }, { 2, "SSAO" }, { TU_tex, "tex" } });
}
- void SphereMapShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const SColorf &ambient)
- {
- if (UserConfigParams::m_ubo_disabled)
- bypassUBO(Program);
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer());
- glUniform3f(uniform_ambient, ambient.r, ambient.g, ambient.b);
- }
+ SphereMapShader *SphereMapShaderInstance;
- GLuint SplattingShader::Program;
- GLuint SplattingShader::uniform_MM;
- GLuint SplattingShader::uniform_ambient;
- GLuint SplattingShader::TU_tex_layout;
- GLuint SplattingShader::TU_tex_detail0;
- GLuint SplattingShader::TU_tex_detail1;
- GLuint SplattingShader::TU_tex_detail2;
- GLuint SplattingShader::TU_tex_detail3;
-
- void SplattingShader::init()
+ SplattingShader::SplattingShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/splatting.frag").c_str());
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
- GLuint uniform_tex_layout = glGetUniformLocation(Program, "tex_layout");
- GLuint uniform_tex_detail0 = glGetUniformLocation(Program, "tex_detail0");
- GLuint uniform_tex_detail1 = glGetUniformLocation(Program, "tex_detail1");
- GLuint uniform_tex_detail2 = glGetUniformLocation(Program, "tex_detail2");
- GLuint uniform_tex_detail3 = glGetUniformLocation(Program, "tex_detail3");
- GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
- GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
- GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO");
- uniform_ambient = glGetUniformLocation(Program, "ambient");
+ AssignUniforms(Program, uniforms, {"ModelMatrix", "ambient"});
TU_tex_layout = 3;
TU_tex_detail0 = 4;
TU_tex_detail1 = 5;
TU_tex_detail2 = 6;
TU_tex_detail3 = 7;
- glUseProgram(Program);
- glUniform1i(uniform_DiffuseMap, 0);
- glUniform1i(uniform_SpecularMap, 1);
- glUniform1i(uniform_SSAO, 2);
- glUniform1i(uniform_tex_layout, TU_tex_layout);
- glUniform1i(uniform_tex_detail0, TU_tex_detail0);
- glUniform1i(uniform_tex_detail1, TU_tex_detail1);
- glUniform1i(uniform_tex_detail2, TU_tex_detail2);
- glUniform1i(uniform_tex_detail3, TU_tex_detail3);
- glUseProgram(0);
+ AssignTextureUnit(Program, { { 0, "DiffuseMap" }, { 1, "SpecularMap" }, { 2, "SSAO" }, { TU_tex_layout, "tex_layout" },
+ { TU_tex_detail0, "tex_detail0" }, { TU_tex_detail1, "tex_detail1" }, { TU_tex_detail2, "tex_detail2" }, { TU_tex_detail3, "tex_detail3" } });
}
- void SplattingShader::setUniforms(const core::matrix4 &ModelMatrix)
- {
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
- glUniform3f(uniform_ambient, s.r, s.g, s.b);
- }
+ SplattingShader *SplattingShaderInstance;
GLuint BubbleShader::Program;
GLuint BubbleShader::uniform_MVP;
@@ -1150,77 +799,41 @@ namespace MeshShader
glUniform1f(uniform_transparency, transparency);
}
- GLuint TransparentShader::Program;
- GLuint TransparentShader::uniform_MVP;
- GLuint TransparentShader::uniform_TM;
- GLuint TransparentShader::uniform_tex;
-
- void TransparentShader::init()
+ TransparentShader::TransparentShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparent.frag").c_str());
- uniform_MVP = glGetUniformLocation(Program, "ModelMatrix");
- uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
- uniform_tex = glGetUniformLocation(Program, "tex");
+ AssignUniforms(Program, uniforms, {"ModelMatrix", "TextureMatrix" });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
+ TU_tex = 0;
+
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
}
- void TransparentShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex)
- {
- glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelMatrix.pointer());
- glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
- glUniform1i(uniform_tex, TU_tex);
- }
+ TransparentShader *TransparentShaderInstance;
- GLuint TransparentFogShader::Program;
- GLuint TransparentFogShader::uniform_MVP;
- GLuint TransparentFogShader::uniform_TM;
- GLuint TransparentFogShader::uniform_tex;
- GLuint TransparentFogShader::uniform_fogmax;
- GLuint TransparentFogShader::uniform_startH;
- GLuint TransparentFogShader::uniform_endH;
- GLuint TransparentFogShader::uniform_start;
- GLuint TransparentFogShader::uniform_end;
- GLuint TransparentFogShader::uniform_col;
-
- void TransparentFogShader::init()
+ TransparentFogShader::TransparentFogShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparentfog.frag").c_str());
- uniform_MVP = glGetUniformLocation(Program, "ModelMatrix");
- uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
- uniform_tex = glGetUniformLocation(Program, "tex");
- uniform_fogmax = glGetUniformLocation(Program, "fogmax");
- uniform_startH = glGetUniformLocation(Program, "startH");
- uniform_endH = glGetUniformLocation(Program, "endH");
- uniform_start = glGetUniformLocation(Program, "start");
- uniform_end = glGetUniformLocation(Program, "end");
- uniform_col = glGetUniformLocation(Program, "col");
+ AssignUniforms(Program, uniforms, { "ModelMatrix", "TextureMatrix", "fogmax", "startH", "endH", "start", "end", "col" });
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
+ TU_tex = 0;
+
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
}
- void TransparentFogShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, const core::vector3df &campos, unsigned TU_tex)
- {
- glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelMatrix.pointer());
- glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
- glUniform1f(uniform_fogmax, fogmax);
- glUniform1f(uniform_startH, startH);
- glUniform1f(uniform_endH, endH);
- glUniform1f(uniform_start, start);
- glUniform1f(uniform_end, end);
- glUniform3f(uniform_col, col.X, col.Y, col.Z);
- glUniform1i(uniform_tex, TU_tex);
- }
+ TransparentFogShader *TransparentFogShaderInstance;
GLuint BillboardShader::Program;
GLuint BillboardShader::attrib_corner;
@@ -1284,10 +897,7 @@ namespace MeshShader
glUniform3f(uniform_col, r, g, b);
}
- GLuint ShadowShader::Program;
- GLuint ShadowShader::uniform_MM;
-
- void ShadowShader::init()
+ ShadowShader::ShadowShader()
{
// Geometry shader needed
if (irr_driver->getGLSLVersion() < 150)
@@ -1305,21 +915,17 @@ namespace MeshShader
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str());
}
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
+ AssignUniforms(Program, uniforms, { "ModelMatrix" });
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
- void ShadowShader::setUniforms(const core::matrix4 &ModelMatrix)
- {
-
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- }
+ ShadowShader *ShadowShaderInstance;
GLuint RSMShader::Program;
GLuint RSMShader::uniform_MM;
- GLuint RSMShader::uniform_tex;
GLuint RSMShader::uniform_RSMMatrix;
+ GLuint RSMShader::TU_tex;
void RSMShader::init()
{
@@ -1329,20 +935,17 @@ namespace MeshShader
GL_VERTEX_SHADER, file_manager->getAsset("shaders/rsm.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/rsm.frag").c_str());
uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
- uniform_tex = glGetUniformLocation(Program, "tex");
uniform_RSMMatrix = glGetUniformLocation(Program, "RSMMatrix");
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
}
- void RSMShader::setUniforms(const core::matrix4 &RSMMatrix, const core::matrix4 &ModelMatrix, unsigned TU_tex)
+ void RSMShader::setUniforms(const core::matrix4 &RSMMatrix, const core::matrix4 &ModelMatrix)
{
glUniformMatrix4fv(uniform_RSMMatrix, 1, GL_FALSE, RSMMatrix.pointer());
glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- glUniform1i(uniform_tex, TU_tex);
}
- GLuint InstancedShadowShader::Program;
-
- void InstancedShadowShader::init()
+ InstancedShadowShader::InstancedShadowShader()
{
// Geometry shader needed
if (irr_driver->getGLSLVersion() < 150)
@@ -1366,15 +969,9 @@ namespace MeshShader
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
- void InstancedShadowShader::setUniforms()
- {
- }
+ InstancedShadowShader *InstancedShadowShaderInstance;
- GLuint RefShadowShader::Program;
- GLuint RefShadowShader::uniform_MM;
- GLuint RefShadowShader::uniform_tex;
-
- void RefShadowShader::init()
+ RefShadowShader::RefShadowShader()
{
// Geometry shader needed
if (irr_driver->getGLSLVersion() < 150)
@@ -1392,22 +989,17 @@ namespace MeshShader
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
}
- uniform_tex = glGetUniformLocation(Program, "tex");
- uniform_MM = glGetUniformLocation(Program, "ModelMatrix");
+ AssignUniforms(Program, uniforms, { "ModelMatrix" });
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
+ TU_tex = 0;
+
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
}
- void RefShadowShader::setUniforms(const core::matrix4 &ModelMatrix, unsigned TU_tex)
- {
- glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer());
- glUniform1i(uniform_tex, TU_tex);
- }
+ RefShadowShader *RefShadowShaderInstance;
- GLuint InstancedRefShadowShader::Program;
- GLuint InstancedRefShadowShader::uniform_tex;
-
- void InstancedRefShadowShader::init()
+ InstancedRefShadowShader::InstancedRefShadowShader()
{
// Geometry shader needed
if (irr_driver->getGLSLVersion() < 150)
@@ -1427,50 +1019,78 @@ namespace MeshShader
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
}
- uniform_tex = glGetUniformLocation(Program, "tex");
+ TU_tex = 0;
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
- void InstancedRefShadowShader::setUniforms(unsigned TU_tex)
+ InstancedRefShadowShader *InstancedRefShadowShaderInstance;
+
+ GrassShadowShader::GrassShadowShader()
{
- glUniform1i(uniform_tex, TU_tex);
+ // Geometry shader needed
+ if (irr_driver->getGLSLVersion() < 150)
+ return;
+ if (irr_driver->hasVSLayerExtension())
+ {
+ Program = LoadProgram(
+ GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow_grass.vert").c_str(),
+ GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
+ }
+ else
+ {
+ Program = LoadProgram(
+ GL_VERTEX_SHADER, file_manager->getAsset("shaders/shadow_grass.vert").c_str(),
+ GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
+ GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
+ }
+ AssignUniforms(Program, uniforms, { "ModelMatrix", "windDir" });
+ GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
+ glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
+ TU_tex = 0;
+
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
}
- GLuint GrassShadowShader::Program;
- GLuint GrassShadowShader::uniform_MVP;
- GLuint GrassShadowShader::uniform_tex;
- GLuint GrassShadowShader::uniform_windDir;
+ GrassShadowShader *GrassShadowShaderInstance;
- void GrassShadowShader::init()
+ InstancedGrassShadowShader::InstancedGrassShadowShader()
{
- return;
- Program = LoadProgram(
- GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass.vert").c_str(),
- GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
- uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
- uniform_tex = glGetUniformLocation(Program, "tex");
- uniform_windDir = glGetUniformLocation(Program, "windDir");
+ // Geometry shader needed
+ if (irr_driver->getGLSLVersion() < 150)
+ return;
+ if (irr_driver->hasVSLayerExtension())
+ {
+ Program = LoadProgram(
+ GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
+ GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanciedgrassshadow.vert").c_str(),
+ GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
+ }
+ else
+ {
+ Program = LoadProgram(
+ GL_VERTEX_SHADER, file_manager->getAsset("shaders/utils/getworldmatrix.vert").c_str(),
+ GL_VERTEX_SHADER, file_manager->getAsset("shaders/instanciedgrassshadow.vert").c_str(),
+ GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/shadow.geom").c_str(),
+ GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str());
+ }
+ TU_tex = 0;
+ AssignTextureUnit(Program, { { TU_tex, "tex" } });
+
+ AssignUniforms(Program, uniforms, { "windDir" });
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
- void GrassShadowShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection, unsigned TU_tex)
- {
- glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
- glUniform1i(uniform_tex, TU_tex);
- glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z);
- }
+ InstancedGrassShadowShader *InstancedGrassShadowShaderInstance;
- GLuint DisplaceMaskShader::Program;
- GLuint DisplaceMaskShader::uniform_MVP;
-
- void DisplaceMaskShader::init()
+ DisplaceMaskShader::DisplaceMaskShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/displace.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/white.frag").c_str());
- uniform_MVP = glGetUniformLocation(Program, "ModelMatrix");
+ AssignUniforms(Program, uniforms, { "ModelMatrix"});
if (!UserConfigParams::m_ubo_disabled)
{
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
@@ -1478,46 +1098,25 @@ namespace MeshShader
}
}
- void DisplaceMaskShader::setUniforms(const core::matrix4 &ModelMatrix)
- {
- glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelMatrix.pointer());
- }
+ DisplaceMaskShader *DisplaceMaskShaderInstance;
- GLuint DisplaceShader::Program;
- GLuint DisplaceShader::uniform_MVP;
- GLuint DisplaceShader::uniform_displacement_tex;
- GLuint DisplaceShader::uniform_mask_tex;
- GLuint DisplaceShader::uniform_color_tex;
- GLuint DisplaceShader::uniform_tex;
- GLuint DisplaceShader::uniform_dir;
- GLuint DisplaceShader::uniform_dir2;
- void DisplaceShader::init()
+ DisplaceShader::DisplaceShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/displace.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/displace.frag").c_str());
- uniform_MVP = glGetUniformLocation(Program, "ModelMatrix");
- uniform_displacement_tex = glGetUniformLocation(Program, "displacement_tex");
- uniform_color_tex = glGetUniformLocation(Program, "color_tex");
- uniform_mask_tex = glGetUniformLocation(Program, "mask_tex");
- uniform_dir = glGetUniformLocation(Program, "dir");
- uniform_dir2 = glGetUniformLocation(Program, "dir2");
- uniform_tex = glGetUniformLocation(Program, "tex");
+ AssignUniforms(Program, uniforms, { "ModelMatrix", "dir", "dir2" });
+ TU_displacement_tex = 0;
+ TU_color_tex = 1;
+ TU_mask_tex = 2;
+ TU_tex = 3;
+ AssignTextureUnit(Program, { { TU_displacement_tex, "displacement_tex" }, { TU_color_tex, "color_tex" }, { TU_mask_tex, "mask_tex" }, { TU_tex, "tex" } });
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
}
- void DisplaceShader::setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex, unsigned TU_tex)
- {
- glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelMatrix.pointer());
- glUniform2f(uniform_dir, dir.X, dir.Y);
- glUniform2f(uniform_dir2, dir2.X, dir2.Y);
- glUniform1i(uniform_displacement_tex, TU_displacement_tex);
- glUniform1i(uniform_mask_tex, TU_mask_tex);
- glUniform1i(uniform_color_tex, TU_color_tex);
- glUniform1i(uniform_tex, TU_tex);
- }
+ DisplaceShader *DisplaceShaderInstance;
GLuint SkyboxShader::Program;
GLuint SkyboxShader::attrib_position;
diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp
index 885d8807a..e5d0eecd2 100644
--- a/src/graphics/shaders.hpp
+++ b/src/graphics/shaders.hpp
@@ -20,6 +20,8 @@
#include
#include
#include
+#include "config/user_config.hpp"
+#include "utils/singleton.hpp"
typedef unsigned int GLuint;
using namespace irr;
@@ -47,196 +49,239 @@ public:
};
}
+void glUniformMatrix4fvWraper(GLuint, size_t, unsigned, const float *mat);
+void glUniform3fWraper(GLuint, float, float, float);
+void glUniform2fWraper(GLuint a, float b, float c);
+void glUniform1fWrapper(GLuint, float);
+
+struct UniformHelper
+{
+ template
+ static void setUniformsHelper(const std::vector &uniforms)
+ {
+ }
+
+ template
+ static void setUniformsHelper(const std::vector &uniforms, const core::matrix4 &mat, Args... arg)
+ {
+#ifndef GL_FALSE
+#define GL_FALSE 0
+#endif
+ glUniformMatrix4fvWraper(uniforms[N], 1, GL_FALSE, mat.pointer());
+ setUniformsHelper(uniforms, arg...);
+ }
+
+ template
+ static void setUniformsHelper(const std::vector &uniforms, const video::SColorf &col, Args... arg)
+ {
+ glUniform3fWraper(uniforms[N], col.r, col.g, col.b);
+ setUniformsHelper(uniforms, arg...);
+ }
+
+ template
+ static void setUniformsHelper(const std::vector &uniforms, const core::vector3df &v, Args... arg)
+ {
+ glUniform3fWraper(uniforms[N], v.X, v.Y, v.Z);
+ setUniformsHelper(uniforms, arg...);
+ }
+
+
+ template
+ static void setUniformsHelper(const std::vector &uniforms, const core::vector2df &v, Args... arg)
+ {
+ glUniform2fWraper(uniforms[N], v.X, v.Y);
+ setUniformsHelper(uniforms, arg...);
+ }
+
+ template
+ static void setUniformsHelper(const std::vector &uniforms, float f, Args... arg)
+ {
+ glUniform1fWrapper(uniforms[N], f);
+ setUniformsHelper(uniforms, arg...);
+ }
+
+};
+
+void bypassUBO(GLuint Program);
+
+template
+class ShaderHelper
+{
+protected:
+ std::vector uniforms;
+public:
+ GLuint Program;
+
+ void setUniforms(const Args & ... args) const
+ {
+ if (UserConfigParams::m_ubo_disabled)
+ bypassUBO(Program);
+ UniformHelper::setUniformsHelper(uniforms, args...);
+ }
+};
+
+template
+class ShaderHelperSingleton : public Singleton
+{
+protected:
+ std::vector uniforms;
+public:
+ friend class Singleton;
+ GLuint Program;
+
+ void setUniforms(const Args & ... args) const
+ {
+ if (UserConfigParams::m_ubo_disabled)
+ bypassUBO(Program);
+ UniformHelper::setUniformsHelper(uniforms, args...);
+ }
+};
+
namespace MeshShader
{
-class ObjectPass1Shader
+class ObjectPass1Shader : public ShaderHelperSingleton
{
public:
- static GLuint Program;
- static GLuint uniform_MM, uniform_IMM, uniform_tex;
-
- static void init();
- static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_tex);
+ GLuint TU_tex;
+ ObjectPass1Shader();
};
-class ObjectRefPass1Shader
+class ObjectRefPass1Shader : public ShaderHelperSingleton
{
public:
- static GLuint Program;
- static GLuint uniform_MM, uniform_TM, uniform_IMM, uniform_tex;
-
- static void init();
- static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_texture);
+ GLuint TU_tex;
+ ObjectRefPass1Shader();
};
-class GrassPass1Shader
+class GrassPass1Shader : public ShaderHelperSingleton
{
public:
- static GLuint Program;
- static GLuint uniform_MVP, uniform_TIMV, uniform_tex, uniform_windDir;
+ GLuint TU_tex;
- static void init();
- static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::vector3df &windDirection, unsigned TU_tex);
+ GrassPass1Shader();
};
-class NormalMapShader
+class NormalMapShader : public ShaderHelperSingleton
{
public:
- static GLuint Program;
- static GLuint uniform_MM, uniform_IMM, uniform_normalMap, uniform_DiffuseForAlpha;
-
- static void init();
- static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_normalMap, unsigned TU_uniform_DiffuseForAlpha);
+ GLuint TU_normalmap, TU_glossy;
+ NormalMapShader();
};
-class InstancedObjectPass1Shader
+class InstancedObjectPass1Shader : public ShaderHelper<>
{
public:
- static GLuint Program;
- static GLuint uniform_tex;
+ GLuint TU_tex;
- static void init();
- static void setUniforms(unsigned TU_tex);
+ InstancedObjectPass1Shader();
};
-class InstancedObjectRefPass1Shader
+extern InstancedObjectPass1Shader *InstancedObjectPass1ShaderInstance;
+
+class InstancedObjectRefPass1Shader : public ShaderHelper<>
{
public:
- static GLuint Program;
- static GLuint uniform_tex;
+ GLuint TU_tex;
- static void init();
- static void setUniforms(unsigned TU_tex);
+ InstancedObjectRefPass1Shader();
};
-class InstancedGrassPass1Shader
+extern InstancedObjectRefPass1Shader *InstancedObjectRefPass1ShaderInstance;
+
+class InstancedGrassPass1Shader : public ShaderHelper
{
public:
- static GLuint Program;
- static GLuint uniform_windDir, uniform_tex;
+ GLuint TU_tex;
- static void init();
- static void setUniforms(const core::vector3df &windDir, unsigned TU_tex);
+ InstancedGrassPass1Shader();
};
-class ObjectPass2Shader
+extern InstancedGrassPass1Shader *InstancedGrassPass1ShaderInstance;
+
+class ObjectPass2Shader : public ShaderHelperSingleton
{
public:
- static GLuint Program;
- static GLuint uniform_MM, uniform_TM, uniform_ambient;
- static GLuint TU_Albedo;
+ GLuint TU_Albedo;
- static void init();
- static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix);
+ ObjectPass2Shader();
};
-class InstancedObjectPass2Shader
+class InstancedObjectPass2Shader : public ShaderHelper
{
public:
- static GLuint Program;
- static GLuint uniform_VP, uniform_TM, uniform_ambient;
- static GLuint TU_Albedo;
+ GLuint TU_Albedo;
- static void init();
- static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &TextureMatrix);
+ InstancedObjectPass2Shader();
};
-class InstancedObjectRefPass2Shader
+extern InstancedObjectPass2Shader *InstancedObjectPass2ShaderInstance;
+
+class InstancedObjectRefPass2Shader : public ShaderHelper
{
public:
- static GLuint Program;
- static GLuint uniform_VP, uniform_TM, uniform_ambient;
- static GLuint TU_Albedo;
+ GLuint TU_Albedo;
- static void init();
- static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &TextureMatrix);
+ InstancedObjectRefPass2Shader();
};
-class DetailledObjectPass2Shader
+extern InstancedObjectRefPass2Shader *InstancedObjectRefPass2ShaderInstance;
+
+class DetailledObjectPass2Shader : public ShaderHelperSingleton
{
public:
- static GLuint Program;
- static GLuint uniform_MM, uniform_ambient;
- static GLuint TU_Albedo, TU_detail;
+ GLuint TU_Albedo, TU_detail;
- static void init();
- static void setUniforms(const core::matrix4 &ModelMatrix);
+ DetailledObjectPass2Shader();
};
-class UntexturedObjectShader
+class ObjectUnlitShader : public ShaderHelperSingleton
{
public:
- static GLuint Program;
- static GLuint uniform_MM, uniform_ambient;
+ GLuint TU_tex;
- static void init();
- static void setUniforms(const core::matrix4 &ModelMatrix);
+ ObjectUnlitShader();
};
-class ObjectUnlitShader
+class ObjectRefPass2Shader : public ShaderHelperSingleton
{
public:
- static GLuint Program;
- static GLuint uniform_MM;
- static GLuint TU_tex;
+ GLuint TU_Albedo;
- static void init();
- static void setUniforms(const core::matrix4 &ModelMatrix);
+ ObjectRefPass2Shader();
};
-class ObjectRefPass2Shader
+class GrassPass2Shader : public ShaderHelperSingleton
{
public:
- static GLuint Program;
- static GLuint uniform_MM, uniform_TM, uniform_ambient;
- static GLuint TU_Albedo;
+ GLuint TU_Albedo;
- static void init();
- static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix);
+ GrassPass2Shader();
};
-class GrassPass2Shader
+class InstancedGrassPass2Shader : public ShaderHelper