// File: /workspace/github_cpp_makefile_star2_O3/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 %r14
pushq %rbx
subq $0x68, %rsp
movq %r8, %rbx
movq %rdx, %r14
movq %rdi, %rax
movsd 0x133c(%rip), %xmm0     # 0x5030
movsd %xmm0, (%rcx)
movl $0x3f800000, 0x8(%rcx)  # imm = 0x3F800000
leaq 0xc(%rsi), %rdi
movsd 0xc(%rsi), %xmm4
movsd 0x10(%rdx), %xmm5
movaps %xmm4, %xmm1
mulps %xmm5, %xmm1
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movaps %xmm4, %xmm2
mulss %xmm5, %xmm2
addss %xmm1, %xmm2
movss 0x14(%rsi), %xmm6
movss 0x18(%rdx), %xmm1
movaps %xmm6, %xmm3
mulss %xmm1, %xmm3
addss %xmm2, %xmm3
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm3
movss 0x8(%rax), %xmm0
jbe 0x3d5e
movaps 0x1485(%rip), %xmm2     # 0x51d0
xorps %xmm2, %xmm5
xorps %xmm2, %xmm1
movlps %xmm5, 0x8(%rsp)
movss %xmm1, 0x10(%rsp)
jmp 0x3d8c
leaq 0x10(%r14), %rax
movss 0x12a6(%rip), %xmm2     # 0x5010
divss %xmm0, %xmm2
movq (%rax), %rcx
movq %rcx, 0x8(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x10(%rsp)
movsd 0x8(%rsp), %xmm5
movss 0x10(%rsp), %xmm1
movaps %xmm2, %xmm0
movss %xmm0, 0x18(%rsp)
movaps %xmm4, %xmm2
mulps %xmm5, %xmm2
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movaps %xmm4, %xmm3
mulss %xmm5, %xmm3
addss %xmm2, %xmm3
movaps %xmm6, %xmm2
mulss %xmm1, %xmm2
addss %xmm3, %xmm2
mulss %xmm2, %xmm1
addss %xmm1, %xmm1
movaps %xmm2, 0x30(%rsp)
shufps $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
mulps %xmm5, %xmm2
addps %xmm2, %xmm2
movaps %xmm4, %xmm3
subps %xmm2, %xmm3
movaps %xmm3, 0x50(%rsp)
movaps %xmm6, %xmm2
subss %xmm1, %xmm2
movss %xmm2, 0x4(%rsp)
leaq 0x8(%rsp), %rsi
leaq 0x44(%rsp), %rdx
movaps %xmm4, 0x20(%rsp)
movss %xmm6, (%rsp)
callq 0x3fae
testb %al, %al
je 0x3edb
movaps 0x20(%rsp), %xmm1
movaps %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
mulss %xmm0, %xmm0
mulss %xmm1, %xmm1
addss %xmm0, %xmm1
movss (%rsp), %xmm0
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
sqrtss %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
leaq 0x56a0(%rip), %rdi      # 0x94d8
callq 0x2b9c
leaq 0x6a1c(%rip), %rax      # 0xa860
movss (%rax), %xmm1
movss 0x4(%rax), %xmm2
subss %xmm1, %xmm2
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
movss %xmm2, (%rsp)
movss 0x12ea(%rip), %xmm0     # 0x5150
movss 0x18(%rsp), %xmm2
addss %xmm2, %xmm0
movss 0x1198(%rip), %xmm1     # 0x5010
addss %xmm1, %xmm2
divss %xmm2, %xmm0
mulss %xmm0, %xmm0
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
movsd %xmm2, 0x18(%rsp)
movaps 0x30(%rsp), %xmm2
divss 0x20(%rsp), %xmm2
addss %xmm1, %xmm2
subss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movsd 0x1398(%rip), %xmm1     # 0x5258
callq 0x2220
mulsd 0x30(%rsp), %xmm0
addsd 0x18(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
ucomiss (%rsp), %xmm0
jbe 0x3ef1
movaps 0x50(%rsp), %xmm1
movlps %xmm1, 0xc(%rbx)
movss 0x4(%rsp), %xmm2
movss %xmm2, 0x14(%rbx)
jmp 0x3f0e
leaq 0xc(%rbx), %rax
movl 0x4c(%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x44(%rsp), %rcx
movq %rcx, (%rax)
movsd 0xc(%rbx), %xmm1
movss 0x14(%rbx), %xmm2
mulss 0x133a(%rip), %xmm2     # 0x5250
mulps 0x1323(%rip), %xmm1     # 0x5240
movsd 0x4(%r14), %xmm0
addss 0xc(%r14), %xmm2
addps %xmm1, %xmm0
movlps %xmm0, (%rbx)
movss %xmm2, 0x8(%rbx)
movb $0x1, %al
addq $0x68, %rsp
popq %rbx
popq %r14
retq