@@ -120,11 +120,7 @@ async fn create_context<'a: 'n>(
120120}
121121
122122#[ node_macro:: node( category( "" ) ) ]
123- async fn render < ' a : ' n > (
124- ctx : impl Ctx + ExtractFootprint + ExtractVarArgs ,
125- editor_api : & ' a WasmEditorApi ,
126- data : RenderIntermediate ,
127- ) -> RenderOutput {
123+ async fn render < ' a : ' n > ( ctx : impl Ctx + ExtractFootprint + ExtractVarArgs , editor_api : & ' a WasmEditorApi , data : RenderIntermediate ) -> RenderOutput {
128124 let footprint = ctx. footprint ( ) ;
129125 let render_params = ctx
130126 . vararg ( 0 )
@@ -135,6 +131,10 @@ async fn render<'a: 'n>(
135131 render_params. footprint = * footprint;
136132 let render_params = & render_params;
137133
134+ let scale = render_params. scale ;
135+ let physical_resolution = render_params. footprint . resolution ;
136+ let logical_resolution = ( render_params. footprint . resolution . as_dvec2 ( ) / scale) . round ( ) . as_uvec2 ( ) ;
137+
138138 let RenderIntermediate { ty, mut metadata, contains_artboard } = data;
139139 metadata. apply_transform ( footprint. transform ) ;
140140
@@ -145,8 +145,8 @@ async fn render<'a: 'n>(
145145 rendering. leaf_tag ( "rect" , |attributes| {
146146 attributes. push ( "x" , "0" ) ;
147147 attributes. push ( "y" , "0" ) ;
148- attributes. push ( "width" , footprint . resolution . x . to_string ( ) ) ;
149- attributes. push ( "height" , footprint . resolution . y . to_string ( ) ) ;
148+ attributes. push ( "width" , logical_resolution . x . to_string ( ) ) ;
149+ attributes. push ( "height" , logical_resolution . y . to_string ( ) ) ;
150150 let matrix = format_transform_matrix ( footprint. transform . inverse ( ) ) ;
151151 if !matrix. is_empty ( ) {
152152 attributes. push ( "transform" , matrix) ;
@@ -158,7 +158,7 @@ async fn render<'a: 'n>(
158158 rendering. image_data = svg_data. 1 . clone ( ) ;
159159 rendering. svg_defs = svg_data. 2 . clone ( ) ;
160160
161- rendering. wrap_with_transform ( footprint. transform , Some ( footprint . resolution . as_dvec2 ( ) ) ) ;
161+ rendering. wrap_with_transform ( footprint. transform , Some ( logical_resolution . as_dvec2 ( ) ) ) ;
162162 RenderOutputType :: Svg {
163163 svg : rendering. svg . to_svg_string ( ) ,
164164 image_data : rendering. image_data ,
@@ -170,21 +170,16 @@ async fn render<'a: 'n>(
170170 } ;
171171 let ( child, context) = Arc :: as_ref ( vello_data) ;
172172
173- // Always apply scale when rendering to texture
174- let scale = render_params. scale ;
175-
176173 let scale_transform = glam:: DAffine2 :: from_scale ( glam:: DVec2 :: splat ( scale) ) ;
177174 let footprint_transform = scale_transform * footprint. transform ;
178175 let footprint_transform_vello = vello:: kurbo:: Affine :: new ( footprint_transform. to_cols_array ( ) ) ;
179176
180177 let mut scene = vello:: Scene :: new ( ) ;
181178 scene. append ( child, Some ( footprint_transform_vello) ) ;
182179
183- let resolution = ( footprint. resolution . as_dvec2 ( ) * scale) . as_uvec2 ( ) ;
184-
185180 // We now replace all transforms which are supposed to be infinite with a transform which covers the entire viewport
186181 // See <https://xi.zulipchat.com/#narrow/channel/197075-vello/topic/Full.20screen.20color.2Fgradients/near/538435044> for more detail
187- let scaled_infinite_transform = vello:: kurbo:: Affine :: scale_non_uniform ( resolution . x as f64 , resolution . y as f64 ) ;
182+ let scaled_infinite_transform = vello:: kurbo:: Affine :: scale_non_uniform ( physical_resolution . x as f64 , physical_resolution . y as f64 ) ;
188183 let encoding = scene. encoding_mut ( ) ;
189184 for transform in encoding. transforms . iter_mut ( ) {
190185 if transform. matrix [ 0 ] == f32:: INFINITY {
@@ -198,7 +193,10 @@ async fn render<'a: 'n>(
198193 }
199194
200195 // Always render to texture (unified path for both WASM and desktop)
201- let texture = exec. render_vello_scene_to_texture ( & scene, resolution, context, background) . await . expect ( "Failed to render Vello scene" ) ;
196+ let texture = exec
197+ . render_vello_scene_to_texture ( & scene, physical_resolution, context, background)
198+ . await
199+ . expect ( "Failed to render Vello scene" ) ;
202200
203201 RenderOutputType :: Texture ( ImageTexture { texture } )
204202 }
0 commit comments