POV-Ray : Newsgroups : povray.general : a little ray tracer : Re: a little ray tracer Server Time
6 May 2026 08:20:59 EDT (-0400)
  Re: a little ray tracer  
From: ingo
Date: 6 May 2026 04:59:40
Message: <69fb02fc$1@news.povray.org>
On 2026-05-06 02:45, Mr wrote:
> I suddenly feel like I was off topic as, [...]

No problem.

> [...] what would the syntax invoking them look like?
> 

Currently it's not all very well organized. For example in scene.nim 
there are mixed reposibilities. The whole intersection / traversal logic 
there should go to the raytracer file. Also the loop in main should go 
there.

The ppm generation is only "instant gratification" the database will be 
the result and it will contain HDR data. An image could be extracted 
with something that does:

proc exportPPM*(db: DbConn, frame: int, filename: string) =
   let rows = db.allRows(sql"""
     SELECT pixel_x, pixel_y,
            tonemap_reinhard(sum(rgb_r)) AS r,
            tonemap_reinhard(sum(rgb_g)) AS g,
            tonemap_reinhard(sum(rgb_b)) AS b
     FROM (
       SELECT pixel_x, pixel_y,
              spectral_to_rgb(contribution, wavelength) AS (r,g,b)
       FROM final_pixel_values
       WHERE frame = ?
     ) GROUP BY pixel_x, pixel_y
   """, frame)

   writePPM(filename, rows, width, height)


this is currently the whole scene description:

----
var sc = initScene()

# Materials
let matFloor = sc.addMaterial(Material(colour: vec3(0.8f, 0.8f, 0.8f)))
let matSphere = sc.addMaterial(Material(colour: vec3(0.8f, 0.2f, 0.2f)))
let matBox = sc.addMaterial(Material(colour: vec3(0.2f, 0.6f, 0.2f)))

# Shapes
discard sc.addShape(plane(vec3(0f, 1f, 0f), -1f, matFloor))
discard sc.addShape(sphere(vec3(0f, 0f, -3f), 1f, matSphere))
discard sc.addShape(box(vec3(-2f, -1f, -4f), vec3(-0.5f, 0.5f, -2f), 
matBox))

initPerspectiveCamera(
   relays = relays,
   pos = vec3(0f, 1f, 2f),
   lookAt = vec3(0f, 0f, -3f),
   up = vec3(0f, 1f, 0f),
   fovDeg = 60f,
   width = Width,
   height = Height
)

initRaytracerRenderer(relays, sc)

addPointLight(relays, vec3(5f, 8f, 2f),  vec3(1f, 1f, 1f),       100f)
addPointLight(relays, vec3(-3f, 4f, 0f), vec3(0.4f, 0.6f, 1f),    40f)

initColourMaterial(relays, sc)
initBlueBackground(relays)

----

I do not like that!

initScene() annoyed me. But then, one can put multiple scene in one file 
and render them in orther. Scene2 can the re-use, abuse, data from 
scene1. (Contrived crazy example, Scene One can be an animation of a 
ball bouncing against a wall many times, denting it a bit and leaving 
some colour. Train a little neural net with it. Scene Two uses the net 
for texture and displacement mapping generation.)

Currently an order in the scene is required. Not nice, maybe things can 
be ordered after a "parsing" step.

Initializing the relays can be "hidden", be done lazy. When adding a 
light source check whether a render relay is initialized if not do it.

Also shapes and materials do not look nice, I just chose the easy way to 
get the whole ting going. And, certainly there is a lot I've not thought 
about yet.

ingo


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.