#!/bin/sh

# a substantial ray trace renderer application (see
# www.richardmiskowski.com/JavaScript/JSRender/render.html
# for a web version of this code that has been automatically translated
# to javascript). This version of the application tests the shmall C compiler
# and schant scheme. this script compiles everything followed by rendering
# a test scene into a ppm image file. the render takes ~5m to 130m depending
# on the machines processor speed.

cat \
  render/size.scm \
  render/constants-schant.scm \
  render/random.scm \
  render/readx.scm \
  render/scheme-eval.scm \
  render/projection.scm \
  render/point.scm \
  render/vector.scm \
  render/bounding-box.scm \
  render/AABB.scm \
  render/intersection-object.scm \
  render/phong.scm \
  render/ray.scm \
  render/camera.scm \
  render/fisheye.scm \
  render/scene.scm \
  render/sphere.scm \
  render/plane.scm \
  render/triangle.scm \
  render/cylinder.scm \
  render/light.scm \
  render/octree.scm \
  render/shader.scm \
  render/preliminaries.scm \
  render/gamma.scm \
  render/plot.scm \
  render/init-scene.scm \
  render/write-dims.scm \
  render/main-part.scm \
  render/launch.scm \
  > renderer.scm

echo "compiling some utility commands with shmall C ..."
cd ..
./compile-with-shmall-to-native.sh test-renderer/data2ppm object 100
./compile-with-shmall-to-native.sh test-renderer/fat object 5000
cd test-renderer

echo "compile renderer.scm with the schant compiler ..."
cat ../bin/schant-compiler.txt renderer.scm | \
  ../bin/schant-bigfloat8 \
  >renderer

SCENE=simple-scene.scm
#SCENE=dna-scene.scm
echo "run the renderer with a sample scene. render takes ~5m to 130m"
date
cat renderer sdl.scm $SCENE | \
  ../bin/schant-bigfloat8 | ./fat | ./data2ppm >x.ppm
date

echo "image file x.ppm created. view with feh x.ppm, xv x.ppm, etc"
