Sure! Here's a ShaderToy shader that renders a rotating yellow smiley face emoji using Signed Distance Fields (SDFs). It uses 2D SDF primitives to build up the emoji: a yellow circular face, two eyes, and a smile. It also rotates the entire face around its center using a rotation matrix.
🟡 Features:
- Circular yellow emoji face
- Black smiling mouth using smoothstep
- Black circular eyes
- Continuous rotation over time with
iTime
🧠 Shader Concepts Used:
- Signed distance functions
- SDF composition (union + subtraction + blend)
- Rotation and transformation of UVs
- Coloring with anti-aliasing
✨ ShaderToy Code:
// Title: Rotating Smiley Emoji using SDF
// Author: ChatGPT
// ShaderToy Compatible
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 uv = (fragCoord - 0.5*iResolution.xy) / iResolution.y;
float t = iTime;
// Rotation matrix
float angle = t;
mat2 rot = mat2(cos(angle), -sin(angle), sin(angle), cos(angle));
uv = rot * uv;
// SDF helper functions
float circleSDF(vec2 p, float r) {
return length(p) - r;
}
float rectSDF(vec2 p, vec2 b) {
vec2 d = abs(p) - b;
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);
}
float smileSDF(vec2 p) {
// Move the mouth down
p.y -= 0.15;
float d = abs(length(p) - 0.25) - 0.02;
// Only keep the bottom arc by checking position
if(p.y > 0.0) d = 1.0;
return d;
}
vec3 bgColor = vec3(0.1, 0.1, 0.1); // dark background
vec3 emojiColor = vec3(1.0, 0.85, 0.0); // yellow face
vec3 eyeColor = vec3(0.0);
vec3 mouthColor = vec3(0.0);
vec3 col = bgColor;
// Face SDF
float dFace = circleSDF(uv, 0.4);
float faceAlpha = smoothstep(0.01, 0.0, dFace);
col = mix(col, emojiColor, faceAlpha);
// Eyes
vec2 leye = uv - vec2(-0.15, 0.1);
vec2 reye = uv - vec2(0.15, 0.1);
float dEyeL = circleSDF(leye, 0.05);
float dEyeR = circleSDF(reye, 0.05);
float eyeAlphaL = smoothstep(0.01, 0.0, dEyeL);
float eyeAlphaR = smoothstep(0.01, 0.0, dEyeR);
col = mix(col, eyeColor, eyeAlphaL);
col = mix(col, eyeColor, eyeAlphaR);
// Smile/Mouth
float dMouth = smileSDF(uv);
float mouthAlpha = smoothstep(0.01, 0.0, dMouth);
col = mix(col, mouthColor, mouthAlpha);
fragColor = vec4(col, 1.0);
}
🛠️ How to Use It:
- Go to shadertoy.com
- Click on "New Shader"
- Replace the contents with the code above
- Click Play/Run
✅ What You See:
- A smooth yellow emoji face centered on the screen.
- Two black eyes and a curved smiling mouth.
- The entire emoji rotates slowly over time.
You can enhance this by adding blushes, different expressions, or even animating the smile! Let me know if you'd like a more expressive face or more emoji styles.
Have fun shading! 😊🟡