代码拉取完成,页面将自动刷新
#version 330 core
layout (location = 0) out vec4 FragColor;
layout (location = 1) out vec4 BrightColor;
in VS_OUT {
vec3 FragPos;
vec3 Normal;
vec2 TexCoords;
} fs_in;
struct Light {
vec3 Position;
vec3 Color;
float Brightness;
};
uniform Light lights[100]; // 支持最多100个光源
uniform int numLights; // 当前活动的光源数量
uniform vec3 materialDiffuse;
uniform vec3 materialAmbient;
uniform vec3 materialSpecular;
uniform float materialShininess;
uniform float materialOpacity;
uniform vec3 viewPos;
void main()
{
vec3 color = materialDiffuse;
vec3 normal = normalize(fs_in.Normal);
// ambient
vec3 ambient = materialAmbient * color;
// lighting
vec3 lighting = vec3(0.0);
vec3 viewDir = normalize(viewPos - fs_in.FragPos);
for(int i = 0; i < numLights; i++) // 使用当前活动的光源数量
{
// diffuse
vec3 lightDir = normalize(lights[i].Position - fs_in.FragPos);
float diff = max(dot(lightDir, normal), 0.0);
vec3 diffuse = lights[i].Color * diff * color * lights[i].Brightness;
// specular
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), materialShininess);
vec3 specular = lights[i].Color * spec * materialSpecular * lights[i].Brightness;
// attenuation
float distance = length(lights[i].Position - fs_in.FragPos);
float attenuation = 1.0 / (distance * distance);
lighting += (diffuse + specular) * attenuation;
}
vec3 result = ambient + lighting;
// check whether result is higher than some threshold, if so, output as bloom threshold color
float brightness = dot(result, vec3(0.2126, 0.7152, 0.0722));
if(brightness > 1.0)
BrightColor = vec4(result, 1.0);
else
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
FragColor = vec4(result, materialOpacity);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。