Question

I have very strange shader error. Here is my shader as is:

#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);

}

And here is the RESULT
As you can see error appears at "vec4 half". If rename "half", to lets say "half_v" it compiles.

BUT WHHHYYYY???

Était-ce utile?

La solution

Your graphics card seems to implement the GL_NV_half_float extension. This extension introduces a new GLSL datatype named half. Half float is an IEEE 754r standard (binary16) half-precision data type used for values of lesser precision and range. This data type is of size 16-bits: 1 bit for sign, 5 bits for exponent and 10 bits for significand, excluding the one implicit bit.

Autres conseils

half is a keyword resrved for future use, according to the GLSL spec (section 3.6 on pp20-22)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top