我创建了着色器文件
crop.frag
将效果裁剪为 Texture
为圆形:
#version 150
varying vec4 v_color;
varying vec2 v_texCoord0;
uniform sampler2D u_texture;
vec4 borderColor;
uniform vec3 outlineColor;
uniform float outlineAlpha;
uniform float offset;
uniform float outerRadius;
uniform float innerRadius;
uniform float intensity;
uniform float brightness;
void main() {
vec4 color = texture2D(u_texture, v_texCoord0) * v_color;
borderColor = vec4(outlineColor.rgb, outlineAlpha);
// circle crop
vec2 relativePosition = v_texCoord0.xy - 0.5;
float len = length(relativePosition);
float vignette = smoothstep(outerRadius, innerRadius, len);
color.rgba = mix(color.rgba, color.rgba * vignette, intensity);
// make outline over circle cropped
float vignetteOutline = smoothstep(outerRadius - offset / 100.0, innerRadius - offset / 100.0, len);
borderColor.rgba = mix(borderColor.rgba, color.rgba * vignetteOutline, color.a * vignetteOutline);
gl_FragColor = color * (borderColor + brightness + 0.20);
}
将此着色器应用于
Texture
效果很好。但如果我将其应用于 TextureRegion
中的单个 Texture
,则效果仅适用于 region.getTexture();
。
所以,我想修改着色器文件中的
region
顶点。
我不是 GL Shader 语言专家。
只需使用Texture而不是TextureRegion,因为如您所知,OpenGL仅适用于纹理。