|
@@ -1,6 +1,9 @@
|
|
return lovr.graphics.newShader([[
|
|
return lovr.graphics.newShader([[
|
|
-out vec3 lightDirection;
|
|
|
|
|
|
+
|
|
|
|
+// All of these are in view-space.
|
|
|
|
+out vec3 lightDirection; // A vector from the vertex to the light
|
|
out vec3 normalDirection;
|
|
out vec3 normalDirection;
|
|
|
|
+out vec3 vertexPosition;
|
|
|
|
|
|
vec3 lightPosition = vec3(0, 10, 3);
|
|
vec3 lightPosition = vec3(0, 10, 3);
|
|
|
|
|
|
@@ -10,15 +13,17 @@ vec4 position(mat4 projection, mat4 transform, vec4 vertex) {
|
|
|
|
|
|
lightDirection = normalize(vec3(vLight - vVertex));
|
|
lightDirection = normalize(vec3(vLight - vVertex));
|
|
normalDirection = normalize(lovrNormalMatrix * lovrNormal);
|
|
normalDirection = normalize(lovrNormalMatrix * lovrNormal);
|
|
|
|
+ vertexPosition = vVertex.xyz;
|
|
|
|
|
|
return projection * transform * vertex;
|
|
return projection * transform * vertex;
|
|
}
|
|
}
|
|
]], [[
|
|
]], [[
|
|
in vec3 lightDirection;
|
|
in vec3 lightDirection;
|
|
in vec3 normalDirection;
|
|
in vec3 normalDirection;
|
|
|
|
+in vec3 vertexPosition;
|
|
|
|
|
|
vec3 cAmbient = vec3(.25);
|
|
vec3 cAmbient = vec3(.25);
|
|
-vec3 cDiffuse = vec3(.75);
|
|
|
|
|
|
+vec3 cDiffuse = vec3(1);
|
|
vec3 cSpecular = vec3(.35);
|
|
vec3 cSpecular = vec3(.35);
|
|
|
|
|
|
vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
|
|
vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
|
|
@@ -27,7 +32,7 @@ vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
|
|
|
|
|
|
if (diffuse > 0.) {
|
|
if (diffuse > 0.) {
|
|
vec3 r = reflect(lightDirection, normalDirection);
|
|
vec3 r = reflect(lightDirection, normalDirection);
|
|
- vec3 viewDirection = normalize(-vec3(gl_FragCoord));
|
|
|
|
|
|
+ vec3 viewDirection = normalize(-vertexPosition);
|
|
|
|
|
|
float specularAngle = max(dot(r, viewDirection), 0.);
|
|
float specularAngle = max(dot(r, viewDirection), 0.);
|
|
specular = pow(specularAngle, 5.);
|
|
specular = pow(specularAngle, 5.);
|