[英]gl_FragCoord equivalent in RenderScript ScriptC
我正在将一些GLSL着色器移植到Renderscript中。
在Renderscript ScriptC中模拟gl_FragCoord的等效方式是什么?
GLSL着色器:
uniform sampler2D u_texture;
varying vec2 v_texcoord;
uniform vec2 resolution;
void main()
{
vec4 color = texture2D(u_texture, v_texcoord);
vec2 position = (gl_FragCoord.xy / resolution.xy) - vec2(0.5);
float len = length(position);
gl_FragColor = color * vec4(vec3(len), 1.0);
}
渲染脚本:
rs_allocation texture;
rs_sampler sampler;
float2 resolution;
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y)
{
float2 texcoord = (float2){(float)x, (float)y} * (float2){ 1.0f / resolution.x, 1.0f / resolution.y};
float4 color = rsSample(texture, sampler, texcoord);
-----------------------------------------------------------------
float2 position = (***gl_FragCoord.xy*** / resolution.xy) - 0.5f;
-----------------------------------------------------------------
float len = length(position);
color *= (float4){len, len, len, 1.0f}
return rsPackColorTo8888(color);
}
您已经在代码中使用了它,输入的x
和y
参数等效于gl_FragCoord.xy
,还请注意,乘以resolution.xy
的倒数与首先除以它是相同的:
float2 texcoord = (float2){(float)x, (float)y} / (float2){resolution.x, resolution.y};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.