OpenGL浮雕效果

glsl浮雕算法,可使用shadertoy直接运行。获取一个角度的两个texture进行相减,再进行灰度化。

#iChannel1"file://./car.png"

const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);
const vec2 TexSize = vec2(100.0, 100.0);
const vec4 bkColor = vec4(0.5, 0.5, 0.5, 1.0);

void mainImage(out vec4 fragColor,in vec2 fragCoord)
{
    vec2 uv = fragCoord.xy/iResolution.xy;
    vec2 upLeftUV = vec2(uv.x-1.0/TexSize.x, uv.y-1.0/TexSize.y);
    vec4 curColor = texture2D(iChannel1, uv);
    vec4 upLeftColor = texture2D(iChannel1, upLeftUV);
    vec4 delColor = curColor - upLeftColor;
    float luminance = dot(delColor.rgb, W);
    fragColor = vec4(vec3(luminance), 0.0) + bkColor;
}

原图如下:
OpenGL浮雕效果_第1张图片
效果图如下:
OpenGL浮雕效果_第2张图片

你可能感兴趣的:(OpenGL)