OpenGL ES 2.0: Is there a workaround for missing texture access in vertex shader?
Asked Answered
B

1

6

I'm currently trying out some OpenGL ES 2.0 with Android for a game. My map is a 2d grid map with a heights value for every position. Now I wanted to store the heights of each coordinate in a texture to do the height lookup in the vertex shader.

The benefit of this idea would be that I can generate a generic triangle net and place it (with an offset) on the position of the map the user is currently looking at. Due to the offset I can omit the need to create a new triangle net every time the user moves its view position and the height profile I would read from the texture.

Now there is the problem that many current Android devices (even the Galaxy S3) do not support texture lookups in the vertex shader. Sadly this totally destroys my current approach.

My question: Is there any other possibility to fetch data from the graphic card's memory in the vertex shader? Without specifying the data for each vertex directly, what would force me (as far as I know) to recreate the heights map each time the user changes the view position. (Creating the heights map every time the user changes the view position is to slow...)

Thank you for your help + best regards,

Andreas

Buchheim answered 22/1, 2013 at 16:12 Comment(3)
I haven't tried texture lookups in vertex shader myself but the documentation states; Texture lookup functions are available to both vertex and fragment shaders. OpenGL ES Shading Language specification 1.00 rev 17.Headcloth
Sadly there seems to be a backdoor. See this thread #11398614 They just specify to have zero GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS.Buchheim
I worked around this limitation when doing RGB histogram generation on iOS by feeding in image pixels as vertex data, but that won't be much help here. Would it be that much of a loss in your case to just send in the vertex data instead of trying to translate vertices based on a height map?Prickly
L
3

texture2DLod() function is meant to be used to do texture lookups in vertex shaders.

Please refer to section 8.7 Texture Lookup Functions of GLSL ES specs.

According to andy's comment, don't forget to check GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS before using texture2DLod(). If vertex texture lookup is not supported, you should fall back to another shader without this feature.

Leaving answered 24/1, 2013 at 13:57 Comment(3)
The issue is, that even most current high end smartphones do not have any vertex shader with texture access. Therefore it makes no sence to use textures in the vertex shader if almost no device can use this.Buchheim
@Buchheim Unfortunately you are right. That's why if you need to use vertex texture fetch, you should check GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS first.Leaving
@Leaving You're effectively saying "the answer to this question is to not ask this question". That's not very helpful :(.Faultless

© 2022 - 2024 — McMap. All rights reserved.