2017-12-13 12 views
0

私はいくつかのGLSLシェーダをRenderscriptに移植しようとしています。RenderScript ScriptCでgl_FragCoordと同等です

gl_FragCoordをRenderscript ScriptCにエミュレートする方法はありますか?

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); 
} 

のrenderScript:

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); 
} 

答えて

0

あなたは既にも掛けることに注意して、入力xy引数はgl_FragCoord.xyと同等であり、あなたのコードでそれを持っていますresolution.xyの逆数では、最初にそれで割るのと同じです:

float2 texcoord = (float2){(float)x, (float)y}/(float2){resolution.x, resolution.y}; 
関連する問題