4 Star 0 Fork 0

cyb/Computer Graphics Second Experiment

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
model.fs 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
cyb 提交于 2024-05-22 11:18 . 增加了树模型
#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);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cyb_c/computer-graphics-second-experiment.git
git@gitee.com:cyb_c/computer-graphics-second-experiment.git
cyb_c
computer-graphics-second-experiment
Computer Graphics Second Experiment
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385