예제 #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
}
예제 #2
0
파일: teapot.go 프로젝트: noscripter/pt
func main() {
	scene := pt.Scene{}
	scene.Add(pt.NewSphere(pt.Vector{-2, 5, -3}, 0.5, pt.LightMaterial(pt.Color{1, 1, 1}, 1, pt.NoAttenuation)))
	scene.Add(pt.NewSphere(pt.Vector{5, 5, -3}, 0.5, pt.LightMaterial(pt.Color{1, 1, 1}, 1, pt.NoAttenuation)))
	scene.Add(pt.NewCube(pt.Vector{-30, -1, -30}, pt.Vector{30, 0, 30}, pt.SpecularMaterial(pt.HexColor(0xFCFAE1), 2)))
	mesh, err := pt.LoadOBJ("examples/teapot.obj", pt.SpecularMaterial(pt.HexColor(0xB9121B), 2))
	if err != nil {
		log.Fatalln("LoadOBJ error:", err)
	}
	scene.Add(mesh)
	camera := pt.LookAt(pt.Vector{2, 5, -6}, pt.Vector{0.5, 1, 0}, 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)
	}
}
예제 #3
0
파일: suzanne.go 프로젝트: noscripter/pt
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)
	}
}
예제 #4
0
파일: example2.go 프로젝트: noscripter/pt
func main() {
	scene := pt.Scene{}
	material := pt.GlossyMaterial(pt.HexColor(0xEFC94C), 3, pt.Radians(30))
	whiteMat := pt.GlossyMaterial(pt.Color{1, 1, 1}, 3, pt.Radians(30))
	for x := 0; x < 10; x++ {
		for z := 0; z < 10; z++ {
			center := pt.Vector{float64(x) - 4.5, 0, float64(z) - 4.5}
			scene.Add(pt.NewSphere(center, 0.4, material))
		}
	}
	scene.Add(pt.NewCube(pt.Vector{-100, -1, -100}, pt.Vector{100, 0, 100}, whiteMat))
	scene.Add(pt.NewSphere(pt.Vector{-1, 3, -1}, 0.5, pt.LightMaterial(pt.Color{1, 1, 1}, 1, pt.NoAttenuation)))
	camera := pt.LookAt(pt.Vector{0, 4, -8}, pt.Vector{0, 0, -2}, pt.Vector{0, 1, 0}, 45)
	im := pt.Render(&scene, &camera, 2560/4, 1440/4, 4, 16, 8)
	if err := pt.SavePNG("out.png", im); err != nil {
		log.Fatalln("SavePNG error:", err)
	}
}