AS ( SELECT col FROM generate_series(0, 255) AS gs(col) ),
potential_rows AS ( SELECT row FROM generate_series(0, 255) AS gs(row) ),
cols AS ( SELECT pc.col FROM potential_cols pc, s WHERE pc.col < s.view_w ),
rows_gen AS ( SELECT pr.row FROM potential_rows pr, s WHERE pr.row < s.view_h ),
rays AS ( SELECT c.col, (p.dir - s.fov/2.0 + s.fov * (c.col*1.0 / (s.view_w - 1))) AS angle FROM cols c, s, p ),
raytrace(col, step_count, fx, fy, angle) AS (
  SELECT r.col, 1, p.x + COS(r.angle)*s.step, p.y + SIN(r.angl