| 786 | }; |
| 787 | |
| 788 | struct AccretionDisk : public Object { |
| 789 | af::array disk_color; |
| 790 | af::array center; |
| 791 | af::array normal; |
| 792 | double inner_radius; |
| 793 | double outter_radius; |
| 794 | |
| 795 | AccretionDisk(const af::array& center, const af::array& normal, |
| 796 | double inner_radius, double outter_radius) |
| 797 | : disk_color(af::array(3, {209.f, 77.f, 0.f})) |
| 798 | , center(center) |
| 799 | , normal(normal) |
| 800 | , inner_radius(inner_radius) |
| 801 | , outter_radius(outter_radius) { |
| 802 | // disk_color = af::array(3, {254.f, 168.f, 29.f}); |
| 803 | } |
| 804 | |
| 805 | std::pair<HasHit, HitPos> intersect( |
| 806 | const af::array& ray_begin, const af::array& ray_end) const override { |
| 807 | uint32_t count = ray_begin.dims()[1]; |
| 808 | |
| 809 | // Compute intersection of ray with a plane |
| 810 | af::array has_hit = af::constant(0, count).as(b8); |
| 811 | af::array hit_pos = ray_end; |
| 812 | af::array a = dot3(normal, center - ray_begin); |
| 813 | af::array b = dot3(normal, ray_end - ray_begin); |
| 814 | af::array t = af::select(b != 0.0, a / b, (double)0.0); |
| 815 | |
| 816 | af::array plane_intersect = (ray_end - ray_begin) * t + ray_begin; |
| 817 | af::array dist = norm3(plane_intersect - center); |
| 818 | |
| 819 | t = af::abs(t); |
| 820 | |
| 821 | // Determine if the intersection falls inside the disk radius and occurs |
| 822 | // with the current ray segment |
| 823 | has_hit = af::moddims((dist < outter_radius) && (t <= 1.0) && |
| 824 | (t > 0.0) && (dist > inner_radius), |
| 825 | af::dim4(count)); |
| 826 | hit_pos = plane_intersect; |
| 827 | |
| 828 | return {has_hit, hit_pos}; |
| 829 | } |
| 830 | |
| 831 | af::array get_color(const af::array& ray_begin, |
| 832 | const af::array& ray_end) const override { |
| 833 | auto pair = intersect(ray_begin, ray_end); |
| 834 | af::array hit = pair.first; |
| 835 | af::array pos = pair.second; |
| 836 | |
| 837 | auto val = 1.f - (norm3(pos - center).T() - inner_radius) / |
| 838 | (outter_radius - inner_radius); |
| 839 | |
| 840 | af::array color = |
| 841 | disk_color.T() * 1.5f * (val * val * (val * -2.f + 3.f)).as(f32); |
| 842 | |
| 843 | return af::select(af::tile(hit, af::dim4(1, 3)), color, 0.f); |
| 844 | } |
| 845 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected