如何使用我的顶点着色器解决此问题

时间:2019-07-15 09:48:20

标签: glsl

我试图为粒子制作顶点着色器,但是当我运行它时,出现此错误:

  

0(17):错误C7011:从“ vec4”隐式转换为“ vec3”

我正在Eclipse中工作

以下代码:

顶点着色器


#version 140

in vec2 position;

in mat4 modelViewMatrix;
in vec4 texOffsets;
in float blendFactor;

out vec2 textureCoords1;
out vec2 textureCoords2;
out float blend;

uniform mat4 projectionMatrix;

uniform float numberOfRows;

void main(void){

    vec2 textureCoords = position + vec2(0.5,0.5);
    textureCoords.y = 1.0 - textureCoords.y;
    textureCoords/= numberOfRows;
    textureCoords1 = textureCoords + texOffsets.xy;
    textureCoords2 = textureCoords + texOffsets.zw;
    blend = blendFactor;

    gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 0.0 , 1.0);
    //problem with line 26

}

片段着色器

#version 140

out vec3 out_colour;

in vec2 textureCoords1;
in vec2 textureCoords2;
in float blend;

uniform vec3 colour;

uniform sampler2D particleTexture;

void main(void){

    vec4 colour1 = texture(particleTexture,textureCoords1);
    vec4 colour2 = texture(particleTexture,textureCoords2);

    out_colour = mix(colour1 , colour2,blend);

}

1 个答案:

答案 0 :(得分:0)

片段着色器的以下行引起了该问题:

out_colour = mix(colour1 , colour2,blend);

变量colour1colour2是vec4,而out_colour是vec3。您只需要仔细检查mix的结果即可:

out_colour = mix(colour1 , colour2,blend).xyz;

您还可以将out_colour的类型更改为vec4(我认为这实际上是更好的选择)。