Adjusted sun and added F16 render target

Former-commit-id: 5585e0038846ef34378933eeb9051714ffe2c100
This commit is contained in:
Joshua Barretto 2019-05-06 17:27:21 +01:00
parent d645af7d6a
commit c48a82e78d
7 changed files with 54 additions and 31 deletions

View File

@ -23,8 +23,7 @@ uniform u_globals {
out vec4 tgt_color; out vec4 tgt_color;
void main() { void main() {
// Uncomment to invert colors vec4 src_color = texture2D(src_color, (f_pos + 1.0) / 2.0);
//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); tgt_color = 1.0 - 1.0 / (src_color + 1.0);
} }

View File

@ -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 SKY_BOTTOM = vec3(0.0, 0.05, 0.2);
const vec3 SUN_HALO_COLOR = vec3(1.0, 0.8, 0.5); 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; 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_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_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; 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() { void main() {

View File

@ -23,7 +23,7 @@ pub use self::{
}, },
Globals, Globals,
}, },
renderer::{Renderer, TgtColorFmt, TgtDepthFmt}, renderer::{Renderer, TgtColorFmt, TgtDepthFmt, WinColorFmt, WinDepthFmt},
texture::Texture, texture::Texture,
}; };

View File

@ -12,7 +12,7 @@ use gfx::{
// Local // Local
use super::{ use super::{
super::{Mesh, Pipeline, TgtColorFmt, TgtDepthFmt, Tri}, super::{Mesh, Pipeline, WinColorFmt, WinDepthFmt, Tri},
Globals, Globals,
}; };
@ -31,10 +31,10 @@ gfx_defines! {
locals: gfx::ConstantBuffer<Locals> = "u_locals", locals: gfx::ConstantBuffer<Locals> = "u_locals",
globals: gfx::ConstantBuffer<Globals> = "u_globals", 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_color: gfx::RenderTarget<WinColorFmt> = "tgt_color",
tgt_depth: gfx::DepthTarget<TgtDepthFmt> = gfx::preset::depth::PASS_TEST, tgt_depth: gfx::DepthTarget<WinDepthFmt> = gfx::preset::depth::PASS_TEST,
} }
} }

View File

@ -1,4 +1,4 @@
use super::super::{Pipeline, Quad, TgtColorFmt, TgtDepthFmt, Tri}; use super::super::{Pipeline, Quad, WinColorFmt, WinDepthFmt, Tri};
use gfx::{ use gfx::{
self, self,
// Macros // Macros
@ -25,8 +25,8 @@ gfx_defines! {
scissor: gfx::Scissor = (), scissor: gfx::Scissor = (),
tgt_color: gfx::BlendTarget<TgtColorFmt> = ("tgt_color", gfx::state::ColorMask::all(), gfx::preset::blend::ALPHA), tgt_color: gfx::BlendTarget<WinColorFmt> = ("tgt_color", gfx::state::ColorMask::all(), gfx::preset::blend::ALPHA),
tgt_depth: gfx::DepthTarget<TgtDepthFmt> = gfx::preset::depth::PASS_TEST, tgt_depth: gfx::DepthTarget<WinDepthFmt> = gfx::preset::depth::PASS_TEST,
} }
} }

View File

@ -15,16 +15,26 @@ use gfx::{
use image; use image;
use vek::*; use vek::*;
/// Represents the format of the window's color target. /// Represents the format of the pre-processed color target.
pub type TgtColorFmt = gfx::format::Rgba8; pub type TgtColorFmt = gfx::format::Rgba16F;
/// Represents the format of the window's depth target. /// Represents the format of the pre-processed depth target.
pub type TgtDepthFmt = gfx::format::DepthStencil; 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>; 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>; 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. /// A handle to a render color target as a resource.
pub type TgtColorRes = gfx::handle::ShaderResourceView< pub type TgtColorRes = gfx::handle::ShaderResourceView<
gfx_backend::Resources, gfx_backend::Resources,
@ -39,8 +49,8 @@ pub struct Renderer {
encoder: gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>, encoder: gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>,
factory: gfx_backend::Factory, factory: gfx_backend::Factory,
win_color_view: TgtColorView, win_color_view: WinColorView,
win_depth_view: TgtDepthView, win_depth_view: WinDepthView,
tgt_color_view: TgtColorView, tgt_color_view: TgtColorView,
tgt_depth_view: TgtDepthView, tgt_depth_view: TgtDepthView,
@ -62,8 +72,8 @@ impl Renderer {
pub fn new( pub fn new(
device: gfx_backend::Device, device: gfx_backend::Device,
mut factory: gfx_backend::Factory, mut factory: gfx_backend::Factory,
win_color_view: TgtColorView, win_color_view: WinColorView,
win_depth_view: TgtDepthView, win_depth_view: WinDepthView,
) -> Result<Self, RenderError> { ) -> Result<Self, RenderError> {
// Construct a pipeline for rendering skyboxes // Construct a pipeline for rendering skyboxes
let skybox_pipeline = create_pipeline( 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. /// 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) (&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. /// 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) (&mut self.win_color_view, &mut self.win_depth_view)
} }

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
render::{Renderer, TgtColorFmt, TgtDepthFmt}, render::{Renderer, WinColorFmt, WinDepthFmt},
settings::Settings, settings::Settings,
ui, Error, ui, Error,
}; };
@ -29,8 +29,8 @@ impl Window {
.with_gl(glutin::GlRequest::Specific(glutin::Api::OpenGl, (3, 2))) .with_gl(glutin::GlRequest::Specific(glutin::Api::OpenGl, (3, 2)))
.with_vsync(false); .with_vsync(false);
let (window, device, factory, tgt_color_view, tgt_depth_view) = let (window, device, factory, win_color_view, win_depth_view) =
gfx_window_glutin::init::<TgtColorFmt, TgtDepthFmt>( gfx_window_glutin::init::<WinColorFmt, WinDepthFmt>(
win_builder, win_builder,
ctx_builder, ctx_builder,
&events_loop, &events_loop,
@ -58,7 +58,7 @@ impl Window {
let tmp = Ok(Self { let tmp = Ok(Self {
events_loop, 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, window,
cursor_grabbed: false, cursor_grabbed: false,
needs_refresh_resize: false, needs_refresh_resize: false,
@ -101,7 +101,7 @@ impl Window {
glutin::Event::WindowEvent { event, .. } => match event { glutin::Event::WindowEvent { event, .. } => match event {
glutin::WindowEvent::CloseRequested => events.push(Event::Close), glutin::WindowEvent::CloseRequested => events.push(Event::Close),
glutin::WindowEvent::Resized(glutin::dpi::LogicalSize { width, height }) => { 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); gfx_window_glutin::update_views(&window, &mut color_view, &mut depth_view);
renderer.on_resize().unwrap(); renderer.on_resize().unwrap();
events.push(Event::Resize(Vec2::new(width as u32, height as u32))); events.push(Event::Resize(Vec2::new(width as u32, height as u32)));