Monday, July 2, 2012

A readable scene descripion

I’ve been considering what to use as the base for scene description in my engine. I want the format to be intuitive to construct both with code and by hand, easy to read, and ideally not require too much effort on my end to parse or to support in a translator. From trolling the internet, one popular choice seems to be XML, and while both simple and convenient I personally find it very clunky to read and to write out even simple structures by hand. I also considered using the rib standard, as it already has a wide range of commercial and open source translators from most major 3d softwares, as well as being a fun way of comparing performance. However, it adds a whole layer of complexity I don’t particularly want to deal with in terms of parsing and handling unsupported features, as well as being quite restrictive in layout/form.

Enter python. While technically not a data format, it fits everything else I want in a scene descriptor perfectly. Quietly slip a layer of json between it and the C++ engine, and you got yourself a pretty clean and intuitive way to talk to the renderer. As a bonus it’s widely used, and foreshadows potential future user interface endeavours. But let’s not get ahead of ourselves.

Here’s a mockup of what a python layer might look like.:

import aurora
import math

scene = aurora.core.Scene()

# Settings
options = {
"resolution"    : [512, 512],
           "driver"         : "openexr",
           "filename"       : "dragon.exr",
           "pixelsamples"   : 256,
           "pixelsampler"   : "adaptive",
           "accelerator"    : "uniformgrid",
           "minraydepth"    : 3,
           "raytermination" : "roulette",
           "raybias"        : 0.001,
           "loglevel"       : "debug",
}

scene.options = options

# Camera
renderCam = aurora.core.Camera(fov = math.pi/8)
renderCam.translate(278, 273, -800)

scene.setCamera(renderCam)

# Dragon
dragon = aurora.geometry.ObjMesh("models/stanford/dragon.obj")
dragon.scale(30, 30, 30)
dragon.rotateY(-15)
dragon.translate(280, 0, 280)

material = aurora.shaders.MatteSurface(color(1,1,1))
dragon.material = material

scene.append(dragon)

# Cornell box
scene.append(aurora.core.Archive(“scenes/cornell.asc”))

# Light
light = aurora.lights.SquareAreaLight(exposure = 5.75, color = color(1,1,1))
light.scale(60, 1, 60)
light.translate(280, 548.7, 280)

scene.append(light)

aurora.core.render(scene)


I also named my engine Aurora, for numerous reasons.

-Espen

No comments:

Post a Comment