blob: e1641ec5c6e5593f191acb2a3125a91f96ec7281 (
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
88
89
90
|
;;; 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:
;;
;; Physically based lighting model.
;;
;;; Code:
(define-module (chickadee graphics pbr)
#:use-module (chickadee config)
#:use-module (chickadee math vector)
#:use-module (chickadee graphics blend)
#:use-module (chickadee graphics buffer)
#:use-module (chickadee graphics color)
#:use-module (chickadee graphics engine)
#:use-module (chickadee graphics polygon)
#:use-module (chickadee graphics shader)
#:use-module (chickadee graphics texture)
#:use-module (srfi srfi-9)
#:export (make-pbr-properties
pbr-properties?
pbr-properties-base-color-factor
pbr-properties-base-color-texcoord
pbr-properties-metallic-factor
pbr-properties-roughness-factor
pbr-properties-metallic-roughness-texcoord
pbr-properties-normal-texcoord
pbr-properties-occlusion-texcoord
pbr-properties-emissive-factor
pbr-properties-emissive-texcoord
pbr-properties-alpha-mode
pbr-properties-alpha-cutoff
default-pbr-properties
pbr-shader))
(define-shader-type <pbr-properties>
make-pbr-properties
pbr-properties?
(float-vec3 base-color-factor pbr-properties-base-color-factor)
(int base-color-texcoord pbr-properties-base-color-texcoord)
(float metallic-factor pbr-properties-metallic-factor)
(float roughness-factor pbr-properties-roughness-factor)
(int metallic-roughness-texcoord pbr-properties-metallic-roughness-texcoord)
(int normal-texcoord pbr-properties-normal-texcoord)
(int occlusion-texcoord pbr-properties-occlusion-texcoord)
(float-vec3 emissive-factor pbr-properties-emissive-factor)
(int emissive-texcoord pbr-properties-emissive-texcoord)
(int alpha-mode pbr-properties-alpha-mode)
(float alpha-cutoff pbr-properties-alpha-cutoff))
(define default-pbr-properties
(make-pbr-properties #:base-color-factor #v(1.0 1.0 1.0)
#:base-color-texcoord 0
#:metallic-factor 1.0
#:roughness-factor 1.0
#:metallic-roughness-texcoord 0
#:normal-texcoord 0
#:occlusion-texcoord 0
#:emissive-factor #v(1.0 1.0 1.0)
#:emissive-texcoord 0
#:alpha-mode 0
#:alpha-cutoff 0.5))
(define %pbr-shader
(delay (load-shader (scope-datadir "shaders/pbr-vert.glsl")
(scope-datadir "shaders/pbr-frag.glsl"))))
(define (pbr-shader)
(force %pbr-shader))
;; TODO: Handle vertex colors
;; (buffer-view?
;; (assv-ref vattrs
;; (attribute-location
;; (hash-ref sattrs "color0"))))
|