Ejemplo n.º 1
0
func (s *Renderer) Render(ctx context.Context, req *pb.RenderRequest) (*pb.RenderResponse, error) {
	scene := pt.Scene{}
	wall := pt.SpecularMaterial(pt.HexColor(0x2FC92C), 8)
	//texture, err := pt.LoadTexture("valentyn.jpg")
	img, _, err := image.Decode(bytes.NewReader(req.Texture))
	texture := pt.NewTexture(img)
	if err != nil {
		return nil, err
	}
	wall.Texture = texture
	scene.Add(pt.NewSphere(pt.Vector{1.5, 1, 0}, 1, pt.SpecularMaterial(pt.HexColor(0x334D5C), 8)))
	scene.Add(pt.NewSphere(pt.Vector{-1, 1, 2}, 1, wall))
	scene.Add(pt.NewSphere(pt.Vector{-3, 1, 0.5}, 1, wall))
	scene.Add(pt.NewSphere(pt.Vector{-0.5, 0.5, -1.4}, 0.7, wall))
	scene.Add(pt.NewCube(pt.Vector{-100, -1, -100}, pt.Vector{100, 0, 100}, pt.DiffuseMaterial(pt.Color{1, 1, 1})))
	scene.Add(pt.NewSphere(pt.Vector{-1, 4, -1}, 0.5, pt.LightMaterial(pt.Color{1, 1, 1}, 3, pt.LinearAttenuation(1))))
	camera := pt.LookAt(pt.Vector{-1.5 + rand.Float64()*2, 2 + rand.Float64()*2, -5}, pt.Vector{0, 0, 3}, pt.Vector{0, 1, 0}, 45)
	im := pt.Render(&scene, &camera, 320, 240, 4, 16, 18)
	buf := new(bytes.Buffer)
	err = jpeg.Encode(buf, im, nil)
	if err != nil {
		return nil, err
	}
	return &pb.RenderResponse{Image: buf.Bytes()}, nil
}
Ejemplo n.º 2
0
func main() {
	scene := pt.Scene{}
	r := 0.4
	var material pt.Material

	material = pt.DiffuseMaterial(pt.HexColor(0x334D5C))
	scene.Add(pt.NewSphere(pt.Vector{-2, r, 0}, r, material))

	material = pt.SpecularMaterial(pt.HexColor(0x334D5C), 2)
	scene.Add(pt.NewSphere(pt.Vector{-1, r, 0}, r, material))

	material = pt.GlossyMaterial(pt.HexColor(0x334D5C), 2, pt.Radians(50))
	scene.Add(pt.NewSphere(pt.Vector{0, r, 0}, r, material))

	material = pt.TransparentMaterial(pt.HexColor(0x334D5C), 2, pt.Radians(20), 1)
	scene.Add(pt.NewSphere(pt.Vector{1, r, 0}, r, material))

	material = pt.ClearMaterial(2, 0)
	scene.Add(pt.NewSphere(pt.Vector{2, r, 0}, r, material))

	material = pt.SpecularMaterial(pt.HexColor(0xFFFFFF), 1000)
	scene.Add(pt.NewSphere(pt.Vector{0, 1.5, -4}, 1.5, material))

	scene.Add(pt.NewCube(pt.Vector{-1000, -1, -1000}, pt.Vector{1000, 0, 1000}, pt.GlossyMaterial(pt.HexColor(0xFFFFFF), 1.4, pt.Radians(20))))
	scene.Add(pt.NewSphere(pt.Vector{0, 5, 0}, 1, pt.LightMaterial(pt.Color{1, 1, 1}, 3, pt.LinearAttenuation(0.4))))
	camera := pt.LookAt(pt.Vector{0, 3, 6}, pt.Vector{0, 1, 0}, pt.Vector{0, 1, 0}, 30)
	pt.IterativeRender("out%03d.png", 1000, &scene, &camera, 2560/2, 1440/2, -1, 16, 16)
}
Ejemplo n.º 3
0
func main() {
	scene := pt.Scene{}
	scene.Add(pt.NewSphere(pt.Vector{1.5, 1, 0}, 1, pt.SpecularMaterial(pt.HexColor(0x334D5C), 2)))
	scene.Add(pt.NewSphere(pt.Vector{-1, 1, 2}, 1, pt.SpecularMaterial(pt.HexColor(0xEFC94C), 2)))
	scene.Add(pt.NewCube(pt.Vector{-100, -1, -100}, pt.Vector{100, 0, 100}, pt.DiffuseMaterial(pt.Color{1, 1, 1})))
	scene.Add(pt.NewSphere(pt.Vector{-1, 4, -1}, 0.5, pt.LightMaterial(pt.Color{1, 1, 1}, 3, pt.LinearAttenuation(1))))
	camera := pt.LookAt(pt.Vector{0, 2, -5}, pt.Vector{0, 0, 3}, pt.Vector{0, 1, 0}, 45)
	pt.IterativeRender("out%03d.png", 10, &scene, &camera, 2560/4, 1440/4, 4, 64, 8)
}
Ejemplo n.º 4
0
func main() {
	white := pt.DiffuseMaterial(pt.Color{0.740, 0.742, 0.734})
	red := pt.DiffuseMaterial(pt.Color{0.366, 0.037, 0.042})
	green := pt.DiffuseMaterial(pt.Color{0.163, 0.409, 0.083})
	light := pt.LightMaterial(pt.Color{0.780, 0.780, 0.776}, 10, pt.QuadraticAttenuation(0.1))
	scene := pt.Scene{}
	n := 10.0
	scene.Add(pt.NewCube(pt.Vector{-n, -11, -n}, pt.Vector{n, -10, n}, white))
	scene.Add(pt.NewCube(pt.Vector{-n, 10, -n}, pt.Vector{n, 11, n}, white))
	scene.Add(pt.NewCube(pt.Vector{-n, -n, 10}, pt.Vector{n, n, 11}, white))
	scene.Add(pt.NewCube(pt.Vector{-11, -n, -n}, pt.Vector{-10, n, n}, red))
	scene.Add(pt.NewCube(pt.Vector{10, -n, -n}, pt.Vector{11, n, n}, green))
	scene.Add(pt.NewSphere(pt.Vector{3, -7, -3}, 3, white))
	cube := pt.NewCube(pt.Vector{-3, -4, -3}, pt.Vector{3, 4, 3}, white)
	transform := pt.Rotate(pt.Vector{0, 1, 0}, pt.Radians(30)).Translate(pt.Vector{-3, -6, 4})
	scene.Add(pt.NewTransformedShape(cube, transform))
	scene.Add(pt.NewCube(pt.Vector{-2, 9.8, -2}, pt.Vector{2, 10, 2}, light))
	camera := pt.LookAt(pt.Vector{0, 0, -20}, pt.Vector{0, 0, 1}, pt.Vector{0, 1, 0}, 65)
	pt.IterativeRender("out%03d.png", 10, &scene, &camera, 512, 512, -1, 16, 4)
}
Ejemplo n.º 5
0
func main() {
	scene := pt.Scene{}
	material := pt.DiffuseMaterial(pt.HexColor(0x334D5C))
	scene.Add(pt.NewSphere(pt.Vector{0.5, 1, 3}, 0.5, pt.LightMaterial(pt.Color{1, 1, 1}, 1, pt.NoAttenuation)))
	scene.Add(pt.NewSphere(pt.Vector{1.5, 1, 3}, 0.5, pt.LightMaterial(pt.Color{1, 1, 1}, 1, pt.NoAttenuation)))
	scene.Add(pt.NewCube(pt.Vector{-5, -5, -2}, pt.Vector{5, 5, -1}, material))
	mesh, err := pt.LoadOBJ("examples/suzanne.obj", pt.SpecularMaterial(pt.HexColor(0xEFC94C), 2))
	if err != nil {
		log.Fatalln("LoadOBJ error:", err)
	}
	scene.Add(mesh)
	camera := pt.LookAt(pt.Vector{1, -0.45, 4}, pt.Vector{1, -0.6, 0.4}, pt.Vector{0, 1, 0}, 45)
	im := pt.Render(&scene, &camera, 2560/4, 1440/4, 4, 16, 4)
	if err := pt.SavePNG("out.png", im); err != nil {
		log.Fatalln("SavePNG error:", err)
	}
}
Ejemplo n.º 6
0
func main() {
	scene := pt.Scene{}
	material := pt.DiffuseMaterial(pt.HexColor(0xFCFAE1))
	scene.Add(pt.NewCube(pt.Vector{-1000, -1, -1000}, pt.Vector{1000, 0, 1000}, material))
	for x := -20; x <= 20; x++ {
		for z := -20; z <= 20; z++ {
			if (x+z)%2 == 0 {
				continue
			}
			s := 0.1
			min := pt.Vector{float64(x) - s, 0, float64(z) - s}
			max := pt.Vector{float64(x) + s, 2, float64(z) + s}
			scene.Add(pt.NewCube(min, max, material))
		}
	}
	scene.Add(pt.NewCube(pt.Vector{-5, 10, -5}, pt.Vector{5, 11, 5}, pt.LightMaterial(pt.Color{1, 1, 1}, 5, pt.QuadraticAttenuation(0.05))))
	camera := pt.LookAt(pt.Vector{20, 10, 0}, pt.Vector{8, 0, 0}, pt.Vector{0, 1, 0}, 45)
	pt.IterativeRender("out%03d.png", 1000, &scene, &camera, 2560/2, 1440/2, -1, 4, 2)
}