mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
fixed lighting issues webgl
- there was a feedback loop formed by simulataneous read and write to depth in a framebuffer
This commit is contained in:
@@ -9,6 +9,7 @@ extern crate rg3d;
|
||||
pub mod shared;
|
||||
|
||||
use crate::shared::create_camera;
|
||||
use rg3d::scene::light::{BaseLightBuilder, PointLightBuilder};
|
||||
use rg3d::{
|
||||
animation::Animation,
|
||||
core::{
|
||||
@@ -64,6 +65,17 @@ async fn create_scene(resource_manager: ResourceManager) -> GameScene {
|
||||
)
|
||||
.await;
|
||||
|
||||
// Add some light.
|
||||
PointLightBuilder::new(BaseLightBuilder::new(
|
||||
BaseBuilder::new().with_local_transform(
|
||||
TransformBuilder::new()
|
||||
.with_local_position(Vector3::new(0.0, 12.0, 0.0))
|
||||
.build(),
|
||||
),
|
||||
))
|
||||
.with_radius(20.0)
|
||||
.build(&mut scene.graph);
|
||||
|
||||
// Load model and animation resource in parallel. Is does *not* adds anything to
|
||||
// our scene - it just loads a resource then can be used later on to instantiate
|
||||
// models from it on scene. Why loading of resource is separated from instantiation?
|
||||
|
||||
@@ -189,10 +189,11 @@ async fn create_scene(resource_manager: ResourceManager, context: Arc<Mutex<Scen
|
||||
PointLightBuilder::new(BaseLightBuilder::new(
|
||||
BaseBuilder::new().with_local_transform(
|
||||
TransformBuilder::new()
|
||||
.with_local_position(Vector3::new(0.0, 2.0, 0.0))
|
||||
.with_local_position(Vector3::new(0.0, 12.0, 0.0))
|
||||
.build(),
|
||||
),
|
||||
))
|
||||
.with_radius(20.0)
|
||||
.build(&mut scene.graph);
|
||||
|
||||
let (model_resource, walk_animation_resource) = rg3d::futures::join!(
|
||||
|
||||
@@ -169,7 +169,7 @@ pub struct GeometryBufferBinding<'a> {
|
||||
buffer: &'a GeometryBuffer,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Default)]
|
||||
pub struct DrawCallStatistics {
|
||||
pub triangles: usize,
|
||||
}
|
||||
|
||||
@@ -497,7 +497,8 @@ impl PipelineState {
|
||||
self.frame_statistics
|
||||
}
|
||||
|
||||
pub fn check_error(&self) {
|
||||
/// Checks for errors, returns true if any error has occurred.
|
||||
pub fn check_error(&self) -> bool {
|
||||
unsafe {
|
||||
let error_code = self.gl.get_error();
|
||||
if error_code != glow::NO_ERROR {
|
||||
@@ -515,6 +516,10 @@ impl PipelineState {
|
||||
MessageKind::Error,
|
||||
format!("{} error has occurred! Stability is not guaranteed!", code),
|
||||
);
|
||||
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+42
-3
@@ -18,6 +18,7 @@ use crate::{
|
||||
},
|
||||
scene::{camera::Camera, mesh::RenderPath},
|
||||
};
|
||||
use glow::HasContext;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
struct InstancedShader {
|
||||
@@ -221,6 +222,22 @@ impl GBuffer {
|
||||
],
|
||||
)?;
|
||||
|
||||
let mut final_frame_depth_stencil_texture = GpuTexture::new(
|
||||
state,
|
||||
GpuTextureKind::Rectangle { width, height },
|
||||
PixelKind::D24S8,
|
||||
MinificationFilter::Nearest,
|
||||
MagnificationFilter::Nearest,
|
||||
1,
|
||||
None,
|
||||
)?;
|
||||
final_frame_depth_stencil_texture
|
||||
.bind_mut(state, 0)
|
||||
.set_wrap(Coordinate::S, WrapMode::ClampToEdge)
|
||||
.set_wrap(Coordinate::T, WrapMode::ClampToEdge);
|
||||
|
||||
let final_frame_depth_stencil = Rc::new(RefCell::new(final_frame_depth_stencil_texture));
|
||||
|
||||
let frame_texture = GpuTexture::new(
|
||||
state,
|
||||
GpuTextureKind::Rectangle { width, height },
|
||||
@@ -231,11 +248,11 @@ impl GBuffer {
|
||||
None,
|
||||
)?;
|
||||
|
||||
let opt_framebuffer = FrameBuffer::new(
|
||||
let final_frame = FrameBuffer::new(
|
||||
state,
|
||||
Some(Attachment {
|
||||
kind: AttachmentKind::DepthStencil,
|
||||
texture: depth_stencil,
|
||||
texture: final_frame_depth_stencil,
|
||||
}),
|
||||
vec![Attachment {
|
||||
kind: AttachmentKind::Color,
|
||||
@@ -249,7 +266,7 @@ impl GBuffer {
|
||||
shader: Shader::new(state)?,
|
||||
width: width as i32,
|
||||
height: height as i32,
|
||||
final_frame: opt_framebuffer,
|
||||
final_frame,
|
||||
matrix_storage: MatrixStorage::new(state)?,
|
||||
instance_data_set: Default::default(),
|
||||
})
|
||||
@@ -555,6 +572,28 @@ impl GBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
// Copy depth-stencil from gbuffer to final frame buffer.
|
||||
unsafe {
|
||||
state
|
||||
.gl
|
||||
.bind_framebuffer(glow::READ_FRAMEBUFFER, Some(self.framebuffer.id()));
|
||||
state
|
||||
.gl
|
||||
.bind_framebuffer(glow::DRAW_FRAMEBUFFER, Some(self.final_frame.id()));
|
||||
state.gl.blit_framebuffer(
|
||||
0,
|
||||
0,
|
||||
self.width,
|
||||
self.height,
|
||||
0,
|
||||
0,
|
||||
self.width,
|
||||
self.height,
|
||||
glow::DEPTH_BUFFER_BIT | glow::STENCIL_BUFFER_BIT,
|
||||
glow::NEAREST,
|
||||
);
|
||||
}
|
||||
|
||||
statistics
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,8 +104,8 @@ impl SpotShadowMapRenderer {
|
||||
.bind_mut(state, 0)
|
||||
.set_magnification_filter(MagnificationFilter::Linear)
|
||||
.set_minification_filter(MinificationFilter::Linear)
|
||||
.set_wrap(Coordinate::T, WrapMode::ClampToBorder)
|
||||
.set_wrap(Coordinate::S, WrapMode::ClampToBorder)
|
||||
.set_wrap(Coordinate::T, WrapMode::ClampToEdge)
|
||||
.set_wrap(Coordinate::S, WrapMode::ClampToEdge)
|
||||
.set_border_color(Color::WHITE);
|
||||
texture
|
||||
};
|
||||
@@ -323,8 +323,8 @@ impl PointShadowMapRenderer {
|
||||
.bind_mut(state, 0)
|
||||
.set_minification_filter(MinificationFilter::Nearest)
|
||||
.set_magnification_filter(MagnificationFilter::Nearest)
|
||||
.set_wrap(Coordinate::S, WrapMode::ClampToBorder)
|
||||
.set_wrap(Coordinate::T, WrapMode::ClampToBorder);
|
||||
.set_wrap(Coordinate::S, WrapMode::ClampToEdge)
|
||||
.set_wrap(Coordinate::T, WrapMode::ClampToEdge);
|
||||
texture
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user