diff options
Diffstat (limited to 'chickadee/graphics/model.scm')
-rw-r--r-- | chickadee/graphics/model.scm | 87 |
1 files changed, 40 insertions, 47 deletions
diff --git a/chickadee/graphics/model.scm b/chickadee/graphics/model.scm index 92d5a28..309b00f 100644 --- a/chickadee/graphics/model.scm +++ b/chickadee/graphics/model.scm @@ -212,23 +212,24 @@ (define (maybe-add-material) (let ((name (assq-ref opts 'name))) (when name - (let* ((ambient (or (assq-ref opts 'ambient-map) (white-texture))) - (diffuse (or (assq-ref opts 'diffuse-map) (white-texture))) - (specular (or (assq-ref opts 'specular-map) (white-texture))) - (normals (or (assq-ref opts 'normal-map) (flat-texture))) - (properties (make-phong-properties - #:ambient (assq-ref opts 'ambient) - #:diffuse (assq-ref opts 'diffuse) - #:specular (assq-ref opts 'specular) - #:shininess (assq-ref opts 'shininess))) + (let* ((ambient-texture (or (assq-ref opts 'ambient-map) + (white-texture))) + (diffuse-texture (or (assq-ref opts 'diffuse-map) + (white-texture))) + (specular-texture (or (assq-ref opts 'specular-map) + (white-texture))) + (normal-texture (or (assq-ref opts 'normal-map) + (flat-texture))) (material - (make-material #:name name - #:shader (phong-shader) - #:texture-0 ambient - #:texture-1 diffuse - #:texture-2 specular - #:texture-3 normals - #:properties properties))) + (make-phong-material #:name name + #:ambient-texture ambient-texture + #:diffuse-texture diffuse-texture + #:specular-texture specular-texture + #:normal-texture normal-texture + #:ambient-factor (assq-ref opts 'ambient) + #:diffuse-factor (assq-ref opts 'diffuse) + #:specular-factor (assq-ref opts 'specular) + #:shininess (assq-ref opts 'shininess)))) (hash-set! material-map name material))))) (match (read-line port) ((? eof-object?) @@ -546,13 +547,7 @@ (hash-ref material-map "default")))))) ;; Register default material (hash-set! material-map "default" - (make-material #:name "default" - #:shader (phong-shader) - #:texture-0 (white-texture) - #:texture-1 (white-texture) - #:texture-2 (white-texture) - #:texture-3 (flat-texture) - #:properties default-phong-properties)) + (make-phong-material #:name "default")) ;; Parse file. (let loop ((material "default")) (match (read-line port) @@ -858,9 +853,9 @@ ;; BLEND. (alpha-mode (match (or (string-ref/optional obj "alphaMode") "OPAQUE") - ("OPAQUE" 0) - ("MASK" 1) - ("BLEND" 2))) + ("OPAQUE" 'opaque) + ("MASK" 'mask) + ("BLEND" 'blend))) (alpha-cutoff (or (number-ref/optional obj "alphaCutoff") 0.5)) (double-sided? (boolean-ref/optional obj "doubleSided")) (extensions (object-ref/optional obj "extensions")) @@ -881,30 +876,28 @@ (parse-texture obj "occlusionTexture" white-texture)) ((emissive-texture emissive-texcoord) (parse-texture obj "emissiveTexture" black-texture))) - (make-material + (make-pbr-material #:name name - #:shader (pbr-shader) - #:blend-mode (if (= alpha-mode 2) blend:alpha blend:replace) + #:blend-mode (if (eq? alpha-mode 'opaque) blend:alpha blend:replace) #:cull-face-mode (if double-sided? no-cull-face-mode back-cull-face-mode) - #:texture-0 base-color-texture - #:texture-1 metal-rough-texture - #:texture-2 normal-texture - #:texture-3 occlusion-texture - #:texture-4 emissive-texture - #:properties (make-pbr-properties - #:base-color-factor base-color-factor - #:base-color-texcoord base-color-texcoord - #:metallic-factor metallic-factor - #:roughness-factor roughness-factor - #:metallic-roughness-texcoord metal-rough-texcoord - #:normal-texcoord normal-texcoord - #:occlusion-texcoord occlusion-texcoord - #:emissive-factor emissive-factor - #:emissive-texcoord emissive-texcoord - #:alpha-mode alpha-mode - #:alpha-cutoff alpha-cutoff))))) + #:base-color-texture base-color-texture + #:metallic-roughness-texture metal-rough-texture + #:normal-texture normal-texture + #:occlusion-texture occlusion-texture + #:emissive-texture emissive-texture + #:base-color-factor base-color-factor + #:base-color-texcoord base-color-texcoord + #:metallic-factor metallic-factor + #:roughness-factor roughness-factor + #:metallic-roughness-texcoord metal-rough-texcoord + #:normal-texcoord normal-texcoord + #:occlusion-texcoord occlusion-texcoord + #:emissive-factor emissive-factor + #:emissive-texcoord emissive-texcoord + #:alpha-mode alpha-mode + #:alpha-cutoff alpha-cutoff)))) (define (attribute-name->index name) (let ((shader (pbr-shader))) (match name @@ -944,7 +937,7 @@ (#f #f) (n (vector-ref accessors n)))) (material (match (number-ref/optional obj "material") - (#f default-pbr-properties) + (#f (make-pbr-material)) (n (vector-ref materials n)))) (mode (match (or (number-ref/optional obj "mode") 4) (0 'points) |