入门
三个着色器:(先只研究图形)
图形
声音
虚拟现实
定义和方法
uniform vec3 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)
uniform float iTimeDelta; // render time (in seconds)
uniform int iFrame; // shader playback frame
uniform float iChannelTime[4]; // channel playback time (in seconds)
uniform vec3 iChannelResolution[4]; // channel resolution (in pixels)
uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down), zw: click
uniform samplerXX iChannel0…3; // input channel. XX = 2D/Cube
uniform vec4 iDate; // (year, month, day, time in seconds)
uniform float iSampleRate; // sound sample rate (i.e., 44100)
都是GLSL的API:
remap:将a-b映射到c-d
remap01:a-b映射到0-1
smoothstep
例子
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
//fragCoord范围是视口大小
// Normalized pixel coordinates (from 0 to 1)
//将屏幕分辨率映射到0-1
vec2 uv = fragCoord/iResolution.xy;
// Time varying pixel color
//时间扰动
vec3 col = 0.5 + 0.5*cos(iTime+uv.xyx+vec3(0,2,4));
// Output to screen
//输出颜色
fragColor = vec4(col,1.0);
}
转换
将GLSL 转换成 需要的着色器语言