mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Adjusted sun and added F16 render target
Former-commit-id: 5585e0038846ef34378933eeb9051714ffe2c100
This commit is contained in:
parent
d645af7d6a
commit
c48a82e78d
@ -23,8 +23,7 @@ uniform u_globals {
|
||||
out vec4 tgt_color;
|
||||
|
||||
void main() {
|
||||
// Uncomment to invert colors
|
||||
//tgt_color = vec4(vec3(1.0, 1.0, 1.0) - texture2D(src_color, (f_pos + 1.0) / 2.0).xyz, 1.0);
|
||||
tgt_color = texture2D(src_color, (f_pos + 1.0) / 2.0);
|
||||
|
||||
vec4 src_color = texture2D(src_color, (f_pos + 1.0) / 2.0);
|
||||
|
||||
tgt_color = 1.0 - 1.0 / (src_color + 1.0);
|
||||
}
|
||||
|
@ -29,16 +29,16 @@ vec3 get_sky_color(vec3 dir, float time_of_day) {
|
||||
const vec3 SKY_BOTTOM = vec3(0.0, 0.05, 0.2);
|
||||
|
||||
const vec3 SUN_HALO_COLOR = vec3(1.0, 0.8, 0.5);
|
||||
const vec3 SUN_SURF_COLOR = vec3(1.0, 0.8, 0.5);
|
||||
const vec3 SUN_SURF_COLOR = vec3(1.0, 0.8, 0.0) * 100.0;
|
||||
|
||||
float sun_angle_rad = time_of_day * TIME_FACTOR;
|
||||
vec3 sun_dir = vec3(sin(sun_angle_rad), 0.0, cos(sun_angle_rad));
|
||||
|
||||
vec3 sun_halo = pow(max(dot(dir, sun_dir), 0.0), 8.0) * SUN_HALO_COLOR;
|
||||
vec3 sun_surf = min(pow(max(dot(dir, sun_dir), 0.0) + 0.01, 16.0), 1.0) * SUN_SURF_COLOR;
|
||||
vec3 sun_surf = pow(max(dot(dir, sun_dir), 0.0), 1000.0) * SUN_SURF_COLOR;
|
||||
vec3 sun_light = sun_halo + sun_surf;
|
||||
|
||||
return mix(SKY_BOTTOM, SKY_TOP, (dir.z + 1.0) / 2.0) + sun_light * 0.5;
|
||||
return mix(SKY_BOTTOM, SKY_TOP, (dir.z + 1.0) / 2.0) + sun_light;
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
@ -23,7 +23,7 @@ pub use self::{
|
||||
},
|
||||
Globals,
|
||||
},
|
||||
renderer::{Renderer, TgtColorFmt, TgtDepthFmt},
|
||||
renderer::{Renderer, TgtColorFmt, TgtDepthFmt, WinColorFmt, WinDepthFmt},
|
||||
texture::Texture,
|
||||
};
|
||||
|
||||
|
@ -12,7 +12,7 @@ use gfx::{
|
||||
|
||||
// Local
|
||||
use super::{
|
||||
super::{Mesh, Pipeline, TgtColorFmt, TgtDepthFmt, Tri},
|
||||
super::{Mesh, Pipeline, WinColorFmt, WinDepthFmt, Tri},
|
||||
Globals,
|
||||
};
|
||||
|
||||
@ -31,10 +31,10 @@ gfx_defines! {
|
||||
locals: gfx::ConstantBuffer<Locals> = "u_locals",
|
||||
globals: gfx::ConstantBuffer<Globals> = "u_globals",
|
||||
|
||||
src_sampler: gfx::TextureSampler<<TgtColorFmt as gfx::format::Formatted>::View> = "src_color",
|
||||
src_sampler: gfx::TextureSampler<<WinColorFmt as gfx::format::Formatted>::View> = "src_color",
|
||||
|
||||
tgt_color: gfx::RenderTarget<TgtColorFmt> = "tgt_color",
|
||||
tgt_depth: gfx::DepthTarget<TgtDepthFmt> = gfx::preset::depth::PASS_TEST,
|
||||
tgt_color: gfx::RenderTarget<WinColorFmt> = "tgt_color",
|
||||
tgt_depth: gfx::DepthTarget<WinDepthFmt> = gfx::preset::depth::PASS_TEST,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::super::{Pipeline, Quad, TgtColorFmt, TgtDepthFmt, Tri};
|
||||
use super::super::{Pipeline, Quad, WinColorFmt, WinDepthFmt, Tri};
|
||||
use gfx::{
|
||||
self,
|
||||
// Macros
|
||||
@ -25,8 +25,8 @@ gfx_defines! {
|
||||
|
||||
scissor: gfx::Scissor = (),
|
||||
|
||||
tgt_color: gfx::BlendTarget<TgtColorFmt> = ("tgt_color", gfx::state::ColorMask::all(), gfx::preset::blend::ALPHA),
|
||||
tgt_depth: gfx::DepthTarget<TgtDepthFmt> = gfx::preset::depth::PASS_TEST,
|
||||
tgt_color: gfx::BlendTarget<WinColorFmt> = ("tgt_color", gfx::state::ColorMask::all(), gfx::preset::blend::ALPHA),
|
||||
tgt_depth: gfx::DepthTarget<WinDepthFmt> = gfx::preset::depth::PASS_TEST,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,16 +15,26 @@ use gfx::{
|
||||
use image;
|
||||
use vek::*;
|
||||
|
||||
/// Represents the format of the window's color target.
|
||||
pub type TgtColorFmt = gfx::format::Rgba8;
|
||||
/// Represents the format of the window's depth target.
|
||||
/// Represents the format of the pre-processed color target.
|
||||
pub type TgtColorFmt = gfx::format::Rgba16F;
|
||||
/// Represents the format of the pre-processed depth target.
|
||||
pub type TgtDepthFmt = gfx::format::DepthStencil;
|
||||
|
||||
/// A handle to a window color target.
|
||||
/// Represents the format of the window's color target.
|
||||
pub type WinColorFmt = gfx::format::Rgba8;
|
||||
/// Represents the format of the window's depth target.
|
||||
pub type WinDepthFmt = gfx::format::DepthStencil;
|
||||
|
||||
/// A handle to a pre-processed color target.
|
||||
pub type TgtColorView = gfx::handle::RenderTargetView<gfx_backend::Resources, TgtColorFmt>;
|
||||
/// A handle to a window depth target.
|
||||
/// A handle to a pre-processed depth target.
|
||||
pub type TgtDepthView = gfx::handle::DepthStencilView<gfx_backend::Resources, TgtDepthFmt>;
|
||||
|
||||
/// A handle to a window color target.
|
||||
pub type WinColorView = gfx::handle::RenderTargetView<gfx_backend::Resources, WinColorFmt>;
|
||||
/// A handle to a window depth target.
|
||||
pub type WinDepthView = gfx::handle::DepthStencilView<gfx_backend::Resources, WinDepthFmt>;
|
||||
|
||||
/// A handle to a render color target as a resource.
|
||||
pub type TgtColorRes = gfx::handle::ShaderResourceView<
|
||||
gfx_backend::Resources,
|
||||
@ -39,8 +49,8 @@ pub struct Renderer {
|
||||
encoder: gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>,
|
||||
factory: gfx_backend::Factory,
|
||||
|
||||
win_color_view: TgtColorView,
|
||||
win_depth_view: TgtDepthView,
|
||||
win_color_view: WinColorView,
|
||||
win_depth_view: WinDepthView,
|
||||
|
||||
tgt_color_view: TgtColorView,
|
||||
tgt_depth_view: TgtDepthView,
|
||||
@ -62,8 +72,8 @@ impl Renderer {
|
||||
pub fn new(
|
||||
device: gfx_backend::Device,
|
||||
mut factory: gfx_backend::Factory,
|
||||
win_color_view: TgtColorView,
|
||||
win_depth_view: TgtDepthView,
|
||||
win_color_view: WinColorView,
|
||||
win_depth_view: WinDepthView,
|
||||
) -> Result<Self, RenderError> {
|
||||
// Construct a pipeline for rendering skyboxes
|
||||
let skybox_pipeline = create_pipeline(
|
||||
@ -139,13 +149,27 @@ impl Renderer {
|
||||
})
|
||||
}
|
||||
|
||||
/// Get references to the internal render target views that get rendered to before post-processing.
|
||||
#[allow(dead_code)]
|
||||
pub fn tgt_views(&self) -> (&TgtColorView, &TgtDepthView) {
|
||||
(&self.tgt_color_view, &self.tgt_depth_view)
|
||||
}
|
||||
|
||||
/// Get references to the internal render target views that get displayed directly by the window.
|
||||
pub fn target_views(&self) -> (&TgtColorView, &TgtDepthView) {
|
||||
#[allow(dead_code)]
|
||||
pub fn win_views(&self) -> (&WinColorView, &WinDepthView) {
|
||||
(&self.win_color_view, &self.win_depth_view)
|
||||
}
|
||||
|
||||
/// Get mutable references to the internal render target views that get rendered to before post-processing.
|
||||
#[allow(dead_code)]
|
||||
pub fn tgt_views_mut(&mut self) -> (&mut TgtColorView, &mut TgtDepthView) {
|
||||
(&mut self.tgt_color_view, &mut self.tgt_depth_view)
|
||||
}
|
||||
|
||||
/// Get mutable references to the internal render target views that get displayed directly by the window.
|
||||
pub fn target_views_mut(&mut self) -> (&mut TgtColorView, &mut TgtDepthView) {
|
||||
#[allow(dead_code)]
|
||||
pub fn win_views_mut(&mut self) -> (&mut WinColorView, &mut WinDepthView) {
|
||||
(&mut self.win_color_view, &mut self.win_depth_view)
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
render::{Renderer, TgtColorFmt, TgtDepthFmt},
|
||||
render::{Renderer, WinColorFmt, WinDepthFmt},
|
||||
settings::Settings,
|
||||
ui, Error,
|
||||
};
|
||||
@ -29,8 +29,8 @@ impl Window {
|
||||
.with_gl(glutin::GlRequest::Specific(glutin::Api::OpenGl, (3, 2)))
|
||||
.with_vsync(false);
|
||||
|
||||
let (window, device, factory, tgt_color_view, tgt_depth_view) =
|
||||
gfx_window_glutin::init::<TgtColorFmt, TgtDepthFmt>(
|
||||
let (window, device, factory, win_color_view, win_depth_view) =
|
||||
gfx_window_glutin::init::<WinColorFmt, WinDepthFmt>(
|
||||
win_builder,
|
||||
ctx_builder,
|
||||
&events_loop,
|
||||
@ -58,7 +58,7 @@ impl Window {
|
||||
|
||||
let tmp = Ok(Self {
|
||||
events_loop,
|
||||
renderer: Renderer::new(device, factory, tgt_color_view, tgt_depth_view)?,
|
||||
renderer: Renderer::new(device, factory, win_color_view, win_depth_view)?,
|
||||
window,
|
||||
cursor_grabbed: false,
|
||||
needs_refresh_resize: false,
|
||||
@ -101,7 +101,7 @@ impl Window {
|
||||
glutin::Event::WindowEvent { event, .. } => match event {
|
||||
glutin::WindowEvent::CloseRequested => events.push(Event::Close),
|
||||
glutin::WindowEvent::Resized(glutin::dpi::LogicalSize { width, height }) => {
|
||||
let (mut color_view, mut depth_view) = renderer.target_views_mut();
|
||||
let (mut color_view, mut depth_view) = renderer.tgt_views_mut();
|
||||
gfx_window_glutin::update_views(&window, &mut color_view, &mut depth_view);
|
||||
renderer.on_resize().unwrap();
|
||||
events.push(Event::Resize(Vec2::new(width as u32, height as u32)));
|
||||
|
Loading…
Reference in New Issue
Block a user