Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Accessing neighbouring textures in current mesh in a shader

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2018
    Posts
    4

    Accessing neighbouring textures in current mesh in a shader

    Hi

    I wish to get information from a texture adjacent to the current "texture" in a fragment shader - i.e. from faces (triangles/quads) which share an edge with the current face.

    I know it isn't possible directly from a fragment shader, of course. But I think the information could be passed to the fragment shader from the vertex shader.

    Can the vertex shader access information about textures from adjacent faces directly - or would I need to implement a geometry shader to somehow orchestrate this?

    Thanks

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,327
    Using the standard pipeline, no, the vertex and fragment shader aren't provided information about the adjacent faces/vertices.

    You can create special batches with adjacency vertices to send down the pipe and process specially with a geometry shader (see tutorials on GL_TRIANGLES_ADJACENCY and GL_TRIANGLE_STRIP_ADJACENCY). That might give you what you want, but it depends on your requirements.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2018
    Posts
    4
    My requirements... I'm writing a parallax occlusion shader which supports real silhouettes at texture edges. There are problems when a texture meets another texture which does not tile with it (specifically, the height maps do not tile).

    That's a general problem with any parallax shader - normally they produce more-or-less nonsense at boundaries - but more so when you support real silhouettes, as you can also see straight through holes at certain angles. I'm considering various strategies to get artifact-free and natural looking boundaries. The bare minimum would be to determine if the adjacent texture is tileable with the current one, and if not, apply a fudge where the height maps are interpolated towards (say) 0.5 as you approach the edge, which of course needs the shader to have some image metadata passed to it about both the current texture and its neighbours.

    A gold-standard solution would actually composite-blend the two textures according to their height maps and work off the resulting composite height map - something which probably requires an off-line mesh processing stage, though it would be nice to be able to do it at runtime if there was a practical means.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,734
    The vertex shader only gets passed information about individual vertices, unrelated to the primitives to which they belong. When a vertex is common to multiple primitives, the vertex shader may only be invoked once, so it can't receive any information about specific primitives (e.g. for a triangle fan, the centre vertex is common to every triangle). And it can't pass out information which wasn't passed in.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •