增加LightPosition3D.vert计算顶点方向光,配合SceneTree范例
This commit is contained in:
parent
0249968785
commit
69343b3bc6
@ -1,4 +1,4 @@
|
||||
#version 450 core
|
||||
#version 450 core
|
||||
|
||||
layout(binding=1) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
@ -9,6 +9,7 @@ layout(binding=1) uniform WorldMatrix // hgl/math/Math.h
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
mat3 normal;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
51
shader/LightPosition3D.vert
Normal file
51
shader/LightPosition3D.vert
Normal file
@ -0,0 +1,51 @@
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec3 Vertex;
|
||||
layout(location = 1) in vec3 Normal;
|
||||
|
||||
layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
mat4 projection;
|
||||
mat4 inverse_projection;
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
vec2 canvas_resolution;
|
||||
vec2 viewport_resolution;
|
||||
}world;
|
||||
|
||||
layout(push_constant) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
}pc;
|
||||
|
||||
layout(binding=1) uniform ColorMaterial
|
||||
{
|
||||
vec4 color;
|
||||
vec4 amibent;
|
||||
} color_material;
|
||||
|
||||
layout(binding=2) uniform Sun
|
||||
{
|
||||
vec3 direction;
|
||||
}sun;
|
||||
|
||||
layout(location=0) out vec4 FragmentColor;
|
||||
|
||||
float GetSunlightIntensity()
|
||||
{
|
||||
return max(dot(normalize(Normal*mat3(world.mvp)),sun.direction),0.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
FragmentColor=color_material.color*GetSunlightIntensity()+color_material.amibent;
|
||||
|
||||
gl_Position=vec4(Vertex,1.0)*(pc.local_to_world*world.mvp);
|
||||
}
|
@ -11,6 +11,7 @@ layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
mat3 normal;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
@ -18,11 +19,11 @@ layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
vec4 view_pos;
|
||||
vec2 canvas_resolution;
|
||||
vec2 viewport_resolution;
|
||||
} world;
|
||||
}world;
|
||||
|
||||
layout(push_constant) uniform Consts {
|
||||
mat4 local_to_world;
|
||||
} pc;
|
||||
}pc;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
{
|
||||
mat4 ortho;
|
||||
|
||||
@ -7,10 +7,12 @@ layout(binding=0) uniform WorldMatrix // hgl/math/Math.h
|
||||
|
||||
mat4 modelview;
|
||||
mat4 inverse_modelview;
|
||||
mat3 normal;
|
||||
|
||||
mat4 mvp;
|
||||
mat4 inverse_mvp;
|
||||
|
||||
vec4 view_pos;
|
||||
vec2 resolution;
|
||||
vec2 canvas_resolution;
|
||||
vec2 viewport_resolution;
|
||||
} world;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#version 450 core
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec4 FragmentColor;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
Loading…
x
Reference in New Issue
Block a user