CGI/exercise2/glsl/terrain.frag

53 lines
1.2 KiB
GLSL
Raw Normal View History

2018-11-16 11:47:55 +00:00
#version 330
2018-11-26 08:59:16 +00:00
// This source code is property of the Computer Graphics and Visualization
// chair of the TU Dresden. Do not distribute!
2018-11-13 08:35:18 +00:00
// Copyright (C) CGV TU Dresden - All Rights Reserved
2018-11-26 08:59:16 +00:00
in vec3 n;
2018-11-26 12:11:05 +00:00
in vec2 uv;
2018-11-26 08:59:16 +00:00
2018-11-13 08:35:18 +00:00
out vec4 color;
uniform vec3 cameraPos;
2018-11-26 12:11:05 +00:00
uniform sampler2D grass;
2018-11-13 08:35:18 +00:00
uniform sampler2D background;
uniform vec2 screenSize;
2018-11-26 08:59:16 +00:00
const vec3 dirToLight = normalize(vec3(1, 3, 1));
2018-11-13 08:35:18 +00:00
//Calculates the visible surface color based on the Blinn-Phong illumination model
vec4 calculateLighting(vec4 materialColor, float specularIntensity, vec3 normalizedNormal, vec3 directionToViewer)
{
vec4 color = materialColor;
vec3 h = normalize(dirToLight + directionToViewer);
color.xyz *= 0.9 * max(dot(normalizedNormal, dirToLight), 0) + 0.1;
color.xyz += specularIntensity * pow(max(dot(h, normalizedNormal), 0), 50);
return color;
}
vec4 getBackgroundColor()
{
return texture(background, gl_FragCoord.xy / screenSize);
}
void main()
{
//surface geometry
2018-11-26 08:59:16 +00:00
//vec3 n = vec3(0, 1, 0);
2018-11-13 08:35:18 +00:00
vec3 dirToViewer = vec3(0, 1, 0);
2018-11-26 08:59:16 +00:00
//material properties
2018-11-26 12:11:05 +00:00
//color = vec4(0.6, 0.6, 0.6, 1);
color = texture(grass, uv);
2018-11-13 08:35:18 +00:00
float specular = 0;
2018-11-26 08:59:16 +00:00
2018-11-13 08:35:18 +00:00
//Calculate light
color = calculateLighting(color, specular, n, dirToViewer);
2018-11-26 08:59:16 +00:00
2018-11-16 08:27:11 +00:00
}