Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "node.h"
- #include "VuoImageRenderer.h"
- VuoModuleMetadata({
- "title" : "GLSL Radial Blur",
- "description" : "Radial Blur",
- "keywords" : [ ],
- "version" : "1.0.0",
- "dependencies" : [
- "VuoImageRenderer"
- ],
- "node": {
- "isInterface" : false
- }
- });
- #include "node.h"
- static const char * fragmentShaderSource = VUOSHADER_GLSL_SOURCE(120,
- // Inputs
- uniform sampler2D texture;
- varying vec4 fragmentTextureCoordinate;
- //
- uniform float time;
- uniform vec2 resolution;
- //
- vec3 deform( in vec2 p )
- {
- vec2 uv;
- vec2 q = vec2( sin(1.1*time+p.x),sin(1.2*time+p.y) );
- float a = atan(q.y,q.x);
- float r = sqrt(dot(q,q));
- uv.x = sin(0.0+1.0*time)+p.x*sqrt(r*r+1.0);
- uv.y = sin(0.6+1.1*time)+p.y*sqrt(r*r+1.0);
- return texture2D( texture, uv*.3).yxx;
- }
- void main()
- {
- vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
- vec2 s = p;
- vec3 total = vec3(0.0);
- vec2 d = (vec2(0.0,0.0)-p)/40.0;
- float w = 1.0;
- for( int i=0; i<40; i++ )
- {
- vec3 res = deform(s);
- res = smoothstep(0.0,1.0,res);
- total += w*res;
- w *= .99;
- s += d;
- }
- total /= 40.0;
- float r = 3.0;
- gl_FragColor = vec4( total*r,1.0);
- }
- );
- struct nodeInstanceData
- {
- VuoShader shader;
- VuoImageRenderer imageRenderer;
- };
- struct nodeInstanceData * nodeInstanceInit(void)
- {
- struct nodeInstanceData * instance = (struct nodeInstanceData *)malloc(sizeof(struct nodeInstanceData));
- VuoRegister(instance, free);
- instance->shader = VuoShader_make("Radial Blur", VuoShader_getDefaultVertexShader(), fragmentShaderSource);
- VuoRetain(instance->shader);
- instance->imageRenderer = VuoImageRenderer_make();
- VuoRetain(instance->imageRenderer);
- return instance;
- }
- void nodeInstanceEvent
- (
- VuoInstanceData(struct nodeInstanceData *) instance,
- VuoInputData(VuoImage) image,
- VuoInputData(VuoReal, {"default":0, "suggestedStep":0.01}) time,
- VuoInputData(VuoPoint2d, {"default":{"x":1024,"y":768}}) resolution,
- VuoOutputData(VuoImage) adjustedImage
- )
- {
- if (! image)
- return;
- // Associate the input image with the shader.
- VuoShader_resetTextures((*instance)->shader);
- VuoShader_addTexture((*instance)->shader, image, "texture");
- // Feed parameters to the shader.
- VuoShader_setUniformFloat((*instance)->shader, "time", time);
- VuoShader_setUniformPoint2d((*instance)->shader, "resolution", resolution);
- // Render.
- *adjustedImage = VuoImageRenderer_draw((*instance)->imageRenderer, (*instance)->shader, image->pixelsWide, image->pixelsHigh);
- }
- void nodeInstanceFini(VuoInstanceData(struct nodeInstanceData *) instance)
- {
- VuoRelease((*instance)->shader);
- VuoRelease((*instance)->imageRenderer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement