blob: 5c00d6072ba3167ff1edd828d7abdb8ce5ab6834 (
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
|
;;; Chickadee Game Toolkit
;;; Copyright © 2019, 2021 David Thompson <dthompson2@worcester.edu>
;;;
;;; Licensed under the Apache License, Version 2.0 (the "License");
;;; you may not use this file except in compliance with the License.
;;; You may obtain a copy of the License at
;;;
;;; http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software
;;; distributed under the License is distributed on an "AS IS" BASIS,
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;; See the License for the specific language governing permissions and
;;; limitations under the License.
;;; 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 <phong-properties> #f)
;; (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)))
|