// File: /workspace/github_cpp_makefile_star2_O2/GUI-Graphics[P]cpuraytracing/dielectric.cpp
// Function: gui::Dielectric::scatter(gui::Ray const&, gui::Intersection const&, gui::Vector3&, gui::Ray&) const
bool Dielectric::scatter(
		const Ray& in,
		const Intersection& intersection,
		Vector3& attenuation,
		Ray& scattered) const {

		attenuation = Vector3(1);

		float niOverNt;
		Vector3 normal;

		if (in.direction.dot(intersection.normal) > 0) {
			niOverNt = ior;
			normal = -intersection.normal;
		} else {
			niOverNt = 1 / ior;
			normal = intersection.normal;
		}

		float cosine = -in.direction.dot(normal) / in.direction.length();

		Vector3 refracted;
		Vector3 reflected = in.direction.reflect(normal);

		if (in.direction.refract(normal, niOverNt, refracted)) {
			if (Math::random() < schlick(cosine, niOverNt)) {
				scattered.direction = reflected;
			} else {
				scattered.direction = refracted;
			}
		} else {
			scattered.direction = reflected;
		}

		scattered.origin = intersection.position + scattered.direction * 0.0001f;

		return true;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r8, %rbx
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbp
movsd 0x1586(%rip), %xmm0     # 0x5030
movsd %xmm0, (%rcx)
movl $0x3f800000, 0x8(%rcx)  # imm = 0x3F800000
leaq 0xc(%rsi), %r15
leaq 0x10(%rdx), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x3a58
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movss 0x8(%rbp), %xmm1
jbe 0x3af9
movq %r13, %rdi
movss %xmm1, (%rsp)
callq 0x3cec
movaps %xmm0, 0x20(%rsp)
movlps %xmm0, 0x8(%rsp)
movaps %xmm1, 0x30(%rsp)
movss %xmm1, 0x10(%rsp)
jmp 0x3b31
movss 0x150f(%rip), %xmm0     # 0x5010
divss %xmm1, %xmm0
movq (%r13), %rax
movq %rax, 0x8(%rsp)
movl 0x8(%r13), %eax
movl %eax, 0x10(%rsp)
movsd 0x8(%rsp), %xmm1
movaps %xmm1, 0x20(%rsp)
movss 0x10(%rsp), %xmm1
movaps %xmm1, 0x30(%rsp)
movss %xmm0, (%rsp)
movss 0xc(%r12), %xmm0
movss %xmm0, 0x18(%rsp)
movss 0x10(%r12), %xmm0
movss %xmm0, 0x14(%rsp)
movss 0x14(%r12), %xmm0
movss %xmm0, 0x1c(%rsp)
leaq 0x8(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x3a1a
movaps %xmm0, 0x50(%rsp)
movss %xmm1, 0x4(%rsp)
leaq 0x44(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
movss (%rsp), %xmm0
callq 0x3d04
testb %al, %al
je 0x3c16
movss 0x14(%rsp), %xmm4
movaps %xmm4, %xmm0
mulss %xmm4, %xmm0
movss 0x18(%rsp), %xmm3
movaps %xmm3, %xmm1
mulss %xmm3, %xmm1
addss %xmm0, %xmm1
movss 0x1c(%rsp), %xmm2
movaps %xmm2, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
sqrtss %xmm0, %xmm0
movaps 0x20(%rsp), %xmm1
mulss %xmm1, %xmm3
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
mulss %xmm4, %xmm1
addss %xmm3, %xmm1
movaps 0x30(%rsp), %xmm3
mulss %xmm2, %xmm3
addss %xmm1, %xmm3
xorps 0x15b4(%rip), %xmm3     # 0x51a0
divss %xmm0, %xmm3
movaps %xmm3, 0x30(%rsp)
callq 0x28e2
movss %xmm0, 0x20(%rsp)
movaps 0x30(%rsp), %xmm0
movss (%rsp), %xmm1
callq 0x3c82
ucomiss 0x20(%rsp), %xmm0
jbe 0x3c2c
movaps 0x50(%rsp), %xmm0
movlps %xmm0, 0xc(%rbx)
movss 0x4(%rsp), %xmm0
movss %xmm0, 0x14(%rbx)
jmp 0x3c3f
leaq 0xc(%rbx), %rax
movl 0x4c(%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x44(%rsp), %rcx
movq %rcx, (%rax)
addq $0x4, %r14
leaq 0xc(%rbx), %rdi
movss 0x15ad(%rip), %xmm0     # 0x51fc
callq 0x359e
leaq 0x68(%rsp), %rsi
movlps %xmm0, (%rsi)
movss %xmm1, 0x8(%rsi)
movq %r14, %rdi
callq 0x35b2
movlps %xmm0, (%rbx)
movss %xmm1, 0x8(%rbx)
movb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq