@@ -8,51 +8,83 @@ steal his words (because this port isn't theft enough):
88> The output of an OpenGL pipeline is a rastered image. The output of raydeon is
99> a set of 2D vector paths.
1010
11- ![ ] ( /raydeon/examples/cityscape.png )
11+ This repository has added support for screen-space hatching based on lights
12+ placed within the scene.
1213
13- Currently less featureful though probably more performant than the prior art.
14+ ![ ] ( /raydeon/examples/cityscape.png )
1415
1516## Example
1617
1718Have a look at any of the [ Rust examples] ( /raydeon/examples ) or
1819[ Python examples] ( /pyraydeon/examples/ ) .
1920
20- The following Rust code draws the cube which is included as an example in the
21- original ` ln ` repo .
21+ The following Rust code draws the 3 cubes below with hatching based on the
22+ lighting .
2223
2324``` rust
25+ use raydeon :: lights :: PointLight ;
2426use raydeon :: shapes :: AxisAlignedCuboid ;
25- use raydeon :: {Camera , Scene , WPoint3 , WVec3 };
27+ use raydeon :: Material ;
28+ use raydeon :: {Camera , Scene , SceneLighting , WPoint3 , WVec3 };
2629use std :: sync :: Arc ;
2730
2831fn main () {
2932 env_logger :: Builder :: from_default_env ()
3033 . format_timestamp_nanos ()
3134 . init ();
3235
33- let scene = Scene :: new (). with_geometry (vec! [Arc :: new (AxisAlignedCuboid :: new (
34- WVec3 :: new (- 1.0 , - 1.0 , - 1.0 ),
35- WVec3 :: new (1.0 , 1.0 , 1.0 ),
36- ))]);
37-
38- let eye = WPoint3 :: new (4.0 , 3.0 , 2.0 );
36+ let scene = Scene :: new ()
37+ . geometry (vec! [
38+ Arc :: new (AxisAlignedCuboid :: tagged (
39+ (- 1.0 , - 1.0 , - 1.0 ),
40+ (1.0 , 1.0 , 1.0 ),
41+ Material :: new (3.0 , 2.0 , 2.0 , 0 ),
42+ )),
43+ Arc :: new (AxisAlignedCuboid :: tagged (
44+ (1.8 , - 1.0 , - 1.0 ),
45+ (3.8 , 1.0 , 1.0 ),
46+ Material :: new (2.0 , 2.0 , 2.0 , 0 ),
47+ )),
48+ Arc :: new (AxisAlignedCuboid :: tagged (
49+ (- 1.4 , 1.8 , - 1.0 ),
50+ (0.6 , 3.8 , 1.0 ),
51+ Material :: new (3.0 , 2.0 , 2.0 , 0 ),
52+ )),
53+ ])
54+ . lighting (
55+ SceneLighting :: new ()
56+ . with_lights (vec! [Arc :: new (PointLight :: new (
57+ 20.0 ,
58+ 100.0 ,
59+ (5.5 , 12.0 , 7.3 ),
60+ 0.0 ,
61+ 0.09 ,
62+ 0.23 ,
63+ ))])
64+ . with_ambient_lighting (0.13 ),
65+ )
66+ . construct ();
67+
68+ let eye = WPoint3 :: new (8.0 , 6.0 , 4.0 );
3969 let focus = WVec3 :: new (0.0 , 0.0 , 0.0 );
4070 let up = WVec3 :: new (0.0 , 0.0 , 1.0 );
4171
4272 let fovy = 50.0 ;
4373 let width = 1024 ;
4474 let height = 1024 ;
4575 let znear = 0.1 ;
46- let zfar = 10 .0 ;
76+ let zfar = 20 .0 ;
4777
48- let camera = Camera :: new ()
49- . look_at (eye , focus , up )
50- . perspective (fovy , width , height , znear , zfar );
78+ let camera = Camera :: configure ()
79+ . observation (Camera :: look_at (eye , focus , up ))
80+ . perspective (Camera :: perspective (fovy , width , height , znear , zfar ))
81+ . build ();
5182
52- let paths = scene . attach_camera (camera ). render ();
83+ let render_result = scene
84+ . attach_camera (camera )
85+ . with_seed (0 )
86+ . render_with_lighting ();
5387
54- // We currently don't have any functionality to aid in emitting SVG images, so you will
55- // be required to use the [svg crate.](https://crates.io/crates/svg)
5688 let mut svg_doc = svg :: Document :: new ()
5789 . set (" width" , " 8in" )
5890 . set (" height" , " 8in" )
@@ -73,7 +105,11 @@ fn main() {
73105 let mut item_group = svg :: node :: element :: Group :: new ()
74106 . set (" transform" , format! (" translate(0, {}) scale(1,-1)" , height ));
75107
76- for path in paths {
108+ for path in render_result
109+ . geometry_paths
110+ . iter ()
111+ . chain (render_result . hatch_paths. iter ())
112+ {
77113 let (p1 , p2 ) = (path . p1, path . p2);
78114 item_group = item_group . add (
79115 svg :: node :: element :: Line :: new ()
@@ -89,4 +125,4 @@ fn main() {
89125}
90126```
91127
92- ![ ] ( /raydeon/examples/cube.png )
128+ ![ ] ( /raydeon/examples/lit_cubes_expected.svg )
0 commit comments