1.随机雪花
float random (vec2 st)
{
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = (fragCoord.xy - 0.5 * iResolution.xy) / iResolution.y;
float c1 = random(uv);
fragColor = vec4(c1 * vec3(1.0,1.0,0.0),1.0);
}
效果:
2:放大和取整
float random (vec2 st)
{
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = (fragCoord.xy - 0.5 * iResolution.xy) / iResolution.y;
uv *= 10.0;
//放大和取整
uv = floor(uv);
float c1 = random(uv);
fragColor = vec4(c1 * vec3(1.0,1.0,0.0),1.0);
}
效果:
3.fract 后的颜色变化
float random (vec2 st)
{
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = (fragCoord.xy - 0.5 * iResolution.xy) / iResolution.y;
uv *= 10.0;
//放大和取整
uv = fract(uv);
//float c1 = random(uv);
vec3 c2 = vec3(uv,0.0);
fragColor = vec4(c2 * vec3(1.0,1.0,0.0),1.0);
}
效果: