polyred

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2021 License: GPL-3.0 Imports: 0 Imported by: 0

README

logo

polyred Go Reference Latest relsease polyred

Software graphics facilities in pure Go.

import "changkun.de/x/polyred"

Caution: experimenting, expect it to break at any time. Use it at your own risk.

About

polyred is a software graphics facility written in pure Go. It implements the rasterization as well as ray tracing pipelines for hybrid rendering. Although it is a software implementation, it remains fast as it is optimized to utilize the full power of CPUs. The project aims to provide a software fallback for real-time and offline geometry processing, rendering, and etc in graphics research. See a full features list.

Getting started

// Create a scene graph
s := scene.NewScene()
s.SetCamera(camera.NewPerspective(
    math.NewVector(0, 0.6, 0.9, 1),         // position
    math.NewVector(0, 0, 0, 1),             // lookAt
    math.NewVector(0, 1, 0, 0),             // up
    45,                                     // fov
    float64(opt.width)/float64(opt.height), // aspect
    0.1,                                    // near
    2,                                      // far
))

// Add lights
s.Add(light.NewPoint(
    light.WithPointLightPosition(math.NewVector(4, 4, 2, 1)),
    light.WithShadowMap(true)),
    light.NewAmbient())

// Load models and setup materials
m := io.MustLoadMesh("bunny.obj")
m.SetMaterial(material.NewBlinnPhong(
    material.WithBlinnPhongTexture(image.NewTexture(
        image.WithSource(io.MustLoadImage("bunny.png",
        io.WithGammaCorrection(true))),
        image.WithIsotropicMipMap(true),
    )),
    material.WithBlinnPhongFactors(0.6, 0.5),
    material.WithBlinnPhongShininess(150),
    material.WithBlinnPhongShadow(true),
    material.WithBlinnPhongAmbientOcclusion(true),
))
s.Add(m)
m = io.MustLoadMesh("ground.obj")
m.SetMaterial(material.NewBlinnPhong(
    material.WithBlinnPhongTexture(image.NewTexture(
        image.WithSource(io.MustLoadImage("ground.png",
        io.WithGammaCorrection(opt.gammaCorrection))),
        image.WithIsotropicMipMap(true),
    )),
    material.WithBlinnPhongFactors(0.6, 0.5),
    material.WithBlinnPhongShininess(150),
    material.WithBlinnPhongShadow(true),
))
s.Add(m)

// Create the renderer then render the scene graph!
r := rend.NewRenderer(
    rend.WithSize(1920, 1080),
    rend.WithMSAA(2),
    rend.WithScene(s),
    rend.WithShadowMap(true),
    rend.WithGammaCorrection(true),
)
utils.Save(r.Render(), "./render.png")

The rendered results:

See more full examples in the examples folder, and a connecting project polywine to put polyred results on a window.

Contributes

Easiest way to contribute is to provide feedback! I would love to hear what you like and what you think is missing. Issue and PRs are also welcome.

License

Copyright © 2020-2021 Changkun Ou. All rights reserved.

Documentation

Overview

Package polyred is a software renderer.

Directories

Path Synopsis
package color provides color management utilities.
package color provides color management utilities.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL