我需要用距离场方法放大RGBA图像。 我有代码计算灰度图片的距离变换。 我如何使用它与32位图片?实际上如何放大图片?
我有用于放大灰度图片的着色器,这里是:
precision highp float;
uniform sampler2D u_Texture; // The input texture.
uniform sampler2D u_DistTexture; // The input texture.
varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment.
const float _128_DIV_255 = 0.50196;
const float DF_SIZE = 16.0;
void postDF()
{
float D = DF_SIZE * (texture2D(u_DistTexture, v_TexCoordinate).r - _128_DIV_255);
float aastep = length(vec2(dFdx(D), dFdy(D)));
//float aastep = DF_SIZE/2.0;
float pattern = smoothstep(-aastep, aastep, D);
if(D >= 0.0)
{
vec4 texColor;
float d_step = D / (DF_SIZE / 2.0);
if (d_step < 0.125)
texColor = texture2D(u_Texture, v_TexCoordinate);
else
texColor = vec4(pattern);
gl_FragColor = mix(texColor, vec4(pattern), pattern);
}
else
gl_FragColor = vec4(vec3(0.0), 1.0);
}
// The entry point for our fragment shader.
void main()
{
if(v_TexCoordinate.x > 0.5)
{
gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
}
else
{
//gl_FragColor = texture2D(u_DistTexture, v_TexCoordinate);
postDF();
}
uniform sampler2D u_Texture; // The input texture.
uniform sampler2D u_DistTexture; // The input texture.
varying vec2 v_TexCoordinate; // Interpolated texture coordinate per fragment.
const float _128_DIV_255 = 0.50196;
const float DF_SIZE = 16.0;
void postDF()
{
float D = DF_SIZE * (texture2D(u_DistTexture, v_TexCoordinate).r - _128_DIV_255);
float aastep = length(vec2(dFdx(D), dFdy(D)));
//float aastep = DF_SIZE/2.0;
float pattern = smoothstep(-aastep, aastep, D);
if(D >= 0.0)
{
vec4 texColor;
float d_step = D / (DF_SIZE / 2.0);
if (d_step < 0.125)
texColor = texture2D(u_Texture, v_TexCoordinate);
else
texColor = vec4(pattern);
gl_FragColor = mix(texColor, vec4(pattern), pattern);
}
else
gl_FragColor = vec4(vec3(0.0), 1.0);
}
// The entry point for our fragment shader.
void main()
{
if(v_TexCoordinate.x > 0.5)
{
gl_FragColor = texture2D(u_Texture, v_TexCoordinate);
}
else
{
//gl_FragColor = texture2D(u_DistTexture, v_TexCoordinate);
postDF();
}
u_Texture是灰度图像,u_DistTexture是它的距离场。 我可以写类似的东西,但是对于RGBA图像吗?