slightly improved renderer performance

This commit is contained in:
Dmitry
2021-04-08 17:24:24 +03:00
parent 6728350df2
commit b606ef94ae
19 changed files with 137 additions and 157 deletions
+2 -1
View File
@@ -8,7 +8,8 @@
[![Discord](https://img.shields.io/discord/756573453561102427)](https://discord.gg/xENF5Uh)
[![Lines of code](https://tokei.rs/b1/github/mrDIMAS/rg3d)](https://github.com/mrDIMAS/rg3d)
A feature-rich 3D game engine written in Rust with a scene editor. Most powerful 3D game engine written in Rust so far.
A feature-rich, general purpose 3D game engine written in Rust with a scene editor. Most powerful
3D game engine written in Rust so far.
## Support
+1 -1
View File
@@ -222,7 +222,7 @@ fn main() {
game.engine.render(fixed_timestep).unwrap();
}
Event::LoopDestroyed => {
rg3d::core::profiler::print();
println!("{:?}", rg3d::core::profiler::print());
}
Event::WindowEvent { event, .. } => {
match event {
+5 -6
View File
@@ -1,7 +1,5 @@
use crate::core::arrayvec::ArrayVec;
use crate::scene::mesh::RenderPath;
use crate::{
core::{algebra::Matrix4, color::Color, pool::Handle},
core::{algebra::Matrix4, arrayvec::ArrayVec, color::Color, pool::Handle, scope_profile},
renderer::{
error::RendererError,
framework::gpu_texture::{
@@ -11,15 +9,14 @@ use crate::{
surface::SurfaceSharedData,
TextureCache,
},
scene::{graph::Graph, node::Node},
scene::{graph::Graph, mesh::RenderPath, node::Node},
};
use std::sync::RwLock;
use std::{
cell::RefCell,
collections::HashMap,
fmt::{Debug, Formatter},
rc::Rc,
sync::Arc,
sync::{Arc, RwLock},
};
pub const BONE_MATRICES_COUNT: usize = 64;
@@ -85,6 +82,8 @@ impl BatchStorage {
specular_dummy: Rc<RefCell<GpuTexture>>,
texture_cache: &mut TextureCache,
) {
scope_profile!();
for batch in self.batches.iter_mut() {
batch.instances.clear();
self.buffers.push(std::mem::take(&mut batch.instances));
+2 -2
View File
@@ -123,7 +123,7 @@ impl Blur {
(
self.shader.world_view_projection_matrix,
UniformValue::Matrix4(
Matrix4::new_orthographic(
&(Matrix4::new_orthographic(
0.0,
viewport.w() as f32,
viewport.h() as f32,
@@ -134,7 +134,7 @@ impl Blur {
viewport.w() as f32,
viewport.h() as f32,
0.0,
)),
))),
),
),
(
+1 -1
View File
@@ -128,7 +128,7 @@ impl DebugRenderer {
},
&[(
self.shader.wvp_matrix,
UniformValue::Matrix4(camera.view_projection_matrix()),
UniformValue::Matrix4(&camera.view_projection_matrix()),
)],
);
+30 -22
View File
@@ -421,7 +421,9 @@ impl DeferredLightRenderer {
let projection_matrix = camera.projection_matrix();
let view_projection = camera.view_projection_matrix();
let inv_projection = projection_matrix.try_inverse().unwrap_or_default();
let inv_view_projection = view_projection.try_inverse().unwrap_or_default();
let camera_global_position = camera.global_position();
// Fill SSAO map.
if settings.use_ssao {
@@ -483,7 +485,7 @@ impl DeferredLightRenderer {
),
(
self.flat_shader.wvp_matrix,
UniformValue::Matrix4(view_projection * wvp),
UniformValue::Matrix4(&(view_projection * wvp)),
),
],
offset: face * 2,
@@ -515,7 +517,7 @@ impl DeferredLightRenderer {
&[
(
self.ambient_light_shader.wvp_matrix,
UniformValue::Matrix4(frame_matrix),
UniformValue::Matrix4(&frame_matrix),
),
(
self.ambient_light_shader.ambient_color,
@@ -699,9 +701,9 @@ impl DeferredLightRenderer {
&[(
self.flat_shader.wvp_matrix,
UniformValue::Matrix4(
view_projection
&(view_projection
* Matrix4::new_translation(&light_position)
* Matrix4::new_nonuniform_scaling(&light_radius_vec),
* Matrix4::new_nonuniform_scaling(&light_radius_vec)),
),
)],
);
@@ -732,9 +734,9 @@ impl DeferredLightRenderer {
&[(
self.flat_shader.wvp_matrix,
UniformValue::Matrix4(
view_projection
&(view_projection
* Matrix4::new_translation(&light_position)
* Matrix4::new_nonuniform_scaling(&light_radius_vec),
* Matrix4::new_nonuniform_scaling(&light_radius_vec)),
),
)],
);
@@ -775,21 +777,24 @@ impl DeferredLightRenderer {
(shader.shadows_enabled, UniformValue::Bool(shadows_enabled)),
(
shader.light_view_proj_matrix,
UniformValue::Matrix4(light_view_projection),
UniformValue::Matrix4(&light_view_projection),
),
(
shader.soft_shadows,
UniformValue::Bool(settings.spot_soft_shadows),
),
(shader.light_position, UniformValue::Vector3(light_position)),
(
shader.light_position,
UniformValue::Vector3(&light_position),
),
(
shader.light_direction,
UniformValue::Vector3(emit_direction),
UniformValue::Vector3(&emit_direction),
),
(shader.light_radius, UniformValue::Float(light_radius)),
(
shader.inv_view_proj_matrix,
UniformValue::Matrix4(inv_view_projection),
UniformValue::Matrix4(&inv_view_projection),
),
(shader.light_color, UniformValue::Color(light.color())),
(
@@ -800,7 +805,7 @@ impl DeferredLightRenderer {
shader.half_cone_angle_cos,
UniformValue::Float((spot_light.full_cone_angle() * 0.5).cos()),
),
(shader.wvp_matrix, UniformValue::Matrix4(frame_matrix)),
(shader.wvp_matrix, UniformValue::Matrix4(&frame_matrix)),
(
shader.shadow_map_inv_size,
UniformValue::Float(
@@ -810,7 +815,7 @@ impl DeferredLightRenderer {
),
(
shader.camera_position,
UniformValue::Vector3(camera.global_position()),
UniformValue::Vector3(&camera_global_position),
),
(
shader.depth_sampler,
@@ -876,17 +881,20 @@ impl DeferredLightRenderer {
shader.soft_shadows,
UniformValue::Bool(settings.point_soft_shadows),
),
(shader.light_position, UniformValue::Vector3(light_position)),
(
shader.light_position,
UniformValue::Vector3(&light_position),
),
(shader.light_radius, UniformValue::Float(light_radius)),
(
shader.inv_view_proj_matrix,
UniformValue::Matrix4(inv_view_projection),
UniformValue::Matrix4(&inv_view_projection),
),
(shader.light_color, UniformValue::Color(light.color())),
(shader.wvp_matrix, UniformValue::Matrix4(frame_matrix)),
(shader.wvp_matrix, UniformValue::Matrix4(&frame_matrix)),
(
shader.camera_position,
UniformValue::Vector3(camera.global_position()),
UniformValue::Vector3(&camera_global_position),
),
(
shader.depth_sampler,
@@ -941,17 +949,17 @@ impl DeferredLightRenderer {
let uniforms = [
(
shader.light_direction,
UniformValue::Vector3(emit_direction),
UniformValue::Vector3(&emit_direction),
),
(
shader.inv_view_proj_matrix,
UniformValue::Matrix4(inv_view_projection),
UniformValue::Matrix4(&inv_view_projection),
),
(shader.light_color, UniformValue::Color(light.color())),
(shader.wvp_matrix, UniformValue::Matrix4(frame_matrix)),
(shader.wvp_matrix, UniformValue::Matrix4(&frame_matrix)),
(
shader.camera_position,
UniformValue::Vector3(camera.global_position()),
UniformValue::Vector3(&camera_global_position),
),
(
shader.depth_sampler,
@@ -1006,8 +1014,8 @@ impl DeferredLightRenderer {
&self.quad,
geometry_cache,
camera.view_matrix(),
projection_matrix.try_inverse().unwrap_or_default(),
camera.view_projection_matrix(),
inv_projection,
view_projection,
viewport,
&scene.graph,
);
+3 -1
View File
@@ -129,7 +129,9 @@ impl ForwardRenderer {
),
(
self.shader.wvp_matrix,
UniformValue::Matrix4(view_projection * instance.world_transform),
UniformValue::Matrix4(
&(view_projection * instance.world_transform),
),
),
(
self.shader.use_skeletal_animation,
+12 -11
View File
@@ -1,8 +1,9 @@
use crate::core::algebra::{Matrix3, Matrix4, Vector2, Vector3, Vector4};
use crate::core::scope_profile;
use crate::utils::log::MessageKind;
use crate::{
core::color::Color,
core::{
algebra::{Matrix3, Matrix4, Vector2, Vector3, Vector4},
color::Color,
scope_profile,
},
renderer::{
error::RendererError,
framework::{
@@ -14,7 +15,7 @@ use crate::{
state::PipelineState,
},
},
utils::log::Log,
utils::log::{Log, MessageKind},
};
use std::{cell::RefCell, ffi::CString, marker::PhantomData, rc::Rc};
@@ -35,19 +36,19 @@ pub struct UniformLocation {
#[allow(dead_code)]
pub enum UniformValue<'a> {
Sampler {
index: usize,
index: u32,
texture: Rc<RefCell<GpuTexture>>,
},
Bool(bool),
Integer(i32),
Float(f32),
Vector2(Vector2<f32>),
Vector3(Vector3<f32>),
Vector4(Vector4<f32>),
Vector2(&'a Vector2<f32>),
Vector3(&'a Vector3<f32>),
Vector4(&'a Vector4<f32>),
Color(Color),
Matrix4(Matrix4<f32>),
Matrix3(Matrix3<f32>),
Matrix4(&'a Matrix4<f32>),
Matrix3(&'a Matrix3<f32>),
IntegerArray(&'a [i32]),
FloatArray(&'a [f32]),
+3 -4
View File
@@ -1,7 +1,6 @@
// Keep this for now, some texture kind might be used in future.
#![allow(dead_code)]
use crate::utils::log::MessageKind;
use crate::{
core::color::Color,
renderer::{
@@ -12,7 +11,7 @@ use crate::{
TextureKind, TextureMagnificationFilter, TextureMinificationFilter, TexturePixelKind,
TextureWrapMode,
},
utils::log::Log,
utils::log::{Log, MessageKind},
};
use std::{ffi::c_void, marker::PhantomData};
@@ -848,13 +847,13 @@ impl GpuTexture {
pub fn bind_mut(
&mut self,
state: &mut PipelineState,
sampler_index: usize,
sampler_index: u32,
) -> TextureBinding<'_> {
state.set_texture(sampler_index, self.kind.to_texture_target(), self.texture);
TextureBinding { texture: self }
}
pub fn bind(&self, state: &mut PipelineState, sampler_index: usize) {
pub fn bind(&self, state: &mut PipelineState, sampler_index: u32) {
state.set_texture(sampler_index, self.kind.to_texture_target(), self.texture);
}
+3 -3
View File
@@ -369,8 +369,8 @@ impl PipelineState {
}
}
pub fn set_texture(&mut self, sampler_index: usize, target: GLenum, texture: GLuint) {
let unit = self.texture_units.get_mut(sampler_index).unwrap();
pub fn set_texture(&mut self, sampler_index: u32, target: GLenum, texture: GLuint) {
let unit = self.texture_units.get_mut(sampler_index as usize).unwrap();
if unit.target != target || unit.texture != texture {
unit.texture = texture;
@@ -379,7 +379,7 @@ impl PipelineState {
self.frame_statistics.texture_binding_changes += 1;
unsafe {
gl::ActiveTexture(gl::TEXTURE0 + sampler_index as u32);
gl::ActiveTexture(gl::TEXTURE0 + sampler_index);
gl::BindTexture(target, texture);
}
}
+4 -5
View File
@@ -92,13 +92,12 @@ impl FxaaRenderer {
blend: false,
},
&[
(self.shader.wvp_matrix, UniformValue::Matrix4(frame_matrix)),
(self.shader.wvp_matrix, UniformValue::Matrix4(&frame_matrix)),
(
self.shader.inverse_screen_size,
UniformValue::Vector2(Vector2::new(
1.0 / viewport.w() as f32,
1.0 / viewport.h() as f32,
)),
UniformValue::Vector2(
&(Vector2::new(1.0 / viewport.w() as f32, 1.0 / viewport.h() as f32)),
),
),
(
self.shader.screen_texture,
+10 -20
View File
@@ -1,10 +1,5 @@
use crate::{
core::{
algebra::{Matrix4, Vector4},
color::Color,
math::Rect,
scope_profile,
},
core::{algebra::Vector4, color::Color, math::Rect, scope_profile},
renderer::{
batch::{BatchStorage, InstanceData, MatrixStorage, BONE_MATRICES_COUNT},
error::RendererError,
@@ -121,7 +116,6 @@ pub struct GBuffer {
pub height: i32,
matrix_storage: MatrixStorage,
instance_data_set: Vec<InstanceData>,
bone_matrices: Vec<Matrix4<f32>>,
}
pub(in crate) struct GBufferRenderContext<'a, 'b> {
@@ -253,7 +247,6 @@ impl GBuffer {
final_frame: opt_framebuffer,
matrix_storage: MatrixStorage::new(state)?,
instance_data_set: Default::default(),
bone_matrices: Default::default(),
})
}
@@ -378,7 +371,7 @@ impl GBuffer {
),
(
self.shader.camera_position,
UniformValue::Vector3(camera.global_position()),
UniformValue::Vector3(&camera.global_position()),
),
(
self.shader.environment_map,
@@ -407,11 +400,13 @@ impl GBuffer {
),
(
self.shader.wvp_matrix,
UniformValue::Matrix4(view_projection * instance.world_transform),
UniformValue::Matrix4(
&(view_projection * instance.world_transform),
),
),
(
self.shader.world_matrix,
UniformValue::Matrix4(instance.world_transform),
UniformValue::Matrix4(&instance.world_transform),
),
(
self.shader.use_skeletal_animation,
@@ -423,12 +418,7 @@ impl GBuffer {
),
(
self.shader.bone_matrices,
UniformValue::Mat4Array({
self.bone_matrices.clear();
self.bone_matrices
.extend_from_slice(instance.bone_matrices.as_slice());
&self.bone_matrices
}),
UniformValue::Mat4Array(instance.bone_matrices.as_slice()),
),
],
);
@@ -490,7 +480,7 @@ impl GBuffer {
),
(
self.instanced_shader.camera_position,
UniformValue::Vector3(camera.global_position()),
UniformValue::Vector3(&camera.global_position()),
),
(
self.instanced_shader.environment_map,
@@ -542,7 +532,7 @@ impl GBuffer {
} else {
unreachable!()
};
Vector4::new(
&Vector4::new(
1.0 / (w as f32),
1.0 / (h as f32),
w as f32,
@@ -552,7 +542,7 @@ impl GBuffer {
),
(
self.instanced_shader.view_projection_matrix,
UniformValue::Matrix4(camera.view_projection_matrix()),
UniformValue::Matrix4(&camera.view_projection_matrix()),
),
],
);
+13 -13
View File
@@ -197,7 +197,7 @@ impl LightVolumeRenderer {
depth_test: true,
blend: false,
},
&[(self.flat_shader.wvp_matrix, UniformValue::Matrix4(mvp))],
&[(self.flat_shader.wvp_matrix, UniformValue::Matrix4(&mvp))],
);
// Make sure to clean stencil buffer after drawing full screen quad.
@@ -226,11 +226,11 @@ impl LightVolumeRenderer {
&[
(
self.spot_light_shader.world_view_proj_matrix,
UniformValue::Matrix4(frame_matrix),
UniformValue::Matrix4(&frame_matrix),
),
(
self.spot_light_shader.inv_proj,
UniformValue::Matrix4(inv_proj),
UniformValue::Matrix4(&inv_proj),
),
(
self.spot_light_shader.cone_angle_cos,
@@ -238,11 +238,11 @@ impl LightVolumeRenderer {
),
(
self.spot_light_shader.light_position,
UniformValue::Vector3(position),
UniformValue::Vector3(&position),
),
(
self.spot_light_shader.light_direction,
UniformValue::Vector3(direction),
UniformValue::Vector3(&direction),
),
(
self.spot_light_shader.depth_sampler,
@@ -253,11 +253,11 @@ impl LightVolumeRenderer {
),
(
self.spot_light_shader.light_color,
UniformValue::Vector3(light.color().as_frgba().xyz()),
UniformValue::Vector3(&light.color().as_frgba().xyz()),
),
(
self.spot_light_shader.scatter_factor,
UniformValue::Vector3(light.scatter()),
UniformValue::Vector3(&light.scatter()),
),
],
)
@@ -301,7 +301,7 @@ impl LightVolumeRenderer {
depth_test: true,
blend: false,
},
&[(self.flat_shader.wvp_matrix, UniformValue::Matrix4(mvp))],
&[(self.flat_shader.wvp_matrix, UniformValue::Matrix4(&mvp))],
);
// Make sure to clean stencil buffer after drawing full screen quad.
@@ -330,15 +330,15 @@ impl LightVolumeRenderer {
&[
(
self.point_light_shader.world_view_proj_matrix,
UniformValue::Matrix4(frame_matrix),
UniformValue::Matrix4(&frame_matrix),
),
(
self.point_light_shader.inv_proj,
UniformValue::Matrix4(inv_proj),
UniformValue::Matrix4(&inv_proj),
),
(
self.point_light_shader.light_position,
UniformValue::Vector3(position),
UniformValue::Vector3(&position),
),
(
self.point_light_shader.depth_sampler,
@@ -353,11 +353,11 @@ impl LightVolumeRenderer {
),
(
self.point_light_shader.light_color,
UniformValue::Vector3(light.color().as_frgba().xyz()),
UniformValue::Vector3(&light.color().as_frgba().xyz()),
),
(
self.point_light_shader.scatter_factor,
UniformValue::Vector3(light.scatter()),
UniformValue::Vector3(&light.scatter()),
),
],
)
+2 -2
View File
@@ -1139,7 +1139,7 @@ impl Renderer {
camera,
geom_cache: &mut self.geometry_cache,
batch_storage: &self.batch_storage,
framebuffer: &mut gbuffer.final_frame, // TODO: GBuffer **must not** containt final frame.
framebuffer: &mut gbuffer.final_frame, // TODO: GBuffer **must not** contain final frame.
viewport,
});
@@ -1179,7 +1179,7 @@ impl Renderer {
&[
(
self.flat_shader.wvp_matrix,
UniformValue::Matrix4({
UniformValue::Matrix4(&{
Matrix4::new_orthographic(
0.0,
viewport.w() as f32,
+12 -9
View File
@@ -142,10 +142,14 @@ impl ParticleSystemRenderer {
state.set_blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
let inv_view = camera.inv_view_matrix().unwrap();
let view_proj = camera.view_projection_matrix();
let camera_up = inv_view.up();
let camera_side = inv_view.side();
let inv_screen_size = Vector2::new(1.0 / frame_width, 1.0 / frame_height);
let proj_params = Vector2::new(camera.z_far(), camera.z_near());
for node in graph.linear_iter() {
let particle_system = if let Node::ParticleSystem(particle_system) = node {
particle_system
@@ -165,6 +169,8 @@ impl ParticleSystemRenderer {
.bind(state)
.set_triangles(self.draw_data.triangles());
let global_transform = node.global_transform();
let uniforms = [
(
self.shader.depth_buffer_texture,
@@ -190,28 +196,25 @@ impl ParticleSystemRenderer {
),
(
self.shader.camera_side_vector,
UniformValue::Vector3(camera_side),
UniformValue::Vector3(&camera_side),
),
(
self.shader.camera_up_vector,
UniformValue::Vector3(camera_up),
UniformValue::Vector3(&camera_up),
),
(
self.shader.view_projection_matrix,
UniformValue::Matrix4(camera.view_projection_matrix()),
UniformValue::Matrix4(&view_proj),
),
(
self.shader.world_matrix,
UniformValue::Matrix4(node.global_transform()),
UniformValue::Matrix4(&global_transform),
),
(
self.shader.inv_screen_size,
UniformValue::Vector2(Vector2::new(1.0 / frame_width, 1.0 / frame_height)),
),
(
self.shader.proj_params,
UniformValue::Vector2(Vector2::new(camera.z_far(), camera.z_near())),
UniformValue::Vector2(&inv_screen_size),
),
(self.shader.proj_params, UniformValue::Vector2(&proj_params)),
];
let draw_params = DrawParameters {
+10 -22
View File
@@ -1,6 +1,5 @@
#![warn(clippy::too_many_arguments)]
use crate::renderer::ShadowMapPrecision;
use crate::{
core::{
algebra::{Matrix4, Point3, Vector3},
@@ -22,7 +21,7 @@ use crate::{
},
state::{ColorMask, PipelineState},
},
GeometryCache, RenderPassStatistics,
GeometryCache, RenderPassStatistics, ShadowMapPrecision,
},
scene::{graph::Graph, node::Node},
};
@@ -61,7 +60,6 @@ pub struct SpotShadowMapRenderer {
// 1 - medium, for lights with medium distance to camera.
// 2 - small, for farthest lights.
cascades: [FrameBuffer; 3],
bone_matrices: Vec<Matrix4<f32>>,
size: usize,
}
@@ -131,7 +129,6 @@ impl SpotShadowMapRenderer {
make_cascade(state, cascade_size(size, 2), precision)?,
],
shader: SpotShadowMapShader::new()?,
bone_matrices: Vec::new(),
})
}
@@ -210,7 +207,7 @@ impl SpotShadowMapRenderer {
(
self.shader.world_view_projection_matrix,
UniformValue::Matrix4(
light_view_projection * instance.world_transform,
&(light_view_projection * instance.world_transform),
),
),
(
@@ -219,12 +216,7 @@ impl SpotShadowMapRenderer {
),
(
self.shader.bone_matrices,
UniformValue::Mat4Array({
self.bone_matrices.clear();
self.bone_matrices
.extend_from_slice(instance.bone_matrices.as_slice());
&self.bone_matrices
}),
UniformValue::Mat4Array(instance.bone_matrices.as_slice()),
),
(
self.shader.diffuse_texture,
@@ -273,7 +265,6 @@ impl PointShadowMapShader {
pub struct PointShadowMapRenderer {
precision: ShadowMapPrecision,
bone_matrices: Vec<Matrix4<f32>>,
shader: PointShadowMapShader,
cascades: [FrameBuffer; 3],
size: usize,
@@ -372,7 +363,6 @@ impl PointShadowMapRenderer {
Ok(Self {
precision,
bone_matrices: Default::default(),
cascades: [
make_cascade(state, cascade_size(size, 0), precision)?,
make_cascade(state, cascade_size(size, 1), precision)?,
@@ -501,15 +491,18 @@ impl PointShadowMapRenderer {
blend: false,
},
&[
(self.shader.light_position, UniformValue::Vector3(light_pos)),
(
self.shader.light_position,
UniformValue::Vector3(&light_pos),
),
(
self.shader.world_matrix,
UniformValue::Matrix4(instance.world_transform),
UniformValue::Matrix4(&instance.world_transform),
),
(
self.shader.world_view_projection_matrix,
UniformValue::Matrix4(
light_view_projection_matrix * instance.world_transform,
&(light_view_projection_matrix * instance.world_transform),
),
),
(
@@ -518,12 +511,7 @@ impl PointShadowMapRenderer {
),
(
self.shader.bone_matrices,
UniformValue::Mat4Array({
self.bone_matrices.clear();
self.bone_matrices
.extend_from_slice(instance.bone_matrices.as_slice());
&self.bone_matrices
}),
UniformValue::Mat4Array(instance.bone_matrices.as_slice()),
),
(
self.shader.diffuse_texture,
+4 -4
View File
@@ -152,19 +152,19 @@ impl SpriteRenderer {
),
(
self.shader.view_projection_matrix,
UniformValue::Matrix4(view_projection),
UniformValue::Matrix4(&view_projection),
),
(
self.shader.world_matrix,
UniformValue::Matrix4(sprite.global_transform()),
UniformValue::Matrix4(&sprite.global_transform()),
),
(
self.shader.camera_up_vector,
UniformValue::Vector3(camera_up),
UniformValue::Vector3(&camera_up),
),
(
self.shader.camera_side_vector,
UniformValue::Vector3(camera_side),
UniformValue::Vector3(&camera_side),
),
(self.shader.size, UniformValue::Float(sprite.size())),
(self.shader.color, UniformValue::Color(sprite.color())),
+5 -5
View File
@@ -262,7 +262,7 @@ impl ScreenSpaceAmbientOcclusionRenderer {
(
self.shader.noise_scale,
UniformValue::Vector2({
Vector2::new(
&Vector2::new(
self.width as f32 / NOISE_SIZE as f32,
self.height as f32 / NOISE_SIZE as f32,
)
@@ -270,17 +270,17 @@ impl ScreenSpaceAmbientOcclusionRenderer {
),
(
self.shader.world_view_proj_matrix,
UniformValue::Matrix4(frame_matrix),
UniformValue::Matrix4(&frame_matrix),
),
(
self.shader.projection_matrix,
UniformValue::Matrix4(projection_matrix),
UniformValue::Matrix4(&projection_matrix),
),
(
self.shader.inv_proj_matrix,
UniformValue::Matrix4(projection_matrix.try_inverse().unwrap_or_default()),
UniformValue::Matrix4(&projection_matrix.try_inverse().unwrap_or_default()),
),
(self.shader.view_matrix, UniformValue::Matrix3(view_matrix)),
(self.shader.view_matrix, UniformValue::Matrix3(&view_matrix)),
],
);
+15 -25
View File
@@ -172,6 +172,7 @@ impl UiRenderer {
geometry_buffer.set_triangles(drawing_context.get_triangles());
let ortho = Matrix4::new_orthographic(0.0, frame_width, frame_height, 0.0, -1.0, 1.0);
let resolution = Vector2::new(frame_width, frame_height);
state.set_scissor_test(true);
@@ -236,7 +237,7 @@ impl UiRenderer {
depth_test: false,
blend: false,
},
&[(self.shader.wvp_matrix, UniformValue::Matrix4(ortho))],
&[(self.shader.wvp_matrix, UniformValue::Matrix4(&ortho))],
);
// Make sure main geometry will be drawn only on marked pixels.
@@ -293,6 +294,13 @@ impl UiRenderer {
let mut raw_stops = [0.0; 16];
let mut raw_colors = [Vector4::default(); 16];
let bounds_max = cmd.bounds.right_bottom_corner();
let (gradient_origin, gradient_end) = match cmd.brush {
Brush::Solid(_) => (Vector2::default(), Vector2::default()),
Brush::LinearGradient { from, to, .. } => (from, to),
Brush::RadialGradient { center, .. } => (center, Vector2::default()),
};
let uniforms = [
(
@@ -302,19 +310,13 @@ impl UiRenderer {
texture: diffuse_texture,
},
),
(self.shader.wvp_matrix, UniformValue::Matrix4(ortho)),
(
self.shader.resolution,
UniformValue::Vector2(Vector2::new(frame_width, frame_height)),
),
(self.shader.wvp_matrix, UniformValue::Matrix4(&ortho)),
(self.shader.resolution, UniformValue::Vector2(&resolution)),
(
self.shader.bounds_min,
UniformValue::Vector2(cmd.bounds.position),
),
(
self.shader.bounds_max,
UniformValue::Vector2(cmd.bounds.right_bottom_corner()),
UniformValue::Vector2(&cmd.bounds.position),
),
(self.shader.bounds_max, UniformValue::Vector2(&bounds_max)),
(self.shader.is_font, UniformValue::Bool(is_font_texture)),
(
self.shader.brush_type,
@@ -337,23 +339,11 @@ impl UiRenderer {
),
(
self.shader.gradient_origin,
UniformValue::Vector2({
match cmd.brush {
Brush::Solid(_) => Vector2::default(),
Brush::LinearGradient { from, .. } => from,
Brush::RadialGradient { center, .. } => center,
}
}),
UniformValue::Vector2(&gradient_origin),
),
(
self.shader.gradient_end,
UniformValue::Vector2({
match cmd.brush {
Brush::Solid(_) => Vector2::default(),
Brush::LinearGradient { to, .. } => to,
Brush::RadialGradient { .. } => Vector2::default(),
}
}),
UniformValue::Vector2(&gradient_end),
),
(
self.shader.gradient_point_count,