"매 rasterized fragment 마다 매 한 번 실행되어 final color 를 계산". 매 GPU pipeline (vertex → primitive assembly → rasterization → fragment → blending) 의 final programmable stage. 2026 시점 WebGPU + WGSL 가 WebGL2 + GLSL 의 후속, native 는 Metal MSL / HLSL SM 6.x / Vulkan SPIR-V.
매 핵심
매 input / output
Input: interpolated vertex output (UV, normal, world pos), uniforms, textures.
Output: 매 RGBA color (+ optional depth, MRT).
매 fragment ≠ pixel — 매 multi-sampling / overdraw 시 매 fragment 가 pixel 보다 많을 수 있다.
매 pipeline (rasterization)
Vertex shader → clip space.
Primitive assembly + clipping.
Rasterization → 매 fragment 생성.
Fragment shader → color.
Depth/stencil test + blending → framebuffer.
매 cost factor
Overdraw: 매 같은 pixel 이 여러 번 shaded.
Texture bandwidth: 매 sample count + filter.
ALU: 매 복잡한 BRDF, lighting loop.
Branch divergence: warp / wave 내 분기.
매 응용
PBR lighting (Cook-Torrance, GGX).
Post-processing (bloom, SSAO, FXAA, TAA).
Procedural texture / SDF.
Compute-like (pre-WebGPU 의 GPGPU hack).
💻 패턴
GLSL — basic textured + Lambert
// fragment.glsl (WebGL2 / GLSL ES 3.00)#version 300 esprecisionhighpfloat;invec2vUV;invec3vNormalW;invec3vPosW;uniformsampler2DuAlbedo;uniformvec3uLightDirW;outvec4outColor;voidmain(){vec3albedo=texture(uAlbedo,vUV).rgb;floatndl=max(dot(normalize(vNormalW),-normalize(uLightDirW)),0.0);outColor=vec4(albedo*(0.1+0.9*ndl),1.0);}