SHARE
TWEET

glsl vuo

a guest Oct 30th, 2013 150 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "node.h"
  2.  
  3. #include "VuoImageRenderer.h"
  4.  
  5. VuoModuleMetadata({
  6.                      "title" : "GLSL Radial Blur",
  7.                      "description" : "Radial Blur",
  8.                                          "keywords" : [ ],
  9.                                          "version" : "1.0.0",
  10.                                          "dependencies" : [
  11.                                                  "VuoImageRenderer"
  12.                                          ],
  13.                                          "node": {
  14.                                                  "isInterface" : false
  15.                                          }
  16.                                  });
  17.  
  18. #include "node.h"
  19.  
  20. static const char * fragmentShaderSource = VUOSHADER_GLSL_SOURCE(120,
  21.     // Inputs
  22.     uniform sampler2D texture;
  23.     varying vec4 fragmentTextureCoordinate;
  24.  
  25.     //
  26.     uniform float time;
  27.     uniform vec2 resolution;
  28.     //
  29.                                                                  
  30.     vec3 deform( in vec2 p )
  31.     {
  32.         vec2 uv;
  33.  
  34.         vec2 q = vec2( sin(1.1*time+p.x),sin(1.2*time+p.y) );
  35.  
  36.         float a = atan(q.y,q.x);
  37.         float r = sqrt(dot(q,q));
  38.  
  39.         uv.x = sin(0.0+1.0*time)+p.x*sqrt(r*r+1.0);
  40.         uv.y = sin(0.6+1.1*time)+p.y*sqrt(r*r+1.0);
  41.  
  42.         return texture2D( texture, uv*.3).yxx;
  43.     }
  44.  
  45.     void main()
  46.     {
  47.         vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
  48.             vec2 s = p;
  49.  
  50.             vec3 total = vec3(0.0);
  51.             vec2 d = (vec2(0.0,0.0)-p)/40.0;
  52.             float w = 1.0;
  53.             for( int i=0; i<40; i++ )
  54.             {
  55.                 vec3 res = deform(s);
  56.                 res = smoothstep(0.0,1.0,res);
  57.                 total += w*res;
  58.                 w *= .99;
  59.                 s += d;
  60.             }
  61.             total /= 40.0;
  62.             float r = 3.0;
  63.  
  64.             gl_FragColor = vec4( total*r,1.0);
  65.     }
  66. );
  67.  
  68.  
  69. struct nodeInstanceData
  70. {
  71.     VuoShader shader;
  72.     VuoImageRenderer imageRenderer;
  73. };
  74.  
  75. struct nodeInstanceData * nodeInstanceInit(void)
  76. {
  77.     struct nodeInstanceData * instance = (struct nodeInstanceData *)malloc(sizeof(struct nodeInstanceData));
  78.     VuoRegister(instance, free);
  79.  
  80.     instance->shader = VuoShader_make("Radial Blur", VuoShader_getDefaultVertexShader(), fragmentShaderSource);
  81.     VuoRetain(instance->shader);
  82.     instance->imageRenderer = VuoImageRenderer_make();
  83.     VuoRetain(instance->imageRenderer);
  84.  
  85.     return instance;
  86. }
  87.  
  88. void nodeInstanceEvent
  89. (
  90.         VuoInstanceData(struct nodeInstanceData *) instance,
  91.         VuoInputData(VuoImage) image,
  92.         VuoInputData(VuoReal, {"default":0, "suggestedStep":0.01}) time,
  93.         VuoInputData(VuoPoint2d, {"default":{"x":1024,"y":768}}) resolution,
  94.         VuoOutputData(VuoImage) adjustedImage
  95. )
  96. {
  97.     if (! image)
  98.         return;
  99.  
  100.     // Associate the input image with the shader.
  101.     VuoShader_resetTextures((*instance)->shader);
  102.     VuoShader_addTexture((*instance)->shader, image, "texture");
  103.  
  104.     // Feed parameters to the shader.
  105.     VuoShader_setUniformFloat((*instance)->shader, "time", time);
  106.     VuoShader_setUniformPoint2d((*instance)->shader, "resolution", resolution);
  107.  
  108.     // Render.
  109.     *adjustedImage = VuoImageRenderer_draw((*instance)->imageRenderer, (*instance)->shader, image->pixelsWide, image->pixelsHigh);
  110. }
  111.  
  112. void nodeInstanceFini(VuoInstanceData(struct nodeInstanceData *) instance)
  113. {
  114.     VuoRelease((*instance)->shader);
  115.     VuoRelease((*instance)->imageRenderer);
  116. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top