Announcement

Collapse
No announcement yet.

Code Tricks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Code Tricks

    Hi all the preset authors. I've got an idea to make a place to share some code pieces. That could be shader,PF,PV and custom vave equations.
    Certainly, first read 'For all the newbies' by Ryan.
    Have fun surfing this thread, and please don't forget to share your own effects and code!

  • #2
    COMP SHADER
    Let' start with a simple one:
    code:

    //PIXELIZE EFFECT
    ret=GetPixel(floor(uv*210)/210);
    //210 is value of pixelizing.
    //Than more it is, than less pixelizing is done.

    Comment


    • #3
      COMP SHADER

      An old effect from Milkdrop 1.x days is the hue shader, which basically is a texture effect that seperates the screen into huge fields of different, cycling colors blending into one another. This color information is available as a float 3.

      The classic implementation in Milkdrop 1 looks like this:

      code:
      ret *= hue_shader;
      However, this effect isn't very strong, and can be increased, for example like this:

      code:
      ret *= (hue_shader*6)-4;
      However, you can vary it with other values - the higher the number you multiply the hue_shader with, the more intense the colors. The number you substract from this changes the brightness - a value 1-2 smaller than your multiplicator should yield good results.

      Of course, you can also use hue_shader in other, more creative manners...

      Comment


      • #4
        SHADERS
        Type this in warp shader
        code:
        //SHARP MOTION EFFECT
        ret=tex2D(sampler_fc_main,float2(uv.x+q1,uv.y+q2));

        And this in PF code
        code:

        q1=dx;
        q2=dy;

        This tweak prevents motion smudging when using dx/dy.

        Comment


        • #5
          working with layers

          one very cool way to achieve a nice threedimensional athmosphere on the flat screen is to work with different motion strengths for each color channel (as also shown in geiss' 3layer presets).

          warp-shader-code:
          code:

          float2 uv1 = lerp(uv_orig,uv,1); //equals uv
          float2 uv2 = lerp(uv_orig,uv,0.2); // 20% of uv
          float2 uv3 = lerp(uv_orig,uv,-0.2); //20% of uv but in the opposite direction

          ret.x = GetPixel(uv1).x;
          ret.y = GetPixel(uv2).y;
          ret.z = GetPixel(uv3).z;

          thus, so far won't look great without recoloring the color channels in the composite shader:

          code:

          float3 base = GetPixel(uv);
          ret = float3(0.2,0,0.1)*base.y; //the green color channel mapped on a very dark purple
          ret = lerp(ret,float3(0.8,0.5,0),base.x); // layered an orange tone from the red channel thereupon
          ret = lerp(ret,1,base.z); // the blue color channel i want to be colored white

          okay, this is something. but what about different decay rates for the color channels? the blue one will cover all the others, so here's an addition to the warp shader again:

          code:

          float2 uv1 = lerp(uv_orig,uv,1); //equals uv
          float2 uv2 = lerp(uv_orig,uv,0.2); // 20% of uv
          float2 uv3 = lerp(uv_orig,uv,-0.2); //20% of uv but in the opposite direction

          ret.x = GetPixel(uv1).x*0.8 - 0.004;
          ret.y = GetPixel(uv2).y*0.98 - 0.004;
          ret.z = GetPixel(uv3).z*0.6 - 0.004;

          combine these shaders with a zoom and/or rotation and you will see.
          i wrote these lines from sketch and have not prooved them how they look. either way the power lies in the finetuning of the parameters and your skill in picking colors that harmonize.
          But remember thinking in the three dimensions of the color space.
          Last edited by Flexi; 19 May 2008, 15:00.
          WebSocket Hub for Kinect SDK 2.0 with Milkdrop shader pipeline in VanillaJS and glsl
          Codepen | Shadertoy | OpenProcessing | studio sketchpad
          Twitter @ Google+ @ YouTube @ Facebook

          Comment


          • #6
            @stahlregen:
            want to squeeze phat colors off the hue shader?

            --> pow(hue_shader,6);
            WebSocket Hub for Kinect SDK 2.0 with Milkdrop shader pipeline in VanillaJS and glsl
            Codepen | Shadertoy | OpenProcessing | studio sketchpad
            Twitter @ Google+ @ YouTube @ Facebook

            Comment


            • #7
              Originally posted by Flexi
              @stahlregen:
              want to squeeze phat colors off the hue shader?

              --> pow(hue_shader,6);
              Actually (hue_shader*X)-(X-1.5) gives me better, clearer results.

              Anyway, here's a piece of code that will arrange the instances of a custom shape in a circle (or rather an elipse, depending on your screen's aspect ratio).

              CUSTOM SHAPE PER-FRAME

              code:
              instance_count = 3.14*instance*(2/(num_instance));
              x = .5 + 0.1 * sin(instance_count);
              y = .5 + 0.1 * cos(instance_count);

              Nothing fancy, really.

              Comment


              • #8
                Damn... I was messing with that trying to fix the aspect problem and realized that aspectx/aspecty is a lil' bit screwy...

                Anyone know exactly what the deal with it is?
                I am the purple heathen.

                Comment


                • #9
                  aspectx/aspecty is only available in the per-frame section - if you want to use it in the custom wave or shape code you have to pass it by 2 of the q_ variables.

                  in shaders the syntax looks a little different: aspect.x/aspect.y
                  WebSocket Hub for Kinect SDK 2.0 with Milkdrop shader pipeline in VanillaJS and glsl
                  Codepen | Shadertoy | OpenProcessing | studio sketchpad
                  Twitter @ Google+ @ YouTube @ Facebook

                  Comment


                  • #10
                    I know, that's what I was doing.

                    Try playing with aspecty on it.
                    I am the purple heathen.

                    Comment


                    • #11
                      q1=apsectx;
                      q2=aspecty;

                      From there I multiply by q1 & q2 whenever I need it.
                      I am the purple heathen.

                      Comment


                      • #12
                        Well then, an improved version...

                        code:
                        PER-FRAME

                        q1 = .5 // central point x...
                        q2 = .5 // ...and y coord. Play around with this!
                        q3 = aspectx;
                        q4 = aspecty;

                        CUSTOM SHAPE PER-FRAME

                        instance_counter = 6.28*instance/num_instance;
                        x = q1 + .1 * (1/q4) * sin(instance_counter);
                        y = q2 + .1 * (1/q3) * cos(instance_counter);
                        ang = instance_counter;

                        Automatically arranges a custom shape's instances in more accurate circles (and turns each instance, too). Vary the factors (+.1*...) in the x/y coords for larger/smaller circles, for example with bass/treb/mid.

                        Also, a way to show custom shapes only in a fraction of all frames:

                        code:
                        PER-FRAME
                        shape_count = if(below(shape_count,5),shape_count+1,1);
                        q1 = shape_count;

                        CUSTOM SHAPE PER-FRAME

                        transparency = if(equal(q1,5),1,0);
                        a = transparency;
                        a2 = transparency;
                        border_a = transparency;

                        This example turns the inner opacity, outer opacity and border opacity of the shape to 1 (opaque) in every 5th frame and to 0 (transparent) in the remaining ones.

                        Comment


                        • #13
                          Some spiral custom wave code I just whipped up as a mental excercise. I do think I saw something similiar in a preset before, though.

                          code:
                          CUSTOM WAVE PER-POINT

                          centerx = .5;
                          centery = .5;
                          amplitude = .15;
                          turns = 6;
                          size = .3;
                          speed = 1; // negative values will make it spin the other way round...

                          x = centerx+(size-size*sample)*sin(speed*3.14*time+sample*6.28*turns)
                          *(1+amplitude*(value1+value2));

                          y = centery+(size-size*sample)*cos(speed*3.14*time+sample*6.28*turns)
                          *(1+amplitude*(value1+value2));

                          If you want it leaner, just directly insert the values.

                          Comment


                          • #14
                            Double-ret

                            hmmm.. I've just written some code to pass 6 vals from warp shader to composite, but it doesn't work!
                            I knew the precision was not too high, but I didn't even think that was THAT kind of LOW.
                            I attached the preset file; please tell me smth about it.
                            Attached Files

                            Comment


                            • #15
                              hey, can you please try to explain what you actually tried to demonstrate with your code.
                              where do you see a lack of quality?

                              one thing always to mention: avoid fractions! - pass the inverse of q1 and do a multiplication!

                              passing 6 or more values is possible, i guess your failure is located at a different place.
                              WebSocket Hub for Kinect SDK 2.0 with Milkdrop shader pipeline in VanillaJS and glsl
                              Codepen | Shadertoy | OpenProcessing | studio sketchpad
                              Twitter @ Google+ @ YouTube @ Facebook

                              Comment

                              Working...
                              X