updated SunLightPureColor.mtl

This commit is contained in:
2024-03-04 12:58:22 +08:00
parent 8b82c6c25c
commit a7af276a44

View File

@@ -0,0 +1,75 @@
#Material
Name BlinnPhong+HalfLambert shading model only color
Reference https://zhuanlan.zhihu.com/p/442023993
Base Std3D/BlinnPhong
//某些Require并不真的存在.ubo文件写成一行一个是为了方便未来改成带路径的
Require LocalToWorld
Require Camera
define HAVE_SPECULAR off //默认不定义HAVE_SPECULAR
UBO
{
File Sun.ubo //文件名
Name sun //在代码中的变量名
Stage Vertex,Fragment //会引用的shader
}
#MaterialInstance
#VertexInput
vec3 Normal
#Vertex
Output
{
vec3 Normal;
}
Code
{
void main()
{
gl_Position=GetPosition3D();
}
}
#Fragment
Output
{
vec4 FragColor;
}
Code
{
void main()
{
//将法线归一化
vec3 world_normal =normalize(Input.Normal);
//对世界坐标下的灯光方法归一化
vec3 world_light_direction =normalize(sun.direction);
//点乘法线和光照
vec3 diffuse =0.5*dot(world_light_direction,world_normal)+0.5;
//直接光颜色
vec3 direct_color =sun.diffuse*diffuse*sun.color;
#ifndef HAVE_SPECULAR
FragColor=vec4(direct_color,1.0);
#else
//归一代视角方向
vec3 view_direction =normalize(camera.pos-world_position);
//世界坐标下的反射光方向
vec3 reflect_direction =normalize(reflect(-world_light_direction,world_normal));
//高光
vec3 specular =sun.specular*pow(saturate(dot(reflect_direction,view_direction)),gloss);
FragColor=vec4(direct_color+specular,1.0);
#endif//HAVE_SPECULAR
}
}