2015-12-15 01:33:16 +00:00
|
|
|
#version 330 core
|
|
|
|
|
|
|
|
// Input
|
2016-12-24 10:05:51 +00:00
|
|
|
layout(location = 0) in vec3 RawPosition;
|
|
|
|
layout(location = 1) in vec3 RawNormal;
|
2015-12-15 01:33:16 +00:00
|
|
|
|
|
|
|
// Output
|
2016-12-24 10:05:51 +00:00
|
|
|
out vec4 LightColor;
|
2015-12-15 01:33:16 +00:00
|
|
|
|
|
|
|
// Uniforms
|
|
|
|
layout(std140) uniform MVPBlock
|
|
|
|
{
|
|
|
|
mat4 ModelMtx;
|
|
|
|
mat4 ViewMtx;
|
|
|
|
mat4 ProjMtx;
|
|
|
|
};
|
|
|
|
|
2017-01-11 13:29:30 +00:00
|
|
|
uniform bool IsFloor;
|
|
|
|
uniform bool IsUnstandable;
|
|
|
|
|
2015-12-15 01:33:16 +00:00
|
|
|
// Main
|
|
|
|
void main()
|
|
|
|
{
|
2016-12-25 21:47:59 +00:00
|
|
|
const vec3 kLightDir = normalize( vec3(0.3, 0, -1) ); // Sets the direction of the light
|
|
|
|
const float kLightColorMin = 0.5; // Sets the minimum light color (color of a vertex facing away from the light)
|
|
|
|
const float kLightColorMax = 0.9; // Sets the maximum light color (color of a vertex facing towards the light)
|
|
|
|
|
|
|
|
// Calculate vertex position
|
2016-12-24 10:05:51 +00:00
|
|
|
mat4 MVP = ModelMtx * ViewMtx * ProjMtx;
|
|
|
|
gl_Position = vec4(RawPosition, 1) * MVP;
|
2015-12-15 01:33:16 +00:00
|
|
|
|
2016-12-25 21:47:59 +00:00
|
|
|
// Apply some simple lighting
|
|
|
|
float LightDot = dot(RawNormal, kLightDir);
|
2016-12-24 10:05:51 +00:00
|
|
|
float Alpha = (-LightDot + 1.0) / 2;
|
2016-12-25 21:47:59 +00:00
|
|
|
float LightAlpha = mix(kLightColorMin, kLightColorMax, Alpha);
|
2016-12-24 10:05:51 +00:00
|
|
|
LightColor = vec4(LightAlpha, LightAlpha, LightAlpha, 1.0);
|
2017-01-11 13:29:30 +00:00
|
|
|
|
|
|
|
// If this is not a floor, make the surface significantly darker
|
|
|
|
// The surface is considered a floor if IsFloor is true OR if the floor normal Z is greater than 0.85
|
|
|
|
float FloorMul = (!IsUnstandable && (IsFloor || RawNormal.z > 0.85)) ? 1.0 : 0.5;
|
|
|
|
LightColor *= FloorMul;
|
2015-12-15 01:33:16 +00:00
|
|
|
}
|