2017-12-13 5 views
0

일부 GLSL 셰이더를 Renderscript로 이식하는 중입니다.RenderScript ScriptC에서 gl_FragCoord 해당 항목

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

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