1 Star 0 Fork 0

liyang/NDK_OpenGLES_3_0

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
BasicLight.glsl 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
ByteFlow 提交于 2019-08-16 19:32 . update doc
#version 300 es
precision mediump float;
in vec2 v_texCoord;
in vec3 ambient;
in vec3 diffuse;
in vec3 specular;
layout(location = 0) out vec4 outColor;
uniform sampler2D s_TextureMap;
void main()
{
vec4 objectColor = texture(s_TextureMap, v_texCoord);
vec3 finalColor = (ambient + diffuse + specular) * vec3(objectColor);
outColor = vec4(finalColor, 1.0);
}
#version 300 es
precision mediump float;
layout(location = 0) in vec4 a_position;
layout(location = 1) in vec2 a_texCoord;
layout(location = 2) in vec3 a_normal;
uniform mat4 u_MVPMatrix;
uniform mat4 u_ModelMatrix;
uniform vec3 lightPos;
uniform vec3 lightColor;
uniform vec3 viewPos;
out vec2 v_texCoord;
out vec3 ambient;
out vec3 diffuse;
out vec3 specular;
void main()
{
gl_Position = u_MVPMatrix * a_position;
vec3 fragPos = vec3(u_ModelMatrix * a_position);
// Ambient
float ambientStrength = 0.3;
ambient = ambientStrength * lightColor;
// Diffuse
vec3 unitNormal = normalize(u_ModelMatrix * vec4(a_normal, 1.0)).xyz;
vec3 lightDir = normalize(lightPos - fragPos);
float diff = max(dot(unitNormal, lightDir), 0.0);
diffuse = diff * lightColor;
// Specular
float specularStrength = 0.5;
vec3 viewDir = normalize(viewPos - fragPos);
//vec3 helfVector = normalize(viewDir + lightDir);
vec3 reflectDir = reflect(-lightDir, unitNormal);
float spec = pow(max(dot(unitNormal, reflectDir), 0.0), 32.0);
specular = specularStrength * spec * lightColor;
v_texCoord = a_texCoord;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liyange/NDK_OpenGLES_3_0.git
git@gitee.com:liyange/NDK_OpenGLES_3_0.git
liyange
NDK_OpenGLES_3_0
NDK_OpenGLES_3_0
master

搜索帮助