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

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.

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.

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.