Jump to content

Passing Vec2 to fragment shader


neseir
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...