topical media & game development

talk show tell print

graphic-player-10-pixel-filter-shaders-GlassBlock.pbk / pbk



  <languageVersion : 1.0;>
  kernel GlassBlock
  <   
      namespace : "Nick Johnston";
      vendor : "http://www.gskinner.com/blog";
      version : 1;
      description : "Creates a glass-block effect, similar to glass-block windows.";
  >
  {
      input image4 src;
      output pixel4 dst;
      
      // Controls the central position of the effect.
      parameter float2 center
      <
          minValue: float2(0.0, 0.0);
          maxValue: float2(250.0, 250.0);
          defaultValue: float2(125.0, 125.0);
      >;
      
      // Controls the size of the "glass blocks"
      parameter float size
      <
          minValue: float(1.0);
          maxValue: float(10.0);
          defaultValue: float(5.0);
      >;
      
      // Controls the distortion of the effect.
      parameter float distortion
      <
          minValue: float(30.0);
          maxValue: float(100.0);
          defaultValue: float(30.0);
      >;
      
      void evaluatePixel() {
          float2 coord = outCoord();
          float2 distFromCenter = length(coord)-center; // Find the distance from the center
          float cosine = cos(coord.x/(distortion/size)); // Find the ratio of the current pixel's x position based on the disortion and size values.
          float sine = sin(coord.y/(distortion/size)); // Find the ratio of the current pixel's y position based on the distortion and size values.
          pixel4 outputImage = sampleNearest(src, ((coord*cosine*sqrt(sine*sine))+distFromCenter)); // Sample the image and do some more trigonometric math.
          dst = outputImage; // Display the effect
      }
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.