瀏覽代碼

~ Fixed switched vertex and pixel shaders on effects. This effectively renders the water effect properly for the nier automata background
~ Updated shader pre-compiler to use the irrlicht functions to read the shaders from

Signed-off-by: Alexis Maiquez Murcia <almamu@almamu.com>

Alexis Maiquez Murcia 7 年之前
父節點
當前提交
83caa05ebf
共有 4 個文件被更改,包括 23 次插入 和 54 次删除
  1. 15 45
      main.cpp
  2. 3 3
      wallpaperengine/effect.cpp
  3. 4 5
      wallpaperengine/shaders/compiler.cpp
  4. 1 1
      wallpaperengine/shaders/compiler.h

+ 15 - 45
main.cpp

@@ -14,52 +14,8 @@
 int WinID = 0;
 irr::SIrrlichtCreationParameters _irr_params;
 
-irr::f32 g_AnimationSpeed = 0.1f;
-irr::f32 g_Scale = 2.5f;
-irr::f32 g_ScrollSpeed = 0.0f;
-irr::f32 g_Direction = 0.0f;
-irr::f32 g_Strength = 0.07f;
-irr::f32 g_SpecularPower = 1.0f;
-irr::f32 g_SpecularStrength = 1.0f;
-irr::f32 g_SpecularColor [3] = {1.0f, 1.0f, 1.0f};
-irr::f32 g_Texture1Resolution [4] = {1.0f, 1.0f, 1.0f, 1.0f};
-irr::f32 g_Texture0 = 0;
-irr::f32 g_Texture1 = 1;
-irr::f32 g_Texture2 = 2;
 irr::f32 g_Time = 0;
 
-class MyShaderCallback : public irr::video::IShaderConstantSetCallBack
-{
-    virtual void OnSetConstants (irr::video::IMaterialRendererServices* services, int32_t userData)
-    {
-        irr::video::IVideoDriver* driver = services->getVideoDriver ();
-
-        irr::core::matrix4 worldViewProj;
-        worldViewProj = driver->getTransform(irr::video::ETS_PROJECTION);
-        worldViewProj *= driver->getTransform(irr::video::ETS_VIEW);
-        worldViewProj *= driver->getTransform(irr::video::ETS_WORLD);
-
-        services->setVertexShaderConstant ("g_AnimationSpeed", &g_AnimationSpeed, 1);
-        services->setVertexShaderConstant ("g_Scale", &g_Scale, 1);
-        services->setVertexShaderConstant ("g_ScrollSpeed", &g_ScrollSpeed, 1);
-        services->setVertexShaderConstant ("g_Direction", &g_Direction, 1);
-        services->setVertexShaderConstant ("g_Time", &g_Time, 1);
-        services->setVertexShaderConstant ("g_ModelViewProjectionMatrix", worldViewProj.pointer(), 16);
-        services->setVertexShaderConstant ("g_Texture0Resolution", &g_Texture1Resolution [0], 4);
-        services->setVertexShaderConstant ("g_Texture1Resolution", &g_Texture1Resolution [1], 4);
-        services->setVertexShaderConstant ("g_Texture2Resolution", &g_Texture1Resolution [2], 4);
-
-        // TODO: Support up to 7 materials (as wallpaper engine)
-        services->setPixelShaderConstant ("g_Strength", &g_Strength, 1);
-        services->setPixelShaderConstant ("g_SpecularPower", &g_SpecularPower, 1);
-        services->setPixelShaderConstant ("g_SpecularStrength", &g_SpecularStrength, 1);
-        services->setPixelShaderConstant ("g_SpecularColor", g_SpecularColor, 3);
-        services->setPixelShaderConstant ("g_Texture0", &g_Texture0, 1);
-        services->setPixelShaderConstant ("g_Texture1", &g_Texture1, 1);
-        services->setPixelShaderConstant ("g_Texture2", &g_Texture2, 1);
-    }
-};
-
 int init_irrlicht()
 {
     // prepare basic configuration for irrlicht
@@ -90,6 +46,21 @@ int init_irrlicht()
     wp::irrlicht::device->setWindowCaption (L"Test game");
     wp::irrlicht::driver = wp::irrlicht::device->getVideoDriver();
 
+    // check for ps and vs support
+    if (
+            wp::irrlicht::driver->queryFeature (irr::video::EVDF_PIXEL_SHADER_1_1) == false &&
+            wp::irrlicht::driver->queryFeature (irr::video::EVDF_ARB_FRAGMENT_PROGRAM_1) == false)
+    {
+        wp::irrlicht::device->getLogger ()->log ("WARNING: Pixel shaders disabled because of missing driver/hardware support");
+    }
+
+    if (
+            wp::irrlicht::driver->queryFeature (irr::video::EVDF_VERTEX_SHADER_1_1) == false &&
+            wp::irrlicht::driver->queryFeature (irr::video::EVDF_ARB_VERTEX_PROGRAM_1) == false)
+    {
+        wp::irrlicht::device->getLogger ()->log ("WARNING: Vertex shaders disabled because of missing driver/hardware support");
+    }
+
     return 0;
 }
 
@@ -112,7 +83,6 @@ int main (int argc, char* argv[])
 
     printf ("Initializing X11 to %d\n", WinID);
 
-
     if (init_irrlicht())
     {
         return 1;

+ 3 - 3
wallpaperengine/effect.cpp

@@ -90,10 +90,10 @@ namespace wp
             wp::shaders::compiler* fragcompiler = new wp::shaders::compiler (fragpath, wp::shaders::compiler::Type::Type_Pixel, false);
             wp::shaders::compiler* vertcompiler = new wp::shaders::compiler (vertpath, wp::shaders::compiler::Type::Type_Vertex, false);
 
-            wp::irrlicht::driver->getGPUProgrammingServices ()
+            this->m_materialType = wp::irrlicht::driver->getGPUProgrammingServices ()
                 ->addHighLevelShaderMaterial (
-                    fragcompiler->precompile ().c_str (), "main", irr::video::EVST_VS_2_0,
-                    vertcompiler->precompile ().c_str (), "main", irr::video::EPST_PS_2_0,
+                    vertcompiler->precompile ().c_str (), "main", irr::video::EVST_VS_2_0,
+                    fragcompiler->precompile ().c_str (), "main", irr::video::EPST_PS_2_0,
                     this, irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL, 0, irr::video::EGSL_DEFAULT
                 );
 

+ 4 - 5
wallpaperengine/shaders/compiler.cpp

@@ -19,7 +19,7 @@ namespace wp
 {
     namespace shaders
     {
-        compiler::compiler (irr::io::path file, Type type, bool recursive)
+        compiler::compiler (irr::io::path& file, Type type, bool recursive)
         {
             // begin with an space so it gets ignored properly on parse
             if (recursive == false)
@@ -41,15 +41,14 @@ namespace wp
                                     "#define atan2 atan\n"
                                     "#define ddx dFdx\n"
                                     "#define ddy(x) dFdy(-(x))\n"
-                                    "#define GLSL 1\n";
+                                    "#define GLSL 1\n\n";
             }
             else
             {
                 this->m_content = "";
             }
 
-            std::ifstream _in (file.c_str ());
-            this->m_content.append (std::istreambuf_iterator<char> (_in), std::istreambuf_iterator<char> ());
+            this->m_content.append (wp::fs::utils::loadFullFile (file));
 
             // append file content
             this->m_type = type;
@@ -235,7 +234,7 @@ namespace wp
 
         std::string compiler::precompile()
         {
-        #define BREAK_IF_ERROR if (this->m_error == true) { wp::irrlicht::device->getLogger ()->log ("ERROR COMPILING SHADER"); wp::irrlicht::device->getLogger ()->log (this->m_errorInfo.c_str ()); return ""; }
+        #define BREAK_IF_ERROR if (this->m_error == true) { wp::irrlicht::device->getLogger ()->log ("ERROR PRE-COMPILING SHADER"); wp::irrlicht::device->getLogger ()->log (this->m_errorInfo.c_str ()); return ""; }
             // parse the shader and find #includes and such things and translate them to the correct name
             // also remove any #version definition to prevent errors
             std::string::const_iterator it = this->m_content.begin ();

+ 1 - 1
wallpaperengine/shaders/compiler.h

@@ -62,7 +62,7 @@ namespace wp
              * @param type The type of shader
              * @param recursive Whether the compiler should add base definitions or not
              */
-            compiler (irr::io::path file, Type type, bool recursive = false);
+            compiler (irr::io::path& file, Type type, bool recursive = false);
             /**
              * Performs the actual pre-compilation/pre-processing over the shader files
              * This step is kinda big, replaces variables names on sVariableReplacement,