dot函数是用来处理向量点乘的,如果传进去是float类型会怎么处理呢?
我写了一段代码用来测试,发现float x 会被处理成Vec_(x,0,0...),x是会被处理成第一项为x的向量参与运算。


#ifdef GL_ES
precision mediump float;
#endif

uniform vec2 u_resolution; //canvas size (width,height)
uniform vec2 u_mouse; //mouse position in screen pixels 
uniform float u_time; //time in seconds since load

void main() {
    vec2 st = gl_FragCoord.xy/u_resolution.xy;
    st.x *= u_resolution.x/u_resolution.y;

    float x = 0.5;
    float xx = dot(x,x);
    vec3 color1 = vec3(0.5,0.,0.);
    vec3 color2 = vec3(xx,0.,0.);
       vec3 color = mix(color1,color2,step(0.5,st.x));
    gl

参考图如下可以看出 x=0.5的情况下点乘的值为0.25


lyh1091106900
1 声望0 粉丝

引用和评论

0 条评论