Capítulo 846 de 859
How to port a Shadertoy fragment shader into three.js as a ShaderMaterial on a full-screen plane, understanding that Shadertoy shaders are a fun per-pixel-math puzzle rather than a performance best practice, and that Shadertoy's iResolution/iTime/fragCoord/fragColor are Shadertoy-specific conventions, not official GLSL.
iResolution (canvas size) and iTime (seconds since load) aren't official GLSL — they're globals Shadertoy's runtime supplies, so porting a shader means declaring and feeding equivalent uniform values yourself.OrthographicCamera sized to a 2-unit plane fills the canvas exactly, giving a simple canvas for pasting in a Shadertoy fragment shader.mainImage: the ported shader still defines its Shadertoy-style mainImage(out vec4 fragColor, in vec2 fragCoord) function; a small wrapper main() calls it with WebGL's real gl_FragColor and gl_FragCoord.xy.fragCoord from pixel coordinates, feeding it from three.js's own texture coordinates (uv, passed from a custom vertex shader as a varying) turns a Shadertoy function into a reusable procedural texture on ordinary geometry, not just a full-screen effect.const uniforms = {
iTime: { value: 0 },
iResolution: { value: new THREE.Vector3() },
};
const material = new THREE.ShaderMaterial({ fragmentShader, uniforms });
// each frame:
uniforms.iResolution.value.set(canvas.width, canvas.height, 1);
uniforms.iTime.value = time;
uniforms that stand in for Shadertoy's implicit iResolution/iTime globals.iResolution, iTime, fragCoord, and fragColor are Shadertoy conventions, not part of GLSL itself; you must declare and feed them as ordinary uniforms in three.js.OrthographicCamera plus a 2-unit plane is the standard way to fill the canvas for a ported full-screen shader.uv texture coordinates (instead of raw pixel coordinates) turns it into a reusable procedural texture rather than a screen-filling effect.