Help with applying Shader on love.graphics shapes[SOLVED!]

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
BruceTheGoose
Citizen
Posts: 76
Joined: Sat Sep 20, 2014 2:54 pm

Help with applying Shader on love.graphics shapes[SOLVED!]

Post by BruceTheGoose »

Hi! I found this shader and I'm trying to modify it to work on love's built-in shape functions. I'm not very familiar with GLSL and would like assistance on this problem. Thank you! :awesome:

Here is some code:

Code: Select all


-- Shader Code
 Distortion = love.graphics.newShader([[

    extern number time;
    extern number size;

    vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords){
    
      vec2 p = texture_coords;
      p.x = p.x + .1 * cos(p.y * size + time) ;
      p.y = p.y + .1 * sin(p.y * size + time) ;
    
      return Texel(texture,p);
    }

  ]]
  
  -- ....
  
  -- in love.draw method
  love.graphics.setShader(Distortion)
  
 
    love.graphics.draw(penguin,Screen.mouseX - penguin:getWidth()/4,Screen.mouseY- penguin:getHeight()/4,0,0.5,0.5)
  
    love.graphics.circle("fill",Screen.mouseX ,Screen.mouseY,100)

    love.graphics.circle("line",Screen.mouseX ,Screen.mouseY,150)

	
love.graphics.setShader()

Attachments
Shaders Test.love.zip
(12.28 KiB) Downloaded 54 times
Last edited by BruceTheGoose on Fri Jun 29, 2018 3:05 am, edited 1 time in total.
"I don't know."
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Help with applying Shader on love.graphics shapes

Post by zorg »

Just a hunch, but that distortion shader works on pixels of a texture, and distorts those; what you want is a vertex shader basically, since the löve builtin shapes aren't textured. (or just use a 1x1 px blank image as texture for a mesh of your creation and shape, and use the shader you found)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
BruceTheGoose
Citizen
Posts: 76
Joined: Sat Sep 20, 2014 2:54 pm

Re: Help with applying Shader on love.graphics shapes

Post by BruceTheGoose »

Aha! Thank you so much! :awesome:

Here's the updated shader:

Code: Select all

[[

  varying vec4 v_pos;

  extern number time;

  vec4 position( mat4 transform_projection, vec4 vertex_position ){

    v_pos = vertex_position ;

    v_pos.x = v_pos.x +  2.0 *  cos(v_pos.x * 20.0 + time);
    v_pos.y = v_pos.y +  2.0 *  sin(v_pos.y * 20.0 + time);

    return transform_projection * v_pos;
  }

  ]]
  
"I don't know."
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 48 guests