mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Move u_globals to shared included file
Former-commit-id: b6122177ce98cd52bc032e2d8414671d3bcb9b5c
This commit is contained in:
parent
95a0c27d7d
commit
ee9f54bacd
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -906,11 +906,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "glsl-include"
|
||||
version = "0.2.3"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2361,7 +2361,7 @@ dependencies = [
|
||||
"gfx 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gfx_device_gl 0.15.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gfx_window_glutin 0.28.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glsl-include 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glsl-include 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glutin 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"guillotiere 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"image 0.21.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -2680,7 +2680,7 @@ dependencies = [
|
||||
"checksum gleam 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "39bb69499005e11b7b7cc0af38404a1bc0f53d954bffa8adcdb6e8d5b14f75d5"
|
||||
"checksum glib 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "81f514a8abd315ede0e94e39ce5987fdb99191c5f812e5066bc5bdb965104fc4"
|
||||
"checksum glib-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8826cbc94631507bdd91ee40f7e099bfaa3cc4f43c086b4d1c15cff5b4e8220b"
|
||||
"checksum glsl-include 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "31c109a006ad24fd612da10d185b51000ef502155578f3634416f102f0d63b6c"
|
||||
"checksum glsl-include 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "daa2afb1631e7ab4543e0dde0e3fc68bb49c58fee89c07f30a26553b1f684ab6"
|
||||
"checksum glutin 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "535c6eda58adbb227604b2db10a022ffd6339d7ea3e970f338e7d98aeb24fcc3"
|
||||
"checksum gobject-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "87373f64e136e9ea192ff5d3ef676a51e9ac6ab06b629223a081e0523c5f04e2"
|
||||
"checksum gtk 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78d69fb7425fd6efba3b0c99f952b130fa4a0fdfdffbceb2b40ba018b2ed6a77"
|
||||
|
@ -31,7 +31,7 @@ specs = "0.14"
|
||||
vek = "0.9"
|
||||
|
||||
# Utility
|
||||
glsl-include = "0.2"
|
||||
glsl-include = "0.3"
|
||||
failure = "0.1"
|
||||
lazy_static = "1.1"
|
||||
log = "0.4"
|
||||
|
@ -1,5 +1,7 @@
|
||||
#version 330 core
|
||||
|
||||
#include <globals.glsl>
|
||||
|
||||
in vec3 f_pos;
|
||||
in vec3 f_norm;
|
||||
in vec3 f_col;
|
||||
@ -10,18 +12,6 @@ uniform u_locals {
|
||||
mat4 model_mat;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 tick;
|
||||
vec4 screen_res;
|
||||
};
|
||||
|
||||
struct BoneData {
|
||||
mat4 bone_mat;
|
||||
};
|
||||
|
@ -1,5 +1,7 @@
|
||||
#version 330 core
|
||||
|
||||
#include <globals.glsl>
|
||||
|
||||
in vec3 v_pos;
|
||||
in vec3 v_norm;
|
||||
in vec3 v_col;
|
||||
@ -10,18 +12,6 @@ uniform u_locals {
|
||||
mat4 model_mat;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 tick;
|
||||
vec4 screen_res;
|
||||
};
|
||||
|
||||
struct BoneData {
|
||||
mat4 bone_mat;
|
||||
};
|
||||
|
11
voxygen/shaders/include/globals.glsl
Normal file
11
voxygen/shaders/include/globals.glsl
Normal file
@ -0,0 +1,11 @@
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 tick;
|
||||
vec4 screen_res;
|
||||
};
|
@ -1,5 +1,7 @@
|
||||
#version 330 core
|
||||
|
||||
#include <globals.glsl>
|
||||
|
||||
uniform sampler2D src_color;
|
||||
|
||||
in vec2 f_pos;
|
||||
@ -9,18 +11,6 @@ uniform u_locals {
|
||||
vec4 nul;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 tick;
|
||||
vec4 screen_res;
|
||||
};
|
||||
|
||||
out vec4 tgt_color;
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,7 @@
|
||||
#version 330 core
|
||||
|
||||
#include <globals.glsl>
|
||||
|
||||
in vec2 v_pos;
|
||||
|
||||
layout (std140)
|
||||
@ -7,18 +9,6 @@ uniform u_locals {
|
||||
vec4 nul;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 tick;
|
||||
vec4 screen_res;
|
||||
};
|
||||
|
||||
out vec2 f_pos;
|
||||
|
||||
void main() {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#version 330 core
|
||||
|
||||
#include <globals.glsl>
|
||||
|
||||
in vec3 f_pos;
|
||||
|
||||
layout (std140)
|
||||
@ -7,18 +9,6 @@ uniform u_locals {
|
||||
vec4 nul;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 tick;
|
||||
vec4 screen_res;
|
||||
};
|
||||
|
||||
out vec4 tgt_color;
|
||||
|
||||
const float PI = 3.141592;
|
||||
|
@ -1,5 +1,7 @@
|
||||
#version 330 core
|
||||
|
||||
#include <globals.glsl>
|
||||
|
||||
in vec3 v_pos;
|
||||
|
||||
layout (std140)
|
||||
@ -7,18 +9,6 @@ uniform u_locals {
|
||||
vec4 nul;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 tick;
|
||||
vec4 screen_res;
|
||||
};
|
||||
|
||||
out vec3 f_pos;
|
||||
|
||||
void main() {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#version 330 core
|
||||
|
||||
#include <globals.glsl>
|
||||
|
||||
in vec3 f_pos;
|
||||
in vec3 f_norm;
|
||||
in vec3 f_col;
|
||||
@ -9,18 +11,6 @@ uniform u_locals {
|
||||
vec3 model_offs;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 tick;
|
||||
vec4 screen_res;
|
||||
};
|
||||
|
||||
out vec4 tgt_color;
|
||||
|
||||
void main() {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#version 330 core
|
||||
|
||||
#include <globals.glsl>
|
||||
|
||||
in vec3 v_pos;
|
||||
in vec3 v_norm;
|
||||
in vec3 v_col;
|
||||
@ -9,18 +11,6 @@ uniform u_locals {
|
||||
vec3 model_offs;
|
||||
};
|
||||
|
||||
layout (std140)
|
||||
uniform u_globals {
|
||||
mat4 view_mat;
|
||||
mat4 proj_mat;
|
||||
vec4 cam_pos;
|
||||
vec4 focus_pos;
|
||||
vec4 view_distance;
|
||||
vec4 time_of_day;
|
||||
vec4 tick;
|
||||
vec4 screen_res;
|
||||
};
|
||||
|
||||
out vec3 f_pos;
|
||||
out vec3 f_norm;
|
||||
out vec3 f_col;
|
||||
|
@ -41,6 +41,7 @@ pub enum RenderError {
|
||||
TexUpdateError(gfx::UpdateError<[u16; 3]>),
|
||||
CombinedError(gfx::CombinedError),
|
||||
BufferCreationError(gfx::buffer::CreationError),
|
||||
IncludeError(glsl_include::Error),
|
||||
}
|
||||
|
||||
/// Used to represent a specific rendering configuration.
|
||||
|
@ -12,6 +12,7 @@ use gfx::{
|
||||
handle::Sampler,
|
||||
traits::{Device, Factory, FactoryExt},
|
||||
};
|
||||
use glsl_include::Context as IncludeContext;
|
||||
use vek::*;
|
||||
|
||||
/// Represents the format of the pre-processed color target.
|
||||
@ -74,50 +75,63 @@ impl Renderer {
|
||||
win_color_view: WinColorView,
|
||||
win_depth_view: WinDepthView,
|
||||
) -> Result<Self, RenderError> {
|
||||
let globals = include_str!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/shaders/include/globals.glsl"
|
||||
));
|
||||
|
||||
let mut include_ctx = IncludeContext::new();
|
||||
include_ctx.include("globals.glsl", globals);
|
||||
|
||||
// Construct a pipeline for rendering skyboxes
|
||||
let skybox_pipeline = create_pipeline(
|
||||
&mut factory,
|
||||
skybox::pipe::new(),
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/skybox.vert")),
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/skybox.frag")),
|
||||
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/skybox.vert")),
|
||||
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/skybox.frag")),
|
||||
&include_ctx,
|
||||
)?;
|
||||
|
||||
// Construct a pipeline for rendering figures
|
||||
let figure_pipeline = create_pipeline(
|
||||
&mut factory,
|
||||
figure::pipe::new(),
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/figure.vert")),
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/figure.frag")),
|
||||
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/figure.vert")),
|
||||
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/figure.frag")),
|
||||
&include_ctx,
|
||||
)?;
|
||||
|
||||
// Construct a pipeline for rendering terrain
|
||||
let terrain_pipeline = create_pipeline(
|
||||
&mut factory,
|
||||
terrain::pipe::new(),
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/terrain.vert")),
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/terrain.frag")),
|
||||
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/terrain.vert")),
|
||||
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/terrain.frag")),
|
||||
&include_ctx,
|
||||
)?;
|
||||
|
||||
// Construct a pipeline for rendering UI elements
|
||||
let ui_pipeline = create_pipeline(
|
||||
&mut factory,
|
||||
ui::pipe::new(),
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/ui.vert")),
|
||||
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/ui.frag")),
|
||||
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/ui.vert")),
|
||||
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/shaders/ui.frag")),
|
||||
&include_ctx,
|
||||
)?;
|
||||
|
||||
// Construct a pipeline for rendering our post-processing
|
||||
let postprocess_pipeline = create_pipeline(
|
||||
&mut factory,
|
||||
postprocess::pipe::new(),
|
||||
include_bytes!(concat!(
|
||||
include_str!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/shaders/postprocess.vert"
|
||||
)),
|
||||
include_bytes!(concat!(
|
||||
include_str!(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/shaders/postprocess.frag"
|
||||
)),
|
||||
&include_ctx,
|
||||
)?;
|
||||
|
||||
let dims = win_color_view.get_dimensions();
|
||||
@ -407,11 +421,15 @@ struct GfxPipeline<P: gfx::pso::PipelineInit> {
|
||||
fn create_pipeline<'a, P: gfx::pso::PipelineInit>(
|
||||
factory: &mut gfx_backend::Factory,
|
||||
pipe: P,
|
||||
vs: &[u8],
|
||||
fs: &[u8],
|
||||
vs: &str,
|
||||
fs: &str,
|
||||
ctx: &IncludeContext,
|
||||
) -> Result<GfxPipeline<P>, RenderError> {
|
||||
let vs = ctx.expand(vs).map_err(RenderError::IncludeError)?;
|
||||
let fs = ctx.expand(fs).map_err(RenderError::IncludeError)?;
|
||||
|
||||
let program = factory
|
||||
.link_program(vs, fs)
|
||||
.link_program(vs.as_bytes(), fs.as_bytes())
|
||||
.map_err(|err| RenderError::PipelineError(gfx::PipelineStateError::Program(err)))?;
|
||||
|
||||
Ok(GfxPipeline {
|
||||
|
Loading…
Reference in New Issue
Block a user