;;; Chickadee Game Toolkit ;;; Copyright © 2019, 2021 David Thompson ;;; ;;; Chickadee is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published ;;; by the Free Software Foundation, either version 3 of the License, ;;; or (at your option) any later version. ;;; ;;; Chickadee is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see ;;; . ;;; Commentary: ;; ;; Simple forward rendered Phong lighting model. ;; ;;; Code: (define-module (chickadee graphics phong) #:use-module (chickadee config) #:use-module (chickadee math vector) #:use-module (chickadee graphics blend) #:use-module (chickadee graphics color) #:use-module (chickadee graphics depth) #:use-module (chickadee graphics engine) #:use-module (chickadee graphics light) #:use-module (chickadee graphics mesh) #:use-module (chickadee graphics polygon) #:use-module (chickadee graphics shader) #:use-module (chickadee graphics stencil) #:use-module (chickadee graphics texture) #:use-module (srfi srfi-9) #:export (make-phong-properties phong-properties? phong-properties-ambient phong-properties-diffuse phong-properties-specular phong-properties-shininess phong-shader make-phong-material)) (define-shader-type make-phong-properties phong-properties? (float-vec3 ambient phong-properties-ambient) (float-vec3 diffuse phong-properties-diffuse) (float-vec3 specular phong-properties-specular) (float shininess phong-properties-shininess)) (define %phong-shader (delay (load-shader (scope-datadir "shaders/phong-vert.glsl") (scope-datadir "shaders/phong-frag.glsl")))) (define (phong-shader) (force %phong-shader)) (define* (make-phong-material #:key (name "anonymous") (blend-mode blend:replace) (polygon-mode fill-polygon-mode) (cull-face-mode back-cull-face-mode) (depth-test basic-depth-test) (stencil-test default-stencil-test) multisample? (ambient-factor (vec3 1.0 1.0 1.0)) (diffuse-factor (vec3 1.0 1.0 1.0)) (specular-factor (vec3 1.0 1.0 1.0)) (shininess 32.0) (ambient-texture (white-texture)) (diffuse-texture (white-texture)) (specular-texture (white-texture)) (normal-texture (flat-texture))) (make-material #:name name #:shader (phong-shader) #:texture-0 ambient-texture #:texture-1 diffuse-texture #:texture-2 specular-texture #:texture-3 normal-texture #:properties (make-phong-properties #:ambient ambient-factor #:diffuse diffuse-factor #:specular specular-factor #:shininess shininess)))