Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hollance/Swift-3D-Demo
Shows how to draw a 3D object without using shaders
https://github.com/hollance/Swift-3D-Demo
Last synced: 3 months ago
JSON representation
Shows how to draw a 3D object without using shaders
- Host: GitHub
- URL: https://github.com/hollance/Swift-3D-Demo
- Owner: hollance
- Created: 2016-12-31T14:07:01.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-12T14:23:11.000Z (over 7 years ago)
- Last Synced: 2024-07-27T18:53:48.937Z (4 months ago)
- Language: Swift
- Size: 26.4 KB
- Stars: 180
- Watchers: 10
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
# 3D Demo in Swift
This is a simple demo app for macOS that shows how to draw a 3D object without using shaders. It illustrates what happens behind the scenes when you use OpenGL or Metal to do 3D drawing.
*Want to know how it works?* Check out [Render.swift](ThreeDee/Render.swift). It has lots of explanations.
Also [read the accompanying blog post](http://machinethink.net/blog/3d-rendering-without-shaders/). It has pretty pictures!
The app doesn't use any 3D or math APIs: everything you see is done by the logic in the **Render.swift** source file. The only API used for drawing is a `setPixel()` function that writes a pixel RGBA value to a bitmap. The math used does not involve matrices, so you can see exactly what happens when and why.
Because this is only intended for educational purposes, there is some stuff that doesn't work super great:
- Triangles are not clipped against the field of view of the camera. This isn't really an issue, unless the z-position of camera comes too close to the vertices, in which case triangles may be drawn incorrectly (upside down or not at all).
- It is quite slow. But of course that's why you'd use a GPU for real 3D work.