########################
# Makefile for GDTrace #
########################

#####################
# Tokyo Hotel Scene #
#####################

# Run 'make program' to only build the program
# [...]

# Run 'make lowres' for a *very* low resolution version
lowres: program
	./MicroTrace 0

# Run 'make highres' for a moderate resolution version (caution: takes quite a while)
highres: program
	./MicroTrace 1 stratified 100

# Run 'make fishtank' for a 360 degrees view from inside the fish tank
fishtank: program
	./MicroTrace 2 stratified 16

# To activate the stereo cams, uncomment STEREOVIEW in /src/defines.
# You might also like to see the caustic scene, 'make caustic', below to see photon mapping.

###############
# Test scenes #
###############

# Run 'make ballsnopm' for the balls test scene without photon mapping
ballsnopm: program
	./MicroTrace 3 stratified 100

# Run 'make barney' for our old friend Barney
barney: program
	./MicroTrace 4 stratified 100

# Run 'make checkers' for the supersampling test scene
checkers: program
	./MicroTrace 5 stratified 100

# Run 'make woodenballs' for the wood procedural shading test scene
woodenballs: program
	./MicroTrace 6 stratified 100

# Run 'make ballspm' for the balls test scene with photon mapping
# Photon mapping can been seen even better in the 'caustic' scene below!
ballspm: program
	./MicroTrace 7 stratified 100 write balls.phm 1E6
	./MicroTrace 7 stratified 100 read balls.phm
	rm balls.phm

# Run 'make woodentiles' for the procedural wooden tiles test scene
woodentiles: program
	./MicroTrace 8 stratified 100

# Run 'make water' for the water demonstration.
water: program
	./MicroTrace 9 stratified 100 write water.phm 1E6
	./MicroTrace 9 stratified 100 read water.phm
	rm water.phm

# Run 'make caustic' for the cool photon mapping demonstration
caustic: program
	./MicroTrace 10 stratified 100 write caustic.phm 1E6
	./MicroTrace 10 stratified 100 read caustic.phm
	rm caustic.phm

# Run 'make SSS' for a demonstration of our subsurface scattering approach
SSS: program
	./MicroTrace 11 stratified 100 write sss.phm 1E6
	./MicroTrace 11 stratified 100 read sss.phm
	rm sss.phm

# Run 'make SSSsingle' for one single barney with slight SSS. This scene was used to create
# the equally oriented barneys on the web page
SSSsingle: program
	./MicroTrace 12 stratified 100 write sss.phm 1E6
	./MicroTrace 12 stratified 100 read sss.phm
	rm sss.phm

# Run 'make glossy' for a cool glossyness demonstration
glossy: program
	./MicroTrace 13 stratified 100 write glossy.phm 1E6
	./MicroTrace 13 stratified 100 read glossy.phm
	rm glossy.phm

# Run 'make dof' for a depth of field simulation
dof: program
	./MicroTrace 15 stratified 100

# Run 'make mountains' for our mountains test scene
mountains: program
	./MicroTrace 16 stratified 100

# Run 'make granite' for a test rendering of the granite texture
granite: program
	./MicroTrace 17 stratified 100

######################################################################################
# Below follow flags and entries to build the program

all: lowres

CC = g++ 
CFLAGS = -O3 -Wall
#CFLAGS = -O0 -g

SOURCE_FILES = $(shell find | grep .cxx$$)

program: obj MicroTrace

clean:
	rm -rf obj MicroTrace
.PHONY: clean

obj:
	mkdir -p $@

obj/%.dep: src/%.cxx
	mkdir -p `dirname $@`
	echo -n `dirname $@`/ > $@
	$(CC) $< -MM | sed -r -e 's,^(.*)\.o\s*\:,\1.o $@ :,g' >> $@

ifneq ($(MAKECMDGOALS),clean)
-include $(SOURCE_FILES:./src/%.cxx=./obj/%.dep)
endif

OBJ_FILES=$(SOURCE_FILES:./src/%.cxx=./obj/%.o)

obj/%.o: src/%.cxx
	mkdir -p `dirname $@`
	$(CC) $(CFLAGS) -c $< -o $@

MicroTrace: $(OBJ_FILES)
	mkdir -p `dirname $@`
	$(CC) $(OBJ_FILES) -o $@

