Skip to content

Commit

Permalink
removed duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Oct 26, 2024
1 parent 4a05353 commit a9e8f7d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 97 deletions.
25 changes: 4 additions & 21 deletions editor/src/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@

use crate::{
fyrox::{
core::{
algebra::{Matrix4, Vector3},
color::Color,
pool::Handle,
sstorage::ImmutableString,
},
core::{color::Color, pool::Handle, sstorage::ImmutableString},
fxhash::FxHashSet,
graph::{BaseSceneGraph, SceneGraph},
renderer::{
bundle::{BundleRenderContext, RenderContext, RenderDataBundleStorage},
bundle::{BundleRenderContext, ObserverInfo, RenderContext, RenderDataBundleStorage},
framework::{
buffer::BufferUsage,
error::FrameworkError,
Expand All @@ -45,13 +40,12 @@ use crate::{
BlendFactor, BlendFunc, BlendParameters, CompareFunc, DrawParameters, ElementRange,
GeometryBufferExt,
},
RenderPassStatistics, SceneRenderPass, SceneRenderPassContext,
make_viewport_matrix, RenderPassStatistics, SceneRenderPass, SceneRenderPassContext,
},
scene::{mesh::surface::SurfaceData, node::Node, Scene},
},
Editor,
};
use fyrox::renderer::bundle::ObserverInfo;
use std::{any::TypeId, cell::RefCell, rc::Rc};

struct EdgeDetectShader {
Expand Down Expand Up @@ -255,18 +249,7 @@ impl SceneRenderPass for HighlightRenderPass {

// Render full screen quad with edge detect shader to draw outline of selected objects.
{
let frame_matrix = Matrix4::new_orthographic(
0.0,
ctx.viewport.w() as f32,
ctx.viewport.h() as f32,
0.0,
-1.0,
1.0,
) * Matrix4::new_nonuniform_scaling(&Vector3::new(
ctx.viewport.w() as f32,
ctx.viewport.h() as f32,
0.0,
));
let frame_matrix = make_viewport_matrix(ctx.viewport);
let shader = &self.edge_detect_shader;
let frame_texture = self.framebuffer.color_attachments()[0].texture.clone();
ctx.framebuffer.draw(
Expand Down
23 changes: 4 additions & 19 deletions fyrox-impl/src/renderer/fxaa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
// SOFTWARE.

use crate::{
core::{
algebra::{Matrix4, Vector2, Vector3},
math::Rect,
sstorage::ImmutableString,
},
core::{algebra::Vector2, math::Rect, sstorage::ImmutableString},
renderer::make_viewport_matrix,
renderer::{
cache::uniform::UniformBufferCache,
framework::{
buffer::BufferUsage,
error::FrameworkError,
framebuffer::{FrameBuffer, ResourceBindGroup, ResourceBinding},
framebuffer::{BufferLocation, FrameBuffer, ResourceBindGroup, ResourceBinding},
geometry_buffer::GeometryBuffer,
gpu_program::{GpuProgram, UniformLocation},
gpu_texture::GpuTexture,
Expand All @@ -41,7 +38,6 @@ use crate::{
},
scene::mesh::surface::SurfaceData,
};
use fyrox_graphics::framebuffer::BufferLocation;
use std::{cell::RefCell, rc::Rc};

struct FxaaShader {
Expand Down Expand Up @@ -91,18 +87,7 @@ impl FxaaRenderer {
) -> Result<RenderPassStatistics, FrameworkError> {
let mut statistics = RenderPassStatistics::default();

let frame_matrix = Matrix4::new_orthographic(
0.0,
viewport.w() as f32,
viewport.h() as f32,
0.0,
-1.0,
1.0,
) * Matrix4::new_nonuniform_scaling(&Vector3::new(
viewport.w() as f32,
viewport.h() as f32,
0.0,
));
let frame_matrix = make_viewport_matrix(viewport);

statistics += frame_buffer.draw(
&*self.quad,
Expand Down
9 changes: 2 additions & 7 deletions fyrox-impl/src/renderer/hdr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use crate::{
core::{
algebra::{Matrix4, Vector2, Vector3},
algebra::{Matrix4, Vector2},
color::Color,
math::Rect,
transmute_slice, value_as_u8_slice,
Expand Down Expand Up @@ -95,12 +95,7 @@ impl LumBuffer {
}

fn matrix(&self) -> Matrix4<f32> {
Matrix4::new_orthographic(0.0, self.size as f32, self.size as f32, 0.0, -1.0, 1.0)
* Matrix4::new_nonuniform_scaling(&Vector3::new(
self.size as f32,
self.size as f32,
0.0,
))
make_viewport_matrix(Rect::new(0, 0, self.size as i32, self.size as i32))
}

fn texture(&self) -> Rc<RefCell<dyn GpuTexture>> {
Expand Down
14 changes: 2 additions & 12 deletions fyrox-impl/src/renderer/light/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::renderer::make_viewport_matrix;
use crate::{
core::{
algebra::{Matrix4, Point3, UnitQuaternion, Vector2, Vector3},
Expand Down Expand Up @@ -301,18 +302,7 @@ impl DeferredLightRenderer {
let frustum = Frustum::from_view_projection_matrix(camera.view_projection_matrix())
.unwrap_or_default();

let frame_matrix = Matrix4::new_orthographic(
0.0,
viewport.w() as f32,
viewport.h() as f32,
0.0,
-1.0,
1.0,
) * Matrix4::new_nonuniform_scaling(&Vector3::new(
viewport.w() as f32,
viewport.h() as f32,
0.0,
));
let frame_matrix = make_viewport_matrix(viewport);

let projection_matrix = camera.projection_matrix();
let view_projection = camera.view_projection_matrix();
Expand Down
15 changes: 2 additions & 13 deletions fyrox-impl/src/renderer/light_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// SOFTWARE.

use crate::renderer::bundle::{LightSource, LightSourceKind};
use crate::renderer::make_viewport_matrix;
use crate::{
core::{
algebra::{Isometry3, Matrix4, Point3, Translation, Vector3},
Expand Down Expand Up @@ -136,19 +137,7 @@ impl LightVolumeRenderer {
) -> Result<RenderPassStatistics, FrameworkError> {
let mut stats = RenderPassStatistics::default();

let frame_matrix = Matrix4::new_orthographic(
0.0,
viewport.w() as f32,
viewport.h() as f32,
0.0,
-1.0,
1.0,
) * Matrix4::new_nonuniform_scaling(&Vector3::new(
viewport.w() as f32,
viewport.h() as f32,
0.0,
));

let frame_matrix = make_viewport_matrix(viewport);
let position = view.transform_point(&Point3::from(light.position)).coords;

match light.kind {
Expand Down
16 changes: 3 additions & 13 deletions fyrox-impl/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ impl AssociatedSceneData {
}
}

pub(crate) fn make_viewport_matrix(viewport: Rect<i32>) -> Matrix4<f32> {
/// Creates a view-projection matrix that projects unit quad a screen with the specified viewport.
pub fn make_viewport_matrix(viewport: Rect<i32>) -> Matrix4<f32> {
Matrix4::new_orthographic(
0.0,
viewport.w() as f32,
Expand Down Expand Up @@ -865,18 +866,7 @@ fn blit_pixels(
viewport: Rect<i32>,
quad: &dyn GeometryBuffer,
) -> Result<DrawCallStatistics, FrameworkError> {
let matrix = Matrix4::new_orthographic(
0.0,
viewport.w() as f32,
viewport.h() as f32,
0.0,
-1.0,
1.0,
) * Matrix4::new_nonuniform_scaling(&Vector3::new(
viewport.w() as f32,
viewport.h() as f32,
0.0,
));
let matrix = make_viewport_matrix(viewport);
let uniform_buffer =
uniform_buffer_cache.write(StaticUniformBuffer::<256>::new().with(&matrix))?;
framebuffer.draw(
Expand Down
14 changes: 2 additions & 12 deletions fyrox-impl/src/renderer/ssao/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use crate::renderer::make_viewport_matrix;
use crate::{
core::{
algebra::{Matrix3, Matrix4, Vector2, Vector3},
Expand Down Expand Up @@ -198,18 +199,7 @@ impl ScreenSpaceAmbientOcclusionRenderer {

let viewport = Rect::new(0, 0, self.width, self.height);

let frame_matrix = Matrix4::new_orthographic(
0.0,
viewport.w() as f32,
viewport.h() as f32,
0.0,
-1.0,
1.0,
) * Matrix4::new_nonuniform_scaling(&Vector3::new(
viewport.w() as f32,
viewport.h() as f32,
0.0,
));
let frame_matrix = make_viewport_matrix(viewport);

self.framebuffer.clear(
viewport,
Expand Down

0 comments on commit a9e8f7d

Please sign in to comment.