3D ray tracing using raycast

I’ve just tried to update the project in WebRepo, I hope I did it correctly. It now contains a demo in the Main tab.

@LoopSpace i don’t see it yet on webrepro. Maybe you could upload a zip to here. I am eager to try the new version.

@LoopSpace arrived on webrepro. The ellipse reflections are still not what i expect, but maybe my expectations are wrong or i have bug! The video below shows reflection from the focus of the ellipse. I expected the reflected rays to meet at the other focus. The ellipse width is 2*height. I use ±sqrt(h2+w2) to calculate the offset from centre for the foci coords shown by the little spheres.

On the other hand, the reflections from the centre of a sphere seem ok.

Hmm. I tried an ellipsoid with and without facets and they looked near identical under a light source which suggests that the normals are right. I’ll try some more tests.

Any chance of seeing the relevant bit of your code?

Here’s a plot of an equator of an ellipsoid. The arrows are the normals, as computed by my code. This isn’t quite a mathematical proof, but it looks right to me.

@LoopSpace i investigated further my ellipse issues…i had made two mistakes in calculating the location of the foci, i had the wrong width and the wrong formula! So now all is good as shown in the image below:

Thanks for your help.

1 Like

@LoopSpace i think there is a small bug with the cylinder model, one of the ends doesn’t linkup properly the other is okay…see image.

Odd, I’ve been unable to replicate that. What are your parameters for the cylinder?

faceted=false seems to make it appear. I don’t know why i had that as one of the parameters!

Still not seeing it. Can you post the full parameter set?

How are you implementing the transparency? Is it by setting the colour or in the shader?

this is the code for the cylinder model:

function makeCylinder()
    local cylMesh = PseudoMesh()   
    print("make cylinder")
    --
    cylMesh:addCylinder({
        axis=vec3(0,1,0),
        faceted=false,
        height=1,
        ends=3,
        size=10,
--        centre=vec3(0,-0.5,0),
        startRadius=1,  endRadius=1,
        --color=color(77, 194, 203, 255),
    })   
    cylModel= cylMesh:toModel()   
end

to set the opacity:

    self.entity.material.blendMode=NORMAL
    self.entity.material.opacity=opacity
    self.entity.material.diffuse=colour

I’ve now been able to replicate it. There’s a normal or two that are the wrong way round. Oddly, it seems to depend on the size parameter. I can get it to appear most reliably with that set to 5, 10, and 14. While I hunt down the actual bug, you coukd try setting it to 12 and see if that makes it disappear.

@LoopSpace With size 12 i do see NOT the issue.

Sorry, I think there’s a word missing there! I can’t tell if size=12 works for you or not.

sorry for typo…size 12 does not have a problem

1 Like

3D reflection inside an ellipse. The rays emitted from one focus arrive at the other focus at identical time.

1 Like

It’s taken me a while, but I think I’ve squashed the normals bug. I’ve uploaded the code to webrepo - I think!, I’m not used to using it yet so I might have made a mistake in the upload.

Sorry to tap in on an old post—did any of y’all’s code here get put on webrepo? All I can find is “Loopspace’s Useless Code” which doesn’t seem to have any raytracing stuff. @piinthesky, did this project of yours get on webrepo ever?

@UberGoober- I may have relevant files but my network is down and can’t access. But - checked up on @piinthesky on the net and found following link -

@UberGoober i did not yet make available my 3d ray tracing program. I intend it as a puzzle game in which the player has to place optical elements (spheres, prisms, ellispoids, blocks, mirrors, filters, etc) in 3d to make the light beams go from an emitter to a sensor. The emitter, sensors and optical elments can be moving and rotating. Light beams can have diffrent colours and depending on the refractive index can refract differently and travel at different speeds. I got all the game mechanics working, and one day i will make all the levels!