diff options
author | David Thompson <dthompson2@worcester.edu> | 2021-05-07 21:17:59 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2021-05-07 21:17:59 -0400 |
commit | 271a2bb9775dd8a4a6e5a232f27af86ca7ffd83e (patch) | |
tree | debf24d4cf81d50cf60fea9619063fc6cd1a4094 /chickadee/graphics/pbr.scm | |
parent | feb3c58215960f2bac66922e8d1a1f8e32b7ff95 (diff) |
model: Improve PBR material handling for glTF models.
Diffstat (limited to 'chickadee/graphics/pbr.scm')
-rw-r--r-- | chickadee/graphics/pbr.scm | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/chickadee/graphics/pbr.scm b/chickadee/graphics/pbr.scm index 1ed3777..4b5b192 100644 --- a/chickadee/graphics/pbr.scm +++ b/chickadee/graphics/pbr.scm @@ -27,6 +27,7 @@ #: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) @@ -35,15 +36,18 @@ pbr-material-name pbr-material-base-color-factor pbr-material-base-color-texture + pbr-material-base-color-texcoord pbr-material-metallic-factor pbr-material-roughness-factor - pbr-material-metallic-roughness-texture pbr-material-normal-factor pbr-material-normal-texture + pbr-material-normal-texcoord pbr-material-occlusion-facgor pbr-material-occlusion-texture + pbr-material-occlusion-texcoord pbr-material-emissive-factor pbr-material-emissive-texture + pbr-material-emissive-texcoord pbr-material-alpha-mode pbr-material-alpha-cutoff pbr-material-double-sided? @@ -57,34 +61,48 @@ (local-field name pbr-material-name) (float-vec3 base-color-factor pbr-material-base-color-factor) (local-field base-color-texture pbr-material-base-color-texture) + (bool base-color-texture-enabled pbr-material-base-color-texture-enabled?) + (int base-color-texcoord pbr-material-base-color-texcoord) (float metallic-factor pbr-material-metallic-factor) (float roughness-factor pbr-material-roughness-factor) - (local-field metallic-roughness-texture pbr-material-metallic-roughness-texture) (float-vec3 normal-factor pbr-material-normal-factor) (local-field normal-texture pbr-material-normal-texture) + (bool normal-texture-enabled pbr-material-normal-texture-enabled) + (int normal-texcoord pbr-material-normal-texcoord) (float-vec3 occlusion-factor pbr-material-occlusion-factor) (local-field occlusion-texture pbr-material-occlusion-texture) + (bool occlusion-texture-enabled pbr-material-occlusion-texture-enabled) + (int occlusion-texcoord pbr-material-occlusion-texcoord) (float-vec3 emissive-factor pbr-material-emissive-factor) (local-field emissive-texture pbr-material-emissive-texture) + (bool emissive-texture-enabled pbr-material-emissive-texture-enabled) + (int emissive-texcoord pbr-material-emissive-texcoord) (local-field alpha-mode pbr-material-alpha-mode) (float alpha-cutoff pbr-material-alpha-cutoff) - (bool double-sided? pbr-material-double-sided?)) + (local-field double-sided? pbr-material-double-sided?)) (define default-pbr-material (make-pbr-material #:name "default" #:base-color-factor #v(1.0 1.0 1.0) #:base-color-texture null-texture + #:base-color-texture-enabled #f + #:base-color-texcoord 0 #:metallic-factor 1.0 #:roughness-factor 1.0 - #:metallic-roughness-texture #f #:normal-factor #v(1.0 1.0 1.0) - #:normal-texture #f + #:normal-texture null-texture + #:normal-texture-enabled #f + #:normal-texcoord 0 #:occlusion-factor #v(1.0 1.0 1.0) - #:occlusion-texture #f + #:occlusion-texture null-texture + #:occlusion-texture-enabled #f + #:occlusion-texcoord 0 #:emissive-factor #v(1.0 1.0 1.0) - #:emissive-texture #f + #:emissive-texture null-texture + #:emissive-texture-enabled #f + #:emissive-texcoord 0 #:alpha-mode 'opaque - #:alpha-cutoff 0.5 + #:alpha-cutoff 1.0 #:double-sided? #f)) (define-graphics-variable pbr-shader @@ -93,24 +111,21 @@ (define (shader-apply/pbr vertex-array material model-matrix view-matrix) (let* ((shader (graphics-variable-ref pbr-shader)) - (base-color-texture (pbr-material-base-color-texture material)) - (secondary-texture (or (pbr-material-metallic-roughness-texture material) - (pbr-material-normal-texture material) - (pbr-material-occlusion-texture material) - (pbr-material-emissive-texture material) - null-texture)) (vattrs (vertex-array-attributes vertex-array)) (sattrs (shader-attributes shader))) - (with-graphics-state ((g:texture-0 base-color-texture) - (g:texture-1 secondary-texture)) + (with-graphics-state ((g:cull-face-mode (if (pbr-material-double-sided? material) + no-cull-face-mode + back-cull-face-mode)) + (g:texture-0 (pbr-material-base-color-texture material)) + (g:texture-1 (pbr-material-normal-texture material)) + (g:texture-2 (pbr-material-occlusion-texture material)) + (g:texture-3 (pbr-material-emissive-texture material))) (shader-apply shader vertex-array #:model model-matrix #:view view-matrix #:projection (current-projection) - #:textured0 (not (eq? base-color-texture null-texture)) - #:textured1 (not (eq? secondary-texture null-texture)) #:vertex-colored (buffer-view? (assv-ref vattrs (attribute-location (hash-ref sattrs "color0")))) - #:base-color-factor (pbr-material-base-color-factor material))))) + #:material material)))) |