Page 1 of 1

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

Posted: Thu Jun 28, 2018 5:05 am
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()


Re: Help with applying Shader on love.graphics shapes

Posted: Thu Jun 28, 2018 5:16 am
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)

Re: Help with applying Shader on love.graphics shapes

Posted: Fri Jun 29, 2018 12:20 am
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;
  }

  ]]