How to use smoothstep function using renderscript in androidIs there a way to run Python on Android?How to save an Android Activity state using save instance state?Activity restart on rotation AndroidClose/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?What is 'Context' on Android?How do I fix android.os.NetworkOnMainThreadException?Proper use cases for Android UserManager.isUserAGoat()?

Rent contract say that pets are not allowed. Possible repercussions if bringing the pet anyway?

What should come first—characters or plot?

Ghidra: Prepend memory segment in assembly listing view

Removal of て in Japanese novels

Could this kind of inaccurate sacrifice be countered?

Tex Quotes(UVa 272)

When calculating a force, why do I get different result when I try to calculate via torque vs via sum of forces at an axis?

HJM in infinite dimensions

Why did Khan ask Admiral James T. Kirk about Project Genesis?

How much does Commander Data weigh?

Does this VCO produce a sine wave or square wave

Evaluated vs. unevaluated Association

How do I make my image comply with the requirements of this photography competition?

What is the loud noise of a helicopter when the rotors are not yet moving?

Was the Boeing 2707 design flawed?

Nothing like a good ol' game of ModTen

How to obtain a polynomial with these conditions?

Discussing work with supervisor in an invited dinner with his family

How is linear momentum conserved in case of a freely falling body?

Do Bayesian credible intervals treat the estimated parameter as a random variable?

Does ostensible/specious make sense in this sentence?

Handling Disruptive Student on the Autism Spectrum

If the Shillelagh cantrip is applied to a club with non-standard damage dice, what is the resulting damage dice?

Immediate Smaller Element Time Limit Exceeded



How to use smoothstep function using renderscript in android


Is there a way to run Python on Android?How to save an Android Activity state using save instance state?Activity restart on rotation AndroidClose/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?What is 'Context' on Android?How do I fix android.os.NetworkOnMainThreadException?Proper use cases for Android UserManager.isUserAGoat()?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















How can we use the smoothstep function in renderscript to smoothen a mask image (already blurred using gaussian blur with kernel size 3 or 5) and make its edges smoother. I tried the following code in other frameworks and they worked as expected.



iOS shader code:-



let kernelStr = """
kernel vec4 myColor(__sample source)
float maskValue = smoothstep(0.3, 0.5, source.r);
return vec4(maskValue,maskValue,maskValue,1.0);

"""


In opengl glsl fragment shader:-



 float mask = btex.r;
float maskValue = smoothstep(0.3, 0.5, mask);
vec4 ress = vec4(maskValue,maskValue,maskValue,1.0);









share|improve this question






























    0















    How can we use the smoothstep function in renderscript to smoothen a mask image (already blurred using gaussian blur with kernel size 3 or 5) and make its edges smoother. I tried the following code in other frameworks and they worked as expected.



    iOS shader code:-



    let kernelStr = """
    kernel vec4 myColor(__sample source)
    float maskValue = smoothstep(0.3, 0.5, source.r);
    return vec4(maskValue,maskValue,maskValue,1.0);

    """


    In opengl glsl fragment shader:-



     float mask = btex.r;
    float maskValue = smoothstep(0.3, 0.5, mask);
    vec4 ress = vec4(maskValue,maskValue,maskValue,1.0);









    share|improve this question


























      0












      0








      0








      How can we use the smoothstep function in renderscript to smoothen a mask image (already blurred using gaussian blur with kernel size 3 or 5) and make its edges smoother. I tried the following code in other frameworks and they worked as expected.



      iOS shader code:-



      let kernelStr = """
      kernel vec4 myColor(__sample source)
      float maskValue = smoothstep(0.3, 0.5, source.r);
      return vec4(maskValue,maskValue,maskValue,1.0);

      """


      In opengl glsl fragment shader:-



       float mask = btex.r;
      float maskValue = smoothstep(0.3, 0.5, mask);
      vec4 ress = vec4(maskValue,maskValue,maskValue,1.0);









      share|improve this question














      How can we use the smoothstep function in renderscript to smoothen a mask image (already blurred using gaussian blur with kernel size 3 or 5) and make its edges smoother. I tried the following code in other frameworks and they worked as expected.



      iOS shader code:-



      let kernelStr = """
      kernel vec4 myColor(__sample source)
      float maskValue = smoothstep(0.3, 0.5, source.r);
      return vec4(maskValue,maskValue,maskValue,1.0);

      """


      In opengl glsl fragment shader:-



       float mask = btex.r;
      float maskValue = smoothstep(0.3, 0.5, mask);
      vec4 ress = vec4(maskValue,maskValue,maskValue,1.0);






      android masking renderscript






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 19:17









      user3177661user3177661

      6410 bronze badges




      6410 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1















          RenderScript doesn't have a buit-in smoothstep function, so the simplest thing is to implement it yourself. Next the source ready to be used in your scripts:



          static inline float smoothstep(float edge0, float edge1, float x)

          float value = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
          return value * value * (3.0f - 2.0f * value);



          Example of usage:



          static inline float smoothstep(float edge0, float edge1, float x)

          float value = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
          return value * value * (3.0f - 2.0f * value);


          uchar4 RS_KERNEL root(uint32_t x, uint32_t y)

          ....
          float mask = btex.r;
          float maskValue = smoothstep(0.3f, 0.5f, mask);
          float4 ress = (float4)maskValue, maskValue, maskValue, 1.0f;
          ....



          And next a link about how smoothstep internally works, in case you have any other doubts:



          smoothstep



          Enjoy






          share|improve this answer



























          • However ,in the following links they do mention about smoothstep functions.. May be they are not currently implemented in rs

            – user3177661
            Mar 27 at 19:44












          • The link in the answer is not related to RenderScript, is just a link about information about how the general smoothstep function works, in case you want to write your own function. And as stated in the answer, RenderScript doesn't have a smoothstep function, so you can use the one I put in the answer, which is a smoothstep function written 100% in RenderScript.

            – PerracoLabs
            Mar 27 at 21:06











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55384939%2fhow-to-use-smoothstep-function-using-renderscript-in-android%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1















          RenderScript doesn't have a buit-in smoothstep function, so the simplest thing is to implement it yourself. Next the source ready to be used in your scripts:



          static inline float smoothstep(float edge0, float edge1, float x)

          float value = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
          return value * value * (3.0f - 2.0f * value);



          Example of usage:



          static inline float smoothstep(float edge0, float edge1, float x)

          float value = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
          return value * value * (3.0f - 2.0f * value);


          uchar4 RS_KERNEL root(uint32_t x, uint32_t y)

          ....
          float mask = btex.r;
          float maskValue = smoothstep(0.3f, 0.5f, mask);
          float4 ress = (float4)maskValue, maskValue, maskValue, 1.0f;
          ....



          And next a link about how smoothstep internally works, in case you have any other doubts:



          smoothstep



          Enjoy






          share|improve this answer



























          • However ,in the following links they do mention about smoothstep functions.. May be they are not currently implemented in rs

            – user3177661
            Mar 27 at 19:44












          • The link in the answer is not related to RenderScript, is just a link about information about how the general smoothstep function works, in case you want to write your own function. And as stated in the answer, RenderScript doesn't have a smoothstep function, so you can use the one I put in the answer, which is a smoothstep function written 100% in RenderScript.

            – PerracoLabs
            Mar 27 at 21:06
















          1















          RenderScript doesn't have a buit-in smoothstep function, so the simplest thing is to implement it yourself. Next the source ready to be used in your scripts:



          static inline float smoothstep(float edge0, float edge1, float x)

          float value = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
          return value * value * (3.0f - 2.0f * value);



          Example of usage:



          static inline float smoothstep(float edge0, float edge1, float x)

          float value = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
          return value * value * (3.0f - 2.0f * value);


          uchar4 RS_KERNEL root(uint32_t x, uint32_t y)

          ....
          float mask = btex.r;
          float maskValue = smoothstep(0.3f, 0.5f, mask);
          float4 ress = (float4)maskValue, maskValue, maskValue, 1.0f;
          ....



          And next a link about how smoothstep internally works, in case you have any other doubts:



          smoothstep



          Enjoy






          share|improve this answer



























          • However ,in the following links they do mention about smoothstep functions.. May be they are not currently implemented in rs

            – user3177661
            Mar 27 at 19:44












          • The link in the answer is not related to RenderScript, is just a link about information about how the general smoothstep function works, in case you want to write your own function. And as stated in the answer, RenderScript doesn't have a smoothstep function, so you can use the one I put in the answer, which is a smoothstep function written 100% in RenderScript.

            – PerracoLabs
            Mar 27 at 21:06














          1














          1










          1









          RenderScript doesn't have a buit-in smoothstep function, so the simplest thing is to implement it yourself. Next the source ready to be used in your scripts:



          static inline float smoothstep(float edge0, float edge1, float x)

          float value = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
          return value * value * (3.0f - 2.0f * value);



          Example of usage:



          static inline float smoothstep(float edge0, float edge1, float x)

          float value = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
          return value * value * (3.0f - 2.0f * value);


          uchar4 RS_KERNEL root(uint32_t x, uint32_t y)

          ....
          float mask = btex.r;
          float maskValue = smoothstep(0.3f, 0.5f, mask);
          float4 ress = (float4)maskValue, maskValue, maskValue, 1.0f;
          ....



          And next a link about how smoothstep internally works, in case you have any other doubts:



          smoothstep



          Enjoy






          share|improve this answer















          RenderScript doesn't have a buit-in smoothstep function, so the simplest thing is to implement it yourself. Next the source ready to be used in your scripts:



          static inline float smoothstep(float edge0, float edge1, float x)

          float value = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
          return value * value * (3.0f - 2.0f * value);



          Example of usage:



          static inline float smoothstep(float edge0, float edge1, float x)

          float value = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
          return value * value * (3.0f - 2.0f * value);


          uchar4 RS_KERNEL root(uint32_t x, uint32_t y)

          ....
          float mask = btex.r;
          float maskValue = smoothstep(0.3f, 0.5f, mask);
          float4 ress = (float4)maskValue, maskValue, maskValue, 1.0f;
          ....



          And next a link about how smoothstep internally works, in case you have any other doubts:



          smoothstep



          Enjoy







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 27 at 21:11

























          answered Mar 27 at 19:29









          PerracoLabsPerracoLabs

          5,0698 gold badges41 silver badges78 bronze badges




          5,0698 gold badges41 silver badges78 bronze badges















          • However ,in the following links they do mention about smoothstep functions.. May be they are not currently implemented in rs

            – user3177661
            Mar 27 at 19:44












          • The link in the answer is not related to RenderScript, is just a link about information about how the general smoothstep function works, in case you want to write your own function. And as stated in the answer, RenderScript doesn't have a smoothstep function, so you can use the one I put in the answer, which is a smoothstep function written 100% in RenderScript.

            – PerracoLabs
            Mar 27 at 21:06


















          • However ,in the following links they do mention about smoothstep functions.. May be they are not currently implemented in rs

            – user3177661
            Mar 27 at 19:44












          • The link in the answer is not related to RenderScript, is just a link about information about how the general smoothstep function works, in case you want to write your own function. And as stated in the answer, RenderScript doesn't have a smoothstep function, so you can use the one I put in the answer, which is a smoothstep function written 100% in RenderScript.

            – PerracoLabs
            Mar 27 at 21:06

















          However ,in the following links they do mention about smoothstep functions.. May be they are not currently implemented in rs

          – user3177661
          Mar 27 at 19:44






          However ,in the following links they do mention about smoothstep functions.. May be they are not currently implemented in rs

          – user3177661
          Mar 27 at 19:44














          The link in the answer is not related to RenderScript, is just a link about information about how the general smoothstep function works, in case you want to write your own function. And as stated in the answer, RenderScript doesn't have a smoothstep function, so you can use the one I put in the answer, which is a smoothstep function written 100% in RenderScript.

          – PerracoLabs
          Mar 27 at 21:06






          The link in the answer is not related to RenderScript, is just a link about information about how the general smoothstep function works, in case you want to write your own function. And as stated in the answer, RenderScript doesn't have a smoothstep function, so you can use the one I put in the answer, which is a smoothstep function written 100% in RenderScript.

          – PerracoLabs
          Mar 27 at 21:06









          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55384939%2fhow-to-use-smoothstep-function-using-renderscript-in-android%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript