我有非常奇怪的着色器错误。这是我的着色器:
#version 100
#define smooth_len 1.799999952316284
#define half_len 1.000000000000000
attribute mediump vec4 vertex; // w = 0 - fade; 1 - not fade (inner/outer) !HAS_FADE :: 1 = ignore
// non normalized
attribute mediump vec4 dir; // xy = rib1, zw = rib2
uniform mediump mat4 matrix;
uniform mediump mat2 rot;
uniform mediump vec3 scale; //yz - inverse scale
uniform lowp vec4 color;
varying lowp vec4 v_color;
//#define smooth_len 0.9*2
//#define smooth_len 10.9*2
//#define half_len 0.5*2
//#define half_len 2.5*2
#define FULL_ZERO 0.00001
#define ONE 0.99999
#define ZERO /*0.0001*/0.001
#define HALF_AA 0.05
const mediump vec4 ZERO_HALF_VEC = vec4(ZERO, ZERO, HALF_AA, HALF_AA);
const mediump vec4 ZERO_VEC = vec4(ZERO, ZERO, ZERO, ZERO);
const mediump vec4 HALF_VEC = vec4(HALF_AA, HALF_AA, HALF_AA, HALF_AA);
const mediump vec2 HALF_LEN_VEC = vec2(half_len, half_len);
const mediump vec2 SMOOTH_LEN_VEC = vec2(smooth_len, smooth_len);
const mediump vec2 ONE_VEC = vec2(1.0, 1.0);
#define SMOOTH_IT smooth_it.xy
#define HALF_IT smooth_it.zw
void main(void)
{
vec2 v = vertex.xy;
/*vec4 dir_norm = vec4(normalize(dir.xy),
normalize(dir.zw));*/
/** just to make sure */
vec2 len2 = vec2(dot(dir.xy,dir.xy), dot(dir.zw,dir.zw));
vec2 inv_sqrt = inversesqrt(len2);
vec4 dir_norm = dir * inv_sqrt.xxyy;
vec4 normale = vec4(-dir_norm.y, dir_norm.x, -dir_norm.w, dir_norm.z);
float is_equal = step( dot(dir_norm.xy, dir_norm.zw), -ONE ); // if == -1 is equal
vec4 real_dir = abs(vec4( rot * dir_norm.xy, rot * dir_norm.zw) ); // .xy = vec1, .zw = vec2
/*vec4 smooth_half1 = step(ZERO_HALF_VEC, real_dir.xyxy);
vec4 smooth_half2 = step(ZERO_HALF_VEC, real_dir.zwzw);
vec4 smooth_half_it = smooth_half1 * smooth_half2; // .xy = smooth, .zw = half
*/
vec4 smooth = step(ZERO_VEC, real_dir);
vec4 half = step(HALF_VEC, real_dir);
vec2 smooth_it = smooth.xz * smooth.yw;
vec2 half_it = half.xz * half.yw;
/*
smooth_it = vec2(1.0,1.0); // 1 - enable
half_it = vec2(0.0,0.0); // 0 - enable
*/
vec2 d = mix(HALF_LEN_VEC, SMOOTH_LEN_VEC, half_it) * smooth_it; // smooth len (for each rib)
vec2 k = vec2( dot(normale.xy, dir_norm.zw), dot(normale.zw, dir_norm.xy) );
k = mix(k, ONE_VEC, is_equal); // avoid division by zero
vec2 dres = d/k;
vec4 offset = dir_norm * dres.yyxx;
vec2 v_offset = mix(offset.xy + offset.zw, normale.xy*d.x, is_equal);
//v += (v_offset * scale.yz) * (1- vertex.w);
v_offset = v_offset - v_offset * vertex.w; // MAD
v += (v_offset * scale.yz);
v_color = vec4(color.xyz, color.w* vertex.w );
gl_Position = matrix * vec4(v, vertex.z, 1.0);
}
这是 RESULT
如您所见,错误出现在“vec4 half”。如果重命名为“half”,可以说“half_v”它会编译。
但是,为什么?
答案 0 :(得分:3)
您的显卡似乎实现了GL_NV_half_float
扩展程序。此扩展引入了名为half
的新GLSL数据类型。半浮点数是IEEE 754r标准(binary16
)半精度数据类型,用于精度和范围较小的值。此数据类型的大小为16位:符号为1位,指数为5位,有效数为10位,不包括一个隐含位。
答案 1 :(得分:1)
half
是保留供将来使用的关键字