简体   繁体   English

在不使用着色器的OpenGL中发布GPU缩放着色

[英]Post GPU scaling colouring in OpenGL without shaders

I am writing a program to plot the distribution of a stream of live noisy data. 我正在编写一个程序来绘制实时嘈杂数据流的分布。 The plots look something like 情节看起来像

在此处输入图片说明

The scene is lit with 3 lights - 2 diffuse and 1 ambient - to allow modeling to be revealed once filtering is applied to the data 场景由3个灯(2个漫反射和1个环境)照亮,一旦对数据应用了过滤,就可以显示模型

在此处输入图片说明

Currently vertical scaling and vertex colour assignment is done by my code before sending the vertices to the GPU using: 目前,垂直缩放和顶点颜色分配是由我的代码完成的,然后使用以下命令将顶点发送到GPU:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(c_vertex), &(vertex_store[0][0].x));
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(3, GL_FLOAT, sizeof(c_vertex),&(vertex_store[0][0].r));
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(c_vertex),&(vertex_store[0][0].nx));
glDrawElements(GL_TRIANGLES, (max_bins-1)*(max_bins-1)*2*3, GL_UNSIGNED_INT, vertex_order);

The use of older functions is so that I can let the fixed pipeline do the lighting calculations with out me writing a shader [something I have not done to the depth needed to do lighting with 3 sources] 使用较早的功能是为了让我无需编写着色器就可以让固定的管线进行照明计算[对于3种光源进行照明所需的深度,我还没有做过]

To speed up processing I would like to send unscaled data to the GPU and apply a matrix with X and Z scale of 1 and Y scale of the appropriate value to make the peaks reach to +1 on the y axis. 为了加快处理速度,我想将未缩放的数据发送到GPU,并应用X和Z比例为1且Y比例为适当值的矩阵,以使峰值在y轴上达到+1。 After this I would then like the GPU to select the colour for the vertex depending on its post scaling Y value from a look-up table which I assume would be a texture map. 之后,我希望GPU根据查找表中缩放后的Y值来选择顶点的颜色,我认为该表将是纹理贴图。

Now I know I can do the last paragraph IF I write my own shaders - but that the necessitates writing code for lighting which I want to avoid doing. 现在,我知道如果我编写自己的着色器,就可以执行最后一段了-但是这需要编写我想避免的照明代码。 Is there anyway of doing this using the buffers in the drawing code above? 无论如何,使用上面的图形代码中的缓冲区来执行此操作吗?

After this I would then like the GPU to select the colour for the vertex depending on its post scaling Y value from a look-up table which I assume would be a texture map. 之后,我希望GPU根据查找表中缩放后的Y值来选择顶点的颜色,我认为该表将是纹理贴图。

You really should write your own shaders for that. 确实应该为此编写自己的着色器。 Writing a shader for 3 light sources isn't more complicated as writing one for just one and making a loop around it. 为3个光源编写一个着色器并不复杂,只为其中一个编写一个并围绕它进行循环。

However, I think what you asked for could still be done with the fixed function pipeline. 但是,我认为您所要求的仍然可以使用固定功能管道完成。 You can use a 1D texture for the colors, enable texturing and the automatic texture coordinate generation , the latter via the glTexGen() family of functions. 您可以为颜色使用一维纹理,启用纹理化和自动纹理坐标生成 (后者通过glTexGen()系列函数)。

In your specific case, the best appraoch seems to set up a GL_OBJECT_LINEAR mapping for s (the first and only texture coordinate that you would need for a 1D texture): 在您的特定情况下,最好的方法似乎是为s (一维纹理所需的第一个也是唯一的纹理坐标)设置GL_OBJECT_LINEAR映射:

glEnable(GL_TEXTURE_GEN_S);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);

What the GL now will do is calcualte s as a function of your input vertex cooridnates (x,y,z,w) such that: 什么现在GL需要做的是calcualte s作为输入顶点cooridnates(X,Y,Z,W),使得函数:

s=a*x + b*y + c*z + d*w

where a , b , c and d are just some coefficients you can freely choose. 其中abcd只是一些系数,您可以自由选择。 I'm assuming your original vertices just need to be scaled along y direction by a scaling factor V , so you can just set b=V and all other to zero: 我假设您的原始顶点仅需要沿y方向按比例因子V进行缩放,因此您可以将b=V设置为零,将所有其他设置为零:

GLfloat coeffs[4]={0.0f, V, 0.0f, 0.0f);
glTexGenfv(GL_S, GL_OBJECT_PLANE, coeffs);

Then, you just have to enable texture mapping and provide a texture to get the desired lookat. 然后,您只需要启用纹理映射并提供纹理即可获得所需的外观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM