English 中文(简体)
用 GL_ LINES 和 OpenGL ES 2. 0 绘制的彩色线, 我如何使用阴影来显示颜色线?
原标题:How do I use a shader to colour lines drawn with GL_LINES and OpenGL ES 2.0

我有一个使用 OpenGL ES 2. 0 的Android 应用程序。 我需要从一个数组中绘制10条线, 每个数组由起始点和终点来描述。 因此有 10 条线 = 20 点 = 60 浮点 = 浮点 。 这些点没有连接, 所以数组中的每一对点与其它点无关, 因此我用 GL_ LINES 来绘制 。

我通过将数值放入浮控缓冲器 和调用这样的帮手代码 来绘制它们:

public void drawLines(FloatBuffer vertexBuffer, float lineWidth,
        int numPoints, float colour[]) {
    GLES20.glLineWidth(lineWidth);
    drawShape(vertexBuffer, GLES20.GL_LINES, numPoints, colour);
}

protected void drawShape(FloatBuffer vertexBuffer, int drawType,
        int numPoints, float colour[]) {
    // ... set shader ...
    GLES20.glDrawArrays(drawType, 0, numPoints);
}

绘图线使用浮点缓冲( 60 个浮点)、 线条、 点数( 20 ) 和 4 个浮点数( 4 个浮点数) 的颜色阵列。 我还没有显示遮光符设置代码, 但是它基本上将颜色变量暴露为统一的uColour 值 。

抓取 uColour 的碎片遮光镜直接插在输出中。

/* Fragment */
precision mediump float;

uniform vec4 uColour;
uniform float uTime;

void main() {
    gl_FragColor = uColour;
}

顶部阴影 :

uniform mat4 uMVPMatrix;

attribute vec4 vPosition;

void main() {
    gl_Position = uMVPMatrix * vPosition;
}

但现在我想做一些不同的事情。 我希望我的缓冲线的每条线都有不同的颜色。 颜色是阵列线位置的函数。 我想遮蔽起始线白, 最后的黑暗灰色, 以及两者之间的分级线, 例如 #ffffffff, #eeeeee, #dddddd etc.

我显然可以把每一条线都单独地将一个新的值插入到 uColour 中, 但效率很低。 我不想在每次可以调用GL十次时给它打10次电话, 并在阴影中修改它的价值 。

或许我可以在我的顶层阴影器中声明一个名为 uVertexCount 的统一值 。 在绘图之前, 我将 uVertexCount 设为 0, 每次顶层阴影器都称为 I 递增值 。 碎片阴影器可以通过查看 uVertexCount 来确定线索引 。 这样它就可以将某个起始值和末值或其它方法之间的颜色的数值内插。 但这取决于每个线条或点是否被认为是原始的, 或者整个线条的阵列是单一原始的 。

这样可行吗? 我不知道顶部遮光镜被称作每个碎片遮光器多少倍。 电话间断的方式是否使它可行, 即顶部0, 顶部1, x * 碎片, 顶部2, 顶部3, x * 碎片等。

有没有人知道一些合理的样本代码 可以证明这个概念 或者指给我其他方法来做类似的事情?

最佳回答

将颜色信息添加到 Vertexbuffer (Floatbuffer) 中,并在阴影中使用属性。

外向缓冲示例 :

uniform mat4 uMVPMatrix;

attribute vec4 vPosition;
attribute vec3 vColor;

varying vec3 color;

void main() {
    gl_Position = uMVPMatrix * vPosition;
    color = vColor;
}

示例碎片阴影 :

precision mediump float;

varying vec3 color;

void main() {
    gl_FragColor = color;
}
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签