3 Replies Latest reply on Dec 1, 2009 3:48 PM by AIF Bob

    clamp float

    Ed Ryzhov

      dst.rgb = float3(0.0, clamp(1.0, 0.25, 0.5), 0.0);


      returns float3(0.0, 1.0, 0.0);



        • 1. Re: clamp float
          AIF Bob Level 3

          I'm testing it here and it seems fine. Can you post the full text of your kernel, and also how you're running it - whether you're in the toolkit, on CPU, on GPU, on Flash. What are the steps that I should take to reproduce this problem?

          • 2. Re: clamp float
            Ed Ryzhov Level 1

            Full text of kernel.

            I run it from flash.

            Green component of the output is always 1.




            <languageVersion: 1.0;>


            kernel NewKernel




                namespace: "Namespace";


                vendor: "Vendor";


                version: 1;


                description: "Your Description1";






                input image3 src;


                output pixel3 dst;


                void evaluatePixel()




                    float3 clr = sampleNearest(src, outCoord());


                    dst.rgb = float3(clr.r, clamp(1.0, 0.25, 0.5), clr.b);










            Flash source:


            package {
                import __AS3__.vec.Vector;
                import flash.display.Bitmap;
                import flash.display.BitmapData;
                import flash.display.Shader;
                import flash.display.ShaderJob;
                import flash.display.Sprite;
                import flash.events.Event;
                import flash.geom.Rectangle;
                import flash.utils.ByteArray;
                import net.hires.debug.Stats;


                [SWF(width='400', height='300', backgroundColor='0x7f7f7f', frameRate='100')]


                public class shaders extends Sprite
                    private var k_hmap:Class;
                    private var b_hmap:Bitmap = new k_hmap();
                    [Embed("../pbj/hgt_lgt.pbj", mimeType="application/octet-stream")]
                    private var hgt_lgt:Class;
                    private var dstBd:BitmapData = new BitmapData(256, 256, false, 0);
                    private var bmp:Bitmap = new Bitmap(dstBd);
                    private var shader:Shader = new Shader(new hgt_lgt() as ByteArray);
                    private var shJob:ShaderJob = null;
                    public function shaders()
                        bmp.x = 100;
                        bmp.y = 0;
                        addChild(new Stats());
                        addEventListener(Event.ENTER_FRAME, onFrame);
                        shader.data.src.input = b_hmap.bitmapData;
                    public function onFrame(e:Event):void
                        shJob = new ShaderJob(shader, dstBd);

            • 3. Re: clamp float
              AIF Bob Level 3

              This is a bug in our compiler. I have filed it, in the meantime use a combination of min and max

              instead of the call to clamp:


              rather than:


                clamp(x, 0.25, 0.5)




                min( max( x, 0.25 ), 0.5 )