Skip to content

Instantly share code, notes, and snippets.

@larsen
Created September 2, 2022 15:38
Show Gist options
  • Select an option

  • Save larsen/6bedaedcb6ebb72c8ce085898f7bdd8a to your computer and use it in GitHub Desktop.

Select an option

Save larsen/6bedaedcb6ebb72c8ce085898f7bdd8a to your computer and use it in GitHub Desktop.
(defun-g frag-stage ((uv :vec3)
(normal :vec3))
(let* ((object-color (v! 0 1 0))
;; Ambient light
(ambient-strength 0.01)
(ambient-light-color (v! 1 1 1))
(ambient (* ambient-light-color
ambient-strength))
;; Diffuse light
(diffuse-strength 0.5)
(diffuse-dir (v:dot normal (v:normalize (- *light-pos* uv))))
(diffuse (* diffuse-strength diffuse-dir))
;; Specular light
(specular-strength 0.0)
(view-dir (- *camera-position* uv))
(reflect-dir (reflect (- (- *light-pos* uv))
normal))
(specular (* specular-strength
ambient-light-color
(v3:dot view-dir reflect-dir)))
;; Final fragment color
(frag-color (* object-color (+ ambient diffuse specular))))
(v! frag-color 0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment