使用 opengl es 2.0 glsl 实现输入一张纹理图片调节阴影和高光效果,写出顶点和片元着色气代码,并在注释中写明每个变量的默认值
时间: 2023-03-15 07:01:38 浏览: 121
GLSL 基础介绍(OpenGLES 2.0)
3星 · 编辑精心推荐
顶点着色代码:attribute vec4 a_Position;
attribute vec2 a_TexCoord;
uniform mat4 u_MVPMatrix;
varying vec2 v_TexCoord;void main(){
gl_Position = u_MVPMatrix * a_Position;
v_TexCoord = a_TexCoord;
}片元着色器代码:precision mediump float;
uniform sampler2D u_TextureUnit;
uniform float u_Shadow; // 阴影值,默认值为0.0
uniform float u_Highlight; // 高光值,默认值为1.0
varying vec2 v_TexCoord;void main(){
vec4 color = texture2D(u_TextureUnit, v_TexCoord);
vec4 shadowColor = vec4(color.rgb * u_Shadow, color.a);
vec4 highlightColor = vec4(color.rgb * u_Highlight, color.a);
gl_FragColor = mix(shadowColor, highlightColor, 0.5);
}
阅读全文