test sunlight UBO ok!
This commit is contained in:
parent
5188d4149c
commit
f3a59c1bb3
@ -1,2 +1,2 @@
|
||||
vec3 direction;
|
||||
vec3 color;
|
||||
vec4 direction;
|
||||
vec4 color;
|
||||
|
@ -14,11 +14,17 @@ UBO
|
||||
File BlinnPhongSun.ubo //文件名,如果/开头表示从ShaderLibrary根目录开始,没有则表示同一目录
|
||||
Struct BlinnPhongSun //结构名称
|
||||
Name sun //在代码中的变量名
|
||||
Stage Vertex,Fragment //会引用的shader
|
||||
Stage Fragment //会引用的shader
|
||||
Set Global //Descriptor Set
|
||||
}
|
||||
|
||||
#MaterialInstance
|
||||
Length 16
|
||||
Stage Fragment
|
||||
Code
|
||||
{
|
||||
vec4 Color;
|
||||
}
|
||||
|
||||
#VertexInput
|
||||
vec3 Normal
|
||||
@ -33,6 +39,7 @@ Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
HandoverMI();
|
||||
gl_Position=GetPosition3D();
|
||||
}
|
||||
}
|
||||
@ -47,31 +54,33 @@ Code
|
||||
{
|
||||
void main()
|
||||
{
|
||||
MaterialInstance mi=GetMI();
|
||||
|
||||
//将法线归一化
|
||||
vec3 world_normal =normalize(Input.Normal);
|
||||
|
||||
//对世界坐标下的灯光方法归一化
|
||||
vec3 world_light_direction =normalize(sun.direction);
|
||||
vec3 world_light_direction =normalize(sun.direction.xyz);
|
||||
|
||||
//点乘法线和光照
|
||||
vec3 diffuse =0.5*dot(world_light_direction,world_normal)+0.5;
|
||||
vec3 diffuse =vec3(0.5)*dot(world_light_direction.xyz,world_normal)+vec3(0.5);
|
||||
|
||||
//直接光颜色
|
||||
vec3 direct_color =sun.diffuse*diffuse*sun.color;
|
||||
vec3 direct_color =sun.color.rgb*mi.Color.rgb;
|
||||
|
||||
#ifndef HAVE_SPECULAR
|
||||
// #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
|
||||
// #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
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ static Color4f white_color(1,1,1,1);
|
||||
|
||||
static mtl::blinnphong::SunLight sun_light=
|
||||
{
|
||||
Vector3f(1,1,1),
|
||||
Vector3f(1,0.975,0.95)
|
||||
Vector4f(1,1,1,0),
|
||||
Vector4f(1,0,0,1)
|
||||
};
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
@ -68,8 +68,6 @@ private:
|
||||
|
||||
bool CreateBlinnPhongUBO()
|
||||
{
|
||||
sun_light.color=Vector3f(1,1,1);
|
||||
|
||||
ubo_sun=db->CreateUBO("sun",sizeof(sun_light),&sun_light);
|
||||
if(!ubo_sun)return(false);
|
||||
|
||||
@ -86,8 +84,9 @@ private:
|
||||
if(!mtl_sun_light)return(false);
|
||||
|
||||
mtl_sun_light->BindUBO(DescriptorSetType::Global,"sun",ubo_sun);
|
||||
mtl_sun_light->Update();
|
||||
|
||||
mi_sphere=db->CreateMaterialInstance(mtl_sun_light);
|
||||
mi_sphere=db->CreateMaterialInstance(mtl_sun_light,nullptr,&white_color);
|
||||
if(!mi_sphere)return(false);
|
||||
|
||||
p_sphere=CreatePipeline(mtl_sun_light,InlinePipeline::Solid3D,Prim::Triangles);
|
||||
@ -163,6 +162,9 @@ public:
|
||||
if(!InitVertexLumMP())
|
||||
return(false);
|
||||
|
||||
if(!CreateBlinnPhongUBO())
|
||||
return(false);
|
||||
|
||||
if(!InitBlinnPhongSunLightMP())
|
||||
return(false);
|
||||
|
||||
|
@ -49,15 +49,15 @@ public:
|
||||
|
||||
virtual ~Material();
|
||||
|
||||
const UTF8String & GetName ()const{return name;}
|
||||
const AnsiString & GetName ()const{return name;}
|
||||
|
||||
const VertexInput * GetVertexInput ()const{return vertex_input;}
|
||||
|
||||
const ShaderStageCreateInfoList & GetStageList ()const{return shader_stage_list;}
|
||||
|
||||
const MaterialDescriptorManager * GetDescriptorSets ()const{return desc_manager;}
|
||||
// const MaterialDescriptorManager * GetDescriptorManager ()const{return desc_manager;}
|
||||
const VkPipelineLayout GetPipelineLayout ()const;
|
||||
const PipelineLayoutData * GetPipelineLayoutData ()const{return pipeline_layout_data;}
|
||||
// const PipelineLayoutData * GetPipelineLayoutData ()const{return pipeline_layout_data;}
|
||||
|
||||
public:
|
||||
|
||||
|
@ -8,8 +8,8 @@ namespace blinnphong
|
||||
{
|
||||
struct SunLight
|
||||
{
|
||||
Vector3f direction;
|
||||
Vector3f color;
|
||||
Vector4f direction;
|
||||
Vector4f color;
|
||||
};//struct SunLight
|
||||
|
||||
constexpr const ShaderBufferSource SBS_SunLight=
|
||||
@ -18,8 +18,8 @@ namespace blinnphong
|
||||
"sun",
|
||||
|
||||
R"(
|
||||
vec3 direction;
|
||||
vec3 color;
|
||||
vec4 direction;
|
||||
vec4 color;
|
||||
)"
|
||||
};
|
||||
}//namespace blinnphong
|
||||
|
Loading…
x
Reference in New Issue
Block a user