http://www.opengl.org/wiki/Vertex_Texture_Fetch

Vertex Texture Fetch

 
 
This article contains inaccurate information. Further details can be found on the talk page.

The following article discusses Vertex Texture Fetch feature of todays GPUs.

Vertex Texture Fetch will be referred to as VTF from now on.
Texture image units will be referred to as TIU.
VS means vertex shader
FS means fragment shader

What version of GL supports VTF?
In order to be able to do VTF, you need shader support. GLSL has been made core since GL 2.0.
You also need a GPU that supports VTF.
As of GL 2.1, texture float formats are not core yet. You need to check if GL_ARB_texture_float is present.
http://www.opengl.org/registry/specs/ARB/texture_float.txt
In GL 3.0, floating point formats became a core feature.

GPUs that support VTF use the same TIUs as the fragment shader. This means that you can bind a texture to TIU 1 and sample that same texture in the vertex shader and also the fragment shader. To bind the texture, it is rather simple :

 glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, textureID);

In order to know how many TIUs your vertex shader has access to, call

 int MaxVertexTextureImageUnits;
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &MaxVertexTextureImageUnits);
int MaxCombinedTextureImageUnits;
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &MaxCombinedTextureImageUnits);

and GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS is the TUI number accessible from your VS and FS combined.
If in your VS and FS, you access the same texture, that counts like accessing 2 TIUs.

An issue with accessing a texture is the texture format. Your GPU might support a wide range of formats that can be accessed by the TIU of the FS but the TIU of the VS simply doesn't support certain formats. For example, nVidia has published Vertex_Format.pdf when Gf6 was released
Gf 6 supports only GL_TEXTURE_2D of format GL_LUMINANCE32F_ARB and GL_RGBA32F_ARB. It doesn't support any of the other floating point formats or fixed point formats. There is no floating point compressed format.
All other formats besides GL_LUMINANCE32F_ARB and GL_RGBA32F_ARB cause the VS to run in software mode.
Gf 7 is similar to the Gf6.
Gf 8 is a DX10 level GPU and all DX10 level GPUs should support VTF with the same formats supported by the fragment pipe.

ATI/AMD :
ATI/AMD chose not to have VTF in their SM 3.0 GPUs.
X300 up to X1950. All of their standard X series.
They said it would be too slow. It would be better to do Render_To_VertexBuffer (R2VB).
In OpenGL, to do R2VB you would need PBO support. http://www.opengl.org/registry/specs/ARB/pixel_buffer_object.txt
PBO became core in GL 2.1 and ATI's driver do support GL 2.1.
ATI's DX10 parts, in other words all their GPUs with the HD in the name, support VTF.
ATI's driver does report 16 for GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS but users are saying that their shaders don't work.

Example code :

 uint vertex_texture;
glGenTextures(1, &vertex_texture);
glBindTexture(GL_TEXTURE_2D, vertex_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//Linear filter might cause a fallback to software rendering so we are using GL_NEAREST
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//Linear filter might cause a fallback to software rendering so we are using GL_NEAREST_MIPMAP_NEAREST
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
//Make sure your GPU support mipmaps with floating point textures
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAPS, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE32F_ARB, width, height, 0, GL_LUMINANCE, GL_FLOAT, data);

If you setup some unsupported filter mode or wrap mode, or some unsupported texture format, it will fall to software vertex processing.

Another thing to remember is that the GPU doesn't know which mipmap to use. It has no way to compute the lambda factor.
You need to choose the mipmap in the VS yourself.
Here is an example of a VS.
Notice how the example uses texture2DLod() and it chooses mipmap 0.

 attribute vec2 inTexCoord;
uniform sampler2D Texture0;
uniform mat4 ProjectionModelviewMatrix;
varying vec2 TexCoord;
void main()
{
vec4 texel, newVertex;
//Read the texture offset. Offset in the z direction only
texel = texture2DLod(Texture0, inTexCoord, 0.0);
newVertex = gl_Vertex;
newVertex.z += texel.x;
gl_Position = ProjectionModelviewMatrix * newVertex;
TexCoord = inTexCoord;
}

Vertex Fetch Texture (VTF)的更多相关文章

  1. [CG] 顶点动画贴图 (Vertex Animation Texture, VAT)

    什么是顶点动画? 简单来说,通过改变网格顶点的位置,使网格变形从而做成的动画.顶点动画的灵活度要远远高于骨骼动画.骨骼动画是靠骨骼(一堆有层级结构的节点,数量应该是远远小于网格顶点的数量的)的变化来驱 ...

  2. 翻译:GLSL的顶点位移贴图

    翻译:GLSL的顶点位移贴图 翻译自: Vertex Displacement Mapping using GLSL 译者: FreeBlues 说明: 之所以选择这篇文档, 是因为现在但凡提到位移贴 ...

  3. Life of a triangle - NVIDIA's logical pipeline

    Home GameWorks Blog Life of a triangle - NVIDIA's logical pipeline   Life of a triangle - NVIDIA's l ...

  4. 【原创】Linux环境下的图形系统和AMD R600显卡编程(11)——R600指令集

    1 低级着色语言tgsi OpenGL程序使用GLSL语言对可编程图形处理器进行编程,GLSL语言(以下高级着色语言就是指GLSL)是语法类似C的高级语言,在GLSL规范中,GLSL语言被先翻译成教低 ...

  5. PatentTips - Sprite Graphics Rendering System

    BACKGROUND This disclosure relates generally to the field of computer graphics. More particularly, b ...

  6. Graphics processing architecture employing a unified shader

    FIELD OF THE INVENTION The present invention generally relates to graphics processors and, more part ...

  7. 深入GPU硬件架构及运行机制

    目录 一.导言 1.1 为何要了解GPU? 1.2 内容要点 1.3 带着问题阅读 二.GPU概述 2.1 GPU是什么? 2.2 GPU历史 2.2.1 NV GPU发展史 2.2.2 NV GPU ...

  8. 性能三 powerVR specfication

    2.Optimising Geometry Interleaving Attributes VBO Draw call size Triangle Size  32个像素/primitive    - ...

  9. 39. Volume Rendering Techniques

    Milan Ikits University of Utah Joe Kniss University of Utah Aaron Lefohn University of California, D ...

随机推荐

  1. Session入门

    Session是运行在服务器的,不可造假,例如:医生需要一个私人账本,记录病人编号和身份的对应关系.由于身份证无法造假,所以能够保证信息不被假冒.两点:身份证无法造假,这个身份证就可以唯一标识这个用户 ...

  2. Android实现电子邮箱客户端

    本文主要讲述了安卓平台上利用QQ邮箱SMTP协议,POP3协议发送与接收消息的实现 发送邮件核心代码 import java.security.Security; import java.util.D ...

  3. javac编译提示编码GBK的不可映射字符

    使用命令行javac命令编译java文件, 提示错误:编码GBK的不可映射字符. 在编译的时候,如果我们没有用-encoding参数指定我们的JAVA源程序的编码格式,则javac.exe会获得我们操 ...

  4. Ubuntu could not write bytes broken pipe

    一.环境变量问题 1 到登录界面的时候,进入命令行模式: alt+ctrl+F1 2 登录 3 修改环境变量(当我输入ls的时候  竟然没有找到命令,然后果断的知道是环境变量的事情,于是改之!) 4 ...

  5. Java Annotation原理分析(一)

    转自:http://blog.csdn.net/blueheart20/article/details/18725801 小引: 在当下的Java语言层面上,Annotation已经被应用到了语言的各 ...

  6. matlab练习程序(多边形顶点凹凸性)

    生成简单多边形后,有时还需要对多边形各顶点的凹凸性做判断. 先计算待处理点与相邻点的两个向量,再计算两向量的叉乘,根据求得结果的正负可以判断凹凸性. 结果为负则为凹顶点,为正则为凸顶点. 凹顶点用o表 ...

  7. Codeforces Round #313 (Div. 2) A. Currency System in Geraldion

    A. Currency System in Geraldion Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...

  8. HDU 2819 — Swap 二分匹配

    Swap Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. 【转】kylin优化

    转自: http://www.bitstech.net/2016/01/04/kylin-olap/ http://www.csdn.net/article/2015-11-27/2826343 ht ...

  10. JVM的栈内存

    每当启动一个新线程时,Java虚拟机都会为它分配一个Java栈.Java栈以帧为单位保存线程的运行状态.虚拟机只会直接对Java栈执行两种操作:以帧为单位的压栈和出栈. 某个线程正在执行的方法被称为该 ...