Code Review: matplotlib raytracer

preview_player
Показать описание
#gamedev #gamedevelopment #programming

Рекомендации по теме
Комментарии
Автор

20:17
This is kind of a cool way to do voxel ray-tracing (or ray-marching I guess), but it has two main issues:
- Performance - for a shadow ray in particular, hitting a voxel should be our early-exit condition that lets us stop ray-marching - we shouldn't keep ray-marching until we hit the light.

- Inaccuracy - If you imagine a long solid wall of blocks with a light on the other side, if the wall is thinner at one point, then the shadow cast by this light will be less dim at that point, but that's not how it should work at all unless the surface is meant to be semitransparent.
A more practical example is how blocks which are low to the ground get shaded with a gradient towards the top (on the faces facing away from the light) - this is (presumably) because the screen rays hitting that block are sending out shadow rays backwards towards the light, and the rays that are closer to the top of the block have these shadow rays travelling less far through the block.

A possible way to speed this up AND make it more accurate without destroying the whole ray-marching thing is to have each ray remember the normal of the block-face it hits, and then any shadow rays it would have shot that are going backwards relative to that normal (which I think you can test for via dot-product) exit early and return a uniform "shadow" colour value.

Tiftid