Scrolling textures ?

jimjim
edited September 2013 in Help request
I was searching of easy 2d water effects and found that texture scrolling along with tiling/repeating can be used to make simple water effects.

So far I have not found anything related to texture scrolling in the forum.

This video demonstrates simple water effect with texture scrolling

As, we can provide our own mesh or vertex list, with scrolling and mesh, the following effect would not be impossible I guess

Detailed description is give here,
http://avatars.imvu.com/shop/includes/iframe_product_description.php?products_id=6820597

Comments

  • edited September 2013
    I bet a simple shader should do the job just fine.
  • jimjim
    edited September 2013
    Thing is, when I search this on the net, most of the places they have done this by offseting UV.
  • jimjim
    edited September 2013
    okay, I have found a shader code that probably does the job,
    http://stackoverflow.com/questions/10847985/glsl-shader-that-scroll-texture
  • edited September 2013
    You already have your answers but I thought I'd give some precisions:
    - for meshes you're drawing yourself with orxDisplay_DrawMesh(), you can easily change the UVs per vertex.
    - for those meshes or any rendered object, really, a simple shader similar to what you've found can be used and it's probably the best/easiest way to do it as you can do much more than just changing the UVs

    However, even if you can manually set the texture wrapping to repeat, I wouldn't do that: that means you can't use a texture atlas/spritesheet, which means you can't batch that rendering with other objects.

    That being said, orx will add some variables to your shaders givin the UV values for the top left and bottom right corners.
    With those, you can simulate repetition as much as you want.

    For example, try pasting that at the end of code/bin/BounceAlt.ini :)
    [Wall1]
    ShaderList = @
    Code = "void main()
    {
      const vec2 vSize   = vec2(texture_right - texture_left, texture_bottom - texture_top);
      const vec2 vOrigin = vec2(texture_left, texture_top);
    
      // Gets original UV coordinates
      vec2 vUV = gl_TexCoord[0].xy;
    
      // Removes origin offset
      vUV = vUV - vOrigin;
    
      // Applies scrolling & wraps around
      vUV = mod(vUV + vec2(time) * speed, vSize);
    
      // Re-applies origin offset
      vUV = vUV + vOrigin;
    
      // Updates output pixel
      gl_FragColor = texture2D(texture, vUV).rgba;
    }"
    ParamList = texture # time # speed
    time = time
    speed = (0, -2, 0)
    
    [Wall2@Wall1]
    speed = (0, -1, 0)
    
    [Wall3@Wall1]
    speed = (1, 0, 0)
    
    [Wall4@Wall1]
    speed = (0.5, 0, 0)
    
  • jimjim
    edited September 2013
    I tried to add the code, but could not see any noticeable difference, with or with this code. what does it suppose to do ?
  • edited September 2013
    All the walls should have scrolling textures, in different directions.

    If it's not working, you should check the debug log (assuming you're running in debug) for any errors, potentially shader compilation ones.
  • jimjim
    edited September 2013
    Hmm, I am getting an error, this might help
    [21:03:00] [DISPLAY] [orxTexture.c:orxTexture_CreateFromFile():651] Failed to lo
    ad bitmap [time] and link it to texture.
    [21:03:00] [DISPLAY] [orxDisplay.c:orxDisplay_GLFW_CompileShader():795] Couldn't
     compile fragment shader:
    ERROR: 0:10: '=' :  assigning non-constant to 'const 2-component vector of float
    '
    ERROR: 0:11: '=' :  assigning non-constant to 'const 2-component vector of float
    '
    

    Edit: I am providing you the whole debug log here http://pastebin.com/VhfbbWph
  • edited September 2013
    First thing I'd try removing the const attribute from the vectors inside the shader code.

    Then it looks like it's not defining the time property correctly, which means that either your copy/paste from here to the config file isn't complete or that you're using an old version, prior to April 2013.
  • jimjim
    edited September 2013
    No, I was using the latest, and mingw build with externs from mingw branch. Afaik I copy/pasted it right, I will check again, once I get to home.
  • jimjim
    edited September 2013
    Yeah, removing the const does the trick, its cool that it is so simple to do, and I definitely need to learn some shader.
  • edited September 2013
    Glad it works.
    Weird that it tries to create a texture named time though, I'll look into it. :)
Sign In or Register to comment.