+ properly set g_Time for shaders

+ properly set g_TextureXResolution for shaders
+ properly set g_TextureX for shaders
+ properly set g_TextureXRotation for shaders

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
Alexis Maiquez 2021-08-08 02:02:17 +02:00
parent 2673179909
commit 4309ca722d
4 changed files with 41 additions and 60 deletions

View File

@ -19,6 +19,7 @@ enum BACKGROUND_RUN_MODE
}; };
WallpaperEngine::Irrlicht::CContext* IrrlichtContext = nullptr; WallpaperEngine::Irrlicht::CContext* IrrlichtContext = nullptr;
irr::f32 g_Time;
void print_help (const char* route) void print_help (const char* route)
{ {
@ -195,6 +196,7 @@ int main (int argc, char* argv[])
continue; continue;
startTime = IrrlichtContext->getDevice ()->getTimer ()->getTime (); startTime = IrrlichtContext->getDevice ()->getTimer ()->getTime ();
g_Time = startTime / 1000.0f;
IrrlichtContext->renderFrame (wallpaper); IrrlichtContext->renderFrame (wallpaper);

View File

@ -3,8 +3,6 @@
using namespace WallpaperEngine; using namespace WallpaperEngine;
using namespace WallpaperEngine::Render::Objects; using namespace WallpaperEngine::Render::Objects;
extern irr::f32 g_Time;
CImage::CImage (CScene* scene, Core::Objects::CImage* image) : CImage::CImage (CScene* scene, Core::Objects::CImage* image) :
Render::CObject (scene, Type, image), Render::CObject (scene, Type, image),
m_image (image) m_image (image)
@ -150,7 +148,7 @@ void CImage::generateMaterial (irr::video::ITexture* resultTexture)
this->m_irrlichtMaterial.setFlag (irr::video::EMF_BLEND_OPERATION, true); this->m_irrlichtMaterial.setFlag (irr::video::EMF_BLEND_OPERATION, true);
this->m_irrlichtMaterial.Wireframe = false; this->m_irrlichtMaterial.Wireframe = false;
this->m_irrlichtMaterial.Lighting = false; this->m_irrlichtMaterial.Lighting = false;
/// TODO: XXXHACK: This material is used to flip textures upside down based on the amount of passes /// TODO: XXXHACK: This material is used to flip textures upside down based on the amount of passes
/// TODO: XXXHACK: This fixes an issue with opengl render that I had no better idea of how to solve /// TODO: XXXHACK: This fixes an issue with opengl render that I had no better idea of how to solve
/// TODO: XXXHACK: For the love of god, If you have a better fix, please LET ME KNOW! /// TODO: XXXHACK: For the love of god, If you have a better fix, please LET ME KNOW!

View File

@ -19,6 +19,8 @@ using namespace WallpaperEngine::Render::Shaders::Variables;
using namespace WallpaperEngine::Render::Objects::Effects; using namespace WallpaperEngine::Render::Objects::Effects;
extern irr::f32 g_Time;
CPass::CPass (Irrlicht::CContext* context, CMaterial* material, Core::Objects::Images::Materials::CPass* pass, irr::video::ITexture* texture) : CPass::CPass (Irrlicht::CContext* context, CMaterial* material, Core::Objects::Images::Materials::CPass* pass, irr::video::ITexture* texture) :
m_material (material), m_material (material),
m_pass (pass), m_pass (pass),
@ -79,35 +81,8 @@ const irr::video::SMaterial& CPass::getMaterial () const
void CPass::OnSetConstants (irr::video::IMaterialRendererServices *services, int32_t userData) void CPass::OnSetConstants (irr::video::IMaterialRendererServices *services, int32_t userData)
{ {
irr::f32 g_Texture0 = 0;
irr::f32 g_Texture1 = 1;
irr::f32 g_Texture2 = 2;
irr::f32 g_Texture3 = 3;
irr::f32 g_Texture4 = 4;
irr::f32 g_Texture5 = 5;
irr::f32 g_Texture6 = 6;
irr::f32 g_Texture7 = 7;
const Core::Objects::CImage* image = this->m_material->getImage ()->getImage (); const Core::Objects::CImage* image = this->m_material->getImage ()->getImage ();
irr::f32 g_Texture0Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z };
irr::f32 g_Texture1Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z };
irr::f32 g_Texture2Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z };
irr::f32 g_Texture3Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z };
irr::f32 g_Texture4Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z };
irr::f32 g_Texture5Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z };
irr::f32 g_Texture6Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z };
irr::f32 g_Texture7Rotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z };
irr::f32 g_Texture0Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y };
irr::f32 g_Texture1Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y };
irr::f32 g_Texture2Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y };
irr::f32 g_Texture3Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y };
irr::f32 g_Texture4Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y };
irr::f32 g_Texture5Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y };
irr::f32 g_Texture6Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y };
irr::f32 g_Texture7Resolution [4] = { image->getSize ().X, image->getSize ().Y, image->getSize ().X, image->getSize ().Y };
irr::video::IVideoDriver* driver = services->getVideoDriver (); irr::video::IVideoDriver* driver = services->getVideoDriver ();
irr::core::matrix4 worldViewProj; irr::core::matrix4 worldViewProj;
@ -191,32 +166,35 @@ void CPass::OnSetConstants (irr::video::IMaterialRendererServices *services, int
services->setVertexShaderConstant ("g_ModelViewProjectionMatrix", worldViewProj.pointer(), 16); services->setVertexShaderConstant ("g_ModelViewProjectionMatrix", worldViewProj.pointer(), 16);
services->setVertexShaderConstant ("g_Texture0Resolution", g_Texture0Resolution, 4); auto textureCur = this->m_textures.begin ();
services->setVertexShaderConstant ("g_Texture1Resolution", g_Texture1Resolution, 4); auto textureEnd = this->m_textures.end ();
services->setVertexShaderConstant ("g_Texture2Resolution", g_Texture2Resolution, 4);
services->setVertexShaderConstant ("g_Texture3Resolution", g_Texture3Resolution, 4);
services->setVertexShaderConstant ("g_Texture4Resolution", g_Texture4Resolution, 4);
services->setVertexShaderConstant ("g_Texture5Resolution", g_Texture5Resolution, 4);
services->setVertexShaderConstant ("g_Texture6Resolution", g_Texture6Resolution, 4);
services->setVertexShaderConstant ("g_Texture7Resolution", g_Texture7Resolution, 4);
services->setVertexShaderConstant ("g_Texture0Rotation", g_Texture0Rotation, 4); char resolution [22];
services->setVertexShaderConstant ("g_Texture1Rotation", g_Texture1Rotation, 4); char sampler [12];
services->setVertexShaderConstant ("g_Texture2Rotation", g_Texture2Rotation, 4); char rotation [20];
services->setVertexShaderConstant ("g_Texture3Rotation", g_Texture3Rotation, 4);
services->setVertexShaderConstant ("g_Texture4Rotation", g_Texture4Rotation, 4);
services->setVertexShaderConstant ("g_Texture5Rotation", g_Texture5Rotation, 4);
services->setVertexShaderConstant ("g_Texture6Rotation", g_Texture6Rotation, 4);
services->setVertexShaderConstant ("g_Texture7Rotation", g_Texture7Rotation, 4);
services->setPixelShaderConstant ("g_Texture0", &g_Texture0, 1); irr::f32 textureRotation [4] = { image->getAngles ().X, image->getAngles ().Y, image->getAngles ().Z, image->getAngles ().Z };
services->setPixelShaderConstant ("g_Texture1", &g_Texture1, 1);
services->setPixelShaderConstant ("g_Texture2", &g_Texture2, 1); for (int index = 0; textureCur != textureEnd; textureCur ++, index ++)
services->setPixelShaderConstant ("g_Texture3", &g_Texture3, 1); {
services->setPixelShaderConstant ("g_Texture4", &g_Texture4, 1); irr::s32 textureResolution [4] = {
services->setPixelShaderConstant ("g_Texture5", &g_Texture5, 1); static_cast<irr::s32>((*textureCur)->getSize ().Width),
services->setPixelShaderConstant ("g_Texture6", &g_Texture6, 1); static_cast<irr::s32>((*textureCur)->getSize ().Height),
services->setPixelShaderConstant ("g_Texture7", &g_Texture7, 1); 1, 1
};
sprintf (resolution, "g_Texture%dResolution", index);
sprintf (sampler, "g_Texture%d", index);
sprintf (rotation, "g_Texture%dRotation", index);
services->setVertexShaderConstant (resolution, textureResolution, 4);
services->setPixelShaderConstant (sampler, &index, 1);
services->setVertexShaderConstant (rotation, textureRotation, 4);
}
// set variables for time
services->setVertexShaderConstant ("g_Time", &g_Time, 1);
services->setPixelShaderConstant ("g_Time", &g_Time, 1);
} }
void CPass::setupShaderVariables () void CPass::setupShaderVariables ()
@ -271,15 +249,16 @@ void CPass::setupTextures ()
for (int textureNumber = 0; textureCur != textureEnd; textureCur ++, textureNumber ++) for (int textureNumber = 0; textureCur != textureEnd; textureCur ++, textureNumber ++)
{ {
irr::video::ITexture* texture = this->m_inputTexture;
// XXXHACK: TODO: PROPERLY DETECT WHERE THE INPUT TEXTURE SHOULD BE USED IN THE SHADER GRAPH // XXXHACK: TODO: PROPERLY DETECT WHERE THE INPUT TEXTURE SHOULD BE USED IN THE SHADER GRAPH
if (textureNumber == 0) if (textureNumber != 0)
this->m_irrlichtMaterial.setTexture (0, this->m_inputTexture);
else
{ {
irr::io::path texturepath = this->m_context->resolveMaterials (*textureCur); irr::io::path texturepath = this->m_context->resolveMaterials (*textureCur);
irr::video::ITexture* texture = this->m_context->getDevice ()->getVideoDriver ()->getTexture (texturepath); texture = this->m_context->getDevice ()->getVideoDriver ()->getTexture (texturepath);
this->m_irrlichtMaterial.setTexture (textureNumber, texture);
} }
this->m_irrlichtMaterial.setTexture (textureNumber, texture);
this->m_textures.push_back (texture);
} }
} }

View File

@ -38,5 +38,7 @@ namespace WallpaperEngine::Render::Objects::Effects
Render::Shaders::Compiler* m_fragShader; Render::Shaders::Compiler* m_fragShader;
Render::Shaders::Compiler* m_vertShader; Render::Shaders::Compiler* m_vertShader;
std::vector<irr::video::ITexture*> m_textures;
}; };
} }