Touchdesigner the video into a six-angle, triangular, and rounded pixel effect through GLSL

Source: Internet
Author: User

Do a few similar filter experiment, mainly want to make the ordinary video can have some comparative style effect, refer to shadertoys inside some cases, and then in the Touchdesigner to achieve the six angle shape, triangle and round mosaic effect, If you do some more color adjustment can actually achieve more interesting interactive effect. Here are the following:

Original

Hexagon

Circle

Triangle

Of course, all the effects are real-time.

Here's the code:

HEXAGON, this effect in the search for the nearest hexagon there is a great God has already put the algorithm done, directly according to his use is good:

http://www.gamedev.net/page/resources/_/technical/game-programming/coordinates-in-hexagon-based-tile-maps-r1800

Layout (location =0) outVEC4 Fragcolor;uniformfloatSize;uniformfloatEdge;uniformfloatsamples;Const floatPI =3.14159265359;Const floatTAU =2.0*PI;Const floatDeg30 = tau/12.0; VEC4 resolution= utd2dinfos[0].res;floatHexdist (Vec2 A, vec2 b) {VEC2 P= ABS (b-a); floats =sin (deg30); floatc =cos (DEG30); floatDiagdist = s*p.x + c*p.y; returnMax (Diagdist, p.x)/C;} VEC2 Nearesthex (floatS, VEC2 St) {    floath = sin (deg30) *s; floatr = cos (deg30) *s; floatB = S +2.0*h; floatA =2.0*R; floatm = h/R; VEC2 Sect= ST/VEC2 (2.0*r, H +s); VEC2 SECTPXL= MoD (St, VEC2 (2.0*r, H +s)); floatasection = mod (Floor (SECT.Y),2.0); VEC2 coord=Floor (Sect); if(Asection >0.0){        if(Sectpxl.y < (h-sectpxl.x*m)) {coord-=1.0; }        Else if(Sectpxl.y < (-H + sectpxl.x*m)) {Coord.y-=1.0; }    }    Else{        if(Sectpxl.x >R) {            if(Sectpxl.y < (2.0*h-sectpxl.x *m)) {Coord.y-=1.0; }        }        Else{            if(Sectpxl.y < (sectpxl.x*m)) {Coord.y-=1.0; }            Else{coord.x-=1.0; }        }    }        floatXoff = mod (COORD.Y,2.0)*R; returnVEC2 (coord.x*2.0*r-xoff, coord.y* (h+s)) +VEC2 (r*2.0, s);} Vec4 Samplecolor (vec2 position) {vec2 hor= VEC2 (0.002,0.0); VEC2 ver= VEC2 (0.0,0.002); intCount =0; VEC3 Amountcolor= VEC3 (0.0);  for(inti =1; I <= samples; i++) {vec2 Tmphor= Hor *i; VEC2 Tmpver= ver *i; Amountcolor+ = Texture (std2dinputs[0], Position-tmphor). RGB +Texture (std2dinputs[0], Position + tmphor). RGB +Texture (std2dinputs[0], position-tmpver). RGB +Texture (std2dinputs[0], Position +tmpver). RGB; Count++; } Amountcolor/= (float(count) *4.0); returnVEC4 (Amountcolor,1.0);}voidMain () {VEC4 Videocolor= Texture (std2dinputs[0], vuv.st); VEC2 Nearest= Nearesthex (Size, resolution.zw*vuv.st); VEC4 Samplecolor= Samplecolor (nearest/resolution.zw); floatDist = hexdist (Vuv.st *resolution.zw, nearest); floatInterior =1.0-Smoothstep (Size-edge, size, dist); Fragcolor= Vec4 (Samplecolor.rgb*interior,1.0);}

CIRCLE

Layout (location =0) outVEC4 Fragcolor;uniformfloatSize;uniformfloatSamples;uniformfloatBoard;Const floatPI =3.14159265359;Const floatTAU =2.0*PI;Const floatDeg30 = tau/12.0; VEC4 resolution= utd2dinfos[0].res;intCutedge (floatDistfloatsize) {    intFlag; if(Dist <= (size-board)/2.0) {flag =1;} Else{flag =0;} returnFlag;} Vec4 Filtercolor (vec2 position) {vec2 hor= VEC2 (0.001,0.0); VEC2 ver= VEC2 (0.0,0.001); intCount =0; VEC3 Amountcolor= VEC3 (0.0);  for(inti =1; I <= samples; i++) {vec2 Tmphor= Hor *i; VEC2 Tmpver= ver *i; Amountcolor+ = Texture (std2dinputs[0], Position-tmphor). RGB +Texture (std2dinputs[0], Position + tmphor). RGB +Texture (std2dinputs[0], position-tmpver). RGB +Texture (std2dinputs[0], Position +tmpver). RGB; Count++; } Amountcolor/= (float(count) *4.0); returnVEC4 (Amountcolor,1.0);} VEC2 Nearestcenter (floatsize, VEC2 St) {VEC2 Currentpos= St *RESOLUTION.ZW; //Find the UnitVEC2 unit = Floor (Currentpos/vec2 (size)); returnUnit * size + VEC2 (size/2.0);}voidMain () {VEC4 Videocolor= Texture (std2dinputs[0], vuv.st); VEC2 Nearcenter=nearestcenter (size, vuv.st); VEC4 Samplecolor= Filtercolor (Nearcenter/resolution.zw); floatDist = distance (nearcenter, Vuv.st *resolution.zw); intInterior =Cutedge (dist, size); Fragcolor= VEC4 (Samplecolor.rgb * interior,1.0); //Fragcolor = VEC4 (VEC3 (interior), 1.0);}

TRIANGLE

This effect is directly copied from the algorithm of a great God, Mom really God, a simple line on the definition of the method of image sampling, to show you the results of feedback and TM is the best. I don't know what these gods are like. What's in the head?

0  out vec4 fragcolor;uniform vec2 tile_num; void Main () {    = vuv.st;     = Floor (uv*tile_num)/tile_num;     -= uv2    ; *= tile_num;     = Texture (std2dinputs[0],                         + vec2 (step (1.0-uv.y,uv.x)/(2.0*tile_ num.x), Step (UV.X,UV.Y)/(2.0*tile_num.y))                         );    }

Touchdesigner the video into a pixelated effect of six corners, triangles, and circles by GLSL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.