Browse Source

Convert 1.3 lw-tag to annotated tag at the time of its creation.

Yao Wei Tjong 姚伟忠 12 years ago
parent
commit
d3382cbb13
100 changed files with 2039 additions and 1419 deletions
  1. 107 0
      .bash_helpers.sh
  2. 63 0
      .gitignore
  3. 54 0
      .travis.yml
  4. 0 2
      Bin/CompileAllShaders.bat
  5. 7 7
      Bin/ConvertModels.bat
  6. 4 1
      Bin/CoreData/RenderPaths/Deferred.xml
  7. 4 1
      Bin/CoreData/RenderPaths/Forward.xml
  8. 4 1
      Bin/CoreData/RenderPaths/ForwardDepth.xml
  9. 4 1
      Bin/CoreData/RenderPaths/Prepass.xml
  10. 3 0
      Bin/CoreData/RenderPaths/PrepassHDR.xml
  11. 73 0
      Bin/CoreData/Shaders/GLSL/AutoExposure.glsl
  12. 18 3
      Bin/CoreData/Shaders/GLSL/Basic.glsl
  13. 0 23
      Bin/CoreData/Shaders/GLSL/Basic.vert
  14. 0 16
      Bin/CoreData/Shaders/GLSL/Basic.xml
  15. 19 5
      Bin/CoreData/Shaders/GLSL/Bloom.glsl
  16. 0 9
      Bin/CoreData/Shaders/GLSL/Bloom.xml
  17. 73 0
      Bin/CoreData/Shaders/GLSL/BloomHDR.glsl
  18. 43 0
      Bin/CoreData/Shaders/GLSL/Blur.glsl
  19. 21 0
      Bin/CoreData/Shaders/GLSL/ColorCorrection.glsl
  20. 0 10
      Bin/CoreData/Shaders/GLSL/CopyFramebuffer.frag
  21. 11 6
      Bin/CoreData/Shaders/GLSL/CopyFramebuffer.glsl
  22. 0 13
      Bin/CoreData/Shaders/GLSL/CopyFramebuffer.vert
  23. 0 3
      Bin/CoreData/Shaders/GLSL/CopyFramebuffer.xml
  24. 27 4
      Bin/CoreData/Shaders/GLSL/DeferredLight.glsl
  25. 0 33
      Bin/CoreData/Shaders/GLSL/DeferredLight.vert
  26. 0 16
      Bin/CoreData/Shaders/GLSL/DeferredLight.xml
  27. 0 15
      Bin/CoreData/Shaders/GLSL/Depth.frag
  28. 24 0
      Bin/CoreData/Shaders/GLSL/Depth.glsl
  29. 0 13
      Bin/CoreData/Shaders/GLSL/Depth.vert
  30. 0 10
      Bin/CoreData/Shaders/GLSL/Depth.xml
  31. 18 4
      Bin/CoreData/Shaders/GLSL/EdgeFilter.glsl
  32. 0 13
      Bin/CoreData/Shaders/GLSL/EdgeFilter.vert
  33. 0 3
      Bin/CoreData/Shaders/GLSL/EdgeFilter.xml
  34. 0 14
      Bin/CoreData/Shaders/GLSL/Fog.frag
  35. 24 0
      Bin/CoreData/Shaders/GLSL/Fog.glsl
  36. 21 0
      Bin/CoreData/Shaders/GLSL/GammaCorrection.glsl
  37. 0 12
      Bin/CoreData/Shaders/GLSL/GreyScale.frag
  38. 22 0
      Bin/CoreData/Shaders/GLSL/GreyScale.glsl
  39. 0 13
      Bin/CoreData/Shaders/GLSL/GreyScale.vert
  40. 0 3
      Bin/CoreData/Shaders/GLSL/GreyScale.xml
  41. 90 17
      Bin/CoreData/Shaders/GLSL/Lighting.glsl
  42. 0 83
      Bin/CoreData/Shaders/GLSL/Lighting.vert
  43. 0 69
      Bin/CoreData/Shaders/GLSL/LitParticle.frag
  44. 130 0
      Bin/CoreData/Shaders/GLSL/LitParticle.glsl
  45. 0 59
      Bin/CoreData/Shaders/GLSL/LitParticle.vert
  46. 0 46
      Bin/CoreData/Shaders/GLSL/LitParticle.xml
  47. 0 171
      Bin/CoreData/Shaders/GLSL/LitSolid.frag
  48. 297 0
      Bin/CoreData/Shaders/GLSL/LitSolid.glsl
  49. 0 119
      Bin/CoreData/Shaders/GLSL/LitSolid.vert
  50. 0 66
      Bin/CoreData/Shaders/GLSL/LitSolid.xml
  51. 87 0
      Bin/CoreData/Shaders/GLSL/PostProcess.glsl
  52. 26 4
      Bin/CoreData/Shaders/GLSL/PrepassLight.glsl
  53. 0 33
      Bin/CoreData/Shaders/GLSL/PrepassLight.vert
  54. 0 16
      Bin/CoreData/Shaders/GLSL/PrepassLight.xml
  55. 11 8
      Bin/CoreData/Shaders/GLSL/Samplers.glsl
  56. 2 1
      Bin/CoreData/Shaders/GLSL/ScreenPos.glsl
  57. 0 15
      Bin/CoreData/Shaders/GLSL/Shadow.frag
  58. 24 0
      Bin/CoreData/Shaders/GLSL/Shadow.glsl
  59. 0 13
      Bin/CoreData/Shaders/GLSL/Shadow.vert
  60. 0 10
      Bin/CoreData/Shaders/GLSL/Shadow.xml
  61. 0 9
      Bin/CoreData/Shaders/GLSL/Skybox.frag
  62. 9 3
      Bin/CoreData/Shaders/GLSL/Skybox.glsl
  63. 0 3
      Bin/CoreData/Shaders/GLSL/Skybox.xml
  64. 0 6
      Bin/CoreData/Shaders/GLSL/Stencil.frag
  65. 9 3
      Bin/CoreData/Shaders/GLSL/Stencil.glsl
  66. 0 3
      Bin/CoreData/Shaders/GLSL/Stencil.xml
  67. 87 11
      Bin/CoreData/Shaders/GLSL/TerrainBlend.glsl
  68. 0 74
      Bin/CoreData/Shaders/GLSL/TerrainBlend.vert
  69. 0 48
      Bin/CoreData/Shaders/GLSL/TerrainBlend.xml
  70. 40 0
      Bin/CoreData/Shaders/GLSL/Tonemap.glsl
  71. 10 4
      Bin/CoreData/Shaders/GLSL/Transform.glsl
  72. 0 22
      Bin/CoreData/Shaders/GLSL/Uniforms.frag
  73. 64 0
      Bin/CoreData/Shaders/GLSL/Uniforms.glsl
  74. 0 32
      Bin/CoreData/Shaders/GLSL/Uniforms.vert
  75. 0 25
      Bin/CoreData/Shaders/GLSL/Unlit.frag
  76. 67 0
      Bin/CoreData/Shaders/GLSL/Unlit.glsl
  77. 0 21
      Bin/CoreData/Shaders/GLSL/Unlit.vert
  78. 0 13
      Bin/CoreData/Shaders/GLSL/Unlit.xml
  79. 15 7
      Bin/CoreData/Shaders/GLSL/Vegetation.glsl
  80. 0 27
      Bin/CoreData/Shaders/GLSL/Vegetation.xml
  81. 3 3
      Bin/CoreData/Shaders/GLSL/VegetationDepth.glsl
  82. 0 6
      Bin/CoreData/Shaders/GLSL/VegetationDepth.xml
  83. 3 3
      Bin/CoreData/Shaders/GLSL/VegetationShadow.glsl
  84. 0 6
      Bin/CoreData/Shaders/GLSL/VegetationShadow.xml
  85. 59 0
      Bin/CoreData/Shaders/GLSL/Water.glsl
  86. 95 0
      Bin/CoreData/Shaders/HLSL/AutoExposure.hlsl
  87. 0 16
      Bin/CoreData/Shaders/HLSL/Basic.xml
  88. 0 9
      Bin/CoreData/Shaders/HLSL/Bloom.xml
  89. 111 0
      Bin/CoreData/Shaders/HLSL/BloomHDR.hlsl
  90. 44 0
      Bin/CoreData/Shaders/HLSL/Blur.hlsl
  91. 22 0
      Bin/CoreData/Shaders/HLSL/ColorCorrection.hlsl
  92. 0 3
      Bin/CoreData/Shaders/HLSL/CopyFrameBuffer.xml
  93. 0 0
      Bin/CoreData/Shaders/HLSL/CopyFramebuffer.hlsl
  94. 0 17
      Bin/CoreData/Shaders/HLSL/DeferredLight.xml
  95. 0 10
      Bin/CoreData/Shaders/HLSL/Depth.xml
  96. 0 3
      Bin/CoreData/Shaders/HLSL/EdgeFilter.xml
  97. 14 4
      Bin/CoreData/Shaders/HLSL/Fog.hlsl
  98. 22 0
      Bin/CoreData/Shaders/HLSL/GammaCorrection.hlsl
  99. 0 3
      Bin/CoreData/Shaders/HLSL/GreyScale.xml
  100. 54 41
      Bin/CoreData/Shaders/HLSL/Lighting.hlsl

+ 107 - 0
.bash_helpers.sh

@@ -0,0 +1,107 @@
+#
+# Copyright (c) 2008-2014 the Urho3D project.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+
+# Define helpers
+msg() {
+    echo -e "\n$1\n================================================================================"
+}
+
+post_cmake() {
+    # Check if xmlstarlet software package is available for fixing the generated Eclipse project setting
+    if [ $HAS_XMLSTARLET ]; then
+        # Common fixes for all builds
+        #
+        # Remove build type from project name
+        # Replace deprecated GNU gmake Error Parser with newer version (6.0 -> 7.0) and add GCC Error Parser
+        #
+        xmlstarlet ed -P -L \
+            -u "/projectDescription/name/text()" -x "concat(substring-before(., '-Release'), substring-before(., '-Debug'), substring-before(., '-RelWithDebInfo'))" \
+            -u "/projectDescription/buildSpec/buildCommand/arguments/dictionary/value[../key/text() = 'org.eclipse.cdt.core.errorOutputParser']" -x "concat('org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;', substring-after(., 'org.eclipse.cdt.core.MakeErrorParser'))" \
+            $1/.project
+
+        # Build-specific fixes
+        if [ $1 == "android-Build" ]; then
+            # For Android build, add the Android and Java nature to the project setting as it would be done by Eclipse during project import
+            # This fix avoids the step to reimport the project everytime the Eclipse project setting is regenerated by cmake_gcc.sh invocation
+            echo -- Add Android and Java nature to Eclipse project setting files in $( pwd )/$1
+
+            #
+            # Add natures (Android nature must be inserted as first nature)
+            #
+            xmlstarlet ed -P -L \
+                -i "/projectDescription/natures/nature[1]" -t elem -n nature -v "com.android.ide.eclipse.adt.AndroidNature" \
+                -s "/projectDescription/natures" -t elem -n nature -v "org.eclipse.jdt.core.javanature" \
+                $1/.project
+            #
+            # Add build commands
+            #
+            for c in com.android.ide.eclipse.adt.ResourceManagerBuilder com.android.ide.eclipse.adt.PreCompilerBuilder org.eclipse.jdt.core.javabuilder com.android.ide.eclipse.adt.ApkBuilder; do
+                xmlstarlet ed -P -L \
+                    -s "/projectDescription/buildSpec" -t elem -n buildCommandNew -v "" \
+                    -s "/projectDescription/buildSpec/buildCommandNew" -t elem -n name -v $c \
+                    -s "/projectDescription/buildSpec/buildCommandNew" -t elem -n arguments -v "" \
+                    -r "/projectDescription/buildSpec/buildCommandNew" -v "buildCommand" \
+                    $1/.project
+            done
+
+        elif [ $1 == "raspi-Build" ]; then
+            # For Raspberry Pi build, add [Bin-CC] linked resource
+            #
+            # Replace [Subprojects]/Urho3D linked resource to [Targets]/[Bin-CC] instead
+            #
+            xmlstarlet ed -P -L \
+                -u "/projectDescription/linkedResources/link/name/text()[. = '[Subprojects]/Urho3D']" -v "[Targets]/[Bin-CC]" \
+                -u "/projectDescription/linkedResources/link/location[../name/text() = '[Targets]/[Bin-CC]']" -v "$( pwd )/Bin-CC" \
+                $1/.project
+
+        else
+            # For native build, move the Eclipse project setting files back to Source folder to fix source code versioning
+            echo -- Eclipse project setting files have been relocated to: $( pwd )/Source
+            for f in .project .cproject; do mv $1/$f Source; done
+
+            #
+            # Replace [Source directory] linked resource to [Build] instead
+            # Modify build argument to first change directory to Build folder
+            # Replace [Subprojects]/Urho3D linked resource to [Build]/[Bin] instead
+            #
+            xmlstarlet ed -P -L \
+                -u "/projectDescription/linkedResources/link/name/text()[. = '[Source directory]']" -v "[Build]" \
+                -u "/projectDescription/linkedResources/link/location[../name/text() = '[Build]']" -v "$( pwd )/$1" \
+                -u "/projectDescription/buildSpec/buildCommand/arguments/dictionary/value[../key/text() = 'org.eclipse.cdt.make.core.build.arguments']" -x "concat('-C ../$1 ', .)" \
+                -u "/projectDescription/linkedResources/link/name/text()[. = '[Subprojects]/Urho3D']" -v "[Build]/[Bin]" \
+                -u "/projectDescription/linkedResources/link/location[../name/text() = '[Build]/[Bin]']" -v "$( pwd )/Bin" \
+                Source/.project
+            #
+            # Fix source path entry to Source folder and modify its filter condition
+            # Fix output path entry to [Build] linked resource and modify its filter condition
+            #
+            xmlstarlet ed -P -L \
+                -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']/@path" -v "" \
+                -s "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'src']" -t attr -n "excluding" -v "[Subprojects]/|[Targets]/" \
+                -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@path" -v "[Build]" \
+                -u "/cproject/storageModule/cconfiguration/storageModule/pathentry[@kind = 'out']/@excluding" -x "substring-after(., '[Source directory]/|')" \
+                Source/.cproject
+        fi
+    fi
+}
+
+# vi: set ts=4 sw=4 expandtab:

+ 63 - 0
.gitignore

@@ -0,0 +1,63 @@
+# Build directories
+Build/
+*-Build/
+
+# Output directories
+Bin/*
+!Bin/**/
+!Bin/*.bat
+!Bin/*.sh
+Bin/*.app/
+Bin/*.app.dSYM/
+Bin/Data/LuaScripts/jit/
+*-Bin/
+Lib/
+*-Lib/
+
+# Compiled shaders
+*.vs2
+*.vs3
+*.ps2
+*.ps3
+
+# Compiled AngelScript
+*.asc
+
+# Compiled Lua script
+*.luc
+
+# Generated documentation
+Docs/html/
+Docs/Doxyfile
+Docs/minimal-*
+
+# Eclipse project settings
+Source/.*project
+Source/.settings
+
+# Android in-the-source project settings
+Source/Android/project.properties
+Source/Android/local.properties
+Source/Android/proguard-project.txt
+
+# Android in-the-source build and output directories
+Source/Android/Engine
+Source/Android/ThirdParty
+Source/Android/libs
+
+# Android in-the-source CMake build files
+CMakeCache.txt
+CMakeFiles/
+CMakeScripts/
+Makefile
+cmake_install.cmake
+install_manifest.txt
+
+# Misc.
+configure*
+*~
+*.swp
+.DS_Store
+*.log
+*.bak
+Thumbs.db

+ 54 - 0
.travis.yml

@@ -0,0 +1,54 @@
+#
+# Copyright (c) 2008-2014 the Urho3D project.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+
+env:
+  global:
+    - secure: DE9IUM+pIV757GU0ccfDJhA752442pKu3DyBthrzHW9+GbsqbfuJOx045CYNN5vOWutFPC0A51B9WxhLNpXXqD3mfU8MhP1gkF7SskrHvcAPrCyfdqZf1Q8XDP5phm2KbHhhwxQMYmmicd6yj8DPNy2wRoSgPSDp/ZUDk51XZDU=
+    - DISPLAY=:99.0
+  matrix:
+    - WINDOWS=1 ENABLE_64BIT=1 URHO3D_LIB_TYPE=STATIC
+    - WINDOWS=1 ENABLE_64BIT=1 URHO3D_LIB_TYPE=SHARED
+    - LINUX=1   ENABLE_64BIT=1 URHO3D_LIB_TYPE=STATIC SITE_UPDATE=1
+    - LINUX=1   ENABLE_64BIT=1 URHO3D_LIB_TYPE=SHARED
+    - LINUX=1                  URHO3D_LIB_TYPE=STATIC
+    - LINUX=1                  URHO3D_LIB_TYPE=SHARED
+    - ANDROID=1                URHO3D_LIB_TYPE=STATIC
+    - ANDROID=1                URHO3D_LIB_TYPE=SHARED
+#matrix:
+#  fast_finish: true
+#  allow_failures:
+#    - env:
+language: cpp
+compiler: gcc
+before_install:
+    - bash -c "[ $ANDROID ]" && wget -q http://dl.google.com/android/ndk/android-ndk-r9c-linux-x86_64.tar.bz2 && tar xjf *.bz2 && rm *.bz2 && ln -s android-ndk* android-ndk && export ANDROID_NDK=$(pwd)/android-ndk || true
+    - bash -c "[ $SITE_UPDATE ] && [ $TRAVIS_PULL_REQUEST == 'false' ]" && sudo add-apt-repository ppa:george-edison55/precise-backports -y || true
+    - sudo apt-get update -q -y
+install:
+    - sudo apt-get install -q -y --no-install-recommends libasound2-dev
+    - rvm gemset use global && gem install rake
+    - bash -c "[ x$ENABLE_64BIT == 'x' ]" && sudo apt-get remove -q -y gvfs-daemons && sudo apt-get install -q -y libxrandr-dev:i386 libgl1-mesa-dev:i386 libxext-dev:i386 libxrender-dev:i386 g++-multilib && export CMAKE_PREFIX_PATH=/usr/lib/i386-linux-gnu || true
+    - bash -c "[ $SITE_UPDATE ] && [ $TRAVIS_PULL_REQUEST == 'false' ]" && sudo apt-get install -q -y --no-install-recommends doxygen graphviz || true
+    - bash -c "[ $WINDOWS ]" && sudo apt-get install -q -y gcc-mingw-w64 gcc-mingw-w64-i686 gcc-mingw-w64-x86-64 g++-mingw-w64 g++-mingw-w64-i686 g++-mingw-w64-x86-64 binutils-mingw-w64 binutils-mingw-w64-i686 binutils-mingw-w64-x86-64 && export MINGW_PREFIX=/usr/bin/x86_64-w64 MINGW_ROOT=/usr/x86_64-w64-mingw32 || true
+    - bash -e /etc/init.d/xvfb start
+script: rake travis_ci
+after_success: rake travis_ci_site_update && rake travis_ci_rebase

+ 0 - 2
Bin/CompileAllShaders.bat

@@ -1,2 +0,0 @@
-shadercompiler CoreData/Shaders/HLSL/*.xml CoreData/Shaders/HLSL/SM3 -dSM3
-shadercompiler CoreData/Shaders/HLSL/*.xml CoreData/Shaders/HLSL/SM2

+ 7 - 7
Bin/ConvertModels.bat

@@ -1,7 +1,7 @@
-OgreImporter ../SourceAssets/Jack.mesh.xml Data/Models/Jack.mdl
-OgreImporter ../SourceAssets/Level.mesh.xml Data/Models/Level.mdl
-OgreImporter ../SourceAssets/Mushroom.mesh.xml Data/Models/Mushroom.mdl
-OgreImporter ../SourceAssets/Ninja.mesh.xml Data/Models/Ninja.mdl
-OgreImporter ../SourceAssets/Potion.mesh.xml Data/Models/Potion.mdl
-OgreImporter ../SourceAssets/SnowBall.mesh.xml Data/Models/SnowBall.mdl
-OgreImporter ../SourceAssets/SnowCrate.mesh.xml Data/Models/SnowCrate.mdl
+OgreImporter ../SourceAssets/Jack.mesh.xml Data/Models/Jack.mdl -t
+OgreImporter ../SourceAssets/Level.mesh.xml Data/Models/Level.mdl -t
+OgreImporter ../SourceAssets/Mushroom.mesh.xml Data/Models/Mushroom.mdl -t
+OgreImporter ../SourceAssets/Ninja.mesh.xml Data/Models/Ninja.mdl -t
+OgreImporter ../SourceAssets/Potion.mesh.xml Data/Models/Potion.mdl -t
+OgreImporter ../SourceAssets/SnowBall.mesh.xml Data/Models/SnowBall.mdl -t 
+OgreImporter ../SourceAssets/SnowCrate.mesh.xml Data/Models/SnowCrate.mdl -t

+ 4 - 1
Bin/CoreData/RenderPaths/Deferred.xml

@@ -14,7 +14,10 @@
         <texture unit="normal" name="normal" />
         <texture unit="depth" name="depth" />
     </command>
-    <command type="scenepass" pass="prealpha" />
+    <command type="scenepass" pass="postopaque" />
+    <command type="scenepass" pass="refract">
+        <texture unit="environment" name="viewport" />
+    </command>
     <command type="scenepass" pass="alpha" usescissor="true" vertexlights="true" sort="backtofront" metadata="alpha" />
     <command type="scenepass" pass="postalpha" sort="backtofront" />
 </renderpath>

+ 4 - 1
Bin/CoreData/RenderPaths/Forward.xml

@@ -2,7 +2,10 @@
     <command type="clear" color="fog" depth="1.0" stencil="0" />
     <command type="scenepass" pass="base" vertexlights="true" metadata="base" />
     <command type="forwardlights" pass="light" />
-    <command type="scenepass" pass="prealpha" />
+    <command type="scenepass" pass="postopaque" />
+    <command type="scenepass" pass="refract">
+        <texture unit="environment" name="viewport" />
+    </command>
     <command type="scenepass" pass="alpha" usescissor="true" vertexlights="true" sort="backtofront" metadata="alpha" />
     <command type="scenepass" pass="postalpha" sort="backtofront" />
 </renderpath>

+ 4 - 1
Bin/CoreData/RenderPaths/ForwardDepth.xml

@@ -5,7 +5,10 @@
     <command type="clear" color="fog" depth="1.0" stencil="0" />
     <command type="scenepass" pass="base" vertexlights="true" metadata="base" />
     <command type="forwardlights" pass="light" />
-    <command type="scenepass" pass="prealpha" />
+    <command type="scenepass" pass="postopaque" />
+    <command type="scenepass" pass="refract">
+        <texture unit="environment" name="viewport" />
+    </command>
     <command type="scenepass" pass="alpha" usescissor="true" vertexlights="true" sort="backtofront" metadata="alpha" />
     <command type="scenepass" pass="postalpha" sort="backtofront" />
 </renderpath>

+ 4 - 1
Bin/CoreData/RenderPaths/Prepass.xml

@@ -15,7 +15,10 @@
     <command type="scenepass" pass="material" vertexlights="true">
         <texture unit="light" name="light" />
     </command>
-    <command type="scenepass" pass="prealpha"/>
+    <command type="scenepass" pass="postopaque" />
+    <command type="scenepass" pass="refract">
+        <texture unit="environment" name="viewport" />
+    </command>
     <command type="scenepass" pass="alpha" usescissor="true" vertexlights="true" sort="backtofront" metadata="alpha" />
     <command type="scenepass" pass="postalpha" sort="backtofront" />
 </renderpath>

+ 3 - 0
Bin/CoreData/RenderPaths/PrepassHDR.xml

@@ -0,0 +1,3 @@
+<renderpath inherit="RenderPaths/Prepass.xml">
+    <replace sel="/renderpath/rendertarget[@name='light']/@format">rgba16f</replace>
+</renderpath>

+ 73 - 0
Bin/CoreData/Shaders/GLSL/AutoExposure.glsl

@@ -0,0 +1,73 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "PostProcess.glsl"
+
+varying vec2 vTexCoord;
+varying vec2 vScreenPos;
+
+#ifdef COMPILEPS
+uniform float cAutoExposureAdaptRate;
+uniform vec2 cAutoExposureLumRange;
+uniform float cAutoExposureMiddleGrey;
+uniform vec2 cHDR128InvSize;
+uniform vec2 cLum64InvSize;
+uniform vec2 cLum16InvSize;
+uniform vec2 cLum4InvSize;
+
+float GatherAvgLum(sampler2D texSampler, vec2 texCoord, vec2 texelSize)
+{
+    float lumAvg = 0.0;
+    lumAvg += texture2D(texSampler, texCoord + vec2(1.0, -1.0) * texelSize).r;
+    lumAvg += texture2D(texSampler, texCoord + vec2(-1.0, 1.0) * texelSize).r;
+    lumAvg += texture2D(texSampler, texCoord + vec2(1.0, 1.0) * texelSize).r;
+    lumAvg += texture2D(texSampler, texCoord + vec2(1.0, -1.0) * texelSize).r;
+    return lumAvg / 4.0;
+}
+#endif
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = GetQuadTexCoord(gl_Position);
+    vScreenPos = GetScreenPosPreDiv(gl_Position);
+}
+
+void PS()
+{
+    #ifdef LUMINANCE64
+    float logLumSum = 0.0;
+    logLumSum += log(dot(texture2D(sDiffMap, vTexCoord + vec2(-1.0, -1.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
+    logLumSum += log(dot(texture2D(sDiffMap, vTexCoord + vec2(-1.0, 1.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
+    logLumSum += log(dot(texture2D(sDiffMap, vTexCoord + vec2(1.0, 1.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
+    logLumSum += log(dot(texture2D(sDiffMap, vTexCoord + vec2(1.0, -1.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
+    gl_FragColor.r = logLumSum;
+    #endif
+
+    #ifdef LUMINANCE16
+    gl_FragColor.r = GatherAvgLum(sDiffMap, vTexCoord, cLum64InvSize);
+    #endif
+
+    #ifdef LUMINANCE4
+    gl_FragColor.r = GatherAvgLum(sDiffMap, vTexCoord, cLum16InvSize);
+    #endif
+
+    #ifdef LUMINANCE1
+    gl_FragColor.r = exp(GatherAvgLum(sDiffMap, vTexCoord, cLum4InvSize) / 16.0);
+    #endif
+
+    #ifdef ADAPTLUMINANCE
+    float adaptedLum = texture2D(sDiffMap, vTexCoord).r;
+    float lum = clamp(texture2D(sNormalMap, vTexCoord).r, cAutoExposureLumRange.x, cAutoExposureLumRange.y);
+    gl_FragColor.r = adaptedLum + (lum - adaptedLum) * (1.0 - exp(-cDeltaTimePS * cAutoExposureAdaptRate));
+    #endif
+
+    #ifdef EXPOSE
+    vec3 color = texture2D(sDiffMap, vScreenPos).rgb;
+    float adaptedLum = texture2D(sNormalMap, vTexCoord).r;
+    gl_FragColor = vec4(color * (cAutoExposureMiddleGrey / adaptedLum), 1.0);
+    #endif
+}

+ 18 - 3
Bin/CoreData/Shaders/GLSL/Basic.frag → Bin/CoreData/Shaders/GLSL/Basic.glsl

@@ -1,5 +1,6 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
 
 #if defined(DIFFMAP) || defined(ALPHAMAP)
     varying vec2 vTexCoord;
@@ -8,7 +9,21 @@
     varying vec4 vColor;
 #endif
 
-void main()
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    
+    #ifdef DIFFMAP
+        vTexCoord = iTexCoord;
+    #endif
+    #ifdef VERTEXCOLOR
+        vColor = iColor;
+    #endif
+}
+
+void PS()
 {
     vec4 diffColor = cMatDiffColor;
 

+ 0 - 23
Bin/CoreData/Shaders/GLSL/Basic.vert

@@ -1,23 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-
-#ifdef DIFFMAP
-    varying vec2 vTexCoord;
-#endif
-#ifdef VERTEXCOLOR
-    varying vec4 vColor;
-#endif
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    
-    #ifdef DIFFMAP
-        vTexCoord = iTexCoord;
-    #endif
-    #ifdef VERTEXCOLOR
-        vColor = iColor;
-    #endif
-}

+ 0 - 16
Bin/CoreData/Shaders/GLSL/Basic.xml

@@ -1,16 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <option name="Diff" define="DIFFMAP" />
-        <option name="VCol" define="VERTEXCOLOR" />
-        <variation name="" />
-        <variation name="Skinned" define="SKINNED" />
-        <variation name="Instanced" define="INSTANCED" />
-        <variation name="Billboard" define="BILLBOARD" />
-    </shader>
-    <shader type="ps">
-        <option name="Diff" define="DIFFMAP" exclude="Alpha" />
-        <option name="Alpha" define="ALPHAMAP" exclude="Diff" />
-        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />
-        <option name="VCol" define="VERTEXCOLOR" />
-    </shader>
-</shaders>

+ 19 - 5
Bin/CoreData/Shaders/GLSL/Bloom.frag → Bin/CoreData/Shaders/GLSL/Bloom.glsl

@@ -1,14 +1,27 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
 
+varying vec2 vTexCoord;
+varying vec2 vScreenPos;
+
+#ifdef COMPILEPS
 uniform float cBloomThreshold;
 uniform vec2 cBloomMix;
 uniform vec2 cHBlurInvSize;
+#endif
 
-varying vec2 vTexCoord;
-varying vec2 vScreenPos;
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = GetQuadTexCoord(gl_Position);
+    vScreenPos = GetScreenPosPreDiv(gl_Position);
+}
 
-void main()
+void PS()
 {
     #ifdef BRIGHT
     vec3 rgb = texture2D(sDiffMap, vScreenPos).rgb;
@@ -41,3 +54,4 @@ void main()
     gl_FragColor = vec4(original + bloom, 1.0);
     #endif
 }
+

+ 0 - 9
Bin/CoreData/Shaders/GLSL/Bloom.xml

@@ -1,9 +0,0 @@
-<shaders>
-    <shader type="vs" />
-    <shader type="ps">
-        <variation name="Bright" define="BRIGHT" />
-        <variation name="HBlur" define="HBLUR" />
-        <variation name="VBlur" define="VBLUR" />
-        <variation name="Combine" define="COMBINE" />
-    </shader>
-</shaders>

+ 73 - 0
Bin/CoreData/Shaders/GLSL/BloomHDR.glsl

@@ -0,0 +1,73 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "PostProcess.glsl"
+
+varying vec2 vTexCoord;
+varying vec2 vScreenPos;
+
+#ifdef COMPILEPS
+uniform float cBloomHDRThreshold;
+uniform float cBloomHDRBlurSigma;
+uniform float cBloomHDRBlurRadius;
+uniform vec2 cBloomHDRBlurDir;
+uniform vec2 cBloomHDRMix;
+uniform vec2 cBright2InvSize;
+uniform vec2 cBright4InvSize;
+uniform vec2 cBright8InvSize;
+uniform vec2 cBright16InvSize;
+
+const int BlurKernelSize = 5;
+#endif
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = GetQuadTexCoord(gl_Position);
+    vScreenPos = GetScreenPosPreDiv(gl_Position);
+}
+
+void PS()
+{
+    #ifdef BRIGHT
+    vec3 color = texture2D(sDiffMap, vScreenPos).rgb;
+    gl_FragColor = vec4(max(color - cBloomHDRThreshold, 0.0), 1.0);
+    #endif
+
+    #ifdef BLUR16
+    gl_FragColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright16InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, vScreenPos);
+    #endif
+
+    #ifdef BLUR8
+    gl_FragColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright8InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, vScreenPos);
+    #endif
+
+    #ifdef BLUR4
+    gl_FragColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright4InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, vScreenPos);
+    #endif
+
+    #ifdef BLUR2
+    gl_FragColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright2InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, vScreenPos);
+    #endif
+
+    #ifdef COMBINE16
+    gl_FragColor = texture2D(sDiffMap, vScreenPos) + texture2D(sNormalMap, vTexCoord);
+    #endif
+
+    #ifdef COMBINE8
+    gl_FragColor = texture2D(sDiffMap, vScreenPos) + texture2D(sNormalMap, vTexCoord);
+    #endif
+
+    #ifdef COMBINE4
+    gl_FragColor = texture2D(sDiffMap, vScreenPos) + texture2D(sNormalMap, vTexCoord);
+    #endif
+
+    #ifdef COMBINE2
+    vec3 color = texture2D(sDiffMap, vScreenPos).rgb * cBloomHDRMix.x;
+    vec3 bloom = texture2D(sNormalMap, vTexCoord).rgb * cBloomHDRMix.y;
+    gl_FragColor = vec4(color + bloom, 1.0);
+    #endif
+}

+ 43 - 0
Bin/CoreData/Shaders/GLSL/Blur.glsl

@@ -0,0 +1,43 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "PostProcess.glsl"
+
+varying vec2 vTexCoord;
+varying vec2 vScreenPos;
+
+#ifdef COMPILEPS
+uniform vec2 cBlurDir;
+uniform float cBlurRadius;
+uniform float cBlurSigma;
+uniform vec2 cBlurHInvSize;
+#endif
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = GetQuadTexCoord(gl_Position);
+    vScreenPos = GetScreenPosPreDiv(gl_Position);
+}
+
+void PS()
+{
+    #ifdef BLUR3
+        gl_FragColor = GaussianBlur(3, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, vTexCoord);
+    #endif
+
+    #ifdef BLUR5
+        gl_FragColor = GaussianBlur(5, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, vTexCoord);
+    #endif
+
+    #ifdef BLUR7
+        gl_FragColor = GaussianBlur(7, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, vTexCoord);
+    #endif
+
+    #ifdef BLUR9
+        gl_FragColor = GaussianBlur(9, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, vTexCoord);
+    #endif
+}

+ 21 - 0
Bin/CoreData/Shaders/GLSL/ColorCorrection.glsl

@@ -0,0 +1,21 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "PostProcess.glsl"
+
+varying vec2 vScreenPos;
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vScreenPos = GetScreenPosPreDiv(gl_Position);
+}
+
+void PS()
+{
+    vec3 color = texture2D(sDiffMap, vScreenPos).rgb;
+    gl_FragColor = vec4(ColorCorrection(color, sVolumeMap), 1.0);
+}

+ 0 - 10
Bin/CoreData/Shaders/GLSL/CopyFramebuffer.frag

@@ -1,10 +0,0 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-
-varying vec2 vScreenPos;
-
-void main()
-{
-    gl_FragColor = texture2D(sDiffMap, vScreenPos);
-}
-

+ 11 - 6
Bin/CoreData/Shaders/GLSL/Bloom.vert → Bin/CoreData/Shaders/GLSL/CopyFramebuffer.glsl

@@ -1,15 +1,20 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "ScreenPos.vert"
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
 
-varying vec2 vTexCoord;
 varying vec2 vScreenPos;
 
-void main()
+void VS()
 {
     mat4 modelMatrix = iModelMatrix;
     vec3 worldPos = GetWorldPos(modelMatrix);
     gl_Position = GetClipPos(worldPos);
-    vTexCoord = GetQuadTexCoord(gl_Position);
     vScreenPos = GetScreenPosPreDiv(gl_Position);
 }
+
+void PS()
+{
+    gl_FragColor = texture2D(sDiffMap, vScreenPos);
+}
+

+ 0 - 13
Bin/CoreData/Shaders/GLSL/CopyFramebuffer.vert

@@ -1,13 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "ScreenPos.vert"
-
-varying vec2 vScreenPos;
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    vScreenPos = GetScreenPosPreDiv(gl_Position);
-}

+ 0 - 3
Bin/CoreData/Shaders/GLSL/CopyFramebuffer.xml

@@ -1,3 +0,0 @@
-<shaders>
-    <shader />
-</shaders>

+ 27 - 4
Bin/CoreData/Shaders/GLSL/DeferredLight.frag → Bin/CoreData/Shaders/GLSL/DeferredLight.glsl

@@ -1,6 +1,8 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-#include "Lighting.frag"
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "Lighting.glsl"
 
 #ifdef DIRLIGHT
     varying vec2 vScreenPos;
@@ -12,7 +14,28 @@ varying vec3 vFarRay;
     varying vec3 vNearRay;
 #endif
 
-void main()
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    #ifdef DIRLIGHT
+        vScreenPos = GetScreenPosPreDiv(gl_Position);
+        vFarRay = GetFarRay(gl_Position);
+        #ifdef ORTHO
+            vNearRay = GetNearRay(gl_Position);
+        #endif
+    #else
+        vScreenPos = GetScreenPos(gl_Position);
+        vFarRay = GetFarRay(gl_Position) * gl_Position.w;
+        #ifdef ORTHO
+            vNearRay = GetNearRay(gl_Position) * gl_Position.w;
+        #endif
+    #endif
+}
+
+
+void PS()
 {
     // If rendering a directional light quad, optimize out the w divide
     #ifdef DIRLIGHT

+ 0 - 33
Bin/CoreData/Shaders/GLSL/DeferredLight.vert

@@ -1,33 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "ScreenPos.vert"
-
-#ifdef DIRLIGHT
-    varying vec2 vScreenPos;
-#else
-    varying vec4 vScreenPos;
-#endif
-varying vec3 vFarRay;
-#ifdef ORTHO
-    varying vec3 vNearRay;
-#endif
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    #ifdef DIRLIGHT
-        vScreenPos = GetScreenPosPreDiv(gl_Position);
-        vFarRay = GetFarRay(gl_Position);
-        #ifdef ORTHO
-            vNearRay = GetNearRay(gl_Position);
-        #endif
-    #else
-        vScreenPos = GetScreenPos(gl_Position);
-        vFarRay = GetFarRay(gl_Position) * gl_Position.w;
-        #ifdef ORTHO
-            vNearRay = GetNearRay(gl_Position) * gl_Position.w;
-        #endif
-    #endif
-}

+ 0 - 16
Bin/CoreData/Shaders/GLSL/DeferredLight.xml

@@ -1,16 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <option name="Ortho" define="ORTHO" />
-        <option name="Dir" define="DIRLIGHT" />
-    </shader>
-    <shader type="ps">
-        <option name="Ortho" define="ORTHO" />
-        <variation name="Dir" define="DIRLIGHT" />
-        <variation name="Spot" define="SPOTLIGHT" />
-        <variation name="Point" define="POINTLIGHT" />
-        <option name="Mask" define="CUBEMASK" require="POINTLIGHT" />
-        <option name="Spec" define="SPECULAR" />
-        <option name="Shadow" define="SHADOW" />
-        <option name="LQ" define="LQSHADOW" />
-    </shader>
-</shaders>

+ 0 - 15
Bin/CoreData/Shaders/GLSL/Depth.frag

@@ -1,15 +0,0 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-
-varying vec3 vTexCoord;
-
-void main()
-{
-    #ifdef ALPHAMASK
-        float alpha = texture2D(sDiffMap, vTexCoord.xy).a;
-        if (alpha < 0.5)
-            discard;
-    #endif
-
-    gl_FragColor = vec4(EncodeDepth(vTexCoord.z), 1.0);
-}

+ 24 - 0
Bin/CoreData/Shaders/GLSL/Depth.glsl

@@ -0,0 +1,24 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+
+varying vec3 vTexCoord;
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = vec3(GetTexCoord(iTexCoord), GetDepth(gl_Position));
+}
+
+void PS()
+{
+    #ifdef ALPHAMASK
+        float alpha = texture2D(sDiffMap, vTexCoord.xy).a;
+        if (alpha < 0.5)
+            discard;
+    #endif
+
+    gl_FragColor = vec4(EncodeDepth(vTexCoord.z), 1.0);
+}

+ 0 - 13
Bin/CoreData/Shaders/GLSL/Depth.vert

@@ -1,13 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-
-varying vec3 vTexCoord;
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    vTexCoord = vec3(GetTexCoord(iTexCoord), GetDepth(gl_Position));
-}
-

+ 0 - 10
Bin/CoreData/Shaders/GLSL/Depth.xml

@@ -1,10 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <variation name="" />
-        <variation name="Skinned" define="SKINNED" />
-        <variation name="Instanced" define="INSTANCED" />
-    </shader>
-    <shader type="ps">
-        <option name="AlphaMask" define="ALPHAMASK" />
-    </shader>
-</shaders>

+ 18 - 4
Bin/CoreData/Shaders/GLSL/EdgeFilter.frag → Bin/CoreData/Shaders/GLSL/EdgeFilter.glsl

@@ -6,13 +6,26 @@
 
 // Adapted for Urho3D from http://timothylottes.blogspot.com/2011/04/nvidia-fxaa-ii-for-console.html
 
-#include "Uniforms.frag"
-#include "Samplers.frag"
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
 
-uniform vec3 cEdgeFilterParams;
 varying vec2 vScreenPos;
 
-void main()
+#ifdef COMPILEPS
+uniform vec3 cEdgeFilterParams;
+#endif
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vScreenPos = GetScreenPosPreDiv(gl_Position);
+}
+
+void PS()
 {
     float FXAA_SUBPIX_SHIFT = 1.0/4.0; // Not used
     float FXAA_SPAN_MAX = 8.0;
@@ -72,3 +85,4 @@ void main()
     else
         gl_FragColor = vec4(rgbM, 1.0);
 }
+

+ 0 - 13
Bin/CoreData/Shaders/GLSL/EdgeFilter.vert

@@ -1,13 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "ScreenPos.vert"
-
-varying vec2 vScreenPos;
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    vScreenPos = GetScreenPosPreDiv(gl_Position);
-}

+ 0 - 3
Bin/CoreData/Shaders/GLSL/EdgeFilter.xml

@@ -1,3 +0,0 @@
-<shaders>
-    <shader />
-</shaders>

+ 0 - 14
Bin/CoreData/Shaders/GLSL/Fog.frag

@@ -1,14 +0,0 @@
-vec3 GetFog(vec3 color, float depth)
-{
-    return mix(cFogColor, color, clamp((cFogParams.x - depth) * cFogParams.y, 0.0, 1.0));
-}
-
-vec3 GetLitFog(vec3 color, float depth)
-{
-    return color * clamp((cFogParams.x - depth) * cFogParams.y, 0.0, 1.0);
-}
-
-float GetFogFactor(float depth)
-{
-    return clamp((cFogParams.x - depth) * cFogParams.y, 0.0, 1.0);
-}

+ 24 - 0
Bin/CoreData/Shaders/GLSL/Fog.glsl

@@ -0,0 +1,24 @@
+#ifdef COMPILEPS
+vec3 GetFog(vec3 color, float fogFactor)
+{
+    return mix(cFogColor, color, fogFactor);
+}
+
+vec3 GetLitFog(vec3 color, float fogFactor)
+{
+    return color * fogFactor;
+}
+
+float GetFogFactor(float depth)
+{
+    return clamp((cFogParams.x - depth) * cFogParams.y, 0.0, 1.0);
+}
+
+float GetHeightFogFactor(float depth, float height)
+{
+    float fogFactor = GetFogFactor(depth);
+    float heightFogFactor = (height - cFogParams.z) * cFogParams.w;
+    heightFogFactor = 1.0 - clamp(exp(-(heightFogFactor * heightFogFactor)), 0.0, 1.0);
+    return min(heightFogFactor, fogFactor);
+}
+#endif

+ 21 - 0
Bin/CoreData/Shaders/GLSL/GammaCorrection.glsl

@@ -0,0 +1,21 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "PostProcess.glsl"
+
+varying vec2 vScreenPos;
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vScreenPos = GetScreenPosPreDiv(gl_Position);
+}
+
+void PS()
+{
+    vec3 color = texture2D(sDiffMap, vScreenPos).rgb;
+    gl_FragColor = vec4(ToInverseGamma(color), 1.0);
+}

+ 0 - 12
Bin/CoreData/Shaders/GLSL/GreyScale.frag

@@ -1,12 +0,0 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-#include "Lighting.frag"
-
-varying vec2 vScreenPos;
-
-void main()
-{
-    vec3 rgb = texture2D(sDiffMap, vScreenPos).rgb;
-    float intensity = GetIntensity(rgb);
-    gl_FragColor = vec4(intensity, intensity, intensity, 1.0);
-}

+ 22 - 0
Bin/CoreData/Shaders/GLSL/GreyScale.glsl

@@ -0,0 +1,22 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "Lighting.glsl"
+
+varying vec2 vScreenPos;
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vScreenPos = GetScreenPosPreDiv(gl_Position);
+}
+
+void PS()
+{
+    vec3 rgb = texture2D(sDiffMap, vScreenPos).rgb;
+    float intensity = GetIntensity(rgb);
+    gl_FragColor = vec4(intensity, intensity, intensity, 1.0);
+}

+ 0 - 13
Bin/CoreData/Shaders/GLSL/GreyScale.vert

@@ -1,13 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "ScreenPos.vert"
-
-varying vec2 vScreenPos;
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    vScreenPos = GetScreenPosPreDiv(gl_Position);
-}

+ 0 - 3
Bin/CoreData/Shaders/GLSL/GreyScale.xml

@@ -1,3 +0,0 @@
-<shaders>
-    <shader />
-</shaders>

+ 90 - 17
Bin/CoreData/Shaders/GLSL/Lighting.frag → Bin/CoreData/Shaders/GLSL/Lighting.glsl

@@ -1,3 +1,86 @@
+#ifdef COMPILEVS
+vec3 GetAmbient(float zonePos)
+{
+    return cAmbientStartColor + zonePos * cAmbientEndColor;
+}
+
+#ifdef NUMVERTEXLIGHTS
+float GetVertexLight(int index, vec3 worldPos, vec3 normal)
+{
+    vec3 lightDir = cVertexLights[index * 3 + 1].xyz;
+    vec3 lightPos = cVertexLights[index * 3 + 2].xyz;
+    float invRange = cVertexLights[index * 3].w;
+    float cutoff = cVertexLights[index * 3 + 1].w;
+    float invCutoff = cVertexLights[index * 3 + 2].w;
+
+    // Directional light
+    if (invRange == 0.0)
+    {
+        float NdotL = max(dot(normal, lightDir), 0.0);
+        return NdotL;
+    }
+    // Point/spot light
+    else
+    {
+        vec3 lightVec = (lightPos - worldPos) * invRange;
+        float lightDist = length(lightVec);
+        vec3 localDir = lightVec / lightDist;
+        float NdotL = max(dot(normal, localDir), 0.0);
+        float atten = clamp(1.0 - lightDist * lightDist, 0.0, 1.0);
+        float spotEffect = dot(localDir, lightDir);
+        float spotAtten = clamp((spotEffect - cutoff) * invCutoff, 0.0, 1.0);
+        return NdotL * atten * spotAtten;
+    }
+}
+
+float GetVertexLightVolumetric(int index, vec3 worldPos)
+{
+    vec3 lightDir = cVertexLights[index * 3 + 1].xyz;
+    vec3 lightPos = cVertexLights[index * 3 + 2].xyz;
+    float invRange = cVertexLights[index * 3].w;
+    float cutoff = cVertexLights[index * 3 + 1].w;
+    float invCutoff = cVertexLights[index * 3 + 2].w;
+
+    // Directional light
+    if (invRange == 0.0)
+        return 1.0;
+    // Point/spot light
+    else
+    {
+        vec3 lightVec = (lightPos - worldPos) * invRange;
+        float lightDist = length(lightVec);
+        vec3 localDir = lightVec / lightDist;
+        float atten = clamp(1.0 - lightDist * lightDist, 0.0, 1.0);
+        float spotEffect = dot(localDir, lightDir);
+        float spotAtten = clamp((spotEffect - cutoff) * invCutoff, 0.0, 1.0);
+        return atten * spotAtten;
+    }
+}
+#endif
+
+#ifdef SHADOW
+
+#if defined(DIRLIGHT) && !defined(GL_ES)
+    #define NUMCASCADES 4
+#else
+    #define NUMCASCADES 1
+#endif
+
+vec4 GetShadowPos(int index, vec4 projWorldPos)
+{
+    #if defined(DIRLIGHT)
+        return cLightMatrices[index] * projWorldPos;
+    #elif defined(SPOTLIGHT)
+        return cLightMatrices[1] * projWorldPos;
+    #else
+        return vec4(projWorldPos.xyz - cLightPos.xyz, 1.0);
+    #endif
+}
+
+#endif
+#endif
+
+#ifdef COMPILEPS
 float GetDiffuse(vec3 normal, vec3 lightVec, out vec3 lightDir)
 {
     #ifdef DIRLIGHT
@@ -39,12 +122,8 @@ float GetIntensity(vec3 color)
 
 #ifdef SHADOW
 
-#ifdef DIRLIGHT
-    #ifndef GL_ES
-        #define NUMCASCADES 4
-    #else
-        #define NUMCASCADES 2
-    #endif
+#if defined(DIRLIGHT) && !defined(GL_ES)
+    #define NUMCASCADES 4
 #else
     #define NUMCASCADES 1
 #endif
@@ -73,9 +152,9 @@ float GetShadow(vec4 shadowPos)
             return cShadowIntensity.y + cShadowIntensity.x * inLight;
         #endif
     #else
-        vec2 offsets = cShadowMapInvSize * shadowPos.w;
         #ifndef LQSHADOW
             // Take four samples and average them
+            vec2 offsets = cShadowMapInvSize * shadowPos.w;
             vec4 inLight = vec4(
                 texture2DProj(sShadowMap, shadowPos).r * shadowPos.w > shadowPos.z,
                 texture2DProj(sShadowMap, vec4(shadowPos.x + offsets.x, shadowPos.yzw)).r * shadowPos.w > shadowPos.z,
@@ -85,7 +164,7 @@ float GetShadow(vec4 shadowPos)
             return cShadowIntensity.y + dot(inLight, vec4(cShadowIntensity.x));
         #else
             // Take one sample
-            return cShadowIntensity.y + (texture2DProj(sShadowMap, shadowPos).r * shadowPos.w > shadowPos.z) ? cShadowIntensity.x : 0.0;
+            return cShadowIntensity.y + (texture2DProj(sShadowMap, shadowPos).r * shadowPos.w > shadowPos.z ? cShadowIntensity.x : 0.0);
         #endif
     #endif
 }
@@ -153,14 +232,7 @@ float GetDirShadowDeferred(vec4 projWorldPos, float depth)
 #else
 float GetDirShadow(const vec4 iShadowPos[NUMCASCADES], float depth)
 {
-    vec4 shadowPos;
-
-    if (depth < cShadowSplits.x)
-        shadowPos = iShadowPos[0];
-    else
-        shadowPos = iShadowPos[1];
-
-    return GetDirShadowFade(GetShadow(shadowPos), depth);
+    return GetDirShadowFade(GetShadow(iShadowPos[0]), depth);
 }
 #endif
 #endif
@@ -190,4 +262,5 @@ float GetShadowDeferred(vec4 projWorldPos, float depth)
     #endif
 }
 #endif
-#endif
+#endif
+#endif

+ 0 - 83
Bin/CoreData/Shaders/GLSL/Lighting.vert

@@ -1,83 +0,0 @@
-vec3 GetAmbient(float zonePos)
-{
-    return cAmbientStartColor + zonePos * cAmbientEndColor;
-}
-
-#ifdef NUMVERTEXLIGHTS
-float GetVertexLight(int index, vec3 worldPos, vec3 normal)
-{
-    vec3 lightDir = cVertexLights[index * 3 + 1].xyz;
-    vec3 lightPos = cVertexLights[index * 3 + 2].xyz;
-    float invRange = cVertexLights[index * 3].w;
-    float cutoff = cVertexLights[index * 3 + 1].w;
-    float invCutoff = cVertexLights[index * 3 + 2].w;
-
-    // Directional light
-    if (invRange == 0.0)
-    {
-        float NdotL = max(dot(normal, lightDir), 0.0);
-        return NdotL;
-    }
-    // Point/spot light
-    else
-    {
-        vec3 lightVec = (lightPos - worldPos) * invRange;
-        float lightDist = length(lightVec);
-        vec3 localDir = lightVec / lightDist;
-        float NdotL = max(dot(normal, localDir), 0.0);
-        float atten = clamp(1.0 - lightDist * lightDist, 0.0, 1.0);
-        float spotEffect = dot(localDir, lightDir);
-        float spotAtten = clamp((spotEffect - cutoff) * invCutoff, 0.0, 1.0);
-        return NdotL * atten * spotAtten;
-    }
-}
-
-float GetVertexLightVolumetric(int index, vec3 worldPos)
-{
-    vec3 lightDir = cVertexLights[index * 3 + 1].xyz;
-    vec3 lightPos = cVertexLights[index * 3 + 2].xyz;
-    float invRange = cVertexLights[index * 3].w;
-    float cutoff = cVertexLights[index * 3 + 1].w;
-    float invCutoff = cVertexLights[index * 3 + 2].w;
-
-    // Directional light
-    if (invRange == 0.0)
-        return 1.0;
-    // Point/spot light
-    else
-    {
-        vec3 lightVec = (lightPos - worldPos) * invRange;
-        float lightDist = length(lightVec);
-        vec3 localDir = lightVec / lightDist;
-        float atten = clamp(1.0 - lightDist * lightDist, 0.0, 1.0);
-        float spotEffect = dot(localDir, lightDir);
-        float spotAtten = clamp((spotEffect - cutoff) * invCutoff, 0.0, 1.0);
-        return atten * spotAtten;
-    }
-}
-#endif
-
-#ifdef SHADOW
-
-#ifdef DIRLIGHT
-    #ifndef GL_ES
-        #define NUMCASCADES 4
-    #else
-        #define NUMCASCADES 2
-    #endif
-#else
-    #define NUMCASCADES 1
-#endif
-
-vec4 GetShadowPos(int index, vec4 projWorldPos)
-{
-    #if defined(DIRLIGHT)
-        return cLightMatrices[index] * projWorldPos;
-    #elif defined(SPOTLIGHT)
-        return cLightMatrices[1] * projWorldPos;
-    #else
-        return vec4(projWorldPos.xyz - cLightPos.xyz, 1.0);
-    #endif
-}
-
-#endif

+ 0 - 69
Bin/CoreData/Shaders/GLSL/LitParticle.frag

@@ -1,69 +0,0 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-#include "Lighting.frag"
-#include "Fog.frag"
-
-varying vec2 vTexCoord;
-#ifdef VERTEXCOLOR
-    varying vec4 vColor;
-#endif
-#ifdef PERPIXEL
-    varying vec4 vLightVec;
-    #ifdef SPOTLIGHT
-        varying vec4 vSpotPos;
-    #endif
-    #ifdef POINTLIGHT
-        varying vec3 vCubeMaskVec;
-    #endif
-#else
-    varying vec4 vVertexLight;
-#endif
-
-void main()
-{
-    // Get material diffuse albedo
-    #ifdef DIFFMAP
-        vec4 diffInput = texture2D(sDiffMap, vTexCoord);
-        #ifdef ALPHAMASK
-            if (diffInput.a < 0.5)
-                discard;
-        #endif
-        vec4 diffColor = cMatDiffColor * diffInput;
-    #else
-        vec4 diffColor = cMatDiffColor;
-    #endif
-
-    #ifdef VERTEXCOLOR
-        diffColor *= vColor;
-    #endif
-
-    #ifdef PERPIXEL
-        // Per-pixel forward lighting
-        vec3 lightColor;
-        vec3 finalColor;
-        float diff;
-    
-        diff = GetDiffuseVolumetric(vLightVec.xyz);
-
-        #if defined(SPOTLIGHT)
-            lightColor = vSpotPos.w > 0.0 ? texture2DProj(sLightSpotMap, vSpotPos).rgb * cLightColor.rgb : vec3(0.0, 0.0, 0.0);
-        #elif defined(CUBEMASK)
-            lightColor = textureCube(sLightCubeMap, vCubeMaskVec).rgb * cLightColor.rgb;
-        #else
-            lightColor = cLightColor.rgb;
-        #endif
-    
-        finalColor = diff * lightColor * diffColor.rgb;
-        
-        #ifdef AMBIENT
-            finalColor += cAmbientColor * diffColor.rgb;
-            gl_FragColor = vec4(GetFog(finalColor, vLightVec.w), diffColor.a);
-        #else
-            gl_FragColor = vec4(GetLitFog(finalColor, vLightVec.w), diffColor.a);
-        #endif
-    #else
-        // Ambient & per-vertex lighting
-        vec3 finalColor = vVertexLight.rgb * diffColor.rgb;
-        gl_FragColor = vec4(GetFog(finalColor, vVertexLight.a), diffColor.a);
-    #endif
-}

+ 130 - 0
Bin/CoreData/Shaders/GLSL/LitParticle.glsl

@@ -0,0 +1,130 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "Lighting.glsl"
+#include "Fog.glsl"
+
+varying vec2 vTexCoord;
+#ifdef HEIGHTFOG
+    varying vec3 vWorldPos;
+#endif
+#ifdef VERTEXCOLOR
+    varying vec4 vColor;
+#endif
+#ifdef PERPIXEL
+    varying vec4 vLightVec;
+    #ifdef SPOTLIGHT
+        varying vec4 vSpotPos;
+    #endif
+    #ifdef POINTLIGHT
+        varying vec3 vCubeMaskVec;
+    #endif
+#else
+    varying vec4 vVertexLight;
+#endif
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = GetTexCoord(iTexCoord);
+    
+    #ifdef HEIGHTFOG
+        vWorldPos = worldPos;
+    #endif
+
+    #ifdef VERTEXCOLOR
+        vColor = iColor;
+    #endif
+
+    #ifdef PERPIXEL
+        // Per-pixel forward lighting
+        vec4 projWorldPos = vec4(worldPos, 1.0);
+    
+        #ifdef DIRLIGHT
+            vLightVec = vec4(cLightDir, GetDepth(gl_Position));
+        #else
+            vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
+        #endif
+    
+        #ifdef SPOTLIGHT
+            // Spotlight projection: transform from world space to projector texture coordinates
+            vSpotPos = cLightMatrices[0] * projWorldPos;
+        #endif
+    
+        #ifdef POINTLIGHT
+            vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * vLightVec.xyz;
+        #endif
+    #else
+        // Ambient & per-vertex lighting
+        vVertexLight = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
+
+        #ifdef NUMVERTEXLIGHTS
+            for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
+                vVertexLight.rgb += GetVertexLightVolumetric(i, worldPos) * cVertexLights[i * 3].rgb;
+        #endif
+    #endif
+}
+
+void PS()
+{
+    // Get material diffuse albedo
+    #ifdef DIFFMAP
+        vec4 diffInput = texture2D(sDiffMap, vTexCoord);
+        #ifdef ALPHAMASK
+            if (diffInput.a < 0.5)
+                discard;
+        #endif
+        vec4 diffColor = cMatDiffColor * diffInput;
+    #else
+        vec4 diffColor = cMatDiffColor;
+    #endif
+
+    #ifdef VERTEXCOLOR
+        diffColor *= vColor;
+    #endif
+
+    #ifdef PERPIXEL
+        // Per-pixel forward lighting
+        vec3 lightColor;
+        vec3 finalColor;
+        float diff;
+    
+        diff = GetDiffuseVolumetric(vLightVec.xyz);
+
+        #if defined(SPOTLIGHT)
+            lightColor = vSpotPos.w > 0.0 ? texture2DProj(sLightSpotMap, vSpotPos).rgb * cLightColor.rgb : vec3(0.0, 0.0, 0.0);
+        #elif defined(CUBEMASK)
+            lightColor = textureCube(sLightCubeMap, vCubeMaskVec).rgb * cLightColor.rgb;
+        #else
+            lightColor = cLightColor.rgb;
+        #endif
+    
+        finalColor = diff * lightColor * diffColor.rgb;
+
+        #ifdef HEIGHTFOG
+            float fogFactor = GetHeightFogFactor(vLightVec.w, vWorldPos.y);
+        #else
+            float fogFactor = GetFogFactor(vLightVec.w);
+        #endif
+        
+        #ifdef AMBIENT
+            finalColor += cAmbientColor * diffColor.rgb;
+            gl_FragColor = vec4(GetFog(finalColor, fogFactor), diffColor.a);
+        #else
+            gl_FragColor = vec4(GetLitFog(finalColor, fogFactor), diffColor.a);
+        #endif
+    #else
+        // Ambient & per-vertex lighting
+        vec3 finalColor = vVertexLight.rgb * diffColor.rgb;
+        
+        #ifdef HEIGHTFOG
+            float fogFactor = GetHeightFogFactor(vVertexLight.a, vWorldPos.y);
+        #else
+            float fogFactor = GetFogFactor(vVertexLight.a);
+        #endif
+
+        gl_FragColor = vec4(GetFog(finalColor, fogFactor), diffColor.a);
+    #endif
+}

+ 0 - 59
Bin/CoreData/Shaders/GLSL/LitParticle.vert

@@ -1,59 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "Lighting.vert"
-
-varying vec2 vTexCoord;
-#ifdef VERTEXCOLOR
-    varying vec4 vColor;
-#endif
-#ifdef PERPIXEL
-    varying vec4 vLightVec;
-    #ifdef SPOTLIGHT
-        varying vec4 vSpotPos;
-    #endif
-    #ifdef POINTLIGHT
-        varying vec3 vCubeMaskVec;
-    #endif
-#else
-    varying vec4 vVertexLight;
-#endif
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    vTexCoord = GetTexCoord(iTexCoord);
-
-    #ifdef VERTEXCOLOR
-        vColor = iColor;
-    #endif
-
-    #ifdef PERPIXEL
-        // Per-pixel forward lighting
-        vec4 projWorldPos = vec4(worldPos, 1.0);
-    
-        #ifdef DIRLIGHT
-            vLightVec = vec4(cLightDir, GetDepth(gl_Position));
-        #else
-            vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
-        #endif
-    
-        #ifdef SPOTLIGHT
-            // Spotlight projection: transform from world space to projector texture coordinates
-            vSpotPos = cLightMatrices[0] * projWorldPos;
-        #endif
-    
-        #ifdef POINTLIGHT
-            vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * vLightVec.xyz;
-        #endif
-    #else
-        // Ambient & per-vertex lighting
-        vVertexLight = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
-
-        #ifdef NUMVERTEXLIGHTS
-            for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
-                vVertexLight.rgb += GetVertexLightVolumetric(i, worldPos) * cVertexLights[i * 3].rgb;
-        #endif
-    #endif
-}

+ 0 - 46
Bin/CoreData/Shaders/GLSL/LitParticle.xml

@@ -1,46 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <option name="VCol" define="VERTEXCOLOR" />
-        <variation name="" define="AMBIENT" />
-        <variation name="1VL" define="NUMVERTEXLIGHTS=1" />
-        <variation name="2VL" define="NUMVERTEXLIGHTS=2" />
-        <variation name="3VL" define="NUMVERTEXLIGHTS=3" />
-        <variation name="4VL" define="NUMVERTEXLIGHTS=4" />
-        <variation name="Dir">
-            <define name="DIRLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Spot">
-            <define name="SPOTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Point">
-            <define name="POINTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <option name="" /> <!-- Dummy option to separate the two variation groups -->
-        <variation name="" />
-        <variation name="Skinned" define="SKINNED" />
-        <variation name="Instanced" define="INSTANCED" />
-        <variation name="Billboard" define="BILLBOARD" />
-    </shader>
-    <shader type="ps">
-        <option name="Diff" define="DIFFMAP" />
-        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />
-        <option name="VCol" define="VERTEXCOLOR" />
-        <variation name="" define="AMBIENT" />
-        <variation name="Dir">
-            <define name="DIRLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Spot">
-            <define name="SPOTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Point">
-            <define name="POINTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <option name="Mask" define="CUBEMASK" require="POINTLIGHT" />
-    </shader>
-</shaders>

+ 0 - 171
Bin/CoreData/Shaders/GLSL/LitSolid.frag

@@ -1,171 +0,0 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-#include "Lighting.frag"
-#include "Fog.frag"
-
-varying vec2 vTexCoord;
-#ifdef PERPIXEL
-    varying vec4 vLightVec;
-    #ifdef SPECULAR
-        varying vec3 vEyeVec;
-    #endif
-    #ifndef NORMALMAP
-        varying vec3 vNormal;
-    #endif
-    #ifdef SHADOW
-        varying vec4 vShadowPos[NUMCASCADES];
-    #endif
-    #ifdef SPOTLIGHT
-        varying vec4 vSpotPos;
-    #endif
-    #ifdef POINTLIGHT
-        varying vec3 vCubeMaskVec;
-    #endif
-#else
-    varying vec4 vVertexLight;
-    varying vec3 vNormal;
-    #ifdef NORMALMAP
-        varying vec3 vTangent;
-        varying vec3 vBitangent;
-    #endif
-    varying vec4 vScreenPos;
-    #ifdef ENVCUBEMAP
-        varying vec3 vReflectionVec;
-    #endif
-    #ifdef LIGHTMAP
-        varying vec2 vTexCoord2;
-    #endif
-#endif
-
-void main()
-{
-    // Get material diffuse albedo
-    #ifdef DIFFMAP
-        vec4 diffInput = texture2D(sDiffMap, vTexCoord);
-        #ifdef ALPHAMASK
-            if (diffInput.a < 0.5)
-                discard;
-        #endif
-        vec4 diffColor = cMatDiffColor * diffInput;
-    #else
-        vec4 diffColor = cMatDiffColor;
-    #endif
-    
-    // Get material specular albedo
-    #ifdef SPECMAP
-        vec3 specColor = cMatSpecColor.rgb * texture2D(sSpecMap, vTexCoord).rgb;
-    #else
-        vec3 specColor = cMatSpecColor.rgb;
-    #endif
-
-    #if defined(PERPIXEL)
-        // Per-pixel forward lighting
-        vec3 lightColor;
-        vec3 lightDir;
-        vec3 finalColor;
-        float diff;
-
-        #ifdef NORMALMAP
-            vec3 normal = DecodeNormal(texture2D(sNormalMap, vTexCoord));
-        #else
-            vec3 normal = normalize(vNormal);
-        #endif
-    
-        diff = GetDiffuse(normal, vLightVec.xyz, lightDir);
-    
-        #ifdef SHADOW
-            diff *= GetShadow(vShadowPos, vLightVec.w);
-        #endif
-    
-        #if defined(SPOTLIGHT)
-            lightColor = vSpotPos.w > 0.0 ? texture2DProj(sLightSpotMap, vSpotPos).rgb * cLightColor.rgb : vec3(0.0, 0.0, 0.0);
-        #elif defined(CUBEMASK)
-            lightColor = textureCube(sLightCubeMap, vCubeMaskVec).rgb * cLightColor.rgb;
-        #else
-            lightColor = cLightColor.rgb;
-        #endif
-    
-        #ifdef SPECULAR
-            float spec = GetSpecular(normal, vEyeVec, lightDir, cMatSpecColor.a);
-            finalColor = diff * lightColor * (diffColor.rgb + spec * specColor * cLightColor.a);
-        #else
-            finalColor = diff * lightColor * diffColor.rgb;
-        #endif
-
-        #ifdef AMBIENT
-            finalColor += cAmbientColor * diffColor.rgb;
-            gl_FragColor = vec4(GetFog(finalColor, vLightVec.w), diffColor.a);
-        #else
-            gl_FragColor = vec4(GetLitFog(finalColor, vLightVec.w), diffColor.a);
-        #endif
-    #elif defined(PREPASS)
-        // Fill light pre-pass G-Buffer
-        #ifdef NORMALMAP
-            mat3 tbn = mat3(vTangent, vBitangent, vNormal);
-            vec3 normal = tbn * DecodeNormal(texture2D(sNormalMap, vTexCoord.xy));
-        #else
-            vec3 normal = vNormal;
-        #endif
-
-        float specPower = cMatSpecColor.a / 255.0;
-
-        gl_FragData[0] = vec4(normal * 0.5 + 0.5, specPower);
-        gl_FragData[1] = vec4(EncodeDepth(vVertexLight.a), 0.0);
-    #elif defined(DEFERRED)
-        // Fill deferred G-buffer
-        #ifdef NORMALMAP
-            mat3 tbn = mat3(vTangent, vBitangent, vNormal);
-            vec3 normal = tbn * DecodeNormal(texture2D(sNormalMap, vTexCoord));
-        #else
-            vec3 normal = vNormal;
-        #endif
-
-        float specIntensity = specColor.g;
-        float specPower = cMatSpecColor.a / 255.0;
-
-        vec3 finalColor = vVertexLight.rgb * diffColor.rgb;
-
-        #ifdef ENVCUBEMAP
-            normal = normalize(normal);
-            finalColor = cMatEnvMapColor * textureCube(sEnvCubeMap, reflect(vReflectionVec, normal)).rgb;
-        #endif
-        #ifdef LIGHTMAP
-            finalColor += texture2D(sEmissiveMap, vTexCoord2).rgb * diffColor.rgb;
-        #endif
-
-        gl_FragData[0] = vec4(GetFog(finalColor, vVertexLight.a), 1.0);
-        gl_FragData[1] = GetFogFactor(vVertexLight.a) * vec4(diffColor.rgb, specIntensity);
-        gl_FragData[2] = vec4(normal * 0.5 + 0.5, specPower);
-        gl_FragData[3] = vec4(EncodeDepth(vVertexLight.a), 0.0);
-
-
-    #else
-        // Ambient & per-vertex lighting
-        vec3 finalColor = vVertexLight.rgb * diffColor.rgb;
-
-        #ifdef MATERIAL
-            // Add light pre-pass accumulation result
-            // Lights are accumulated at half intensity. Bring back to full intensity now
-            vec4 lightInput = 2.0 * texture2DProj(sLightBuffer, vScreenPos);
-            vec3 lightSpecColor = lightInput.a * lightInput.rgb / max(GetIntensity(lightInput.rgb), 0.001);
-
-            finalColor += lightInput.rgb * diffColor.rgb + lightSpecColor * specColor;
-        #endif
-
-        #ifdef ENVCUBEMAP
-            #ifdef NORMALMAP
-                mat3 tbn = mat3(vTangent, vBitangent, vNormal);
-                vec3 normal = tbn * DecodeNormal(texture2D(sNormalMap, vTexCoord));
-            #else
-                vec3 normal = vNormal;
-            #endif
-            normal = normalize(normal);
-            finalColor += cMatEnvMapColor * textureCube(sEnvCubeMap, reflect(vReflectionVec, normal)).rgb;
-        #endif
-        #ifdef LIGHTMAP
-            finalColor += texture2D(sEmissiveMap, vTexCoord2).rgb * diffColor.rgb;
-        #endif
-
-        gl_FragColor = vec4(GetFog(finalColor, vVertexLight.a), diffColor.a);
-    #endif
-}

+ 297 - 0
Bin/CoreData/Shaders/GLSL/LitSolid.glsl

@@ -0,0 +1,297 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "Lighting.glsl"
+#include "Fog.glsl"
+
+varying vec2 vTexCoord;
+#ifdef HEIGHTFOG
+    varying vec3 vWorldPos;
+#endif
+#ifdef PERPIXEL
+    varying vec4 vLightVec;
+    #ifdef SPECULAR
+        varying vec3 vEyeVec;
+    #endif
+    #ifndef NORMALMAP
+        varying vec3 vNormal;
+    #endif
+    #ifdef SHADOW
+        varying vec4 vShadowPos[NUMCASCADES];
+    #endif
+    #ifdef SPOTLIGHT
+        varying vec4 vSpotPos;
+    #endif
+    #ifdef POINTLIGHT
+        varying vec3 vCubeMaskVec;
+    #endif
+#else
+    varying vec4 vVertexLight;
+    varying vec3 vNormal;
+    #ifdef NORMALMAP
+        varying vec3 vTangent;
+        varying vec3 vBitangent;
+    #endif
+    varying vec4 vScreenPos;
+    #ifdef ENVCUBEMAP
+        varying vec3 vReflectionVec;
+    #endif
+    #if defined(LIGHTMAP) || defined(AO)
+        varying vec2 vTexCoord2;
+    #endif
+#endif
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = GetTexCoord(iTexCoord);
+    
+    #ifdef HEIGHTFOG
+        vWorldPos = worldPos;
+    #endif
+
+    #if defined(PERPIXEL) && defined(NORMALMAP)
+        vec3 vNormal;
+        vec3 vTangent;
+        vec3 vBitangent;
+    #endif
+
+    vNormal = GetWorldNormal(modelMatrix);
+    #ifdef NORMALMAP
+        vTangent = GetWorldTangent(modelMatrix);
+        vBitangent = cross(vTangent, vNormal) * iTangent.w;
+    #endif
+    
+    #ifdef PERPIXEL
+        // Per-pixel forward lighting
+        vec4 projWorldPos = vec4(worldPos, 1.0);
+
+        #ifdef SHADOW
+            // Shadow projection: transform from world space to shadow space
+            for (int i = 0; i < NUMCASCADES; i++)
+                vShadowPos[i] = GetShadowPos(i, projWorldPos);
+        #endif
+
+        #ifdef SPOTLIGHT
+            // Spotlight projection: transform from world space to projector texture coordinates
+            vSpotPos = cLightMatrices[0] * projWorldPos;
+        #endif
+    
+        #ifdef POINTLIGHT
+            vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * (cLightPos.xyz - worldPos);
+        #endif
+    
+        #ifdef NORMALMAP
+            mat3 tbn = mat3(vTangent, vBitangent, vNormal);
+            #ifdef DIRLIGHT
+                vLightVec = vec4(cLightDir * tbn, GetDepth(gl_Position));
+            #else
+                vLightVec = vec4((cLightPos.xyz - worldPos) * tbn * cLightPos.w, GetDepth(gl_Position));
+            #endif
+            #ifdef SPECULAR
+                vEyeVec = (cCameraPos - worldPos) * tbn;
+            #endif
+        #else
+            #ifdef DIRLIGHT
+                vLightVec = vec4(cLightDir, GetDepth(gl_Position));
+            #else
+                vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
+            #endif
+            #ifdef SPECULAR
+                vEyeVec = cCameraPos - worldPos;
+            #endif
+        #endif
+    #else
+        // Ambient & per-vertex lighting
+        #if defined(LIGHTMAP) || defined(AO)
+            // If using lightmap, disregard zone ambient light
+            // If using AO, calculate ambient in the PS
+            vVertexLight = vec4(0.0, 0.0, 0.0, GetDepth(gl_Position));
+            vTexCoord2 = iTexCoord2;
+        #else
+            vVertexLight = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
+        #endif
+        
+        #ifdef NUMVERTEXLIGHTS
+            for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
+                vVertexLight.rgb += GetVertexLight(i, worldPos, vNormal) * cVertexLights[i * 3].rgb;
+        #endif
+        
+        vScreenPos = GetScreenPos(gl_Position);
+
+        #ifdef ENVCUBEMAP
+            vReflectionVec = worldPos - cCameraPos;
+        #endif
+    #endif
+}
+
+void PS()
+{
+    // Get material diffuse albedo
+    #ifdef DIFFMAP
+        vec4 diffInput = texture2D(sDiffMap, vTexCoord);
+        #ifdef ALPHAMASK
+            if (diffInput.a < 0.5)
+                discard;
+        #endif
+        vec4 diffColor = cMatDiffColor * diffInput;
+    #else
+        vec4 diffColor = cMatDiffColor;
+    #endif
+    
+    // Get material specular albedo
+    #ifdef SPECMAP
+        vec3 specColor = cMatSpecColor.rgb * texture2D(sSpecMap, vTexCoord).rgb;
+    #else
+        vec3 specColor = cMatSpecColor.rgb;
+    #endif
+
+    #if defined(PERPIXEL)
+        // Per-pixel forward lighting
+        vec3 lightColor;
+        vec3 lightDir;
+        vec3 finalColor;
+        float diff;
+
+        #ifdef NORMALMAP
+            vec3 normal = DecodeNormal(texture2D(sNormalMap, vTexCoord));
+        #else
+            vec3 normal = normalize(vNormal);
+        #endif
+    
+        diff = GetDiffuse(normal, vLightVec.xyz, lightDir);
+    
+        #ifdef SHADOW
+            diff *= GetShadow(vShadowPos, vLightVec.w);
+        #endif
+    
+        #if defined(SPOTLIGHT)
+            lightColor = vSpotPos.w > 0.0 ? texture2DProj(sLightSpotMap, vSpotPos).rgb * cLightColor.rgb : vec3(0.0, 0.0, 0.0);
+        #elif defined(CUBEMASK)
+            lightColor = textureCube(sLightCubeMap, vCubeMaskVec).rgb * cLightColor.rgb;
+        #else
+            lightColor = cLightColor.rgb;
+        #endif
+    
+        #ifdef SPECULAR
+            float spec = GetSpecular(normal, vEyeVec, lightDir, cMatSpecColor.a);
+            finalColor = diff * lightColor * (diffColor.rgb + spec * specColor * cLightColor.a);
+        #else
+            finalColor = diff * lightColor * diffColor.rgb;
+        #endif
+
+        #ifdef HEIGHTFOG
+            float fogFactor = GetHeightFogFactor(vLightVec.w, vWorldPos.y);
+        #else
+            float fogFactor = GetFogFactor(vLightVec.w);
+        #endif
+
+        #ifdef AMBIENT
+            finalColor += cAmbientColor * diffColor.rgb;
+            finalColor += cMatEmissiveColor;
+            gl_FragColor = vec4(GetFog(finalColor, fogFactor), diffColor.a);
+        #else
+            gl_FragColor = vec4(GetLitFog(finalColor, fogFactor), diffColor.a);
+        #endif
+    #elif defined(PREPASS)
+        // Fill light pre-pass G-Buffer
+        #ifdef NORMALMAP
+            mat3 tbn = mat3(vTangent, vBitangent, vNormal);
+            vec3 normal = tbn * DecodeNormal(texture2D(sNormalMap, vTexCoord.xy));
+        #else
+            vec3 normal = vNormal;
+        #endif
+
+        float specPower = cMatSpecColor.a / 255.0;
+
+        gl_FragData[0] = vec4(normal * 0.5 + 0.5, specPower);
+        gl_FragData[1] = vec4(EncodeDepth(vVertexLight.a), 0.0);
+    #elif defined(DEFERRED)
+        // Fill deferred G-buffer
+        #ifdef NORMALMAP
+            mat3 tbn = mat3(vTangent, vBitangent, vNormal);
+            vec3 normal = tbn * DecodeNormal(texture2D(sNormalMap, vTexCoord));
+        #else
+            vec3 normal = vNormal;
+        #endif
+
+        float specIntensity = specColor.g;
+        float specPower = cMatSpecColor.a / 255.0;
+
+        vec3 finalColor = vVertexLight.rgb * diffColor.rgb;
+        #ifdef AO
+            // If using AO, the vertex light ambient is black, calculate occluded ambient here
+            finalColor += texture2D(sEmissiveMap, vTexCoord2).rgb * cAmbientColor * diffColor.rgb;
+        #endif
+
+        #ifdef ENVCUBEMAP
+            normal = normalize(normal);
+            finalColor = cMatEnvMapColor * textureCube(sEnvCubeMap, reflect(vReflectionVec, normal)).rgb;
+        #endif
+        #ifdef LIGHTMAP
+            finalColor += texture2D(sEmissiveMap, vTexCoord2).rgb * diffColor.rgb;
+        #endif
+        #ifdef EMISSIVEMAP
+            finalColor += cMatEmissiveColor * texture2D(sEmissiveMap, vTexCoord).rgb;
+        #else
+            finalColor += cMatEmissiveColor;
+        #endif
+
+        #ifdef HEIGHTFOG
+            float fogFactor = GetHeightFogFactor(vVertexLight.a, vWorldPos.y);
+        #else
+            float fogFactor = GetFogFactor(vVertexLight.a);
+        #endif
+
+        gl_FragData[0] = vec4(GetFog(finalColor, fogFactor), 1.0);
+        gl_FragData[1] = fogFactor * vec4(diffColor.rgb, specIntensity);
+        gl_FragData[2] = vec4(normal * 0.5 + 0.5, specPower);
+        gl_FragData[3] = vec4(EncodeDepth(vVertexLight.a), 0.0);
+    #else
+        // Ambient & per-vertex lighting
+        vec3 finalColor = vVertexLight.rgb * diffColor.rgb;
+        #ifdef AO
+            // If using AO, the vertex light ambient is black, calculate occluded ambient here
+            finalColor += texture2D(sEmissiveMap, vTexCoord2).rgb * cAmbientColor * diffColor.rgb;
+        #endif
+        
+        #ifdef MATERIAL
+            // Add light pre-pass accumulation result
+            // Lights are accumulated at half intensity. Bring back to full intensity now
+            vec4 lightInput = 2.0 * texture2DProj(sLightBuffer, vScreenPos);
+            vec3 lightSpecColor = lightInput.a * lightInput.rgb / max(GetIntensity(lightInput.rgb), 0.001);
+
+            finalColor += lightInput.rgb * diffColor.rgb + lightSpecColor * specColor;
+        #endif
+
+        #ifdef ENVCUBEMAP
+            #ifdef NORMALMAP
+                mat3 tbn = mat3(vTangent, vBitangent, vNormal);
+                vec3 normal = tbn * DecodeNormal(texture2D(sNormalMap, vTexCoord));
+            #else
+                vec3 normal = vNormal;
+            #endif
+            normal = normalize(normal);
+            finalColor += cMatEnvMapColor * textureCube(sEnvCubeMap, reflect(vReflectionVec, normal)).rgb;
+        #endif
+        #ifdef LIGHTMAP
+            finalColor += texture2D(sEmissiveMap, vTexCoord2).rgb * diffColor.rgb;
+        #endif
+        #ifdef EMISSIVEMAP
+            finalColor += cMatEmissiveColor * texture2D(sEmissiveMap, vTexCoord).rgb;
+        #else
+            finalColor += cMatEmissiveColor;
+        #endif
+
+        #ifdef HEIGHTFOG
+            float fogFactor = GetHeightFogFactor(vVertexLight.a, vWorldPos.y);
+        #else
+            float fogFactor = GetFogFactor(vVertexLight.a);
+        #endif
+
+        gl_FragColor = vec4(GetFog(finalColor, fogFactor), diffColor.a);
+    #endif
+}

+ 0 - 119
Bin/CoreData/Shaders/GLSL/LitSolid.vert

@@ -1,119 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "ScreenPos.vert"
-#include "Lighting.vert"
-
-varying vec2 vTexCoord;
-#ifdef PERPIXEL
-    varying vec4 vLightVec;
-    #ifdef SPECULAR
-        varying vec3 vEyeVec;
-    #endif
-    #ifndef NORMALMAP
-        varying vec3 vNormal;
-    #endif
-    #ifdef SHADOW
-        varying vec4 vShadowPos[NUMCASCADES];
-    #endif
-    #ifdef SPOTLIGHT
-        varying vec4 vSpotPos;
-    #endif
-    #ifdef POINTLIGHT
-        varying vec3 vCubeMaskVec;
-    #endif
-#else
-    varying vec4 vVertexLight;
-    varying vec3 vNormal;
-    #ifdef NORMALMAP
-        varying vec3 vTangent;
-        varying vec3 vBitangent;
-    #endif
-    varying vec4 vScreenPos;
-    #ifdef ENVCUBEMAP
-        varying vec3 vReflectionVec;
-    #endif
-    #ifdef LIGHTMAP
-        varying vec2 vTexCoord2;
-    #endif
-#endif
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    vTexCoord = GetTexCoord(iTexCoord);
-
-    #if defined(PERPIXEL) && defined(NORMALMAP)
-        vec3 vNormal;
-        vec3 vTangent;
-        vec3 vBitangent;
-    #endif
-
-    vNormal = GetWorldNormal(modelMatrix);
-    #ifdef NORMALMAP
-        vTangent = GetWorldTangent(modelMatrix);
-        vBitangent = cross(vTangent, vNormal) * iTangent.w;
-    #endif
-    
-    #ifdef PERPIXEL
-        // Per-pixel forward lighting
-        vec4 projWorldPos = vec4(worldPos, 1.0);
-
-        #ifdef SHADOW
-            // Shadow projection: transform from world space to shadow space
-            for (int i = 0; i < NUMCASCADES; i++)
-                vShadowPos[i] = GetShadowPos(i, projWorldPos);
-        #endif
-
-        #ifdef SPOTLIGHT
-            // Spotlight projection: transform from world space to projector texture coordinates
-            vSpotPos = cLightMatrices[0] * projWorldPos;
-        #endif
-    
-        #ifdef POINTLIGHT
-            vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * (cLightPos.xyz - worldPos);
-        #endif
-    
-        #ifdef NORMALMAP
-            mat3 tbn = mat3(vTangent, vBitangent, vNormal);
-            #ifdef DIRLIGHT
-                vLightVec = vec4(cLightDir * tbn, GetDepth(gl_Position));
-            #else
-                vLightVec = vec4((cLightPos.xyz - worldPos) * tbn * cLightPos.w, GetDepth(gl_Position));
-            #endif
-            #ifdef SPECULAR
-                vEyeVec = (cCameraPos - worldPos) * tbn;
-            #endif
-        #else
-            #ifdef DIRLIGHT
-                vLightVec = vec4(cLightDir, GetDepth(gl_Position));
-            #else
-                vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
-            #endif
-            #ifdef SPECULAR
-                vEyeVec = cCameraPos - worldPos;
-            #endif
-        #endif
-    #else
-        // Ambient & per-vertex lighting
-        #ifndef LIGHTMAP
-            vVertexLight = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
-        #else
-            // If using lightmap, disregard zone ambient light
-            vVertexLight = vec4(0.0, 0.0, 0.0, GetDepth(gl_Position));
-            vTexCoord2 = iTexCoord2;
-        #endif
-        
-        #ifdef NUMVERTEXLIGHTS
-            for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
-                vVertexLight.rgb += GetVertexLight(i, worldPos, vNormal) * cVertexLights[i * 3].rgb;
-        #endif
-        
-        vScreenPos = GetScreenPos(gl_Position);
-
-        #ifdef ENVCUBEMAP
-            vReflectionVec = worldPos - cCameraPos;
-        #endif
-    #endif
-}

+ 0 - 66
Bin/CoreData/Shaders/GLSL/LitSolid.xml

@@ -1,66 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <option name="Normal" define="NORMALMAP" />
-        <option name="EnvCube" define="ENVCUBEMAP" />
-        <option name="LightMap" define="LIGHTMAP" />
-        <variation name="" define="AMBIENT" />
-        <variation name="1VL" define="NUMVERTEXLIGHTS=1" />
-        <variation name="2VL" define="NUMVERTEXLIGHTS=2" />
-        <variation name="3VL" define="NUMVERTEXLIGHTS=3" />
-        <variation name="4VL" define="NUMVERTEXLIGHTS=4" />
-        <variation name="Dir" exclude="EnvCube">
-            <define name="DIRLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Spot" exclude="EnvCube">
-            <define name="SPOTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Point" exclude="EnvCube">
-            <define name="POINTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <option name="Spec" define="SPECULAR" require="PERPIXEL" />
-        <option name="Shadow" define="SHADOW" require="PERPIXEL" />
-        <variation name="" />
-        <variation name="Skinned" define="SKINNED" />
-        <variation name="Instanced" define="INSTANCED" />
-        <variation name="Billboard" define="BILLBOARD" />
-    </shader>
-    <shader type="ps">
-        <option name="Diff" define="DIFFMAP" />
-        <option name="Normal" define="NORMALMAP" require="DIFFMAP" />
-        <option name="Packed" define="PACKEDNORMAL" require="NORMALMAP" />
-        <option name="SpecMap" define="SPECMAP" require="DIFFMAP" />
-        <option name="EnvCube" define="ENVCUBEMAP" />
-        <option name="LightMap" define="LIGHTMAP" />
-        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />
-        <option name="Ambient" define="AMBIENT" require="PERPIXEL" />
-        <variation name="" define="AMBIENT" />
-        <variation name="Dir">
-            <exclude name="EnvCube" />
-            <exclude name="LightMap" />
-            <define name="DIRLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Spot">
-            <exclude name="EnvCube" />
-            <exclude name="LightMap" />
-            <define name="SPOTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Point">
-            <exclude name="EnvCube" />
-            <exclude name="LightMap" />
-            <define name="POINTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Prepass" define="PREPASS" exclude="EnvCube" />
-        <variation name="Material" define="MATERIAL" />
-        <variation name="Deferred" define="DEFERRED" />
-        <option name="Mask" define="CUBEMASK" require="POINTLIGHT" />
-        <option name="Spec" define="SPECULAR" require="PERPIXEL" />
-        <option name="Shadow" define="SHADOW" require="PERPIXEL" />
-        <option name="LQ" define="LQSHADOW" require="SHADOW" />
-    </shader>
-</shaders>

+ 87 - 0
Bin/CoreData/Shaders/GLSL/PostProcess.glsl

@@ -0,0 +1,87 @@
+#ifdef COMPILEPS
+const float PI = 3.14159265;
+
+vec2 Noise(vec2 coord)
+{
+    float noiseX = clamp(fract(sin(dot(coord, vec2(12.9898, 78.233))) * 43758.5453), 0.0, 1.0);
+    float noiseY = clamp(fract(sin(dot(coord, vec2(12.9898, 78.233) * 2.0)) * 43758.5453), 0.0, 1.0);
+    return vec2(noiseX, noiseY);
+}
+
+// Adapted: http://callumhay.blogspot.com/2010/09/gaussian-blur-shader-glsl.html
+vec4 GaussianBlur(int blurKernelSize, vec2 blurDir, vec2 blurRadius, float sigma, sampler2D texSampler, vec2 texCoord)
+{
+    int blurKernelSizeHalfSize = blurKernelSize / 2;
+
+    // Incremental Gaussian Coefficent Calculation (See GPU Gems 3 pp. 877 - 889)
+    vec3 gaussCoeff;
+    gaussCoeff.x = 1.0 / (sqrt(2.0 * PI) * sigma);
+    gaussCoeff.y = exp(-0.5 / (sigma * sigma));
+    gaussCoeff.z = gaussCoeff.y * gaussCoeff.y;
+
+    vec2 blurVec = blurRadius * blurDir;
+    vec4 avgValue = vec4(0.0);
+    float gaussCoeffSum = 0.0;
+
+    avgValue += texture2D(texSampler, texCoord) * gaussCoeff.x;
+    gaussCoeffSum += gaussCoeff.x;
+    gaussCoeff.xy *= gaussCoeff.yz;
+
+    for (int i = 1; i <= blurKernelSizeHalfSize; i++)
+    {
+        avgValue += texture2D(texSampler, texCoord - i * blurVec) * gaussCoeff.x;
+        avgValue += texture2D(texSampler, texCoord + i * blurVec) * gaussCoeff.x;
+
+        gaussCoeffSum += 2.0 * gaussCoeff.x;
+        gaussCoeff.xy *= gaussCoeff.yz;
+    }
+
+    return avgValue / gaussCoeffSum;
+}
+
+const vec3 LumWeights = vec3(0.2126, 0.7152, 0.0722);
+
+vec3 ReinhardEq3Tonemap(vec3 x)
+{
+    return x / (1.0 + x);
+}
+
+vec3 ReinhardEq4Tonemap(vec3 x, float white)
+{
+    return x * (1.0 + x / white) / (1.0 + x);
+}
+
+// Unchared2 tone mapping (See http://filmicgames.com)
+const float A = 0.15;
+const float B = 0.50;
+const float C = 0.10;
+const float D = 0.20;
+const float E = 0.02;
+const float F = 0.30;
+
+vec3 Uncharted2Tonemap(vec3 x)
+{
+   return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
+}
+
+vec3 ColorCorrection(vec3 color, sampler3D lut)
+{
+    float lutSize = 16.0;
+    float scale = (lutSize - 1.0) / lutSize;
+    float offset = 1.0 / (2.0 * lutSize);
+    return texture3D(lut, clamp(color, 0.0, 1.0) * scale + offset).rgb;
+}
+
+const float Gamma = 2.2;
+const float InverseGamma = 1.0 / 2.2;
+
+vec3 ToGamma(vec3 color)
+{
+    return vec3(pow(color.r, Gamma), pow(color.g, Gamma), pow(color.b, Gamma));
+}
+
+vec3 ToInverseGamma(vec3 color)
+{
+    return vec3(pow(color.r, InverseGamma), pow(color.g, InverseGamma), pow(color.b, InverseGamma));
+}
+#endif

+ 26 - 4
Bin/CoreData/Shaders/GLSL/PrepassLight.frag → Bin/CoreData/Shaders/GLSL/PrepassLight.glsl

@@ -1,6 +1,8 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-#include "Lighting.frag"
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "Lighting.glsl"
 
 #ifdef DIRLIGHT
     varying vec2 vScreenPos;
@@ -12,7 +14,27 @@ varying vec3 vFarRay;
     varying vec3 vNearRay;
 #endif
 
-void main()
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    #ifdef DIRLIGHT
+        vScreenPos = GetScreenPosPreDiv(gl_Position);
+        vFarRay = GetFarRay(gl_Position);
+        #ifdef ORTHO
+            vNearRay = GetNearRay(gl_Position);
+        #endif
+    #else
+        vScreenPos = GetScreenPos(gl_Position);
+        vFarRay = GetFarRay(gl_Position) * gl_Position.w;
+        #ifdef ORTHO
+            vNearRay = GetNearRay(gl_Position) * gl_Position.w;
+        #endif
+    #endif
+}
+
+void PS()
 {
     // If rendering a directional light quad, optimize out the w divide
     #ifdef DIRLIGHT

+ 0 - 33
Bin/CoreData/Shaders/GLSL/PrepassLight.vert

@@ -1,33 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "ScreenPos.vert"
-
-#ifdef DIRLIGHT
-    varying vec2 vScreenPos;
-#else
-    varying vec4 vScreenPos;
-#endif
-varying vec3 vFarRay;
-#ifdef ORTHO
-    varying vec3 vNearRay;
-#endif
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    #ifdef DIRLIGHT
-        vScreenPos = GetScreenPosPreDiv(gl_Position);
-        vFarRay = GetFarRay(gl_Position);
-        #ifdef ORTHO
-            vNearRay = GetNearRay(gl_Position);
-        #endif
-    #else
-        vScreenPos = GetScreenPos(gl_Position);
-        vFarRay = GetFarRay(gl_Position) * gl_Position.w;
-        #ifdef ORTHO
-            vNearRay = GetNearRay(gl_Position) * gl_Position.w;
-        #endif
-    #endif
-}

+ 0 - 16
Bin/CoreData/Shaders/GLSL/PrepassLight.xml

@@ -1,16 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <option name="Ortho" define="ORTHO" />
-        <option name="Dir" define="DIRLIGHT" />
-    </shader>
-    <shader type="ps">
-        <option name="Ortho" define="ORTHO" />
-        <variation name="Dir" define="DIRLIGHT" />
-        <variation name="Spot" define="SPOTLIGHT" />
-        <variation name="Point" define="POINTLIGHT" />
-        <option name="Mask" define="CUBEMASK" require="POINTLIGHT" />
-        <option name="Spec" define="SPECULAR" />
-        <option name="Shadow" define="SHADOW" />
-        <option name="LQ" define="LQSHADOW" />
-    </shader>
-</shaders>

+ 11 - 8
Bin/CoreData/Shaders/GLSL/Samplers.frag → Bin/CoreData/Shaders/GLSL/Samplers.glsl

@@ -1,3 +1,4 @@
+#ifdef COMPILEPS
 uniform sampler2D sDiffMap;
 uniform samplerCube sDiffCubeMap;
 uniform sampler2D sNormalMap;
@@ -9,15 +10,16 @@ uniform sampler2D sLightRampMap;
 uniform sampler2D sLightSpotMap;
 uniform samplerCube sLightCubeMap;
 #ifndef GL_ES
-uniform sampler2D sAlbedoBuffer;
-uniform sampler2D sNormalBuffer;
-uniform sampler2D sDepthBuffer;
-uniform sampler2D sLightBuffer;
-uniform sampler2DShadow sShadowMap;
-uniform samplerCube sFaceSelectCubeMap;
-uniform samplerCube sIndirectionCubeMap;
+    uniform sampler3D sVolumeMap;
+    uniform sampler2D sAlbedoBuffer;
+    uniform sampler2D sNormalBuffer;
+    uniform sampler2D sDepthBuffer;
+    uniform sampler2D sLightBuffer;
+    uniform sampler2DShadow sShadowMap;
+    uniform samplerCube sFaceSelectCubeMap;
+    uniform samplerCube sIndirectionCubeMap;
 #else
-uniform sampler2D sShadowMap;
+    uniform sampler2D sShadowMap;
 #endif
 
 vec3 DecodeNormal(vec4 normalInput)
@@ -49,3 +51,4 @@ float DecodeDepth(vec3 depth)
     const vec3 dotValues = vec3(1.0, 1.0 / 255.0, 1.0 / (255.0 * 255.0));
     return dot(depth, dotValues);
 }
+#endif

+ 2 - 1
Bin/CoreData/Shaders/GLSL/ScreenPos.vert → Bin/CoreData/Shaders/GLSL/ScreenPos.glsl

@@ -1,3 +1,4 @@
+#ifdef COMPILEVS
 vec4 GetScreenPos(vec4 clipPos)
 {
     return vec4(
@@ -47,4 +48,4 @@ vec3 GetNearRay(vec4 clipPos)
     
     return (cCameraRot * viewRay) * cDepthMode.x;
 }
-
+#endif

+ 0 - 15
Bin/CoreData/Shaders/GLSL/Shadow.frag

@@ -1,15 +0,0 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-
-varying vec2 vTexCoord;
-
-void main()
-{
-    #ifdef ALPHAMASK
-        float alpha = texture2D(sDiffMap, vTexCoord).a;
-        if (alpha < 0.5)
-            discard;
-    #endif
-
-    gl_FragColor = vec4(1.0);
-}

+ 24 - 0
Bin/CoreData/Shaders/GLSL/Shadow.glsl

@@ -0,0 +1,24 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+
+varying vec2 vTexCoord;
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = GetTexCoord(iTexCoord);
+}
+
+void PS()
+{
+    #ifdef ALPHAMASK
+        float alpha = texture2D(sDiffMap, vTexCoord).a;
+        if (alpha < 0.5)
+            discard;
+    #endif
+
+    gl_FragColor = vec4(1.0);
+}

+ 0 - 13
Bin/CoreData/Shaders/GLSL/Shadow.vert

@@ -1,13 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-
-varying vec2 vTexCoord;
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    vTexCoord = GetTexCoord(iTexCoord);
-}
-

+ 0 - 10
Bin/CoreData/Shaders/GLSL/Shadow.xml

@@ -1,10 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <variation name="" />
-        <variation name="Skinned" define="SKINNED" />
-        <variation name="Instanced" define="INSTANCED" />
-    </shader>
-    <shader type="ps">
-        <option name="AlphaMask" define="ALPHAMASK" />
-    </shader>
-</shaders>

+ 0 - 9
Bin/CoreData/Shaders/GLSL/Skybox.frag

@@ -1,9 +0,0 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-
-varying vec3 vTexCoord;
-
-void main()
-{
-    gl_FragColor = cMatDiffColor * textureCube(sDiffCubeMap, vTexCoord);
-}

+ 9 - 3
Bin/CoreData/Shaders/GLSL/Skybox.vert → Bin/CoreData/Shaders/GLSL/Skybox.glsl

@@ -1,9 +1,10 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
 
 varying vec3 vTexCoord;
 
-void main()
+void VS()
 {
     mat4 modelMatrix = iModelMatrix;
     vec3 worldPos = GetWorldPos(modelMatrix);
@@ -12,3 +13,8 @@ void main()
     gl_Position.z = gl_Position.w;
     vTexCoord = iPos.xyz;
 }
+
+void PS()
+{
+    gl_FragColor = cMatDiffColor * textureCube(sDiffCubeMap, vTexCoord);
+}

+ 0 - 3
Bin/CoreData/Shaders/GLSL/Skybox.xml

@@ -1,3 +0,0 @@
-<shaders>
-    <shader />
-</shaders>

+ 0 - 6
Bin/CoreData/Shaders/GLSL/Stencil.frag

@@ -1,6 +0,0 @@
-#include "Uniforms.frag"
-
-void main()
-{
-    gl_FragColor = vec4(1.0);
-}

+ 9 - 3
Bin/CoreData/Shaders/GLSL/Stencil.vert → Bin/CoreData/Shaders/GLSL/Stencil.glsl

@@ -1,9 +1,15 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
+#include "Uniforms.glsl"
+#include "Transform.glsl"
 
-void main()
+void VS()
 {
     mat4 modelMatrix = iModelMatrix;
     vec3 worldPos = GetWorldPos(modelMatrix);
     gl_Position = GetClipPos(worldPos);
 }
+
+void PS()
+{
+    gl_FragColor = vec4(1.0);
+}
+

+ 0 - 3
Bin/CoreData/Shaders/GLSL/Stencil.xml

@@ -1,3 +0,0 @@
-<shaders>
-    <shader />
-</shaders>

+ 87 - 11
Bin/CoreData/Shaders/GLSL/TerrainBlend.frag → Bin/CoreData/Shaders/GLSL/TerrainBlend.glsl

@@ -1,9 +1,14 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-#include "Lighting.frag"
-#include "Fog.frag"
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "Lighting.glsl"
+#include "Fog.glsl"
 
 varying vec2 vTexCoord;
+#ifdef HEIGHTFOG
+    varying vec3 vWorldPos;
+#endif
 #ifdef PERPIXEL
     varying vec4 vLightVec;
     #ifdef SPECULAR
@@ -25,14 +30,67 @@ varying vec2 vTexCoord;
     varying vec4 vScreenPos;
 #endif
 
+#ifdef COMPILEPS
 uniform sampler2D sWeightMap0;
 uniform sampler2D sDetailMap1;
 uniform sampler2D sDetailMap2;
 uniform sampler2D sDetailMap3;
-
 uniform vec2 cDetailTiling;
+#endif
 
-void main()
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = GetTexCoord(iTexCoord);
+    vNormal = GetWorldNormal(modelMatrix);
+
+    #ifdef HEIGHTFOG
+        vWorldPos = worldPos;
+    #endif
+
+    #ifdef PERPIXEL
+        // Per-pixel forward lighting
+        vec4 projWorldPos = vec4(worldPos, 1.0);
+
+        #ifdef SHADOW
+            // Shadow projection: transform from world space to shadow space
+            for (int i = 0; i < NUMCASCADES; i++)
+                vShadowPos[i] = GetShadowPos(i, projWorldPos);
+        #endif
+
+        #ifdef SPOTLIGHT
+            // Spotlight projection: transform from world space to projector texture coordinates
+            vSpotPos = cLightMatrices[0] * projWorldPos;
+        #endif
+
+        #ifdef POINTLIGHT
+            vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * (cLightPos.xyz - worldPos);
+        #endif
+
+        #ifdef DIRLIGHT
+            vLightVec = vec4(cLightDir, GetDepth(gl_Position));
+        #else
+            vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
+        #endif
+        #ifdef SPECULAR
+            vEyeVec = cCameraPos - worldPos;
+        #endif
+    #else
+        // Ambient & per-vertex lighting
+        vVertexLight = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
+
+        #ifdef NUMVERTEXLIGHTS
+            for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
+                vVertexLight.rgb += GetVertexLight(i, worldPos, vNormal) * cVertexLights[i * 3].rgb;
+        #endif
+        
+        vScreenPos = GetScreenPos(gl_Position);
+    #endif
+}
+
+void PS()
 {
     // Get material diffuse albedo
     vec3 weights = texture2D(sWeightMap0, vTexCoord).rgb;
@@ -75,11 +133,17 @@ void main()
             finalColor = diff * lightColor * diffColor.rgb;
         #endif
 
+        #ifdef HEIGHTFOG
+            float fogFactor = GetHeightFogFactor(vLightVec.w, vWorldPos.y);
+        #else
+            float fogFactor = GetFogFactor(vLightVec.w);
+        #endif
+
         #ifdef AMBIENT
             finalColor += cAmbientColor * diffColor.rgb;
-            gl_FragColor = vec4(GetFog(finalColor, vLightVec.w), diffColor.a);
+            gl_FragColor = vec4(GetFog(finalColor, fogFactor), diffColor.a);
         #else
-            gl_FragColor = vec4(GetLitFog(finalColor, vLightVec.w), diffColor.a);
+            gl_FragColor = vec4(GetLitFog(finalColor, fogFactor), diffColor.a);
         #endif
     #elif defined(PREPASS)
         // Fill light pre-pass G-Buffer
@@ -96,8 +160,14 @@ void main()
         float specIntensity = specColor.g;
         float specPower = cMatSpecColor.a / 255.0;
 
-        gl_FragData[0] = vec4(GetFog(vVertexLight.rgb * diffColor.rgb, vVertexLight.a), 1.0);
-        gl_FragData[1] = GetFogFactor(vVertexLight.a) * vec4(diffColor.rgb, specIntensity);
+        #ifdef HEIGHTFOG
+            float fogFactor = GetHeightFogFactor(vVertexLight.a, vWorldPos.y);
+        #else
+            float fogFactor = GetFogFactor(vVertexLight.a);
+        #endif
+
+        gl_FragData[0] = vec4(GetFog(vVertexLight.rgb * diffColor.rgb, fogFactor), 1.0);
+        gl_FragData[1] = fogFactor * vec4(diffColor.rgb, specIntensity);
         gl_FragData[2] = vec4(normal * 0.5 + 0.5, specPower);
         gl_FragData[3] = vec4(EncodeDepth(vVertexLight.a), 0.0);
     #else
@@ -113,6 +183,12 @@ void main()
             finalColor += lightInput.rgb * diffColor.rgb + lightSpecColor * specColor;
         #endif
 
-        gl_FragColor = vec4(GetFog(finalColor, vVertexLight.a), diffColor.a);
+        #ifdef HEIGHTFOG
+            float fogFactor = GetHeightFogFactor(vVertexLight.a, vWorldPos.y);
+        #else
+            float fogFactor = GetFogFactor(vVertexLight.a);
+        #endif
+
+        gl_FragColor = vec4(GetFog(finalColor, fogFactor), diffColor.a);
     #endif
 }

+ 0 - 74
Bin/CoreData/Shaders/GLSL/TerrainBlend.vert

@@ -1,74 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "ScreenPos.vert"
-#include "Lighting.vert"
-
-varying vec2 vTexCoord;
-#ifdef PERPIXEL
-    varying vec4 vLightVec;
-    #ifdef SPECULAR
-        varying vec3 vEyeVec;
-    #endif
-    varying vec3 vNormal;
-    #ifdef SHADOW
-        varying vec4 vShadowPos[NUMCASCADES];
-    #endif
-    #ifdef SPOTLIGHT
-        varying vec4 vSpotPos;
-    #endif
-    #ifdef POINTLIGHT
-        varying vec3 vCubeMaskVec;
-    #endif
-#else
-    varying vec4 vVertexLight;
-    varying vec3 vNormal;
-    varying vec4 vScreenPos;
-#endif
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    vTexCoord = GetTexCoord(iTexCoord);
-    vNormal = GetWorldNormal(modelMatrix);
-
-    #ifdef PERPIXEL
-        // Per-pixel forward lighting
-        vec4 projWorldPos = vec4(worldPos, 1.0);
-
-        #ifdef SHADOW
-            // Shadow projection: transform from world space to shadow space
-            for (int i = 0; i < NUMCASCADES; i++)
-                vShadowPos[i] = GetShadowPos(i, projWorldPos);
-        #endif
-
-        #ifdef SPOTLIGHT
-            // Spotlight projection: transform from world space to projector texture coordinates
-            vSpotPos = cLightMatrices[0] * projWorldPos;
-        #endif
-
-        #ifdef POINTLIGHT
-            vCubeMaskVec = mat3(cLightMatrices[0][0].xyz, cLightMatrices[0][1].xyz, cLightMatrices[0][2].xyz) * (cLightPos.xyz - worldPos);
-        #endif
-
-        #ifdef DIRLIGHT
-            vLightVec = vec4(cLightDir, GetDepth(gl_Position));
-        #else
-            vLightVec = vec4((cLightPos.xyz - worldPos) * cLightPos.w, GetDepth(gl_Position));
-        #endif
-        #ifdef SPECULAR
-            vEyeVec = cCameraPos - worldPos;
-        #endif
-    #else
-        // Ambient & per-vertex lighting
-        vVertexLight = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
-
-        #ifdef NUMVERTEXLIGHTS
-            for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
-                vVertexLight.rgb += GetVertexLight(i, worldPos, vNormal) * cVertexLights[i * 3].rgb;
-        #endif
-        
-        vScreenPos = GetScreenPos(gl_Position);
-    #endif
-}

+ 0 - 48
Bin/CoreData/Shaders/GLSL/TerrainBlend.xml

@@ -1,48 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <variation name="" define="AMBIENT" />
-        <variation name="1VL" define="NUMVERTEXLIGHTS=1" />
-        <variation name="2VL" define="NUMVERTEXLIGHTS=2" />
-        <variation name="3VL" define="NUMVERTEXLIGHTS=3" />
-        <variation name="4VL" define="NUMVERTEXLIGHTS=4" />
-        <variation name="Dir">
-            <define name="DIRLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Spot">
-            <define name="SPOTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Point">
-            <define name="POINTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <option name="Spec" define="SPECULAR" require="PERPIXEL" />
-        <option name="Shadow" define="SHADOW" require="PERPIXEL" />
-        <variation name="" />
-        <variation name="Instanced" define="INSTANCED" />
-    </shader>
-    <shader type="ps">
-        <option name="Ambient" define="AMBIENT" require="PERPIXEL" />
-        <variation name="" define="AMBIENT" />
-        <variation name="Dir">
-            <define name="DIRLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Spot">
-            <define name="SPOTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Point">
-            <define name="POINTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Prepass" define="PREPASS" />
-        <variation name="Material" define="MATERIAL" />
-        <variation name="Deferred" define="DEFERRED" />
-        <option name="Mask" define="CUBEMASK" require="POINTLIGHT" />
-        <option name="Spec" define="SPECULAR" require="PERPIXEL" />
-        <option name="Shadow" define="SHADOW" require="PERPIXEL" />
-        <option name="LQ" define="LQSHADOW" require="SHADOW" />
-    </shader>
-</shaders>

+ 40 - 0
Bin/CoreData/Shaders/GLSL/Tonemap.glsl

@@ -0,0 +1,40 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "PostProcess.glsl"
+
+varying vec2 vScreenPos;
+
+#ifdef COMPILEPS
+uniform float cTonemapExposureBias;
+uniform float cTonemapMaxWhite;
+#endif
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vScreenPos = GetScreenPosPreDiv(gl_Position);
+}
+
+void PS()
+{
+    #ifdef REINHARDEQ3
+    vec3 color = ReinhardEq3Tonemap(max(texture2D(sDiffMap, vScreenPos).rgb * cTonemapExposureBias, 0.0));
+    gl_FragColor = vec4(color, 1.0);
+    #endif
+
+    #ifdef REINHARDEQ4
+    vec3 color = ReinhardEq4Tonemap(max(texture2D(sDiffMap, vScreenPos).rgb * cTonemapExposureBias, 0.0), cTonemapMaxWhite);
+    gl_FragColor = vec4(color, 1.0);
+    #endif
+
+    #ifdef UNCHARTED2
+    vec3 color = Uncharted2Tonemap(max(texture2D(sDiffMap, vScreenPos).rgb * cTonemapExposureBias, 0.0)) / 
+        Uncharted2Tonemap(vec3(cTonemapMaxWhite, cTonemapMaxWhite, cTonemapMaxWhite));
+    gl_FragColor = vec4(color, 1.0);
+    #endif
+}
+

+ 10 - 4
Bin/CoreData/Shaders/GLSL/Transform.vert → Bin/CoreData/Shaders/GLSL/Transform.glsl

@@ -1,3 +1,4 @@
+#ifdef COMPILEVS
 attribute vec4 iPos;
 attribute vec3 iNormal;
 attribute vec4 iColor;
@@ -46,7 +47,12 @@ vec2 GetTexCoord(vec2 texCoord)
 
 vec4 GetClipPos(vec3 worldPos)
 {
-    return cViewProj * vec4(worldPos, 1.0);
+    vec4 ret = cViewProj * vec4(worldPos, 1.0);
+    // While getting the clip coordinate, also automatically set gl_ClipVertex for user clip planes
+    #ifndef GL_ES
+    gl_ClipVertex = ret;
+    #endif
+    return ret;
 }
 
 float GetZonePos(vec3 worldPos)
@@ -61,12 +67,12 @@ float GetDepth(vec4 clipPos)
 
 vec3 GetBillboardPos(vec4 iPos, vec2 iSize, mat4 modelMatrix)
 {
-    return (modelMatrix * vec4(iPos.xyz + iSize.x * cViewRightVector + iSize.y * cViewUpVector, 1.0)).xyz;
+    return (modelMatrix * iPos).xyz + cBillboardRot * vec3(iSize.x, iSize.y, 0.0);
 }
 
 vec3 GetBillboardNormal()
 {
-    return vec3(-cCameraRot[2][0], -cCameraRot[2][1], -cCameraRot[2][2]);
+    return vec3(-cBillboardRot[2][0], -cBillboardRot[2][1], -cBillboardRot[2][2]);
 }
 
 // Note: the skinning/instancing model matrix is a transpose, so the matrix multiply order must be swapped
@@ -110,4 +116,4 @@ vec3 GetWorldTangent(mat4 modelMatrix)
         return normalize(normalMatrix * iTangent.xyz);
     #endif
 }
-
+#endif

+ 0 - 22
Bin/CoreData/Shaders/GLSL/Uniforms.frag

@@ -1,22 +0,0 @@
-#ifdef GL_ES
-    precision mediump float;
-#endif
-
-uniform vec3 cAmbientColor;
-uniform float cElapsedTimePS;
-uniform vec2 cFogParams;
-uniform vec3 cFogColor;
-uniform vec2 cGBufferInvSize;
-uniform vec4 cLightColor;
-uniform vec3 cLightDirPS;
-uniform vec4 cLightPosPS;
-uniform vec4 cMatDiffColor;
-uniform vec3 cMatEmissiveColor;
-uniform vec3 cMatEnvMapColor;
-uniform vec4 cMatSpecColor;
-uniform vec4 cShadowCubeAdjust;
-uniform vec4 cShadowDepthFade;
-uniform vec2 cShadowIntensity;
-uniform vec2 cShadowMapInvSize;
-uniform vec4 cShadowSplits;
-uniform mat4 cLightMatricesPS[4];

+ 64 - 0
Bin/CoreData/Shaders/GLSL/Uniforms.glsl

@@ -0,0 +1,64 @@
+#ifdef COMPILEVS
+uniform vec3 cAmbientStartColor;
+uniform vec3 cAmbientEndColor;
+uniform mat3 cBillboardRot;
+uniform vec3 cCameraPos;
+uniform mat3 cCameraRot;
+uniform float cNearClip;
+uniform float cFarClip;
+uniform vec4 cDepthMode;
+uniform vec3 cFrustumSize;
+uniform float cDeltaTime;
+uniform float cElapsedTime;
+uniform vec4 cGBufferOffsets;
+uniform vec3 cLightDir;
+uniform vec4 cLightPos;
+uniform mat4 cModel;
+uniform mat4 cViewProj;
+uniform vec4 cUOffset;
+uniform vec4 cVOffset;
+uniform mat4 cZone;
+#ifndef GL_ES
+    uniform mat4 cLightMatrices[4];
+#else
+    uniform mat4 cLightMatrices[2];
+#endif
+#ifdef SKINNED
+    #ifdef RASPI
+        uniform vec4 cSkinMatrices[32*3];
+    #else
+        uniform vec4 cSkinMatrices[64*3];
+    #endif
+#endif
+#ifdef NUMVERTEXLIGHTS
+    uniform vec4 cVertexLights[4*3];
+#endif
+#endif
+
+#ifdef COMPILEPS
+#ifdef GL_ES
+    precision mediump float;
+#endif
+
+uniform vec3 cAmbientColor;
+uniform float cDeltaTimePS;
+uniform float cElapsedTimePS;
+uniform vec4 cFogParams;
+uniform vec3 cFogColor;
+uniform vec2 cGBufferInvSize;
+uniform vec4 cLightColor;
+uniform vec3 cLightDirPS;
+uniform vec4 cLightPosPS;
+uniform vec4 cMatDiffColor;
+uniform vec3 cMatEmissiveColor;
+uniform vec3 cMatEnvMapColor;
+uniform vec4 cMatSpecColor;
+uniform float cNearClipPS;
+uniform float cFarClipPS;
+uniform vec4 cShadowCubeAdjust;
+uniform vec4 cShadowDepthFade;
+uniform vec2 cShadowIntensity;
+uniform vec2 cShadowMapInvSize;
+uniform vec4 cShadowSplits;
+uniform mat4 cLightMatricesPS[4];
+#endif

+ 0 - 32
Bin/CoreData/Shaders/GLSL/Uniforms.vert

@@ -1,32 +0,0 @@
-uniform vec3 cAmbientStartColor;
-uniform vec3 cAmbientEndColor;
-uniform vec3 cCameraPos;
-uniform mat3 cCameraRot;
-uniform vec4 cDepthMode;
-uniform vec3 cFrustumSize;
-uniform float cElapsedTime;
-uniform vec4 cGBufferOffsets;
-uniform vec3 cLightDir;
-uniform vec4 cLightPos;
-uniform mat4 cModel;
-uniform mat4 cViewProj;
-uniform vec4 cUOffset;
-uniform vec4 cVOffset;
-uniform vec3 cViewRightVector;
-uniform vec3 cViewUpVector;
-uniform mat4 cZone;
-#ifndef GL_ES
-    uniform mat4 cLightMatrices[4];
-#else
-    uniform mat4 cLightMatrices[2];
-#endif
-#ifdef SKINNED
-    #ifdef RASPI
-        uniform vec4 cSkinMatrices[32*3];
-    #else
-        uniform vec4 cSkinMatrices[64*3];
-    #endif
-#endif
-#ifdef NUMVERTEXLIGHTS
-    uniform vec4 cVertexLights[4*3];
-#endif

+ 0 - 25
Bin/CoreData/Shaders/GLSL/Unlit.frag

@@ -1,25 +0,0 @@
-#include "Uniforms.frag"
-#include "Samplers.frag"
-#include "Fog.frag"
-
-varying vec2 vTexCoord;
-#ifdef VERTEXCOLOR
-    varying vec4 vColor;
-#endif
-varying float vDepth;
-
-void main()
-{
-    #ifdef DIFFMAP
-        vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord);
-    #else
-        vec4 diffColor = cMatDiffColor;
-    #endif
-
-    #ifdef VERTEXCOLOR
-        diffColor *= vColor;
-    #endif
-
-    gl_FragColor = vec4(GetFog(diffColor.rgb, vDepth), diffColor.a);
-}
-

+ 67 - 0
Bin/CoreData/Shaders/GLSL/Unlit.glsl

@@ -0,0 +1,67 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "Fog.glsl"
+
+varying vec2 vTexCoord;
+#ifdef VERTEXCOLOR
+    varying vec4 vColor;
+#endif
+#ifdef HEIGHTFOG
+    varying vec3 vWorldPos;
+#endif
+varying float vDepth;
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vTexCoord = GetTexCoord(iTexCoord);
+    vDepth = GetDepth(gl_Position);
+
+    #ifdef HEIGHTFOG
+        vWorldPos = worldPos;
+    #endif
+
+    #ifdef VERTEXCOLOR
+        vColor = iColor;
+    #endif
+}
+
+void PS()
+{
+    #ifdef DIFFMAP
+        vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord);
+        #ifdef ALPHAMASK
+            if (diffColor.a < 0.5)
+                discard;
+        #endif
+    #else
+        vec4 diffColor = cMatDiffColor;
+    #endif
+
+    #ifdef VERTEXCOLOR
+        diffColor *= vColor;
+    #endif
+
+    #ifdef HEIGHTFOG
+        float fogFactor = GetHeightFogFactor(vDepth, vWorldPos.y);
+    #else
+        float fogFactor = GetFogFactor(vDepth);
+    #endif
+
+    #if defined(PREPASS)
+        // Fill light pre-pass G-Buffer
+        gl_FragData[0] = vec4(0.5, 0.5, 0.5, 1.0);
+        gl_FragData[1] = vec4(EncodeDepth(vDepth), 0.0);
+    #elif defined(DEFERRED)
+        gl_FragData[0] = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
+        gl_FragData[1] = vec4(0.0, 0.0, 0.0, 0.0);
+        gl_FragData[2] = vec4(0.5, 0.5, 0.5, 1.0);
+        gl_FragData[3] = vec4(EncodeDepth(vDepth), 0.0);
+    #else
+        gl_FragColor = vec4(GetFog(diffColor.rgb, fogFactor), diffColor.a);
+    #endif
+}

+ 0 - 21
Bin/CoreData/Shaders/GLSL/Unlit.vert

@@ -1,21 +0,0 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-
-varying vec2 vTexCoord;
-#ifdef VERTEXCOLOR
-    varying vec4 vColor;
-#endif
-varying float vDepth;
-
-void main()
-{
-    mat4 modelMatrix = iModelMatrix;
-    vec3 worldPos = GetWorldPos(modelMatrix);
-    gl_Position = GetClipPos(worldPos);
-    vTexCoord = GetTexCoord(iTexCoord);
-    vDepth = GetDepth(gl_Position);
-
-    #ifdef VERTEXCOLOR
-        vColor = iColor;
-    #endif
-}

+ 0 - 13
Bin/CoreData/Shaders/GLSL/Unlit.xml

@@ -1,13 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <option name="VCol" define="VERTEXCOLOR" />
-        <variation name="" />
-        <variation name="Skinned" define="SKINNED" />
-        <variation name="Instanced" define="INSTANCED" />
-        <variation name="Billboard" define="BILLBOARD" />
-    </shader>
-    <shader type="ps">
-        <option name="Diff" define="DIFFMAP" />
-        <option name="VCol" define="VERTEXCOLOR" />
-    </shader>
-</shaders>

+ 15 - 7
Bin/CoreData/Shaders/GLSL/Vegetation.vert → Bin/CoreData/Shaders/GLSL/Vegetation.glsl

@@ -1,7 +1,7 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
-#include "ScreenPos.vert"
-#include "Lighting.vert"
+#include "Uniforms.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "Lighting.glsl"
 
 uniform float cWindHeightFactor;
 uniform float cWindHeightPivot;
@@ -9,6 +9,9 @@ uniform float cWindPeriod;
 uniform vec2 cWindWorldSpacing;
 
 varying vec2 vTexCoord;
+#ifdef HEIGHTFOG
+    varying vec3 vWorldPos;
+#endif
 #ifdef PERPIXEL
     varying vec4 vLightVec;
     #ifdef SPECULAR
@@ -36,12 +39,13 @@ varying vec2 vTexCoord;
     varying vec4 vScreenPos;
 #endif
 
-void main()
+void VS()
 {
     mat4 modelMatrix = iModelMatrix;
     vec3 worldPos = GetWorldPos(modelMatrix);
+    float height = worldPos.y - cModel[3][1];
 
-    float windStrength = max(iPos.y - cWindHeightPivot, 0.0) * cWindHeightFactor;
+    float windStrength = max(height - cWindHeightPivot, 0.0) * cWindHeightFactor;
     float windPeriod = cElapsedTime * cWindPeriod + dot(worldPos.xz, cWindWorldSpacing);
     worldPos.x += windStrength * sin(windPeriod);
     worldPos.z -= windStrength * cos(windPeriod);
@@ -49,6 +53,10 @@ void main()
     gl_Position = GetClipPos(worldPos);
     vTexCoord = GetTexCoord(iTexCoord);
 
+    #ifdef HEIGHTFOG
+        vWorldPos = worldPos;
+    #endif
+
     #if defined(PERPIXEL) && defined(NORMALMAP)
         vec3 vNormal;
         vec3 vTangent;
@@ -103,7 +111,7 @@ void main()
     #else
         // Ambient & per-vertex lighting
         vVertexLight = vec4(GetAmbient(GetZonePos(worldPos)), GetDepth(gl_Position));
-
+        
         #ifdef NUMVERTEXLIGHTS
             for (int i = 0; i < NUMVERTEXLIGHTS; ++i)
                 vVertexLight.rgb += GetVertexLight(i, worldPos, vNormal) * cVertexLights[i * 3].rgb;

+ 0 - 27
Bin/CoreData/Shaders/GLSL/Vegetation.xml

@@ -1,27 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <option name="Normal" define="NORMALMAP" />
-        <variation name="" define="AMBIENT" />
-        <variation name="1VL" define="NUMVERTEXLIGHTS=1" />
-        <variation name="2VL" define="NUMVERTEXLIGHTS=2" />
-        <variation name="3VL" define="NUMVERTEXLIGHTS=3" />
-        <variation name="4VL" define="NUMVERTEXLIGHTS=4" />
-        <variation name="Dir">
-            <define name="DIRLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Spot">
-            <define name="SPOTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <variation name="Point">
-            <define name="POINTLIGHT" />
-            <define name="PERPIXEL" />
-        </variation>
-        <option name="Spec" define="SPECULAR" require="PERPIXEL" />
-        <option name="Shadow" define="SHADOW" require="PERPIXEL" />
-        <variation name="" />
-        <variation name="Instanced" define="INSTANCED" />
-        <variation name="Billboard" define="BILLBOARD" />
-    </shader>
-</shaders>

+ 3 - 3
Bin/CoreData/Shaders/GLSL/VegetationDepth.vert → Bin/CoreData/Shaders/GLSL/VegetationDepth.glsl

@@ -1,5 +1,5 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
+#include "Uniforms.glsl"
+#include "Transform.glsl"
 
 uniform float cWindHeightFactor;
 uniform float cWindHeightPivot;
@@ -8,7 +8,7 @@ uniform vec2 cWindWorldSpacing;
 
 varying vec3 vTexCoord;
 
-void main()
+void VS()
 {
     mat4 modelMatrix = iModelMatrix;
     vec3 worldPos = GetWorldPos(modelMatrix);

+ 0 - 6
Bin/CoreData/Shaders/GLSL/VegetationDepth.xml

@@ -1,6 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <variation name="" />
-        <variation name="Instanced" define="INSTANCED" />
-    </shader>
-</shaders>

+ 3 - 3
Bin/CoreData/Shaders/GLSL/VegetationShadow.vert → Bin/CoreData/Shaders/GLSL/VegetationShadow.glsl

@@ -1,5 +1,5 @@
-#include "Uniforms.vert"
-#include "Transform.vert"
+#include "Uniforms.glsl"
+#include "Transform.glsl"
 
 uniform float cWindHeightFactor;
 uniform float cWindHeightPivot;
@@ -8,7 +8,7 @@ uniform vec2 cWindWorldSpacing;
 
 varying vec2 vTexCoord;
 
-void main()
+void VS()
 {
     mat4 modelMatrix = iModelMatrix;
     vec3 worldPos = GetWorldPos(modelMatrix);

+ 0 - 6
Bin/CoreData/Shaders/GLSL/VegetationShadow.xml

@@ -1,6 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <variation name="" />
-        <variation name="Instanced" define="INSTANCED" />
-    </shader>
-</shaders>

+ 59 - 0
Bin/CoreData/Shaders/GLSL/Water.glsl

@@ -0,0 +1,59 @@
+#include "Uniforms.glsl"
+#include "Samplers.glsl"
+#include "Transform.glsl"
+#include "ScreenPos.glsl"
+#include "Fog.glsl"
+
+varying vec4 vScreenPos;
+varying vec2 vReflectUV;
+varying vec2 vWaterUV;
+varying vec3 vNormal;
+varying vec4 vEyeVec;
+
+#ifdef COMPILEVS
+uniform vec2 cNoiseSpeed;
+uniform float cNoiseTiling;
+#endif
+#ifdef COMPILEPS
+uniform float cNoiseStrength;
+uniform float cFresnelPower;
+uniform vec3 cWaterTint;
+#endif
+
+void VS()
+{
+    mat4 modelMatrix = iModelMatrix;
+    vec3 worldPos = GetWorldPos(modelMatrix);
+    gl_Position = GetClipPos(worldPos);
+    vScreenPos = GetScreenPos(gl_Position);
+    // GetQuadTexCoord() returns a vec2 that is OK for quad rendering; multiply it with output W
+    // coordinate to make it work with arbitrary meshes such as the water plane (perform divide in pixel shader)
+    // Also because the quadTexCoord is based on the clip position, and Y is flipped when rendering to a texture
+    // on OpenGL, must flip again to cancel it out
+    vReflectUV = GetQuadTexCoord(gl_Position);
+    vReflectUV.y = 1.0 - vReflectUV.y;
+    vReflectUV *= gl_Position.w;
+    vWaterUV = iTexCoord * cNoiseTiling + cElapsedTime * cNoiseSpeed;
+    vNormal = GetWorldNormal(modelMatrix);
+    vEyeVec = vec4(cCameraPos - worldPos, GetDepth(gl_Position));
+}
+
+void PS()
+{
+    vec2 refractUV = vScreenPos.xy / vScreenPos.w;
+    vec2 reflectUV = vReflectUV.xy / vScreenPos.w;
+
+    vec2 noise = (texture2D(sNormalMap, vWaterUV).rg - 0.5) * cNoiseStrength;
+    refractUV += noise;
+    // Do not shift reflect UV coordinate upward, because it will reveal the clipping of geometry below water
+    if (noise.y < 0.0)
+        noise.y = 0.0;
+    reflectUV += noise;
+
+    float fresnel = pow(1.0 - clamp(dot(normalize(vEyeVec.xyz), vNormal), 0.0, 1.0), cFresnelPower);
+    vec3 refractColor = texture2D(sEnvMap, refractUV).rgb * cWaterTint;
+    vec3 reflectColor = texture2D(sDiffMap, reflectUV).rgb;
+    vec3 finalColor = mix(refractColor, reflectColor, fresnel);
+
+    gl_FragColor = vec4(GetFog(finalColor, GetFogFactor(vEyeVec.w)), 1.0);
+}

+ 95 - 0
Bin/CoreData/Shaders/HLSL/AutoExposure.hlsl

@@ -0,0 +1,95 @@
+#include "Uniforms.hlsl"
+#include "Transform.hlsl"
+#include "Samplers.hlsl"
+#include "ScreenPos.hlsl"
+#include "PostProcess.hlsl"
+
+uniform float cAutoExposureAdaptRate;
+uniform float2 cAutoExposureLumRange;
+uniform float cAutoExposureMiddleGrey;
+uniform float2 cHDR128Offsets;
+uniform float2 cLum64Offsets;
+uniform float2 cLum16Offsets;
+uniform float2 cLum4Offsets;
+uniform float2 cHDR128InvSize;
+uniform float2 cLum64InvSize;
+uniform float2 cLum16InvSize;
+uniform float2 cLum4InvSize;
+
+float GatherAvgLum(sampler2D texSampler, float2 texCoord, float2 texelSize)
+{
+    float lumAvg = 0.0;
+    lumAvg += tex2D(texSampler, texCoord + float2(0.0, 0.0) * texelSize).r;
+    lumAvg += tex2D(texSampler, texCoord + float2(0.0, 2.0) * texelSize).r;
+    lumAvg += tex2D(texSampler, texCoord + float2(2.0, 2.0) * texelSize).r;
+    lumAvg += tex2D(texSampler, texCoord + float2(2.0, 0.0) * texelSize).r;
+    return lumAvg / 4.0;
+}
+
+void VS(float4 iPos : POSITION,
+    out float4 oPos : POSITION,
+    out float2 oTexCoord : TEXCOORD0,
+    out float2 oScreenPos : TEXCOORD1)
+{
+    float4x3 modelMatrix = iModelMatrix;
+    float3 worldPos = GetWorldPos(modelMatrix);
+    oPos = GetClipPos(worldPos);
+
+    oTexCoord = GetQuadTexCoord(oPos);
+
+    #ifdef LUMINANCE64
+    oTexCoord = GetQuadTexCoord(oPos) + cHDR128Offsets;
+    #endif
+
+    #ifdef LUMINANCE16
+    oTexCoord = GetQuadTexCoord(oPos) + cLum64Offsets;
+    #endif
+
+    #ifdef LUMINANCE4
+    oTexCoord = GetQuadTexCoord(oPos) + cLum16Offsets;
+    #endif
+
+    #ifdef LUMINANCE1
+    oTexCoord = GetQuadTexCoord(oPos) + cLum4Offsets;
+    #endif
+
+    oScreenPos = GetScreenPosPreDiv(oPos);
+}
+
+void PS(float2 iTexCoord : TEXCOORD0,
+    float2 iScreenPos : TEXCOORD1,
+    out float4 oColor : COLOR0)
+{
+    #ifdef LUMINANCE64
+    float logLumSum = 0.0;
+    logLumSum += log(dot(tex2D(sDiffMap, iTexCoord + float2(0.0, 0.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
+    logLumSum += log(dot(tex2D(sDiffMap, iTexCoord + float2(0.0, 2.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
+    logLumSum += log(dot(tex2D(sDiffMap, iTexCoord + float2(2.0, 2.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
+    logLumSum += log(dot(tex2D(sDiffMap, iTexCoord + float2(2.0, 0.0) * cHDR128InvSize).rgb, LumWeights) + 1e-5);
+    oColor = logLumSum;
+    #endif
+
+    #ifdef LUMINANCE16
+    oColor = GatherAvgLum(sDiffMap, iTexCoord, cLum64InvSize);
+    #endif
+
+    #ifdef LUMINANCE4
+    oColor = GatherAvgLum(sDiffMap, iTexCoord, cLum16InvSize);
+    #endif
+
+    #ifdef LUMINANCE1
+    oColor = exp(GatherAvgLum(sDiffMap, iTexCoord, cLum4InvSize) / 16.0);
+    #endif
+
+    #ifdef ADAPTLUMINANCE
+    float adaptedLum = tex2D(sDiffMap, iTexCoord).r;
+    float lum = clamp(tex2D(sNormalMap, iTexCoord).r, cAutoExposureLumRange.x, cAutoExposureLumRange.y);
+    oColor = adaptedLum + (lum - adaptedLum) * (1.0 - exp(-cDeltaTimePS * cAutoExposureAdaptRate));
+    #endif
+
+    #ifdef EXPOSE
+    float3 color = tex2D(sDiffMap, iScreenPos).rgb;
+    float adaptedLum = tex2D(sNormalMap, iTexCoord).r;
+    oColor = float4(color * (cAutoExposureMiddleGrey / adaptedLum), 1.0);
+    #endif
+}

+ 0 - 16
Bin/CoreData/Shaders/HLSL/Basic.xml

@@ -1,16 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <option name="Diff" define="DIFFMAP" />
-        <option name="VCol" define="VERTEXCOLOR" />
-        <variation name="" />
-        <variation name="Skinned" define="SKINNED" />
-        <variation name="Instanced" define="INSTANCED" require="SM3" />
-        <variation name="Billboard" define="BILLBOARD" />
-    </shader>
-    <shader type="ps">
-        <option name="Diff" define="DIFFMAP" exclude="Alpha" />
-        <option name="Alpha" define="ALPHAMAP" exclude="Diff" />
-        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />
-        <option name="VCol" define="VERTEXCOLOR" />
-    </shader>
-</shaders>

+ 0 - 9
Bin/CoreData/Shaders/HLSL/Bloom.xml

@@ -1,9 +0,0 @@
-<shaders>
-    <shader type="vs" />
-    <shader type="ps">
-        <variation name="Bright" define="BRIGHT" />
-        <variation name="HBlur" define="HBLUR" />
-        <variation name="VBlur" define="VBLUR" />
-        <variation name="Combine" define="COMBINE" />
-    </shader>
-</shaders>

+ 111 - 0
Bin/CoreData/Shaders/HLSL/BloomHDR.hlsl

@@ -0,0 +1,111 @@
+#include "Uniforms.hlsl"
+#include "Transform.hlsl"
+#include "Samplers.hlsl"
+#include "ScreenPos.hlsl"
+#include "PostProcess.hlsl"
+
+uniform float cBloomHDRThreshold;
+uniform float2 cBloomHDRBlurDir;
+uniform float cBloomHDRBlurRadius;
+uniform float cBloomHDRBlurSigma;
+uniform float2 cBloomHDRMix;
+uniform float2 cBright2Offsets;
+uniform float2 cBright4Offsets;
+uniform float2 cBright8Offsets;
+uniform float2 cBright16Offsets;
+uniform float2 cBright2InvSize;
+uniform float2 cBright4InvSize;
+uniform float2 cBright8InvSize;
+uniform float2 cBright16InvSize;
+
+static const int BlurKernelSize = 5;
+
+void VS(float4 iPos : POSITION,
+    out float4 oPos : POSITION,
+    out float2 oTexCoord : TEXCOORD0,
+    out float2 oScreenPos : TEXCOORD1)
+{
+    float4x3 modelMatrix = iModelMatrix;
+    float3 worldPos = GetWorldPos(modelMatrix);
+    oPos = GetClipPos(worldPos);
+
+    oTexCoord = GetQuadTexCoord(oPos);
+
+    #ifdef BLUR2
+    oTexCoord = GetQuadTexCoord(oPos) + cBright2Offsets;
+    #endif
+
+    #ifdef BLUR4
+    oTexCoord = GetQuadTexCoord(oPos) + cBright4Offsets;
+    #endif
+
+    #ifdef BLUR8
+    oTexCoord = GetQuadTexCoord(oPos) + cBright8Offsets;
+    #endif
+
+    #ifdef BLUR16
+    oTexCoord = GetQuadTexCoord(oPos) + cBright16Offsets;
+    #endif
+
+    #ifdef COMBINE2
+    oTexCoord = GetQuadTexCoord(oPos) + cBright2Offsets;
+    #endif
+
+    #ifdef COMBINE4
+    oTexCoord = GetQuadTexCoord(oPos) + cBright4Offsets;
+    #endif
+
+    #ifdef COMBINE8
+    oTexCoord = GetQuadTexCoord(oPos) + cBright8Offsets;
+    #endif
+
+    #ifdef COMBINE16
+    oTexCoord = GetQuadTexCoord(oPos) + cBright16Offsets;
+    #endif
+
+    oScreenPos = GetScreenPosPreDiv(oPos);
+}
+
+void PS(float2 iTexCoord : TEXCOORD0,
+    float2 iScreenPos : TEXCOORD1,
+    out float4 oColor : COLOR0)
+{
+    #ifdef BRIGHT
+    float3 color = tex2D(sDiffMap, iScreenPos).rgb;
+    oColor = float4(max(color - cBloomHDRThreshold, 0.0), 1.0);
+    #endif
+
+    #ifdef BLUR16
+    oColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright16InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, iTexCoord);
+    #endif
+
+    #ifdef BLUR8
+    oColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright8InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, iTexCoord);
+    #endif
+
+    #ifdef BLUR4
+    oColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright4InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, iTexCoord);
+    #endif
+
+    #ifdef BLUR2
+    oColor = GaussianBlur(BlurKernelSize, cBloomHDRBlurDir, cBright2InvSize * cBloomHDRBlurRadius, cBloomHDRBlurSigma, sDiffMap, iTexCoord);
+    #endif
+
+    #ifdef COMBINE16
+    oColor = tex2D(sDiffMap, iScreenPos) + tex2D(sNormalMap, iTexCoord);
+    #endif
+
+    #ifdef COMBINE8
+    oColor = tex2D(sDiffMap, iScreenPos) + tex2D(sNormalMap, iTexCoord);
+    #endif
+
+    #ifdef COMBINE4
+    oColor = tex2D(sDiffMap, iScreenPos) + tex2D(sNormalMap, iTexCoord);
+    #endif
+
+    #ifdef COMBINE2
+    float3 color = tex2D(sDiffMap, iScreenPos).rgb * cBloomHDRMix.x;
+    float3 bloom = tex2D(sNormalMap, iTexCoord).rgb * cBloomHDRMix.y;
+    oColor = float4(color + bloom, 1.0);
+    #endif
+}

+ 44 - 0
Bin/CoreData/Shaders/HLSL/Blur.hlsl

@@ -0,0 +1,44 @@
+#include "Uniforms.hlsl"
+#include "Transform.hlsl"
+#include "Samplers.hlsl"
+#include "ScreenPos.hlsl"
+#include "PostProcess.hlsl"
+
+uniform float2 cBlurDir;
+uniform float cBlurRadius;
+uniform float cBlurSigma;
+uniform float2 cBlurHOffsets;
+uniform float2 cBlurHInvSize;
+
+void VS(float4 iPos : POSITION,
+    out float4 oPos : POSITION,
+    out float2 oTexCoord : TEXCOORD0,
+    out float2 oScreenPos : TEXCOORD1)
+{
+    float4x3 modelMatrix = iModelMatrix;
+    float3 worldPos = GetWorldPos(modelMatrix);
+    oPos = GetClipPos(worldPos);
+    oTexCoord = GetQuadTexCoord(oPos) + cBlurHOffsets;
+    oScreenPos = GetScreenPosPreDiv(oPos);
+}
+
+void PS(float2 iTexCoord : TEXCOORD0,
+    float2 iScreenPos : TEXCOORD1,
+    out float4 oColor : COLOR0)
+{
+    #ifdef BLUR3
+        oColor = GaussianBlur(3, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, iTexCoord);
+    #endif
+
+    #ifdef BLUR5
+        oColor = GaussianBlur(5, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, iTexCoord);
+    #endif
+
+    #ifdef BLUR7
+        oColor = GaussianBlur(7, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, iTexCoord);
+    #endif
+
+    #ifdef BLUR9
+        oColor = GaussianBlur(9, cBlurDir, cBlurHInvSize * cBlurRadius, cBlurSigma, sDiffMap, iTexCoord);
+    #endif
+}

+ 22 - 0
Bin/CoreData/Shaders/HLSL/ColorCorrection.hlsl

@@ -0,0 +1,22 @@
+#include "Uniforms.hlsl"
+#include "Transform.hlsl"
+#include "Samplers.hlsl"
+#include "ScreenPos.hlsl"
+#include "PostProcess.hlsl"
+
+void VS(float4 iPos : POSITION,
+    out float4 oPos : POSITION,
+    out float2 oScreenPos : TEXCOORD0)
+{
+    float4x3 modelMatrix = iModelMatrix;
+    float3 worldPos = GetWorldPos(modelMatrix);
+    oPos = GetClipPos(worldPos);
+    oScreenPos = GetScreenPosPreDiv(oPos);
+}
+
+void PS(float2 iScreenPos : TEXCOORD0,
+    out float4 oColor : COLOR0)
+{
+    float3 color = tex2D(sDiffMap, iScreenPos).rgb;
+    oColor = float4(ColorCorrection(color, sVolumeMap), 1.0);
+}

+ 0 - 3
Bin/CoreData/Shaders/HLSL/CopyFrameBuffer.xml

@@ -1,3 +0,0 @@
-<shaders>
-    <shader />
-</shaders>

+ 0 - 0
Bin/CoreData/Shaders/HLSL/CopyFrameBuffer.hlsl → Bin/CoreData/Shaders/HLSL/CopyFramebuffer.hlsl


+ 0 - 17
Bin/CoreData/Shaders/HLSL/DeferredLight.xml

@@ -1,17 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <option name="Ortho" define="ORTHO" />
-        <option name="Dir" define="DIRLIGHT" />
-    </shader>
-    <shader type="ps">
-        <option name="Ortho" define="ORTHO" />
-        <variation name="Dir" define="DIRLIGHT" />
-        <variation name="Spot" define="SPOTLIGHT" />
-        <variation name="Point" define="POINTLIGHT" />
-        <option name="Mask" define="CUBEMASK" require="POINTLIGHT" />
-        <option name="Spec" define="SPECULAR" />
-        <option name="Shadow" define="SHADOW" />
-        <option name="LQ" define="LQSHADOW" require="HWSHADOW" />
-        <option name="HW" define="HWSHADOW" require="SHADOW" />
-    </shader>
-</shaders>

+ 0 - 10
Bin/CoreData/Shaders/HLSL/Depth.xml

@@ -1,10 +0,0 @@
-<shaders>
-    <shader type="vs">
-        <variation name="" />
-        <variation name="Skinned" define="SKINNED" />
-        <variation name="Instanced" define="INSTANCED" require="SM3" />
-    </shader>
-    <shader type="ps">
-        <option name="AlphaMask" define="ALPHAMASK" />
-    </shader>
-</shaders>

+ 0 - 3
Bin/CoreData/Shaders/HLSL/EdgeFilter.xml

@@ -1,3 +0,0 @@
-<shaders>
-    <shader />
-</shaders>

+ 14 - 4
Bin/CoreData/Shaders/HLSL/Fog.hlsl

@@ -1,14 +1,24 @@
-float3 GetFog(float3 color, float depth)
+#ifdef COMPILEPS
+float3 GetFog(float3 color, float fogFactor)
 {
-    return lerp(cFogColor, color, saturate((cFogParams.x - depth) * cFogParams.y));
+    return lerp(cFogColor, color, fogFactor);
 }
 
-float3 GetLitFog(float3 color, float depth)
+float3 GetLitFog(float3 color, float fogFactor)
 {
-    return color * saturate((cFogParams.x - depth) * cFogParams.y);
+    return color * fogFactor;
 }
 
 float GetFogFactor(float depth)
 {
     return saturate((cFogParams.x - depth) * cFogParams.y);
 }
+
+float GetHeightFogFactor(float depth, float height)
+{
+    float fogFactor = GetFogFactor(depth);
+    float heightFogFactor = (height - cFogParams.z) * cFogParams.w;
+    heightFogFactor = 1.0 - saturate(exp(-(heightFogFactor * heightFogFactor)));
+    return min(heightFogFactor, fogFactor);
+}
+#endif

+ 22 - 0
Bin/CoreData/Shaders/HLSL/GammaCorrection.hlsl

@@ -0,0 +1,22 @@
+#include "Uniforms.hlsl"
+#include "Transform.hlsl"
+#include "Samplers.hlsl"
+#include "ScreenPos.hlsl"
+#include "PostProcess.hlsl"
+
+void VS(float4 iPos : POSITION,
+    out float4 oPos : POSITION,
+    out float2 oScreenPos : TEXCOORD0)
+{
+    float4x3 modelMatrix = iModelMatrix;
+    float3 worldPos = GetWorldPos(modelMatrix);
+    oPos = GetClipPos(worldPos);
+    oScreenPos = GetScreenPosPreDiv(oPos);
+}
+
+void PS(float2 iScreenPos : TEXCOORD0,
+    out float4 oColor : COLOR0)
+{
+    float3 color = tex2D(sDiffMap, iScreenPos).rgb;
+    oColor = float4(ToInverseGamma(color), 1.0);
+}

+ 0 - 3
Bin/CoreData/Shaders/HLSL/GreyScale.xml

@@ -1,3 +0,0 @@
-<shaders>
-    <shader />
-</shaders>

+ 54 - 41
Bin/CoreData/Shaders/HLSL/Lighting.hlsl

@@ -1,49 +1,11 @@
 #pragma warning(disable:3571)
 
-float GetDiffuse(float3 normal, float3 lightVec, out float3 lightDir)
-{
-    #ifdef DIRLIGHT
-        #ifdef NORMALMAP
-            // In normal mapped forward lighting, the tangent space light vector needs renormalization
-            lightDir = normalize(lightVec);
-        #else
-            lightDir = lightVec;
-        #endif
-
-        return saturate(dot(normal, lightDir));
-    #else
-        float lightDist = length(lightVec);
-        lightDir = lightVec / lightDist;
-        return saturate(dot(normal, lightDir)) * tex1D(sLightRampMap, lightDist).r;
-    #endif
-}
-
-float GetDiffuseVolumetric(float3 lightVec)
-{
-    #ifdef DIRLIGHT
-        return 1.0;
-    #else
-        float lightDist = length(lightVec);
-        return tex1D(sLightRampMap, lightDist).r;
-    #endif
-}
-
-float GetSpecular(float3 normal, float3 eyeVec, float3 lightDir, float specularPower)
-{
-    float3 halfVec = normalize(normalize(eyeVec) + lightDir);
-    return pow(dot(normal, halfVec), specularPower);
-}
-
+#ifdef COMPILEVS
 float3 GetAmbient(float zonePos)
 {
     return cAmbientStartColor + zonePos * cAmbientEndColor;
 }
 
-float GetIntensity(float3 color)
-{
-    return dot(color, float3(0.333, 0.333, 0.333));
-}
-
 #ifdef NUMVERTEXLIGHTS
 float GetVertexLight(int index, float3 worldPos, float3 normal)
 {
@@ -122,6 +84,56 @@ void GetShadowPos(float4 projWorldPos, out float4 shadowPos[NUMCASCADES])
         shadowPos[0] = float4(projWorldPos.xyz - cLightPos.xyz, 0.0);
     #endif
 }
+#endif
+#endif
+
+#ifdef COMPILEPS
+float GetDiffuse(float3 normal, float3 lightVec, out float3 lightDir)
+{
+    #ifdef DIRLIGHT
+        #ifdef NORMALMAP
+            // In normal mapped forward lighting, the tangent space light vector needs renormalization
+            lightDir = normalize(lightVec);
+        #else
+            lightDir = lightVec;
+        #endif
+
+        return saturate(dot(normal, lightDir));
+    #else
+        float lightDist = length(lightVec);
+        lightDir = lightVec / lightDist;
+        return saturate(dot(normal, lightDir)) * tex1D(sLightRampMap, lightDist).r;
+    #endif
+}
+
+float GetDiffuseVolumetric(float3 lightVec)
+{
+    #ifdef DIRLIGHT
+        return 1.0;
+    #else
+        float lightDist = length(lightVec);
+        return tex1D(sLightRampMap, lightDist).r;
+    #endif
+}
+
+float GetSpecular(float3 normal, float3 eyeVec, float3 lightDir, float specularPower)
+{
+    float3 halfVec = normalize(normalize(eyeVec) + lightDir);
+    return pow(dot(normal, halfVec), specularPower);
+}
+
+float GetIntensity(float3 color)
+{
+    return dot(color, float3(0.333, 0.333, 0.333));
+}
+
+#ifdef SHADOW
+
+#ifdef DIRLIGHT
+    #define NUMCASCADES 4
+#else
+    #define NUMCASCADES 1
+#endif
 
 float GetShadow(float4 shadowPos)
 {
@@ -139,7 +151,7 @@ float GetShadow(float4 shadowPos)
             tex2Dproj(sShadowMap, float4(shadowPos.x, shadowPos.y + offsets.y, shadowPos.zw)).r,
             tex2Dproj(sShadowMap, float4(shadowPos.xy + offsets.xy, shadowPos.zw)).r
         );
-        #ifdef HWSHADOW
+        #ifndef SHADOWCMP
             return cShadowIntensity.y + dot(inLight, cShadowIntensity.x);
         #else
             #ifndef POINTLIGHT
@@ -151,7 +163,7 @@ float GetShadow(float4 shadowPos)
     #else
         // Take one sample
         float inLight = tex2Dproj(sShadowMap, shadowPos).r;
-        #ifdef HWSHADOW
+        #ifndef SHADOWCMP
             return cShadowIntensity.y + cShadowIntensity.x * inLight;
         #else
             #ifndef POINTLIGHT
@@ -256,4 +268,5 @@ float GetShadowDeferred(float4 projWorldPos, float depth)
         return GetPointShadow(shadowPos);
     #endif
 }
+#endif
 #endif

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