shadmar Posted May 9, 2014 Share Posted May 9, 2014 I'm trying to make a little effect class which I can easily add lua shaders in c++ This is what I got so far (this is not for framework or anything like that) #define BLOOMSHADER "Shadmar_Shaders/08_PP_Bloom.lua" using namespace Leadwerks; class Bloom { private: float m_luminance; float m_middlegray; float m_whitecutoff; std::string m_shader; Camera* m_camera; public: Bloom(); Bloom(Camera* camera); Bloom(Camera* camera, std::string shader); ~Bloom(){}; void SetParams(float lum, float midgray, float cutoff); const std::string default_shader = BLOOMSHADER; }; In my app I can then do : Camera* camera = Camera::Create(); Bloom BloomEffect(camera); BloomEffect.SetParams(0.06, 0.5, 0.9); SetParams() also works runtime for adjusting the stuff on the fly. This works and all, but then I got 6 more shaders where the class would look almost the same. Shadername would change and parameters for it. Any tip? or I just make copies of my class and change names and parameters for each shader? Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Rick Posted May 9, 2014 Share Posted May 9, 2014 I think the shader name should be inside the class itself since the shader is basically the reason for the class. Also more options for setting properties on their own instead of 1 since a person might want to alter just 1 property instead of all of them. Other than that, I think you just make copies (you could make a base class that has the camera & shader variable inside of it and inherit those since all effects would require those, but that's not that big of a deal. Someone might point out that you could just have set property with a string for key/value, but I'd point out the benefit here is that VS will tell you what properties are available per effect where using just string key names doesn't and you'd have to look them up which would be a pain. Also, when are you thinking of actually applying the effect to the camera? I may want to make an instance at startup but not actually apply it until later on when something happens to the player that should cause the effect. Something to think about. Getter for each parameter would be nice too so we can use it to add/subtract to. 1 Quote Link to comment Share on other sites More sharing options...
shadmar Posted May 10, 2014 Author Share Posted May 10, 2014 Thanks so this would be a nice way to do it then : class Bloom { private: float m_luminance; float m_middlegray; float m_whitecutoff; std::string m_shader; Camera* m_camera; public: Bloom(); Bloom(Camera* camera); Bloom(Camera* camera, bool active); Bloom(Camera* camera, bool active, std::string shader); ~Bloom(){}; void Activate(); void SetParams(const float lum, const float midgray, const float cutoff); void SetLuminance(const float lum); void SetMiddlegray(const float midgray); void SetCutOff(const float cutoff); const float GetLuminance() { return m_luminance; } const float GetMiddlegray() { return m_middlegray; } const float GetCutOff() { return m_whitecutoff; } const std::string default_shader = "Shadmar_Shaders/08_PP_Bloom.lua"; }; In my app I then do Bloom* mybloom = new Bloom(camera, false); mybloom->SetParams(0.06, 0.5, 0.9); mybloom->Activate(); mybloom->SetLuminance(0.1); Runtime : mybloom->SetLuminance(mybloom->GetLuminance() - 0.001); Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
shadmar Posted May 10, 2014 Author Share Posted May 10, 2014 Ok added 2 classes to the git repository along with shaders. Let me know if it works out or not or I'm going about the wrong way. https://github.com/Aggror/LeadwerksRenderFramework Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Rick Posted May 10, 2014 Share Posted May 10, 2014 I would also add an activate that takes a camera parameter also. This would allow someone to not have to make a pointer to the class or require a camera when the class is created and activate it later. This is how I see I would use this because there wouldn't be anything to clean up when my class goes out of scope since it won't be a pointer. class My Class { private: Bloom myBloom public: void Update(window* window, Camera* camera) { if(window->KeyHit(Key::A)) { myBloom.SetParams(5, 3, 1); myBloom.Activate(camera); } } }; Quote Link to comment Share on other sites More sharing options...
shadmar Posted May 10, 2014 Author Share Posted May 10, 2014 Death effect using DOF dof->SetFarStart(std::max(dof->GetFarStart() - 0.75, 0.0)); dof->SetFarDist(std::max(dof->GetFarDist() - 0.75, 0.0)); dof->SetVinetteInnerBorder(std::max(dof->GetVinetteInnerBorder()-0.01,-1.0)); dof->SetVinetteOuterBorder(std::max(dof->GetVinetteOuterBorder()-0.01,0.0)); Image Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.