Skip to content

bchao1/go-render

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-render

A simple renderer (rasterization-based) written in Go.

The OG 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 <path to .obj file> <path to texture file>

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 <path to .obj file> <path to texture file>

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
img img

Shading

Flat shading Gouraud shading Phong shading
img img img
img img img

Perspective

img img img img

Textures

Kudos to the author of this article for providing custom Stanford bunny texture files.

Colored Terracotta
img img

Camera

img img img img
img img img img

Light

img img img img
img img img img

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
img img img

.obj sources