All Projects → gh123man → Portal-Raycaster

gh123man / Portal-Raycaster

Licence: other
A software portal rendering game engine

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Portal-Raycaster

SlimApp
A minimalist andf platform-agnostic application layer for writing graphical applications, with a strong emphasis on simplicity and ease of use.
Stars: ✭ 33 (-19.51%)
Mutual labels:  software-rendering
esp32 mmd
esp32でmmd
Stars: ✭ 93 (+126.83%)
Mutual labels:  software-rendering
cub3d
This project is inspired by the world-famous eponymous 90’s game, which was the first FPS ever. It will enable you to explore ray-casting. Your goal will be to make a dynamic view inside a maze, in which you’ll have to find your way.
Stars: ✭ 18 (-56.1%)
Mutual labels:  raycasting
retro-ngon
A well-featured retro-oriented 3D software renderer for the HTML5 canvas.
Stars: ✭ 30 (-26.83%)
Mutual labels:  software-rendering
SlimTracin
Software ray tracer written from scratch in C that can run on CPU or GPU with emphasis on ease of use and trivial setup
Stars: ✭ 49 (+19.51%)
Mutual labels:  software-rendering
sdl2-raycast
SDL2 C++ raycasting engine with vertical movement, floor/ceiling texture mapping and sprites.
Stars: ✭ 80 (+95.12%)
Mutual labels:  raycasting
sparse-octree
A sparse octree data structure.
Stars: ✭ 68 (+65.85%)
Mutual labels:  raycasting
SoftwareRenderer
Simple header-only C++ software renderer
Stars: ✭ 29 (-29.27%)
Mutual labels:  software-rendering
ray engine
A toy raycasting engine in Go + Ebiten
Stars: ✭ 19 (-53.66%)
Mutual labels:  raycasting
alephone-android
Port of the AlephOne engine on Android
Stars: ✭ 30 (-26.83%)
Mutual labels:  raycasting
currender
Currender: A CPU renderer for computer vision
Stars: ✭ 26 (-36.59%)
Mutual labels:  software-rendering
Tinyrenderer
A brief computer graphics / rendering course
Stars: ✭ 11,776 (+28621.95%)
Mutual labels:  software-rendering
ofxRaycaster
Plane, 2D and 3D Ray objects for openFrameworks.It checks for the intersection of a ray with a segment, a sphere, a triangle, a plane, an ofPrimitive, an ofPolyline an with an ofMesh.
Stars: ✭ 54 (+31.71%)
Mutual labels:  raycasting
Theatherflix
Theatherflix OpenSource Project - A visual tool for wiring digital movies, to sort and list the top latest movie trailers. We are constantly developing and making changes. Do you want to be part? Contact us!
Stars: ✭ 51 (+24.39%)
Mutual labels:  software-rendering
SoftLight
A shader-based Software Renderer Using The LightSky Framework.
Stars: ✭ 2 (-95.12%)
Mutual labels:  software-rendering
MoravaEngine
2D/3D graphics engine written in C++ language. It currently supports the following graphics APIs: OpenGL 3.3+, Vulkan 1.2, DirectX 11. Its current purpose is to experiment with various CG concepts and techniques.
Stars: ✭ 129 (+214.63%)
Mutual labels:  raycasting
docker-opengl
Multi-Arch Docker - Mesa 3D OpenGL Software Rendering (Gallium) - LLVMpipe, and OpenSWR Drivers
Stars: ✭ 68 (+65.85%)
Mutual labels:  software-rendering
RaycastVisualization
This asset allows users to view raycasts as the user fires them.
Stars: ✭ 61 (+48.78%)
Mutual labels:  raycasting
GPU-Zen-2-Baker
🥧 An OpenGL 4.x example of GPU Zen 2's ray casting techniques for baked texture generation chapter.
Stars: ✭ 32 (-21.95%)
Mutual labels:  raycasting
flutterstein-3d
🔫 A 3D raycaster implemented in Flutter
Stars: ✭ 40 (-2.44%)
Mutual labels:  raycasting

Raycasting Portals

This repo contains sample code from an early prototype of Gate Escape. There are likely bugs and other issues since the actual game was totally rewritten in c. Do not expect good performance as I learned early on that Kotlin and other GC'd languages are not good choices for software render engines. However this should run fine on most modern PCs and a good place to experiment!

How does it work?

Raycasing is a pseudo-3D rendering technique that uses rays cast from the player or camera to the walls in the scene. Raycasting is like ray tracing except rays are only cast horizontally across the frame (once for each column of pixels) instead of one for each pixel. Columns are then drawn vertically across the screen proportional to the distance the ray traveled. As a result, it is very performant for a pure software renderer, however it has many limitations (you can never look up and down).

If you don't already know much about raycasting I highly recommend this classic tutorial: https://lodev.org/cgtutor/raycasting.html

Aside from the obvious limitations, some things are actually much easier to do via raycasting than with traditional raster render systems such as windows, mirrors, and portals. This project is an example of how a portal raycaster could be implemented.

Casting Rays

When a ray is cast from the camera, it either terminates on a wall, or passes through a portal. When a ray hits a portal a second ray needs to be cast from the exit portal. So we will end up with 1 or more rays for each column of pixels on the screen. The rays are stored in a buffer ordered from first to last in casting order (starting at the camera)

Above, you can see a ray cast from the player camera hitting a portal. This first ray is stored in the buffer and a new ray is cast from the exit portal. When a ray is cast from a portal, it is broke into 2 parts as seen below:

a: the ray cast from the portal exit to the next wall

b: the complete length of the ray used for calculating the actual distance the wall is from the player.

The a component is used for collision detection. We would not want to detect walls between the false camera and the exit portal.

The b component is used just for measuring the height of the wall slice we need to draw proportional to the length of the ray.

If you are sick of reading and want to see how this actually happens, here is the code for all of the above.

Rendering

Once the ray buffer is built via either hitting a non-portal wall, or hitting the cast depth limit, the ray buffer is drawn by the renderer. The renderer reads the ray buffer back to front and starts drawing the furthest away walls first.

This GIF gives a rough idea of the order in which things are drawn.

  1. walls
  2. floors/ceilings
  3. masks (portal holes)

These 3 steps are repeated for each ray that was cast until we reach the first ray that was cast from the player camera.

The portal specific renderer code can be found here.

Performance

It probably sounds like this would have terrible performance. What if rays pass through lots of portals and bounce all over the place? Or what if two portals are pointed at each other?

It actually is not an issue at all. In this engine walls must be at the very least 1 unit apart in order for portals to face each other which due to the spread of rays from the camera causes fewer rays to hit a given wall the further you are from it. So as the nested portal depth grows, the number of rays passing through that portal shrinks. Drawing is so much more expensive than casting, you could have many portals in a scene with litte to no performance impact!

There are of course some cases where a max depth will be needed to prevent an infinite casting loop. I use a depth of 100 since its more than enough to never see the end of a portal tunnel like this:

Other Notes

As stated at the top, this is early prototype code. I ended up rewriting this engine and building a full game out of it. If you enjoy this work or want to see more raycasting, please give my game a try! Otherwise feel free to modify/experiment.

How to use this repo

Building

Clone the repo and open in intellij

Movement

WSAD

Settings

You can change key engine parameters starting here Change the number of threads to the number of cores in your machine for best performance.

The map can be modified and portals can be placed on any wall facing any cardinal direction.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].