You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Prepass" camera that renders into the RenderTexture (same parameters as main camera different layers);
Main camera (2d, OrthographicProjection) -> target is primary window;
Postprocessing that outputs prepass into final result, by adding color from RT, same uv's as main camera.
Basically, I want to achieve same behavior as setting camera target to window but written into RT.
Main issue - with camera target set to RT - RT result is stretched instead of being clipped.
Been digging a lot through the sources, can't find how its done.
Ideally, I'd like to render larger view area than main camera's. But can't figure it out even with 1 to 1 scale and same camera parameters.
Here's how RT size is computed:
let target_size = main_cam.logical_viewport_size().unwrap_or_default();
let (proj_width, proj_height) =
compute_projection_width_height(target_size.x, target_size.y, scaling_mode);
And I've found camera.rs's update function that computes projection width / height based on OrthoProjection + ScalingMode:
pub fn compute_projection_width_height(
width: f32,
height: f32,
scaling_mode: &ScalingMode
) -> (f32, f32) {
let (projection_width, projection_height) = match *scaling_mode {
ScalingMode::WindowSize(pixel_scale) => (width / pixel_scale, height / pixel_scale),
ScalingMode::AutoMin {
min_width,
min_height,
} => {
// Compare Pixels of current width and minimal height and Pixels of minimal width with current height.
// Then use bigger (min_height when true) as what it refers to (height when true) and calculate rest so it can't get under minimum.
if width * min_height > min_width * height {
(width * min_height / height, min_height)
} else {
(min_width, height * min_width / width)
}
}
ScalingMode::AutoMax {
max_width,
max_height,
} => {
// Compare Pixels of current width and maximal height and Pixels of maximal width with current height.
// Then use smaller (max_height when true) as what it refers to (height when true) and calculate rest so it can't get over maximum.
if width * max_height < max_width * height {
(width * max_height / height, max_height)
} else {
(max_width, height * max_width / width)
}
}
ScalingMode::FixedVertical(viewport_height) => {
(width * viewport_height / height, viewport_height)
}
ScalingMode::FixedHorizontal(viewport_width) => {
(viewport_width, height * viewport_width / width)
}
ScalingMode::Fixed { width, height } => (width, height),
};
(projection_width, projection_height)
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I've got the following setup:
Basically, I want to achieve same behavior as setting camera target to window but written into RT.
Main issue - with camera target set to RT - RT result is stretched instead of being clipped.
Been digging a lot through the sources, can't find how its done.
Ideally, I'd like to render larger view area than main camera's. But can't figure it out even with 1 to 1 scale and same camera parameters.
Here's how RT size is computed:
And I've found camera.rs's update function that computes projection width / height based on OrthoProjection + ScalingMode:
Beta Was this translation helpful? Give feedback.
All reactions