https://github.com/bchao1/go-render
🎦 3D renderer in Go.
https://github.com/bchao1/go-render
3d 3d-graphics camera computer-graphics geometry go golang light rasterization rendering texture
Last synced: 6 months ago
JSON representation
🎦 3D renderer in Go.
- Host: GitHub
- URL: https://github.com/bchao1/go-render
- Owner: bchao1
- Created: 2020-08-12T06:40:56.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-18T09:42:46.000Z (about 5 years ago)
- Last Synced: 2025-03-26T08:37:05.412Z (7 months ago)
- Topics: 3d, 3d-graphics, camera, computer-graphics, geometry, go, golang, light, rasterization, rendering, texture
- Language: Go
- Homepage:
- Size: 66.8 MB
- Stars: 19
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# go-render
A simple renderer (rasterization-based) written in Go.
![]()
![]()
![]()
The OG [tinyrenderer](https://github.com/ssloy/tinyrenderer) project helped me alot. It's amazing stuff, and I highly recommend everyone check it out.
## Usage
The code is pretty self-contained. I only used a 3rd-party library `imaging` to flip images vertically.
To do your custom render:
```
go run render.go
```
For example, see `run.sh`:
```
go run data/obj/bunny_2.obj data/textures/bunny_texture.jpg
```Of course, you can first build `render.go`, and then run the executable:
```
go build render.go
./render
```### Customization
You could also play with some other parameters (light direction, camera position, spectral lighting, and etc) in `render.go`.
- `eye`: The camera position. Default is (0, 0, 1).
- `center`: Position the camera is looking at Default is (0, 0, 0).
- `up`: The vertical axis of the camera. Default is (0, 1, 0), which is the y-axis.
- `lightDir`: Light ray direction. Default is (0, 0, -1), which means the light is parellel to user's eye.
- `specCoeff`: Weight of spectral lighting. (For the shiny dragon above, I used 20.0)
- `imageHeight`: Pixel height of output image.
- `background`: Whether to color output image background black. If not, then output image has transparent background.
- `outFile`: Render output file path.
- `defaultFill`: If no texture is specified, use this color.## Demo
> Basics
|||
|--|--|
|Wireframe|Triangle rasterization|
|||> Shading
|Flat shading|Gouraud shading|Phong shading|
|--|--|--|
||||
||||> Perspective
|||||
|--|--|--|--|
|||||> Textures
Kudos to the author of [this article](https://blenderartists.org/t/uv-unwrapped-stanford-bunny-happy-spring-equinox/1101297) for providing custom Stanford bunny texture files.
|Colored|Terracotta|
|--|--|
|||> Camera
|||||
|--|--|--|--|
|||||
|||||> Light
|||||
|--|--|--|--|
|||||
||||> Specular lighting
The stronger specular lighting is, the more "glossy" the object surface becomes. I simply used uniform power for each pixel since specular intensity is not specified in my texture files.
|No specular|Some specular (used)|Intense specular|
|--|--|--|
||||## `.obj` sources
- https://www.prinmath.com/csci5229/OBJ/index.html
- https://people.sc.fsu.edu/~jburkardt/data/obj/obj.html
- https://groups.csail.mit.edu/graphics/classes/6.837/F03/models/
- https://casual-effects.com/data/
- https://github.com/alecjacobson/common-3d-test-models