add specular lighting based on cw5 earlier shaders #6
@ -1,17 +1,26 @@
|
|||||||
#version 410 core
|
#version 410 core
|
||||||
|
|
||||||
uniform sampler2D textureSampler;
|
uniform sampler2D textureSampler;
|
||||||
uniform vec3 lightDir;
|
//uniform vec3 lightDir;
|
||||||
|
uniform vec3 lightPos;
|
||||||
|
uniform vec3 cameraPos;
|
||||||
|
uniform vec3 objectColor;
|
||||||
|
|
||||||
|
in vec3 fragPos;
|
||||||
in vec3 interpNormal;
|
in vec3 interpNormal;
|
||||||
in vec2 interpTexCoord;
|
in vec2 interpTexCoord;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
vec3 lightDir = normalize(lightPos-fragPos);
|
||||||
|
vec3 V = normalize(cameraPos-fragPos);
|
||||||
vec2 modifiedTexCoord = vec2(interpTexCoord.x, 1.0 - interpTexCoord.y); // Poprawka dla tekstur Ziemi, ktore bez tego wyswietlaja sie 'do gory nogami'
|
vec2 modifiedTexCoord = vec2(interpTexCoord.x, 1.0 - interpTexCoord.y); // Poprawka dla tekstur Ziemi, ktore bez tego wyswietlaja sie 'do gory nogami'
|
||||||
vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb;
|
vec3 color = texture2D(textureSampler, modifiedTexCoord).rgb;
|
||||||
vec3 normal = normalize(interpNormal);
|
vec3 normal = normalize(interpNormal);
|
||||||
|
float diffuse = max(0,dot(normal,normalize(lightDir)));
|
||||||
|
vec3 R = reflect(-normalize(lightDir),normal);
|
||||||
float ambient = 0.2;
|
float ambient = 0.2;
|
||||||
float diffuse = max(dot(normal, -lightDir), 0.1);
|
float specular = pow(max(0,dot(R,V)),1000);
|
||||||
gl_FragColor = vec4(color * (ambient + (1-ambient) * diffuse * 0.6 ), 1.0);
|
gl_FragColor = vec4(color*(ambient + (1-ambient)*diffuse)+vec3(1)*specular*0.2, 1.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,12 @@ uniform mat4 modelMatrix;
|
|||||||
|
|
||||||
out vec3 interpNormal;
|
out vec3 interpNormal;
|
||||||
out vec2 interpTexCoord;
|
out vec2 interpTexCoord;
|
||||||
|
out vec3 fragPos;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
||||||
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
|
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
|
||||||
|
fragPos = (modelMatrix*vec4(vertexPosition,1)).xyz;
|
||||||
interpTexCoord = vertexTexCoord;
|
interpTexCoord = vertexTexCoord;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user