neseir Posted February 25, 2014 Share Posted February 25, 2014 Hi I'm trying to modify one of the standard shaders to accept one more Vec2 parameter. In the fragment part of the shader I have added : in vec2 my_offset; Settings this vector to different values changes the offset drawing the texture from the material (offset values added to the texture coordinates) in the material editor works fine. The problem is how to access this input Vector from the lua code. I have added a part witch loads a material and connects the same shader i used in the material editor (from the Start function after the map is loaded) : --Load a material local material = Material:Load("Materials/Mine/greystuff.mat") self.shader = Shader:Load("Shaders/Model/mydefault.shader") material:SetShader(self.shader) -- self.shader:Release() --Create a model local model = Model:Sphere() model:SetMaterial(material) model:SetPosition(0,3,0) self.roll = Vec2(0.0, 0.0) In the app function i have added (before the world:Update()) : self.roll.y = self.roll.y + 0.001 self.shader:SetVec2("my_offset", self.roll) But the texture is not moving. Is this the proper way of doing this ? I found some code doing this in an earlier relase of Leadwerks but it was in C and I'm not sure if I got this wrong trying to translate to lua (think he was using SetShaderVec2 instead of Shader:SetVec2). BR Eirik Quote Link to comment Share on other sites More sharing options...
shadmar Posted February 25, 2014 Share Posted February 25, 2014 Hard to tell without seeing mydefault.shader Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Rastar Posted February 25, 2014 Share Posted February 25, 2014 If you specify that variable as "in vec2" it is supposed to be a vertex attribute, ie have a different value per vertex. However, the Shader:SetXY() methods set shader uniforms. So I guess, in your case you should define that as uniform vec2 my_offset; Quote Link to comment Share on other sites More sharing options...
neseir Posted February 25, 2014 Author Share Posted February 25, 2014 Hi Thanks, I did not notice that when I tested this. Will check this and update with more information when I'm home again. Regards Eirik Quote Link to comment Share on other sites More sharing options...
neseir Posted February 25, 2014 Author Share Posted February 25, 2014 Hi @Rastar: Did as You said and it worked perfectly. Thanks BR Eirik Quote 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.