Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I am learning to write shaders. I came across the Las Vegas Sphere thread on X and I love the instant feedback that Alexandre Devaux has created on his site. My attempt to create the Amiga BOING! resulted in a full sphere instead of being cut off at the base like all the other examples. Can someone clue me into why this has occurred and how to fix it? My code is very "hacky" and I only partially understand what I've done here. Any help would be appreciated.

    uniform float time;
    varying vec2 vUv;
    varying vec3 vNormal;

    float rows = 20.0,
          cols = 10.0;
  
    float direction = -1.0;
   
    vec4 colorOne = vec4(1.0,1.0,1.0,0.1),
         colorTwo = vec4(1.0,0.0,0.0,0.1);
    vec4 amiga =  vec4(1.0,0.0,0.0,0.1);

    vec4 amigaMe (vec2 uv, vec4 colorOne, vec4 colorTwo);

    void main()
        {
        vec2 uv = vUv + (direction *(5.0*sin(time) * 0.1));
        amiga = amigaMe (uv, colorOne, colorTwo);
        gl_FragColor  = vec4(amiga.x,amiga.y,amiga.z,0.1);
        }
 
    vec4 amigaMe (vec2 uv, vec4 colorOne, vec4 colorTwo) 
       {    
       vec4 finalColor;
       float patternX = floor(uv.x*rows),
             patternY = floor(uv.y*cols);
       if(mod(patternX + patternY, 2.0) == 0.0)
            {
            finalColor = colorTwo;
            }  
        else 
            {
            finalColor = colorOne + colorTwo ;
            }
        return finalColor;
       }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: