// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, %rbx
movq %rdx, %r14
movq %rsi, %r15
movabsq $0x3f8000003f800000, %rax # imm = 0x3F8000003F800000
movq %rax, (%rcx)
movl $0x3f800000, 0x8(%rcx)  # imm = 0x3F800000
movss 0xc(%rsi), %xmm7
movss 0x10(%rsi), %xmm8
movss 0x10(%rdx), %xmm0
movss 0x14(%rdx), %xmm1
movaps %xmm8, %xmm2
mulss %xmm1, %xmm2
movaps %xmm7, %xmm3
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss 0x14(%rsi), %xmm5
movss 0x18(%rdx), %xmm2
movaps %xmm5, %xmm4
mulss %xmm2, %xmm4
addss %xmm3, %xmm4
xorps %xmm3, %xmm3
ucomiss %xmm3, %xmm4
movss 0x8(%rdi), %xmm6
jbe 0x3eff
movaps 0x1237(%rip), %xmm3     # 0x5120
xorps %xmm3, %xmm2
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
xorps %xmm3, %xmm0
movlps %xmm0, 0x18(%rsp)
movss %xmm2, 0x20(%rsp)
jmp 0x3f21
leaq 0x10(%r14), %rax
movss 0x1105(%rip), %xmm0     # 0x5010
divss %xmm6, %xmm0
movl 0x8(%rax), %ecx
movl %ecx, 0x20(%rsp)
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movaps %xmm0, %xmm6
leaq 0xc(%r15), %r12
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x38(%rsp)
movss 0x1c(%rsp), %xmm0
movss %xmm0, 0x34(%rsp)
movss 0x20(%rsp), %xmm0
movss %xmm0, 0x3c(%rsp)
movss %xmm8, 0x40(%rsp)
movaps %xmm8, %xmm0
mulss %xmm8, %xmm0
movss %xmm7, 0x4(%rsp)
movaps %xmm7, %xmm1
mulss %xmm7, %xmm1
addss %xmm0, %xmm1
movss %xmm5, 0x8(%rsp)
movaps %xmm5, %xmm0
mulss %xmm5, %xmm0
addss %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movss %xmm6, 0x28(%rsp)
jb 0x3f8f
sqrtss %xmm0, %xmm0
jmp 0x3f9a
callq 0x2250
movss 0x28(%rsp), %xmm6
movss %xmm0, 0x10(%rsp)
movss 0xc(%r15), %xmm7
movss 0x10(%r15), %xmm0
leaq 0x18(%rsp), %rsi
movss (%rsi), %xmm1
movss 0x4(%rsi), %xmm2
movaps %xmm0, %xmm3
mulss %xmm2, %xmm3
movaps %xmm7, %xmm4
mulss %xmm1, %xmm4
addss %xmm3, %xmm4
movss 0x14(%r15), %xmm8
movss 0x8(%rsi), %xmm3
movaps %xmm8, %xmm5
mulss %xmm3, %xmm5
addss %xmm4, %xmm5
mulss %xmm5, %xmm1
mulss %xmm5, %xmm2
mulss %xmm3, %xmm5
addss %xmm1, %xmm1
addss %xmm2, %xmm2
addss %xmm5, %xmm5
subss %xmm1, %xmm7
subss %xmm2, %xmm0
unpcklps %xmm0, %xmm7            # xmm7 = xmm7[0],xmm0[0],xmm7[1],xmm0[1]
movaps %xmm7, 0x50(%rsp)
subss %xmm5, %xmm8
movss %xmm8, 0x14(%rsp)
leaq 0x44(%rsp), %rdx
movq %r12, %rdi
movaps %xmm6, %xmm0
callq 0x41f2
testb %al, %al
je 0x410e
movss 0x40(%rsp), %xmm1
mulss 0x34(%rsp), %xmm1
movss 0x4(%rsp), %xmm0
mulss 0x38(%rsp), %xmm0
addss %xmm1, %xmm0
movss 0x8(%rsp), %xmm1
mulss 0x3c(%rsp), %xmm1
addss %xmm0, %xmm1
divss 0x10(%rsp), %xmm1
movss %xmm1, 0x8(%rsp)
leaq 0x446a(%rip), %rdi      # 0x84d8
callq 0x2bde
leaq 0x57e6(%rip), %rax      # 0x9860
movss (%rax), %xmm1
movss 0x4(%rax), %xmm2
subss %xmm1, %xmm2
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
movss %xmm2, 0x4(%rsp)
movss 0x100b(%rip), %xmm0     # 0x50a8
movss 0x28(%rsp), %xmm2
addss %xmm2, %xmm0
movss 0xf61(%rip), %xmm1      # 0x5010
addss %xmm1, %xmm2
divss %xmm2, %xmm0
mulss %xmm0, %xmm0
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
movsd %xmm2, 0x28(%rsp)
movss 0x8(%rsp), %xmm2
addss %xmm1, %xmm2
subss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movsd 0x108e(%rip), %xmm1     # 0x5180
callq 0x2220
mulsd 0x8(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
ucomiss 0x4(%rsp), %xmm0
jbe 0x4124
movaps 0x50(%rsp), %xmm0
movlps %xmm0, 0xc(%rbx)
movss 0x14(%rsp), %xmm0
movss %xmm0, 0x14(%rbx)
jmp 0x4137
leaq 0xc(%rbx), %rax
movl 0x4c(%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x44(%rsp), %rcx
movq %rcx, (%rax)
movss 0x103d(%rip), %xmm0     # 0x517c
movss 0xc(%rbx), %xmm1
mulss %xmm0, %xmm1
movss 0x10(%rbx), %xmm2
mulss %xmm0, %xmm2
mulss 0x14(%rbx), %xmm0
addss 0x4(%r14), %xmm1
addss 0x8(%r14), %xmm2
addss 0xc(%r14), %xmm0
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movlps %xmm1, (%rbx)
movss %xmm0, 0x8(%rbx)
movb $0x1, %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop