1 Reply Latest reply on Dec 12, 2011 12:08 PM by AIF Bob

    Convert Thermal Vision Effect To Pixel Bender

    mastorix Level 1
      Hello,

      I would like to use an effect coded with
      GLSL code but I did not have the skills to convert it to Pixel Bender.

      #version 120

       

      uniform sampler2D tex;

       

      void main()

      {

      vec4 pixcol = texture2D(tex, gl_TexCoord[0].xy);

      vec4 colors[3];

      colors[0] = vec4(0.,0.,1.,1.);

      colors[1] = vec4(1.,1.,0.,1.);

      colors[2] = vec4(1.,0.,0.,1.);

      float lum = (pixcol.r+pixcol.g+pixcol.b)/3.;

      int ix = (lum < 0.5)? 0:1;

      vec4 thermal = mix(colors[ix],colors[ix+1],(lum-float(ix)*0.5)/0.5);

      gl_FragColor = thermal;

      }

       


      Could someone help me with this ?

      Thank you
        • 1. Re: Convert Thermal Vision Effect To Pixel Bender
          AIF Bob Level 3

          Here's a quick version I knocked together - the only clever bit is using a float4x4 instead of the array of float4 values because PB lacks proper array support.

           

          <languageVersion : 1.0;>

          kernel Thermal
          <   namespace : "AIF test";
              vendor : "Adobe";
              version : 1;
          >
          {
              input image4 src;
              output pixel4 dst;

              void
              evaluatePixel()
              {
                  float4 pixcol = sampleLinear(src, outCoord() );
                  float4x4 colors;
                  colors[0] = float4(0.,0.,1.,1.);
                  colors[1] = float4(1.,1.,0.,1.);
                  colors[2] = float4(1.,0.,0.,1.);

                  float lum = (pixcol.r+pixcol.g+pixcol.b)/3.;
                  int ix = (lum < 0.5)? 0:1;

                  float4 thermal = mix(colors[ix],colors[ix+1],(lum-float(ix)*0.5)/0.5);

                  dst = thermal;
              }
          }