Without lights you wouldn't be able to see anything. Luckily fluxus gives you one for free by default, a white diffuse point light attached to the camera. For more interesting lighting, you'll need these functions. Using the standard fixed function graphics pipeline, simplistically speaking, OpenGL multiplies these values with the surface material (set with local state commands like ambient and diffuse) and the texture colour value to give the fina colour.
; turn off the main light (light-diffuse 0 (vector 0 0 0)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'point 'free)) (light-position mylight (vector 5 2 0)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20))
Returns lightid-number
Makes a new light. The type can be one of: point, directional or spot. If the cameralocked string is not free then it will be attached to the camera, and move around when you move the camera.
Example
; turn off the main light (light-diffuse 0 (vector 0 0 0)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'point 'free)) (light-position mylight (vector 5 2 0)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20))
Returns void
Sets the ambient contribution for the specified light.
Example
; turn off the main light (light-diffuse 0 (vector 0 0 0)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'point 'free)) (light-position mylight (vector 5 2 0)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20))
Returns void
Sets the diffuse contribution for the specified light.
Example
; turn off the main light (light-diffuse 0 (vector 0 0 0)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'point 'free)) (light-position mylight (vector 5 2 0)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20))
Returns void
Sets the specular contribution for the specified light.
Example
; turn off the main light (light-diffuse 0 (vector 0 0 0)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'point 'free)) (light-position mylight (vector 5 2 0)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20))
Returns void
Sets the position of the specified light. In worldspace if free, in camera space is attached.
Example
; turn off the main light (light-diffuse 0 (vector 0 0 0)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'point 'free)) (light-position mylight (vector 5 2 0)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20))
Returns void
Sets the spotlight cone angle of the specified light. If it's not a spot light, this command has no effect.
Example
; turn down the main light (light-diffuse 0 (vector 0.1 0.1 0.1)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'spot 'free)) (light-position mylight (vector (+ 4 (crndf)) (crndf) 2)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (light-spot-angle mylight (+ 5 (random 40))) (light-spot-exponent mylight 500) (light-attenuation mylight 'constant 1) (light-direction mylight (vector -1 0 -1)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20) (scale (vector 10 10 10)) (translate (vector -0.5 -0.5 0)) (build-seg-plane 20 20))
Returns void
Sets the spotlight exponent (fuzzyness of the cone) of the specified light. If it's not a spot light, this command has no effect.
Example
; turn down the main light (light-diffuse 0 (vector 0.1 0.1 0.1)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'spot 'free)) (light-position mylight (vector (+ 4 (crndf)) (crndf) 2)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (light-spot-angle mylight (+ 5 (random 40))) (light-spot-exponent mylight 500) (light-attenuation mylight 'constant 1) (light-direction mylight (vector -1 0 -1)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20) (scale (vector 10 10 10)) (translate (vector -0.5 -0.5 0)) (build-seg-plane 20 20))
Returns void
Sets the light attenuation (fade off with distance) of the specified light. The type symbol can be one of: constant, linear or quadratic.
Example
; turn down the main light (light-diffuse 0 (vector 0.1 0.1 0.1)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'spot 'free)) (light-position mylight (vector (+ 4 (crndf)) (crndf) 2)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (light-spot-angle mylight (+ 5 (random 40))) (light-spot-exponent mylight 500) (light-attenuation mylight 'constant 1) (light-direction mylight (vector -1 0 -1)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20) (scale (vector 10 10 10)) (translate (vector -0.5 -0.5 0)) (build-seg-plane 20 20))
Returns void
Sets the direction of a directional light. If it's not a directional light, this command has no effect.
Example
; turn down the main light (light-diffuse 0 (vector 0.1 0.1 0.1)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'spot 'free)) (light-position mylight (vector (+ 4 (crndf)) (crndf) 2)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (light-spot-angle mylight (+ 5 (random 40))) (light-spot-exponent mylight 500) (light-attenuation mylight 'constant 1) (light-direction mylight (vector -1 0 -1)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20) (scale (vector 10 10 10)) (translate (vector -0.5 -0.5 0)) (build-seg-plane 20 20))