OpenGL ES 3.0 将单个浮点传递给顶点着色器实现

问题描述 投票:0回答:1

我正在尝试将单个浮点传递给我的顶点着色器以用于反射率计算。我希望有一种简单的方法可以做到这一点,但还没有看到实现的示例。

GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + FORESTFLOORTEXTURES);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle[FORESTFLOORTEXTURES]);
GLES20.glUniform1i(mTextureUniformHandle, FORESTFLOORTEXTURES);

TerrainPositions.position(0);
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false,
        0, TerrainPositions);
GLES20.glEnableVertexAttribArray(mPositionHandle);

TerrainNormals.position(0);
GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false,
        0, TerrainNormals);
GLES20.glEnableVertexAttribArray(mNormalHandle);

TerrainTextures.position(0);
GLES20.glVertexAttribPointer(mTextureCoordinateHandle, mTextureCoordinateDataSize, GLES20.GL_FLOAT, false,
        0, TerrainTextures);
GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);

TerrainColors.position(0);
GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false,
        0, TerrainColors);
GLES20.glEnableVertexAttribArray(mColorHandle);

//This doesn't work as it's expecting an array buffer instead of a float
//What should I use instead?
GLES20.glVertexAttribPointer(mReflectanceHandle, 1, GLES20.GL_FLOAT, false,
        0, 0.3f);
GLES20.glEnableVertexAttribArray(mReflectanceHandle);
android opengl-es vertex-shader
1个回答
0
投票

我一直认为一个实际的例子胜过千言万语。

在渲染器中:

GLES20.glVertexAttrib1f(mReflectanceHandle, 0.3f);

在程序声明中:

mReflectanceHandle = GLES20.glGetAttribLocation(LightProgramHandle, "a_Reflectivity");

在顶点着色器中:

"attribute float a_Reflectivity;"+
"varying float v_reflectivity;"
...
"v_reflectivity = a_Reflectivity;"+
© www.soinside.com 2019 - 2024. All rights reserved.