// File: GUI-Graphics[P]cpuraytracing/renderer.cpp
// Function: gui::Renderer::radiance(gui::Ray const&, gui::Scene const&, int) const
Vector3 Renderer::radiance(const Ray& ray, const Scene& scene, int depth) const {
		Intersection intersection;
		if (scene.intersect(ray, 0, 10000, intersection)) {
			Ray scattered;
			Vector3 attenuation;
			if (intersection.material->scatter(
				ray, intersection, attenuation, scattered) && depth < 30) {
				return attenuation * radiance(scattered, scene, ++depth);
			} else {
				return Vector3(0);
			}
		} else {
			Vector3 unit = ray.direction;
			float k = (unit.identity().y + 1) * 0.5f;
			return Vector3(1) * (1 - k) + Vector3(0.5f, 0.7f, 1) * k;
		}
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movl %ecx, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x7230
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq (%rdi), %rax
xorps %xmm0, %xmm0
movss 0x13c8(%rip), %xmm1     # 0x815c
leaq -0x58(%rbp), %rdx
callq *0x10(%rax)
testb $0x1, %al
jne 0x6da4
jmp 0x6e6c
leaq -0x70(%rbp), %rdi
callq 0x7270
leaq -0x7c(%rbp), %rdi
callq 0x47c0
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq (%rdi), %rax
leaq -0x58(%rbp), %rdx
leaq -0x7c(%rbp), %rcx
leaq -0x70(%rbp), %r8
callq *0x10(%rax)
testb $0x1, %al
jne 0x6dd9
jmp 0x6e5b
cmpl $0x1e, -0x2c(%rbp)
jge 0x6e5b
movq -0x140(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
incl %ecx
movl %ecx, -0x2c(%rbp)
leaq -0x70(%rbp), %rsi
callq 0x6d50
movss %xmm1, -0x90(%rbp)
movlpd %xmm0, -0x98(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x80(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x7c(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x72a0
movss %xmm1, -0xa0(%rbp)
movlpd %xmm0, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0xc(%rbp)
movl -0xa0(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6fd6
leaq -0xc(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x3070
jmp 0x6fd6
movq -0x20(%rbp), %rax
movl 0x14(%rax), %ecx
movl %ecx, -0xb0(%rbp)
movq 0xc(%rax), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x5aa0
movss 0x4(%rax), %xmm1
movss 0x1167(%rip), %xmm0     # 0x8004
movss %xmm0, -0x168(%rbp)
addss %xmm0, %xmm1
movss 0x1177(%rip), %xmm2     # 0x8028
movss %xmm2, -0x164(%rbp)
mulss %xmm2, %xmm1
movss %xmm1, -0xbc(%rbp)
leaq -0xd4(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x3070
movq -0x170(%rbp), %rdi
movss -0x168(%rbp), %xmm0
movss -0xbc(%rbp), %xmm1
subss %xmm1, %xmm0
callq 0x47d0
movss -0x168(%rbp), %xmm2
movaps %xmm0, %xmm3
movss -0x164(%rbp), %xmm0
movaps %xmm3, -0x160(%rbp)
movaps %xmm1, %xmm3
movaps -0x160(%rbp), %xmm1
movss %xmm3, -0xe0(%rbp)
movlpd %xmm1, -0xe8(%rbp)
movl -0xe0(%rbp), %eax
movl %eax, -0xc0(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x104(%rbp), %rdi
movq %rdi, -0x148(%rbp)
movss 0x10c4(%rip), %xmm1     # 0x8020
callq 0x2eb0
movq -0x148(%rbp), %rdi
movss -0xbc(%rbp), %xmm0
callq 0x47d0
movss %xmm1, -0x110(%rbp)
movlpd %xmm0, -0x118(%rbp)
movl -0x110(%rbp), %eax
movl %eax, -0xf0(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x5970
movss %xmm1, -0x120(%rbp)
movlpd %xmm0, -0x128(%rbp)
movq -0x128(%rbp), %rax
movq %rax, -0xc(%rbp)
movl -0x120(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x130(%rbp)
movq -0xc(%rbp), %rax
movq %rax, -0x138(%rbp)
movsd -0x138(%rbp), %xmm0
movss -0x130(%rbp), %xmm1
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopw %cs:(%rax,%rax)