blob: 75ed92ed8a586a63125571b867fab7fbad5dbcdb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
;;; Chickadee Game Toolkit
;;; Copyright © 2019, 2021 David Thompson <davet@gnu.org>
;;;
;;; 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
;;; <http://www.gnu.org/licenses/>.
;;; 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-name
phong-properties-ambient
phong-properties-diffuse
phong-properties-specular
phong-properties-shininess
phong-shader
make-phong-material))
(define-shader-type <phong-properties>
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)))
|