跳到主要内容
← Vertex Transformations

Vertex Transformations

Varying

`smooth`可以不写:因为默认情况下opengl就会使用默认插值

实时渲染 · 网格 GLSL

第 7 课:Varying

实现:smooth可以不写:因为默认情况下opengl就会使用默认插值

实现

uniform float iTime;
smooth varying vec3 fragColor;

void main() {
  vec3 fragPos = position + vec3(0.5 * sin(iTime), 0.5 * cos(iTime), 0.0);

  gl_Position = vec4(fragPos, 1.0);
  fragColor = fragPos;
}

复盘笔记

  • smooth可以不写:因为默认情况下opengl就会使用默认插值
  • 当然还有其他插值方式:
  • flat:不插值,直接取某个顶点值(通常是第一个顶点),用于颜色块、索引等不需要过渡的属性。
  • varying(或新版的 out/in)是一个意思,只是varying 语义太模糊
  • HLSL also supports interpolation qualifiers, though they are less commonly used explicitly. You can control interpolation using modifiers:
  • nointerpolation - disables interpolation (like OpenGL’s flat)
  • linear - default smooth interpolation
  • centroid - interpolates using centroid sampling
  • sample - interpolates per-sample (for MSAA)
  • <2025/05/31>
  • ==记录时间: 6月2日 2025, 04:21 下午==