Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-7-sonnet-20250219· AnthropicHugging Face Arena Expert 5K

add this shader to a vertex shader of a diamond "// Anisotropic Sampling with Wave…

  1. User

    add this shader to a vertex shader of a diamond "// Anisotropic Sampling with Wave Interference // Combines directional sampling, Gaussian blur, and wave interference

    float waveInterference(vec2 uv, float time) { // Generate two orthogonal traveling waves float wave1 = sin(dot(uv, vec2(15.0, 0.0)) + time * 2.0); float wave2 = cos(dot(uv, vec2(0.0, 15.0)) + time * 1.5);

    // Create interference pattern (product of waves)
    return (wave1 * wave2 + 1.0) * 0.5;
    

    }

    vec3 directionalBlur(vec2 uv, vec2 dir, float time) { // Directional Gaussian blur parameters const int taps = 7; float weights[taps] = float[taps](0.006, 0.061, 0.242, 0.383, 0.242, 0.061, 0.006); float total = 0.0;

    // Sample along anisotropic direction
    for(int i = 0; i < taps; i++) {
        float offset = float(i - (taps/2)) * 0.008;
        vec2 samplePos = uv + dir * offset;
        total += waveInterference(samplePos, time) * weights[i];
    }
    
    return vec3(total);
    

    }

    vec3 anisotropicSample(vec2 uv, vec2 dir, float time) { // Anisotropic sampling (3-tap box filter along direction) vec3 color = vec3(0.0); for(int i = -1; i <= 1; i++) { vec2 offset = dir * 0.012 * float(i); float sampleee = waveInterference(uv + offset, time); color += vec3(sampleee); } return color / 3.0; }

    void mainImage(out vec4 fragColor, in vec2 fragCoord) { // Normalized UV with aspect ratio correction vec2 uv = fragCoord / iResolution.xy; uv -= 0.5; uv.x *= iResolution.x / iResolution.y; uv += 0.5;

    // Dynamic anisotropic direction (rotating over time)
    vec2 anisotropicDir = normalize(vec2(cos(iTime * 0.7), sin(iTime * 1.3)));
    
    // Generate base wave interference pattern
    float base = waveInterference(uv, iTime);
    
    // Apply directional effects
    vec3 blur = directionalBlur(uv, anisotropicDir, iTime);
    vec3 aniso = anisotropicSample(uv, anisotropicDir, iTime);
    
    // Combine all effects with weighted contribution
    vec3 final = (
        base * vec3(0.2, 0.3, 0.5) +   // Base interference (blue tint)
        blur * vec3(0.5, 0.2, 0.3) +    // Directional blur (red tint)
        aniso * vec3(0.3, 0.5, 0.2)     // Anisotropic sampling (green tint)
        
    
    ) * 1.2;  // Slight brightness boost
    aniso += texture(iChannel0, uv).grb;
    // Add time-varying color pulse
    final *=  sin(iTime*2. + uv.y);
    
    fragColor = vec4(final+aniso, 1.0);
    

    }"

  2. Claude Assistant

    Here's how you could integrate this shader into a vertex shader for a diamond:

    // Standard vertex shader attributes and uniforms
    attribute vec3 position;
    attribute vec2 uv;
    uniform mat4 modelViewMatrix;
    uniform mat4 projectionMatrix;
    uniform float time;
    uniform vec2 resolution;
    
    // Outputs to fragment shader
    varying vec2 vUv;
    varying vec3 vPosition;
    varying vec3 vNormal;
    
    // Anisotropic Sampling with Wave Interference
    // Combines directional sampling, Gaussian blur, and wave interference
    
    float waveInterference(vec2 uv, float time) {
        // Generate two orthogonal traveling waves
        float wave1 = sin(dot(uv, vec2(15.0, 0.0)) + time * 2.0);
        float wave2 = cos(dot(uv, vec2(0.0, 15.0)) + time * 1.5);
        
        // Create interference pattern (product of waves)
        return (wave1 * wave2 + 1.0) * 0.5;
    }
    
    vec3 directionalBlur(vec2 uv, vec2 dir, float time) {
        // Directional Gaussian blur parameters
        const int taps = 7;
        float weights[taps] = float[taps](0.006, 0.061, 0.242, 0.383, 0.242, 0.061, 0.006);
        float total = 0.0;
        
        // Sample along anisotropic direction
        for(int i = 0; i < taps; i++) {
            float offset = float(i - (taps/2)) * 0.008;
            vec2 samplePos = uv + dir * offset;
            total += waveInterference(samplePos, time) * weights[i];
        }
        
        return vec3(total);
    }
    
    vec3 anisotropicSample(vec2 uv, vec2 dir, float time) {
        // Anisotropic sampling (3-tap box filter along direction)
        vec3 color = vec3(0.0);
        for(int i = -1; i <= 1; i++) {
            vec2 offset = dir * 0.012 * float(i);
            float sampleee = waveInterference(uv + offset, time);
            color += vec3(sampleee);
        }
        return color / 3.0;
    }
    
    void main() {
        // Pass UV coordinates to fragment shader
        vUv = uv;
        
        // Calculate normal for lighting in fragment shader
        vNormal = normalize(normalMatrix * normal);
        
        // Apply wave effect to vertex position
        vec2 normalizedUv = uv;
        normalizedUv -= 0.5;
        normalizedUv.x *= resolution.x / resolution.y;
        normalizedUv += 0.5;
        
        // Dynamic anisotropic direction (rotating over time)
        vec2 anisotropicDir = normalize(vec2(cos(time * 0.7), sin(time * 1.3)));
        
        // Generate displacement based on wave interference
        float displacement = waveInterference(normalizedUv, time) * 0.1;
        
        // Apply directional effects for more complex displacement
        vec3 blur = directionalBlur(normalizedUv, anisotropicDir, time);
        vec3 aniso = anisotropicSample(normalizedUv, anisotropicDir, time);
        
        // Combine displacement effects
        float finalDisplacement = displacement + blur.r * 0.05 + aniso.g * 0.05;
        
        // Apply displacement along normal direction
        vec3 displacedPosition = position + normal * finalDisplacement;
        
        // Transform vertex position
        vPosition = displacedPosition;
        gl_Position = projectionMatrix * modelViewMatrix * vec4(displacedPosition, 1.0);
    }
    

    Would you like me to explain or break down this code?

  3. User

    in shadertoy format.

  4. Claude Assistant

    Here's the shader adapted to ShaderToy format:

    // Anisotropic Sampling with Wave Interference for Diamond
    // Combines directional sampling, Gaussian blur, and wave interference
    
    float waveInterference(vec2 uv, float time) {
        // Generate two orthogonal traveling waves
        float wave1 = sin(dot(uv, vec2(15.0, 0.0)) + time * 2.0);
        float wave2 = cos(dot(uv, vec2(0.0, 15.0)) + time * 1.5);
        
        // Create interference pattern (product of waves)
        return (wave1 * wave2 + 1.0) * 0.5;
    }
    
    vec3 directionalBlur(vec2 uv, vec2 dir, float time) {
        // Directional Gaussian blur parameters
        const int taps = 7;
        float weights[taps] = float[taps](0.006, 0.061, 0.242, 0.383, 0.242, 0.061, 0.006);
        float total = 0.0;
        
        // Sample along anisotropic direction
        for(int i = 0; i < taps; i++) {
            float offset = float(i - (taps/2)) * 0.008;
            vec2 samplePos = uv + dir * offset;
            total += waveInterference(samplePos, time) * weights[i];
        }
        
        return vec3(total);
    }
    
    vec3 anisotropicSample(vec2 uv, vec2 dir, float time) {
        // Anisotropic sampling (3-tap box filter along direction)
        vec3 color = vec3(0.0);
        for(int i = -1; i <= 1; i++) {
            vec2 offset = dir * 0.012 * float(i);
            float sampleee = waveInterference(uv + offset, time);
            color += vec3(sampleee);
        }
        return color / 3.0;
    }
    
    // Diamond facet calculation
    vec3 calculateDiamondVertex(vec3 position, vec3 normal, vec2 uv, float displacement) {
        // Apply displacement along normal for diamond facet effect
        return position + normal * displacement;
    }
    
    void mainImage(out vec4 fragColor, in vec2 fragCoord) {
        // Normalized UV with aspect ratio correction
        vec2 uv = fragCoord / iResolution.xy;
        uv -= 0.5;
        uv.x *= iResolution.x / iResolution.y;
        uv += 0.5;
        
        // Dynamic anisotropic direction (rotating over time)
        vec2 anisotropicDir = normalize(vec2(cos(iTime * 0.7), sin(iTime * 1.3)));
        
        // Generate base wave interference pattern
        float base = waveInterference(uv, iTime);
        
        // Apply directional effects
        vec3 blur = directionalBlur(uv, anisotropicDir, iTime);
        vec3 aniso = anisotropicSample(uv, anisotropicDir, iTime);
        
        // Simulate diamond facets with ray-marching-like approach
        vec3 rayDir = normalize(vec3((uv - 0.5) * 2.0, 1.0));
        vec3 normal = normalize(vec3(sin(uv.x * 15.0 + iTime) * cos(uv.y * 15.0), 
                                     sin(uv.y * 15.0 - iTime), 
                                     cos(uv.x * 15.0) * sin(uv.y * 10.0 + iTime)));
        
        // Calculate refraction and reflection
        float fresnel = pow(1.0 - abs(dot(normal, rayDir)), 5.0);
        
        // Combine all effects with weighted contribution
        vec3 final = (
            base * vec3(0.2, 0.3, 0.5) +   // Base interference (blue tint)
            blur * vec3(0.5, 0.2, 0.3) +   // Directional blur (red tint)
            aniso * vec3(0.3, 0.5, 0.2)    // Anisotropic sampling (green tint)
        ) * 1.2;  // Slight brightness boost
        
        // Add texture sampling if available
        if (iChannelCount > 0) {
            aniso += texture(iChannel0, uv).grb;
        }
        
        // Add time-varying color pulse
        final *= sin(iTime*2.0 + uv.y);
        
        // Add diamond-like sparkle
        final += pow(fresnel, 3.0) * vec3(1.0) * (sin(iTime * 5.0) * 0.5 + 0.5);
        
        fragColor = vec4(final + aniso, 1.0);
    }
    

    Would you like me to explain or break down this code?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.