summaryrefslogtreecommitdiff
path: root/chickadee/graphics/phong.scm
diff options
context:
space:
mode:
Diffstat (limited to 'chickadee/graphics/phong.scm')
-rw-r--r--chickadee/graphics/phong.scm107
1 files changed, 40 insertions, 67 deletions
diff --git a/chickadee/graphics/phong.scm b/chickadee/graphics/phong.scm
index 5288075..edb8686 100644
--- a/chickadee/graphics/phong.scm
+++ b/chickadee/graphics/phong.scm
@@ -30,83 +30,56 @@
#:use-module (chickadee graphics shader)
#:use-module (chickadee graphics texture)
#:use-module (srfi srfi-9)
- #:export (make-phong-material
- phong-material?
- phong-material-name
- phong-material-ambient
- phong-material-ambient-map
- phong-material-use-ambient-map?
- phong-material-diffuse
- phong-material-diffuse-map
- phong-material-use-diffuse-map?
- phong-material-specular
- phong-material-specular-map?
- phong-material-use-specular-map?
- phong-material-specular-exponent
- phong-material-bump-map
- phong-material-use-bump-map?
- default-phong-material
- load-phong-shader
- shader-apply/phong))
+ #:export (make-phong-properties
+ phong-properties?
+ phong-properties-name
+ phong-properties-ambient
+ phong-properties-use-ambient-map?
+ phong-properties-diffuse
+ phong-properties-use-diffuse-map?
+ phong-properties-specular
+ phong-properties-specular-map?
+ phong-properties-use-specular-map?
+ phong-properties-specular-exponent
+ phong-properties-use-normal-map?
+ default-phong-properties
+ phong-shader))
;;;
-;;; Phong Material
+;;; Phong Properties
;;;
-(define-shader-type <phong-material>
- make-phong-material
- phong-material?
- (local-field name phong-material-name)
- (float-vec3 ambient phong-material-ambient)
- (local-field ambient-map phong-material-ambient-map)
- (bool use-ambient-map phong-material-use-ambient-map?)
- (float-vec3 diffuse phong-material-diffuse)
- (local-field diffuse-map phong-material-diffuse-map)
- (bool use-diffuse-map phong-material-use-diffuse-map?)
- (float-vec3 specular phong-material-specular)
- (local-field specular-map phong-material-specular-map)
- (bool use-specular-map phong-material-use-specular-map?)
- (float shininess phong-material-shininess)
- (local-field bump-map phong-material-bump-map)
- (bool use-bump-map phong-material-use-bump-map?))
+(define-shader-type <phong-properties>
+ make-phong-properties
+ phong-properties?
+ (float-vec3 ambient phong-properties-ambient)
+ (bool use-ambient-map phong-properties-use-ambient-map?)
+ (float-vec3 diffuse phong-properties-diffuse)
+ (bool use-diffuse-map phong-properties-use-diffuse-map?)
+ (float-vec3 specular phong-properties-specular)
+ (bool use-specular-map phong-properties-use-specular-map?)
+ (float shininess phong-properties-shininess)
+ (bool use-normal-map phong-properties-use-normal-map?))
-(define default-phong-material
- (make-phong-material #:name "default"
- #:ambient (vec3 0.5 0.5 0.5)
- #:ambient-map null-texture
- #:use-ambient-map #f
- #:diffuse (vec3 0.8 0.8 0.8)
- #:diffuse-map null-texture
- #:use-diffuse-map #f
- #:specular (vec3 0.3 0.3 0.3)
- #:specular-map null-texture
- #:use-specular-map #f
- #:shininess 32.0
- #:bump-map null-texture
- #:use-bump-map #f))
+(define default-phong-properties
+ (make-phong-properties #:ambient (vec3 0.5 0.5 0.5)
+ #:use-ambient-map #f
+ #:diffuse (vec3 0.8 0.8 0.8)
+ #:use-diffuse-map #f
+ #:specular (vec3 1.0 1.0 1.0)
+ #:use-specular-map #f
+ #:shininess 32.0
+ #:use-normal-map #f))
;;;
;;; Phong Shader
;;;
-(define-graphics-variable phong-shader
- (load-shader (scope-datadir "shaders/phong-vert.glsl")
- (scope-datadir "shaders/phong-frag.glsl")))
+(define %phong-shader
+ (delay (load-shader (scope-datadir "shaders/phong-vert.glsl")
+ (scope-datadir "shaders/phong-frag.glsl"))))
-(define (shader-apply/phong vertex-array material model-matrix view-matrix
- camera-position lights ambient-light-color)
- (let ((shader (graphics-variable-ref phong-shader)))
- (with-graphics-state ((g:texture-0 (phong-material-ambient-map material))
- (g:texture-1 (phong-material-diffuse-map material))
- (g:texture-2 (phong-material-specular-map material))
- (g:texture-3 (phong-material-bump-map material)))
- (shader-apply shader vertex-array
- #:model model-matrix
- #:view view-matrix
- #:projection (current-projection)
- #:material material
- #:camera-position camera-position
- #:ambient-light-color ambient-light-color
- #:lights lights))))
+(define (phong-shader)
+ (force %phong-shader))