【问题标题】:Remove texture coordinates from fragment shader从片段着色器中删除纹理坐标
【发布时间】:2010-12-04 17:47:30
【问题描述】:

我有一个顶点和片段着色器,我想显示纯色而不是纹理。

我有以下顶点和片段着色器。

static const char* meshVertexShader = " \
  \
attribute vec4 vertexPosition; \
attribute vec4 vertexNormal; \
attribute vec2 vertexTexCoord; \
 \
varying vec2 texCoord; \
varying vec4 normal; \
 \
uniform mat4 modelViewProjectionMatrix; \
 \
void main() \
{ \
   gl_Position = modelViewProjectionMatrix * vertexPosition; \
   normal = vertexNormal; \
   texCoord = vertexTexCoord; \
} \
";


static const char* fragmentShader = " \
 \
precision mediump float; \
 \
varying vec2 texCoord; \
varying vec4 normal; \
 \
uniform sampler2D texSampler2D; \
 \
void main() \
{ \
   gl_FragColor = texture2D(texSampler2D, texCoord); \
} \
";

如何修改片段着色器以不显示纹理? (对不起我的英语)。

谢谢。

【问题讨论】:

    标签: opengl-es fragment-shader vertex-shader opengl-es-2.0


    【解决方案1】:

    改变

    gl_FragColor = texture2D(texSampler2D, texCoord);
    

    gl_FragColor = vec4(1,1,1,1);
    

    它将绘制白色而不是纹理。

    【讨论】:

    • 这显然也意味着您可以根据需要删除对 texCoord 和 texSampler2D 的所有引用,但编译器可能会自动删除它们。
    猜你喜欢
    • 2020-03-03
    • 2013-09-17
    • 1970-01-01
    • 2016-01-10
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    相关资源
    最近更新 更多