着色器编译错误

Shader Compiling Error

本文关键字:错误 编译      更新时间:2023-10-16

我正在开发一个在源代码中隐藏着色器的项目。我收到此错误(在运行时):

Error compiling vertex shader:
Full VS shader source:
//precision highp float;
uniform vec2 uEyeToSourceUVScale;
uniform vec2 uEyeToSourceUVOffset;
attribute vec4 aPosition;         ///< [-1,+1],[-1,+1] over the entire framebuffer. Lerp factor in Pos.z. Vignette fade factorin Pos.w.
attribute vec2 aTanEyeAnglesR;   ///< The tangents of the horizontal and vertical eye angles for the red channel.
attribute vec2 aTanEyeAnglesG;   ///< The tangents of the horizontal and vertical eye angles for the green channel.
attribute vec2 aTanEyeAnglesB;   ///< The tangents of the horizontal and vertical eye angles for the blue channel.
varying vec4 vPosition; 
varying vec2 vTexCoordR; 
varying vec2 vTexCoordG; 
varying vec2 vTexCoordB; 
void main(void)
{
    vPosition = aPosition;
    vTexCoordR = aTanEyeAnglesR * uEyeToSourceUVScale + uEyeToSourceUVOffset;
    vTexCoordG = aTanEyeAnglesG * uEyeToSourceUVScale + uEyeToSourceUVOffset;
    vTexCoordB = aTanEyeAnglesB * uEyeToSourceUVScale + uEyeToSourceUVOffset;
    vTexCoordR.y = 1.0 - vTexCoordR.y;
    vTexCoordG.y = 1.0 - vTexCoordG.y;
    vTexCoordB.y = 1.0 - vTexCoordB.y;
    gl_Position = vec4(aPosition.xy, 0, 1);
}
Shader compilation failed.

我不知道如何解决这个问题(没有着色器经验);但是,我知道着色器代码类似于C++代码,从这个意义上说,这对我来说看起来非常简单(除非我错过了什么)。

这个着色器代码有明显的问题吗?

缺少#version指令意味着#version 110

gl_Position = vec4(aPosition.xy, 0, 1);
                                 ^  ^ int literals

#version 110不支持自动int -> float转换。 请改用float文字:

gl_Position = vec4(aPosition.xy, 0.0, 1.0);
                                 ^^^  ^^^ float literals