// File: /workspace/github_cpp_makefile_star2_O2/soybin[P]idyll/src/renderer.cpp
// Function: renderer::renderer(int, int, seed*, fractal*)
renderer::renderer(int WIDTH, int HEIGHT, seed* s, fractal* f) 	: WIDTH(WIDTH), HEIGHT(HEIGHT), s(s), f(f) {

	// get field of view from config file
	FOV = config::getInt("fov");

	// get sample value from config file
	SAMPLES = config::getInt("samples");

	// get surface bounces per ray
	BOUNCES = config::getInt("bounces");

	// set lower bound for randomness in sky noise
	SKY_NOISE = std::min(std::max(0.8, SAMPLES / 8.0), 1.0);

	// get random glossiness chance and glossiness amount from the
	// region's seed.
	// this represents the probability for a ray to be reflected
	// as glossy instead of as diffuse, and with which intensity
	// it will do so
	GLOSSINESS_CHANCE = s->values["GLOSSINESS_CHANCE"];
	GLOSSINESS_AMOUNT = s->values["GLOSSINESS_AMOUNT"];

	// random positioning of the camera along the surface of a
	// sphere with a certain radius
	math::vec3 dir;
	dir.x = s->values["xcameraDirection"];
	dir.y = s->values["ycameraDirection"];
	dir.z = s->values["zcameraDirection"];
	double distance = s->values["cameraDistance"];
	for (double radius = 0.0; radius < MAX_DIST; ) {
		cameraPosition = dir * radius;
		updateRotationMatrix();
		++radius;
		if (f->de(cameraPosition) < distance) continue;
		bool hit = false;
		for (int i = 0; i < 64; ++i) {
			double y = HEIGHT * s->d(0.0, 1.0);
			double x = WIDTH * s->d(0.0, 1.0);
			double d = march({cameraPosition, calculateRayDirection(x, y)});
			if (d != -1.0) {
				hit = true;
				break;
			}
		}
		if (hit) {
			break;
		}
	}

	// get directional light direction
	lightDirection.x = s->values["xlightDirection"];
	lightDirection.y = s->values["ylightDirection"];
	lightDirection.z = s->values["zlightDirection"];

	// get directional light color
	lightColor.x = s->values["xlightColor"];
	lightColor.y = s->values["ylightColor"];
	lightColor.z = s->values["zlightColor"];
	
	// get sky color
	skyColor.x = s->values["xskyColor"];
	skyColor.y = s->values["yskyColor"];
	skyColor.z = s->values["zskyColor"];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %r8, %r14
movq %rcx, %r12
movl %edx, %r15d
movq %rdi, %rbx
movl %esi, -0x70(%rbp)
movl %esi, (%rdi)
movl %edx, 0x4(%rdi)
leaq 0x30(%rdi), %r13
movq %r13, %rdi
callq 0x5c20
leaq 0x48(%rbx), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x5c20
leaq 0x60(%rbx), %rdi
movq %rdi, -0x98(%rbp)
callq 0x5c20
leaq 0x78(%rbx), %rdi
movq %rdi, -0x90(%rbp)
callq 0x5c20
xorpd %xmm0, %xmm0
movupd %xmm0, 0xb0(%rbx)
movupd %xmm0, 0xa0(%rbx)
movupd %xmm0, 0x90(%rbx)
movq %r14, -0xb0(%rbp)
movq %r14, 0xc0(%rbx)
movq %r12, 0xc8(%rbx)
leaq 0x600e(%rip), %rsi      # 0xc938
leaq -0x188(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x4676
leaq -0x188(%rbp), %rdi
callq 0x53e0
movl %eax, 0x8(%rbx)
leaq -0x188(%rbp), %rdi
callq 0x3100
leaq 0x5fe0(%rip), %rsi      # 0xc93c
leaq -0x168(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x4676
leaq -0x168(%rbp), %rdi
callq 0x53e0
movl %eax, 0xc(%rbx)
leaq -0x168(%rbp), %rdi
callq 0x3100
leaq 0x5fb6(%rip), %rsi      # 0xc944
leaq -0x148(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x4676
leaq -0x148(%rbp), %rdi
callq 0x53e0
movl %eax, 0x10(%rbx)
leaq -0x148(%rbp), %rdi
callq 0x3100
cvtsi2sdl 0xc(%rbx), %xmm0
mulsd 0x5f0a(%rip), %xmm0     # 0xc8d0
maxsd 0x5f0a(%rip), %xmm0     # 0xc8d8
movsd 0x5ca2(%rip), %xmm1     # 0xc678
minsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rbx)
leaq 0x5f66(%rip), %rsi      # 0xc94c
leaq -0x50(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x4676
leaq 0x2718(%r12), %rdi
leaq -0x50(%rbp), %rsi
movq %rdi, -0x58(%rbp)
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rbx)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5f3a(%rip), %rsi      # 0xc95e
leaq -0x50(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rbx)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq -0x88(%rbp), %rdi
movq %rbx, -0x68(%rbp)
callq 0x5c20
leaq 0x5f06(%rip), %rsi      # 0xc970
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5ee1(%rip), %rsi      # 0xc981
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5ebf(%rip), %rsi      # 0xc992
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, -0x78(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5e9d(%rip), %rsi      # 0xc9a3
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3100
cvtsi2sdl -0x70(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
cvtsi2sd %r15d, %xmm0
movsd %xmm0, -0xb8(%rbp)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
leaq -0xf8(%rbp), %r14
movq -0x68(%rbp), %r15
movsd 0x5d75(%rip), %xmm0     # 0xc8e0
ucomisd -0x60(%rbp), %xmm0
jbe 0x6cc6
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
leaq -0x88(%rbp), %rsi
movsd -0x60(%rbp), %xmm0
callq 0x5cf6
movq %r13, %rdi
movq %rbx, %rsi
callq 0x5d8a
movq -0x68(%rbp), %rdi
callq 0x6400
movsd -0x60(%rbp), %xmm0
addsd 0x5ac9(%rip), %xmm0     # 0xc678
movsd %xmm0, -0x60(%rbp)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movupd (%r13), %xmm0
movupd %xmm0, (%rsp)
movq -0xb0(%rbp), %rdi
callq 0x82e0
movsd -0xa8(%rbp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x6b63
pushq $0x41
popq %rbx
decl %ebx
je 0x6b63
xorpd %xmm0, %xmm0
movq %r12, %rdi
movsd 0x5a7c(%rip), %xmm1     # 0xc678
callq 0x966e
movsd %xmm0, -0x70(%rbp)
xorpd %xmm0, %xmm0
movq %r12, %rdi
movsd 0x5a63(%rip), %xmm1     # 0xc678
callq 0x966e
movsd -0x70(%rbp), %xmm1
mulsd -0xb8(%rbp), %xmm1
mulsd -0xc0(%rbp), %xmm0
movq 0x10(%r13), %rax
movq %rax, -0xd0(%rbp)
movups (%r13), %xmm2
movaps %xmm2, -0xe0(%rbp)
leaq -0x128(%rbp), %rdi
movq %r15, %rsi
callq 0x664a
movq -0x118(%rbp), %rax
movq %rax, 0x10(%r14)
movups -0x128(%rbp), %xmm0
movups %xmm0, (%r14)
movaps -0xe0(%rbp), %xmm0
movaps %xmm0, -0x110(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x100(%rbp)
movapd -0x110(%rbp), %xmm0
movapd -0x100(%rbp), %xmm1
movaps -0xf0(%rbp), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %r15, %rdi
callq 0x6f7e
ucomisd 0x5bb2(%rip), %xmm0     # 0xc870
jne 0x6cc6
jnp 0x6be5
leaq 0x5ce5(%rip), %rsi      # 0xc9b2
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movq -0xa0(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5cbc(%rip), %rsi      # 0xc9c2
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
movq -0x68(%rbp), %rbx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rbx)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5c95(%rip), %rsi      # 0xc9d2
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rbx)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5c72(%rip), %rsi      # 0xc9e2
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movq -0x98(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5c45(%rip), %rsi      # 0xc9ee
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%rbx)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5c1e(%rip), %rsi      # 0xc9fa
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, 0x70(%rbx)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5bf7(%rip), %rsi      # 0xca06
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movq -0x90(%rbp), %rax
movsd %xmm0, (%rax)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5bc8(%rip), %rsi      # 0xca10
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, 0x80(%rbx)
leaq -0x50(%rbp), %rdi
callq 0x3100
leaq 0x5b9c(%rip), %rsi      # 0xca1a
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4676
leaq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
callq 0x7838
movsd (%rax), %xmm0
movsd %xmm0, 0x88(%rbx)
leaq -0x50(%rbp), %rdi
callq 0x3100
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6ef5
jmp 0x6f50
jmp 0x6ef5
jmp 0x6f50
jmp 0x6ef5
jmp 0x6f50
jmp 0x6ef5
jmp 0x6f50
jmp 0x6ef5
jmp 0x6f50
jmp 0x6ef5
jmp 0x6f50
jmp 0x6ef5
jmp 0x6f50
jmp 0x6ef5
jmp 0x6f50
jmp 0x6ef5
jmp 0x6f50
jmp 0x6ef5
jmp 0x6f50
jmp 0x6ef5
jmp 0x6f50
jmp 0x6ef5
jmp 0x6f50
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0x3100
jmp 0x6f53
jmp 0x6f50
jmp 0x6f50
jmp 0x6f0b
jmp 0x6f43
movq %rax, %r14
leaq -0x50(%rbp), %rdi
jmp 0x6f3c
jmp 0x6f43
movq %rax, %r14
leaq -0x148(%rbp), %rdi
jmp 0x6f3c
jmp 0x6f43
movq %rax, %r14
leaq -0x168(%rbp), %rdi
jmp 0x6f3c
jmp 0x6f43
movq %rax, %r14
leaq -0x188(%rbp), %rdi
callq 0x3100
jmp 0x6f57
movq %rax, %r14
jmp 0x6f57
jmp 0x6f50
jmp 0x6f50
jmp 0x6f50
jmp 0x6f50
movq %rax, %r14
movq -0x68(%rbp), %rbx
leaq 0x90(%rbx), %r15
addq $0xa8, %rbx
movq %rbx, %rdi
callq 0x4c12
movq %r15, %rdi
callq 0x4c12
movq %r14, %rdi
callq 0x3460
nop