跳到主要内容
← Grass

Grass

Grass - Blade

shader-learning 自学第 1 课:Grass - Blade

实时渲染 · 网格 GLSL

第 1 课:Grass - Blade

实现

attribute int index;

void main() {
  vec3 pos = vec3(0.0);
  vec3 vecR = vec3(1.0, 0.0, 0.0);
  vec3 vecU = vec3(0.0, 1.0, 0.0);
  float height = floor(float(index)/2.0)/9.0;
  float halfWidth = 0.1 * (1.0 - height * height) / 2.0;
  if(index%2 == 0){
    pos -= vecR*halfWidth;
  }else{
    pos += vecR*halfWidth;
  }

  pos += vecU * height;
  gl_Position = projectionMatrix * viewMatrix * vec4(pos, 1.0);
}