shader 变量赋值问题,勾起我的好奇心!

// cocoscreator 版本2.3.0

// 大家好 ,下面变量 a_uv0 和 a_color 我不知道是如何和什么赋值呢,请问各位大佬!!!
// 都带 in 的修饰符,确没有赋值函数, 也没有外部赋值!!!

// Copyright © 2017-2018 Xiamen Yaji Software Co., Ltd.

CCEffect %{
techniques:

  • passes:
    • vert: vs
      frag: fs
      blendState:
      targets:
      • blend: true
        rasterizerState:
        cullMode: none
        properties:
        texture: { value: white }
        time: { value: 0 }
        speed: { value: 0.002 }
        }%

CCProgram vs %{

precision highp float;

#include

in vec3 a_position;

// --------------------------------
// 大家好 in 的修饰符是仅供外接传入的值 函数不能修改
// 但是我在用shader的时候没有给他赋值,但是下面的main函数确直接用了这个值
// 请问下传入值的流程是什么呢, 外部又如何给他赋值呢!
in mediump vec2 a_uv0;
in vec4 a_color;

out vec4 v_color;
out mediump vec2 v_uv0;

void main () {
gl_Position = cc_matViewProj * vec4(a_position, 1);
v_uv0 = a_uv0;
v_color = a_color;
}

}%

CCProgram fs %{
precision highp float;

uniform Time {
float time;
};

uniform SPEED {
float speed;
};

uniform sampler2D texture;
in mediump vec2 v_uv0;
in vec4 v_color;

void main () {
vec2 uv = v_uv0.xy;
uv.x += time * speed;
uv.x = fract(uv.x);
vec4 color = texture2D(texture, uv);
#if CC_USE_ALPHA_ATLAS_TEXTURE
color.a *= texture2D(texture, uv + vec2(0, 0.5)).r;
#endif
gl_FragColor = color;
}
}%

你先看一下opengl吧。看一下什么是顶点数据

这些变量大概都是在顶点输入阶段的时候传进去的,被赋予了材质的对象会把该对象的每一个顶点信息都传进去,其中的顶点信息就可能包括顶点位置、顶点颜色和uv信息,没有了解过cocos具体是怎么处理shader,不过建议先从图形学(安卓平台推荐openglES)搞起来,如果是为了学shader而学shader的话,你会学得很辛苦的、、