computer graphics – Ray tracing tree

Let’s suppose that we have a light source. Which of the following are correct for the tree of recursive ray-tracing (ray tree) that create when we make the colors for each pixel in the screen.
Which of the following are correct:

a) if scene contains of one non-convex polyhedron (random shape and position) then we can’t have a bound for the height of tree in general. (Even the camera is out of range of object)

b) if scene contains of two convex polyhedrons then the height of tree can be at most 2 independent of the position of camera and the position of objects (the camera is out of range of the two objects)

c) if scene contains of two non-convex polyhedrons (random shape and position) then we can’t have a bound for the height of tree in general. (Even the camera is out of range of object)

d) if scene contains of one convex polyhedron then the height of tree can be at most 1 independent of the position of camera and the position of objects (the camera is out of range of the object)

e) if scene contains of one non-convex polyhedron then the height of tree can be at most 1 independent of the position of camera and the position of object (the camera is out of range of the object)

I am confused about the choice of polyhedrons (convex and non-convex), i can’t understand the difference.
Also i don’t understand how the camera out of range of objects can help to make the ray tree.

raycasting – How to find if a Ray intersects a Triangle Clockwise or Counter Clockwise

Assume the triangle’s vertices are wound in the order A, B, C

Form a normal to the triangle N = (B – A) x (C – A)

Now you can detect whether your triangle is clockwise or counter-clockwise by the sign of the dot product between this normal and the ray direction

In a left-handed coordinate system:

  • Negative = Clockwise from ray’s point of view
  • Positive = Counter-clockwise from ray’s point of view

In a right-handed coordinate system, it’s the opposite:

  • Negative = Counter-clockwise from ray’s point of view
  • Positive = Clockwise from ray’s point of view

raytracing – Ray tracing Bug with Diffuse material

I am trying to do ray tracing in python (following the tutorial given in Ray Tracing in a weekend). Basically I am shooting rays from eye and the recursively bounce around, each time they hit something they become weaker (actually this is reverse ray casting but you get the idea). The output I am getting is incorrect.

My output:


Expected output:


The shadows are messed up. What could be wrong?

My code:

import numpy as np
import sys
import random
from PIL import Image
from math import * 
from util import *

width  = 60
height = 60

samples = 20


def reflected(vector, axis):
    return vector - axis * 2 *

def RandomPointInSphere():
    p = None
    while True:
        p = Vector(random.uniform(0,1),random.uniform(0,1),random.uniform(0,1))*2 - Vector(1,1,1)
        if( < 1):
    return p

def GetNearestObject(objects, ray):
    nearest_obj = None
    min_hit = Intersection(None, INF, None, None)
    for obj in objects:
        hit = obj.intersect(ray)
        if(hit.distance < min_hit.distance):
            nearest_obj = obj
            min_hit = hit
    return min_hit


def RayColor(objects, ray):
    # Part 1: Diffuse Material
    result = GetNearestObject(objects, ray)
    if(result.point != None):
        P = result.point
        N = result.normal
        E = RandomPointInSphere()
        target = P + N + E
        newRay = Ray(ray.origin, (target - ray.origin).normalize())
        return RayColor(objects, newRay)*0.5
        t = 0.5 * (ray.direction.y + 1.0);
        color = Vector(1.0, 1.0, 1.0)*(1.0 - t) + Vector(0.5, 0.7, 1.0)*t
        color.x = min(color.x,1.0)
        color.y = min(color.y,1.0)
        color.z = min(color.z,1.0)
        return Vector(1,1,1)
def main():
    global bitmap
    eye    = Vector(0,0,1)
    ratio  = float(width) / height
    screen = Screen(-1, 1 / ratio, 1, -1 / ratio, 0)
    objects = ()
    objects.append(Sphere(Vector(-0.2,0,-1),  0.7, Material(Vector(0.1,0,0),  Vector(0.7,0,0),    Vector(1,1,1), 100, 0.5)))
    objects.append(Sphere(Vector(0,-9000,0),  9000-0.7, Material(Vector(0.1,0.1,0.1),Vector(0.6,0.6,0.6),Vector(1,1,1), 100, 0.5)))
    light = Light(Vector(5,5,5), Material(Vector(1,1,1),Vector(1,1,1),Vector(1,1,1)))
    for frame in range(1):
        img    = = "RGB", size=(width, height), color=Color.WHITE)
        bitmap = img.load() # create the pixel data

#---                    YOUR CODE HERE                      ---
        deltaX = (screen.right - screen.left)/(width-1)
        deltaY = ( - screen.bottom)/(height-1)

        for y in range(height):
            for x in range(width):
                pixel     = Vector(screen.left+x*deltaX,*deltaY, screen.z)
                direction = (pixel - eye).normalize()
                pixelRay = Ray(eye, direction)                

                # Part 1: Diffuse Material
                color = Vector(0,0,0)
                for s in range(samples):
                    color += RayColor(objects, pixelRay)
                color *= 1.0/samples
                #color = Vector(sqrt(color.x), sqrt(color.y), sqrt(color.z))
                bitmap(x,y) = (int(color.x*255), int(color.y*255), int(color.z*255))

            print("progress: %d %%" % ((y+1)/height*100.0))
#--------------------------------------------------------------"pic1.png")"images/fig" + f'{frame:06}' + ".png")
        #print("Saving ---> images/fig" + f'{frame:06}' + ".png")


raytracing – Moving the bulk of a recursive ray tracer function to the gpu, using DirectX12 not DirectX 12X HLSL

So I’m wanting to generate images by ray tracing. I’ve done so, but the main ray function is recursive. I know one can make a non recursive function out of a recursive function using a stack, but is it possible to do in HLSL? I have the bulk of the function I’m using here:

color ray_color(
    const ray& r,
    const color& background,
    const hittable& world,
    const shared_ptr<hittable>& lights,
    int depth) {
hit_record rec;

// If we've exceeded the ray bounce limit, no more light is gathered.
if (depth <= 0)
    return color(0, 0, 0);

// If the ray hits nothing, return the background color.
if (!world.hit(r, 0.001, infinity, rec))
    return background;

scatter_record srec;
color emitted = rec.mat_ptr->emitted(r, rec, rec.u, rec.v, rec.p);

if (!rec.mat_ptr->scatter(r, rec, srec))
    return emitted;

if (srec.is_specular) {
    return srec.attenuation
        * ray_color(srec.specular_ray, background, world, lights, depth - 1);

auto light_ptr = make_shared<hittable_pdf>(lights, rec.p);
mixture_pdf p(light_ptr, srec.pdf_ptr);
ray scattered = ray(rec.p, p.generate(), r.time());
auto pdf_val = p.value(scattered.direction());

return emitted
    + srec.attenuation * rec.mat_ptr->scattering_pdf(r, rec, scattered)
    * ray_color(scattered, background, world, lights, depth - 1)
    / pdf_val;

unity – Why would ray go through colliders for unavoidable reasons?

I’m checking whether there is a object between player and enemy by the following lines of code.

void Update()
    RaycastHit hit;
    if (Physics.Linecast(transform.position, player.transform.position, out hit))
        if (hit.collider.gameObject.tag == "Player")

Collision Problem:

However this rotates the enemy towards player even when there is a wall in between them. I should mention that this doesn’t happen often, only in certain areas this happens. The wall has a box collider, so there is no way the ray is going through wall. How can I get rid of this problem?

directx – Compile shader and root signature of a ray tracing shader into a single binary using DXC

I’m new to DXR, so please

If I got it right, when we want to compile a ray tracing shader using the DirectX Shader Compiler, we need to specify lib_6_* as the target profile.

Now assume I’ve got a HLSL file containing a single ray generation shader RayGen whose root signature is specified by a RootSignature attribute of the form

#define MyRS "RootFlags(LOCAL_ROOT_SIGNATURE),"  
            "UAV(u0, numDescriptors = 1),"  
            "SRV(t0, numDescriptors = 1))"
void RayGen() {}

Using IDxcCompiler::Compile, I’m able to compile both the shader itself using the target profile lib_6_3 and the root signature using the target profile rootsig_1_1, but if I got it right it’s not possible to invoke IDxcCompiler::Compile such that the created IDxcBlob contains both the shader and the root signature. (I’ve tried to add the argument -rootsig-define MyRS to the call for the compilation of the shader, but it seems to me that the compiler expects the root signature specified in this way to be a global root signature.)

So, I end up with two IDxcBlob‘s. Is there any possibility to “merge” them into a single one which can later be used to specify the shader as well in a call of ID3D12Device5::CreateRootSignature?

c++ – How to perform a fast ray cylinder intersection test?

First we’ll subtract the cylinder center from the ray origin, to translate our whole problem to be centered at (0, 0, 0).

Case 0: Inside

First, check if the ray origin is inside the cylinder from the start.

$$text{origin}_x^2 + text{origin}_z^2 leq text{radius}^2 quad text{and}quad
-frac {text{height}} 2 leq text{origin}_y leq frac {text{height}} 2$$

If so, it’s conventional to return no hit (we only count hits going into the cylinder). Though you could instead invert the following cases to check for a hit exiting the cylinder.

Case 1: Above / Below

If our shifted origin is above $frac {text{height}} 2$ or below $-frac {text{height}} 2$, then we check whether its direction takes it closer to the cylinder:

$$text{origin}_y times text{direction}_y < 0 ?$$

If it does not, we know the ray is too high/low to ever hit the cylinder, and we can early-out with no hit.

Otherwise, we can advance the ray to the time $t$ when it crosses the plane of the cylinder’s top (or bottom):

$$t_{text{plane}} = -frac {text{origin}_y} {text{direction}_y}$$

The ray’s position at that time is $vec p_1= vec {text{origin}} + t_text{plane} cdot vec {text{direction}}$

If that point is inside the cylinder’s radius,

$${p_1}_x^2 + {p_1}_z^2 leq text{radius}^2$$

Then we have a hit against the top/bottom cap of the cylinder, with a vertical collision normal.

If not, we can proceed as though the ray had started somewhere beside the cylinder, rather than above/below:

Case 2: Beside

Next we’ll check if the ray hits the circle. For that we want to know the earliest positive time $t$ at which…

$$||vec {text{origin}} + t cdot vec {text{direction}}|| = r\
(vec {text{origin}} + t cdot vec {text{direction}})^2 = r^2\
t^2 cdot text{direction}^2 + t cdot 2(vec {text{origin}} cdot vec {text{direction}}) + text{origin}^2 – r^2 = 0$$

You can solve this with quadratic formula. Choose the smallest positive solution, and call it $t_text{circle}$. If there is no positive real solution, return no hit.

Then, as we did with case 1, find the position at that time: $vec p_2= vec {text{origin}} + t_text{circle} cdot vec {text{direction}}$

Now we check whether that’s on our cylinder, or if it missed:

$$| {p_2}_y| < frac {text{height}} 2 ? $$

If the hit is within this height range, then we have a hit, with collision normal parallel to $vec p_2$. Otherwise, we miss the cylinder and return no hit.

If you do find a hit, add the cylinder center back to the hit position $vec p_1$ or $vec p_2$ to get the hit position in world space.

blu ray – New Blu Ray Player. Stalled and choppy Playback on VLC

So just got a New DVD Player/Writer yesterday, The Asus 16x Blu Ray Writer.

So far whenever I have tried to play any DVD original, or brunt backup, in VLC,It will play for a few minutes with choppy playback and then go back to the menu screen after about 1 to 5 minutes of playing.

I have reloaded the libdvd libraries and reinstalled VLC to no affect. Any Advice ???

dnd 5e – Should Greater Restoration work against Prismatic Spray’s Indigo Ray?

My group is playing DnD 5e. We encountered an ancient blue dragon who cast Prismatic Spray at us. Our Ranger/Druid, who was in Air Elemental wildshape at the time, got struck by the Indigo Ray and failed his Dexterity Save:

6-Indigo: On a failed save, the target is Restrained. It must then make a Constitution saving throw at the end of each of its turns. If it successfully saves three times, the spell ends. If it fails its save three times, it permanently turns to stone and is subjected to the Petrified condition. The successes and failures don’t need to be consecutive, keep track of both until the target collects three of a kind.

Because he was an Air Elemental, he was immune to being restrained, but the DM had him continue to make making Con saves for the 2nd half of that Ray’s effects. Just before he (unknowingly) failed the third Con save, he transformed back into his usual Eladrin form, and became a Petrified stone statue as per the spell’s effects.

Upon defeating the dragon, the group attempted to restore him to his usual form using a Greater Restoration spell that he had stored in a Ring of Spell Storing. The spell successfully removed the Petrified condition, but because the spell says the creature “permanently turns to stone”, our DM ruled that he was now a living stone statue, unless/until he could find some other way to return him to flesh-and-blood status. This transformation came with a -2 to Dex (his main stat) but a +1 to Strength and Con, and some damage resistances. He’s not altogether miffed by these changes and likes the flavor of the ruling, but I’m wondering, should Greater Restoration have worked on its own to return him fully to flesh and blood, even if the spell says “permanently”?