diff options
| author | Dave Houlton <daveh@lunarg.com> | 2018-03-30 17:10:17 -0600 |
|---|---|---|
| committer | Dave Houlton <daveh@lunarg.com> | 2018-04-02 15:25:42 -0600 |
| commit | cb72bd9b0291ba3dc0ee32fc00c7a3b5119b2e23 (patch) | |
| tree | f1a563b2957461d60fe6fa3f5e76438e827e27af | |
| parent | 651b7cd0e960ce11ae403c81f370205e84548682 (diff) | |
| download | usermoji-cb72bd9b0291ba3dc0ee32fc00c7a3b5119b2e23.tar.xz | |
demos: Add some cube lighting
Can stand it no longer. Added some minimal n-dot-L screen-space
lighting.
Change-Id: Ifaf664a5651f59d8904cbb064018c00d385ec3ed
| -rw-r--r-- | demos/cube.frag | 10 | ||||
| -rw-r--r-- | demos/cube.vert | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/demos/cube.frag b/demos/cube.frag index 70ba93ec..5bf6507a 100644 --- a/demos/cube.frag +++ b/demos/cube.frag @@ -24,7 +24,15 @@ layout (binding = 1) uniform sampler2D tex; layout (location = 0) in vec4 texcoord; +layout (location = 1) in vec3 frag_pos; layout (location = 0) out vec4 uFragColor; + +const vec3 lightDir= vec3(0.424, 0.566, 0.707); + void main() { - uFragColor = texture(tex, texcoord.xy); + vec3 dX = dFdx(frag_pos); + vec3 dY = dFdy(frag_pos); + vec3 normal = normalize(cross(dX,dY)); + float light = max(0.0, dot(lightDir, normal)); + uFragColor = light * texture(tex, texcoord.xy); } diff --git a/demos/cube.vert b/demos/cube.vert index 8178d838..63380326 100644 --- a/demos/cube.vert +++ b/demos/cube.vert @@ -28,9 +28,11 @@ layout(std140, binding = 0) uniform buf { } ubuf; layout (location = 0) out vec4 texcoord; +layout (location = 1) out vec3 frag_pos; void main() { texcoord = ubuf.attr[gl_VertexIndex]; gl_Position = ubuf.MVP * ubuf.position[gl_VertexIndex]; + frag_pos = gl_Position.xyz; } |
