Add Normal in vertex. And add light in shader.
This commit is contained in:
parent
8908ef1332
commit
0e96615b32
16 changed files with 221 additions and 85 deletions
|
|
@ -3,9 +3,12 @@
|
|||
out vec4 outputColor;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 lightColor;
|
||||
uniform sampler2D texture0;
|
||||
|
||||
in vec4 FarColor;
|
||||
in vec3 Normal;
|
||||
in vec3 FragPos;
|
||||
in vec2 TexCoord;
|
||||
in vec4 TexType;
|
||||
|
|
@ -41,8 +44,14 @@ void main()
|
|||
vec4 mix2 = mix(blendedColor[1], blendedColor[3], weightX);
|
||||
vec4 finalColor = mix(mix1, mix2, weightY);
|
||||
|
||||
vec3 norm = normalize(Normal);
|
||||
vec3 lightDir = normalize(lightPos - FragPos);
|
||||
float diff = max(dot(norm, lightDir), 0.0);
|
||||
vec3 diffuse = diff * lightColor;
|
||||
|
||||
vec4 litColor = vec4(diffuse, 1.0) * finalColor;
|
||||
|
||||
float distance = length(viewPos - FragPos);
|
||||
float interpolationFactor = clamp(distance / 1000.0, 0.0, 1.0);
|
||||
outputColor = mix(finalColor, FarColor, interpolationFactor);
|
||||
outputColor = mix(litColor, FarColor, interpolationFactor);
|
||||
}
|
||||
|
|
@ -1,16 +1,18 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec4 aColor;
|
||||
layout (location = 2) in vec4 aColorFar;
|
||||
layout (location = 3) in vec2 aTexCoord;
|
||||
layout (location = 4) in vec4 aTexType;
|
||||
layout (location = 5) in float aRealTexType;
|
||||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec4 aColor;
|
||||
layout (location = 3) in vec4 aColorFar;
|
||||
layout (location = 4) in vec2 aTexCoord;
|
||||
layout (location = 5) in vec4 aTexType;
|
||||
layout (location = 6) in float aRealTexType;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
out vec4 Color;
|
||||
out vec4 FarColor;
|
||||
out vec2 TexCoord;
|
||||
|
|
@ -21,6 +23,7 @@ void main()
|
|||
{
|
||||
gl_Position = vec4(aPos, 1.0) * model * view * projection;
|
||||
FragPos = vec3(vec4(aPos, 1.0) * model);
|
||||
Normal = aNormal;
|
||||
Color = aColor;
|
||||
FarColor = aColorFar;
|
||||
TexCoord = aTexCoord;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue