![](/img/trans.png)
[英]How to use android.support.v8.renderscript for renderscript
[英]How to use smoothstep function using renderscript in android
我們如何在渲染腳本中使用smoothstep函數來平滑蒙版圖像(已經使用內核大小為3或5的高斯模糊來模糊)並使其邊緣更平滑。 我在其他框架中嘗試了以下代碼,它們按預期工作。
iOS着色器代碼:-
let kernelStr = """
kernel vec4 myColor(__sample source) {
float maskValue = smoothstep(0.3, 0.5, source.r);
return vec4(maskValue,maskValue,maskValue,1.0);
}
"""
在opengl glsl片段着色器中:-
float mask = btex.r;
float maskValue = smoothstep(0.3, 0.5, mask);
vec4 ress = vec4(maskValue,maskValue,maskValue,1.0);
RenderScript沒有內置的smoothstep函數,因此最簡單的事情是自己實現。 接下來,准備在腳本中使用的源代碼:
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);
}
用法示例:
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};
....
}
接下來是有關平滑步驟內部工作方式的鏈接,以防您有任何其他疑問:
請享用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.