ccdemos/spheres_shadow.cc
author Radek Brich <radek.brich@devl.cz>
Sun, 09 Dec 2007 15:01:51 +0100
branchpyrit
changeset 33 83d0200d4c09
parent 32 8af5c17d368b
child 37 5f954c0d34fc
permissions -rw-r--r--
make over-sampling work together with sub-sampling
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#include "raytracer.h"
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
#include "image.h"
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
int main()
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
{
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
	Raytracer rt;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
     7
	rt.setThreads(2);
32
8af5c17d368b new Raytracer option: oversampling
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
     8
	rt.setOversample(0);
8af5c17d368b new Raytracer option: oversampling
Radek Brich <radek.brich@devl.cz>
parents: 22
diff changeset
     9
	rt.setSubsample(8);
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    10
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    11
	KdTree top;
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    12
	rt.setTop(&top);
16
20bceb605f48 add Raytracer::setThreads()
Radek Brich <radek.brich@devl.cz>
parents: 15
diff changeset
    13
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 16
diff changeset
    14
	Light light1(Vector3(0.0, 5.0, -5.0), Colour(0.7, 0.3, 0.6));
15
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
	rt.addlight(&light1);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 16
diff changeset
    17
	Light light2(Vector3(-2.0, 10.0, -2.0), Colour(0.4, 0.6, 0.3));
15
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
	rt.addlight(&light2);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
	Material mat0(Colour(0.7, 0.7, 0.7));
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
	Box box(Vector3(-20.0, -1.2, -20.0), Vector3(20.0, -1.0, 20.0), &mat0);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
	rt.addshape(&box);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
	Material mat1(Colour(1.0, 0.0, 0.0));
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 16
diff changeset
    26
	Sphere bigsphere(Vector3(3.0, 2.0, -7.0), 3.0, &mat1);
15
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
	rt.addshape(&bigsphere);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
	Material mat2(Colour(0.0, 1.0, 0.0));
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 16
diff changeset
    30
	Sphere smallsphere(Vector3(-5.5, 1.5, -8.0), 2.0, &mat2);
15
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
	rt.addshape(&smallsphere);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
	Material mat3(Colour(0.0, 0.0, 1.0));
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 16
diff changeset
    34
	Sphere tinysphere(Vector3(-1.2, 0.0, -2.0), 0.5, &mat3);
15
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
	rt.addshape(&tinysphere);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    37
	top.optimize();
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    38
19
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 16
diff changeset
    39
	Camera cam;
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 16
diff changeset
    40
	cam.setEye(Vector3(0,0,15));
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 16
diff changeset
    41
	rt.setCamera(&cam);
4e0955fca797 added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents: 16
diff changeset
    42
15
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
	int w = 800;
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
	int h = 600;
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    45
	Float *fdata = (Float *) malloc(w*h*3*sizeof(Float));
20
f22952603f29 new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents: 19
diff changeset
    46
	rt.render(w, h, fdata);
15
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
	struct image *img;
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
	new_image(&img, w, h, 3);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
22
76b7bd51d64a new make infrastructure
Radek Brich <radek.brich@devl.cz>
parents: 20
diff changeset
    51
	Float *fd = fdata;
15
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
	for (char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) {
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
		if (*fd > 1.0)
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
			*cd = 255;
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
		else
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
			*cd = (unsigned char)(*fd * 255.0);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
	}
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
	free(fdata);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
	save_png("spheres_shadow.png", img);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60
	destroy_image(&img);
a0a3e334744f C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
}