first step for BlinnPhongPureColor
This commit is contained in:
parent
4ed0e281b2
commit
c4deceebd9
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit 03443255541b4dde822f147fb7b817b3811cd8b9
|
Subproject commit 006eaa3f1c0b46e70c01a672d919e8740cb8f2bb
|
@ -1,17 +1,12 @@
|
|||||||
#Material
|
#Material
|
||||||
Name Blinn-phong shading model only color
|
Name BlinnPhong+HalfLambert shading model only color
|
||||||
Base Std3D
|
Reference https://zhuanlan.zhihu.com/p/442023993
|
||||||
|
Base Std3D
|
||||||
|
|
||||||
Require LocalToWorld,Camera,Sun
|
Require LocalToWorld,Camera,Sun
|
||||||
|
|
||||||
#MaterialInstance
|
#MaterialInstance
|
||||||
|
|
||||||
Code
|
|
||||||
{
|
|
||||||
float Diffuse;
|
|
||||||
float Intensity;
|
|
||||||
}
|
|
||||||
|
|
||||||
#VertexInput
|
#VertexInput
|
||||||
vec3 Normal
|
vec3 Normal
|
||||||
|
|
||||||
@ -30,4 +25,40 @@ Code
|
|||||||
}
|
}
|
||||||
|
|
||||||
#Fragment
|
#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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ vec2 TexCoord
|
|||||||
#MaterialInstance
|
#MaterialInstance
|
||||||
Length 120
|
Length 120
|
||||||
Stage Fragment
|
Stage Fragment
|
||||||
|
|
||||||
Code
|
Code
|
||||||
{
|
{
|
||||||
vec4 x_color;
|
vec4 x_color;
|
||||||
@ -31,6 +32,7 @@ Output
|
|||||||
{
|
{
|
||||||
vec2 TexCoord
|
vec2 TexCoord
|
||||||
}
|
}
|
||||||
|
|
||||||
Code
|
Code
|
||||||
{
|
{
|
||||||
void main()
|
void main()
|
||||||
@ -72,12 +74,13 @@ Code
|
|||||||
// ======= AXES
|
// ======= AXES
|
||||||
float xb = step(abs(x) - mi.axis_line_width, 0.0);
|
float xb = step(abs(x) - mi.axis_line_width, 0.0);
|
||||||
float yb = step(abs(y) - mi.axis_line_width, 0.0);
|
float yb = step(abs(y) - mi.axis_line_width, 0.0);
|
||||||
|
|
||||||
color.rgb = mix(color.rgb, mi.x_axis_color.rgb, (xb));
|
color.rgb = mix(color.rgb, mi.x_axis_color.rgb, (xb));
|
||||||
color.rgb = mix(color.rgb, mi.y_axis_color.rgb, (yb));
|
color.rgb = mix(color.rgb, mi.y_axis_color.rgb, (yb));
|
||||||
|
|
||||||
// ======= CENTER
|
// ======= CENTER
|
||||||
float cb = length(vec2(x,y))-mi.center_radius;
|
float cb = length(vec2(x,y))-mi.center_radius;
|
||||||
color.rgb = mix(color.rgb, mi.center_color.rgb, cb>0.0?0.0:smoothstep(0,edge*256.0,abs(cb)));
|
color.rgb = mix(color.rgb, mi.center_color.rgb, cb>0.0?0.0:smoothstep(0,edge*mi.scale.y,abs(cb)));
|
||||||
|
|
||||||
FragColor=color;
|
FragColor=color;
|
||||||
}
|
}
|
||||||
|
30
example/Gizmo/BlenderAxis.cpp
Normal file
30
example/Gizmo/BlenderAxis.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Blender axis
|
||||||
|
/**
|
||||||
|
* 0 1 2 3 4 5 6 7
|
||||||
|
* 0+---------->>>> X
|
||||||
|
* 1|
|
||||||
|
* 2|
|
||||||
|
* 3| +--+
|
||||||
|
* 4| +--+
|
||||||
|
* 5|
|
||||||
|
* 6V
|
||||||
|
* 7V
|
||||||
|
*
|
||||||
|
* 坐标轴参考Blender设计
|
||||||
|
*
|
||||||
|
* 单方向坐标轴长度为8
|
||||||
|
* 最终箭头长度为2
|
||||||
|
*
|
||||||
|
* 负责2D平移的方块尺寸为1,位置在3-4
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缩放工具
|
||||||
|
*/
|
||||||
|
class GizmoScale
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
};//class GizmoScale
|
@ -14,4 +14,6 @@ CreateProject(01_PlaneGrid3D PlaneGrid3D.cpp)
|
|||||||
CreateProject(02_RayPicking RayPicking.cpp)
|
CreateProject(02_RayPicking RayPicking.cpp)
|
||||||
CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp)
|
CreateProject(03_MetricCellsGrid MetricCellsGrid.cpp)
|
||||||
|
|
||||||
|
CreateProject(04_Gizmo3DMove Gizmo3DMove.cpp)
|
||||||
|
|
||||||
#CreateProject(03_BlenderAxis BlenderAxis.cpp)
|
#CreateProject(03_BlenderAxis BlenderAxis.cpp)
|
||||||
|
0
example/Gizmo/Gizmo3DMove.cpp
Normal file
0
example/Gizmo/Gizmo3DMove.cpp
Normal file
@ -31,7 +31,7 @@ struct MetricCellsGridData
|
|||||||
|
|
||||||
constexpr const size_t MCG_SIZE=sizeof(MetricCellsGridData);
|
constexpr const size_t MCG_SIZE=sizeof(MetricCellsGridData);
|
||||||
|
|
||||||
constexpr const float PLANE_SIZE=512;
|
constexpr const float PLANE_SIZE=1024;
|
||||||
|
|
||||||
class TestApp:public SceneAppFramework
|
class TestApp:public SceneAppFramework
|
||||||
{
|
{
|
||||||
|
@ -53,10 +53,6 @@ public:
|
|||||||
|
|
||||||
MaterialCreateInfo *CreateVertexColor3D(const Material3DCreateConfig *);
|
MaterialCreateInfo *CreateVertexColor3D(const Material3DCreateConfig *);
|
||||||
MaterialCreateInfo *CreateVertexLuminance3D(const Material3DCreateConfig *);
|
MaterialCreateInfo *CreateVertexLuminance3D(const Material3DCreateConfig *);
|
||||||
//MaterialCreateInfo *CreatePureColor2D(const Material2DCreateConfig *);
|
|
||||||
//MaterialCreateInfo *CreatePureTexture2D(const Material2DCreateConfig *);
|
|
||||||
//MaterialCreateInfo *CreateRectTexture2D(Material2DCreateConfig *);
|
|
||||||
//MaterialCreateInfo *CreateRectTexture2DArray(Material2DCreateConfig *);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从文件加载材质
|
* 从文件加载材质
|
||||||
|
@ -95,7 +95,6 @@ void main()
|
|||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
};//class MaterialRectTexture2D:public Std2DMaterial
|
};//class MaterialRectTexture2D:public Std2DMaterial
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user