#version 430 precision highp float; layout(binding = 0) uniform sampler2D heightTexture; layout(location = 1) uniform float time; layout(std140, binding = 0) uniform SceneUniforms { mat4 PV; //camera projection * view matrix vec4 eye_w; //world-space eye position }; layout(std140, binding = 1) uniform LightUniforms { vec4 La; //ambient light color vec4 Ld; //diffuse light color vec4 Ls; //specular light color vec4 light_w; //world-space light position }; layout(std140, binding = 2) uniform MaterialUniforms { vec4 ka; //ambient material color vec4 kd; //diffuse material color vec4 ks; //specular material color float shininess; //specular exponent }; in vec3 frag_position; in VertexData { vec2 tex_coord; } inData; out vec4 frag_color; //the output color for this fragment void main(void) { //Compute per-fragment Phong lighting // vec4 ktex = texture(diffuse_tex, inData.tex_coord); // vec4 ambient_term = ka*ktex*La; // const float eps = 1e-8; //small value to avoid division by 0 // float d = distance(light_w.xyz, inData.pw.xyz); // float atten = 1.0/(d*d+eps); //d-squared attenuation // vec3 nw = normalize(inData.nw); //world-space unit normal vector // vec3 lw = normalize(light_w.xyz - inData.pw.xyz); //world-space unit light vector // vec4 diffuse_term = atten*kd*ktex*Ld*max(0.0, dot(nw, lw)); // vec3 vw = normalize(eye_w.xyz - inData.pw.xyz); //world-space unit view vector // vec3 rw = reflect(-lw, nw); //world-space unit reflection vector // vec4 specular_term = atten*ks*Ls*pow(max(0.0, dot(rw, vw)), shininess); // fragcolor = ambient_term + diffuse_term + specular_term; float height = texture(heightTexture, inData.tex_coord).r; //frag_color = vec4(inData.tex_coord, 0.0f, 1.0f); // if (height > 0.8) frag_color = vec4(vec3(1.0f-height), 1.0f); // else frag_color = vec4(vec3(height), 1.0f); frag_color = vec4(height, height, height, 1.0); }