.cargo/
ombre/
ombre-derive/
reve/
src/
renderer/
shaders/
mesh.rs
9.3 KiB
scene.rs
3.2 KiB
shaders.rs
6.0 KiB
camera.rs
3.8 KiB
lib.rs
11.7 KiB
main.rs
162 B
renderer.rs
18.6 KiB
Cargo.toml
362 B
README
398 B
syntaxe/
.gitignore
34 B
Cargo.lock
8.5 KiB
Cargo.toml
523 B
README
1.0 KiB
rust-toolchain.toml
77 B
rustfmt.toml
55 B
reve/src/renderer/shaders.rs
raw
| 1 | use ombre::prelude::*; |
| 2 | |
| 3 | // Display shader, for rendering a backbuffer to the frontbuffer. |
| 4 | pub mod display { |
| 5 | use super::*; |
| 6 | |
| 7 | // No uniforms used. |
| 8 | pub type Uniforms = (); |
| 9 | |
| 10 | pub const fn source() -> gfx::ShaderSource<'static> { |
| 11 | gfx::ShaderSource { |
| 12 | vertex: include_str!("shaders/display/vertex.glsl"), |
| 13 | fragment: include_str!("shaders/display/fragment.glsl"), |
| 14 | geometry: None, |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | pub const fn description() -> gfx::ShaderDescriptor<'static> { |
| 19 | gfx::ShaderDescriptor { |
| 20 | textures: &["backbuffer"], |
| 21 | uniforms: gfx::UniformBlockLayout { uniforms: &[] }, |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | /// Constant shader, for gizmos and other UI components. |
| 27 | #[allow(dead_code)] |
| 28 | pub mod constant { |
| 29 | use super::*; |
| 30 | |
| 31 | #[repr(C)] |
| 32 | pub struct Uniforms { |
| 33 | pub model: Transform3D<f32>, |
| 34 | pub view: Transform3D<f32, World>, |
| 35 | pub proj: Transform3D<f32, World, Screen>, |
| 36 | } |
| 37 | unsafe impl bytes::Packed for Uniforms {} |
| 38 | |
| 39 | pub const fn source() -> gfx::ShaderSource<'static> { |
| 40 | gfx::ShaderSource { |
| 41 | vertex: include_str!("shaders/mvp/vertex.glsl"), |
| 42 | fragment: include_str!("shaders/constant/fragment.glsl"), |
| 43 | geometry: None, |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | pub const fn attributes() -> [gfx::VertexAttribute; 2] { |
| 48 | [ |
| 49 | gfx::VertexAttribute::new("position", gfx::VertexFormat::Float3), |
| 50 | gfx::VertexAttribute::new("color", gfx::VertexFormat::Float4), |
| 51 | ] |
| 52 | } |
| 53 | |
| 54 | pub const fn description() -> gfx::ShaderDescriptor<'static> { |
| 55 | gfx::ShaderDescriptor { |
| 56 | textures: &[], |
| 57 | uniforms: gfx::UniformBlockLayout { |
| 58 | uniforms: &[ |
| 59 | gfx::UniformDescriptor { |
| 60 | name: "model", |
| 61 | kind: gfx::UniformKind::Mat4, |
| 62 | arity: 1, |
| 63 | }, |
| 64 | gfx::UniformDescriptor { |
| 65 | name: "view", |
| 66 | kind: gfx::UniformKind::Mat4, |
| 67 | arity: 1, |
| 68 | }, |
| 69 | gfx::UniformDescriptor { |
| 70 | name: "proj", |
| 71 | kind: gfx::UniformKind::Mat4, |
| 72 | arity: 1, |
| 73 | }, |
| 74 | ], |
| 75 | }, |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /// The default shader. |
| 81 | /// This is a Blinn/Cook-Torance shader with some additional capabilities. |
| 82 | pub mod default { |
| 83 | use super::*; |
| 84 | |
| 85 | #[repr(C)] |
| 86 | pub struct Uniforms { |
| 87 | pub model: Transform3D, |
| 88 | pub view: Transform3D<f32, World>, |
| 89 | pub proj: Transform3D<f32, World, Screen>, |
| 90 | pub light: Vector3D, |
| 91 | pub window_size: Size<f32>, |
| 92 | pub enable_tomemap: u32, |
| 93 | pub render_mode: u32, |
| 94 | pub interaction_mode: u32, |
| 95 | pub object_id: u32, |
| 96 | pub vertex_hovered: i32, |
| 97 | } |
| 98 | unsafe impl bytes::Packed for Uniforms {} |
| 99 | |
| 100 | pub const fn source() -> gfx::ShaderSource<'static> { |
| 101 | gfx::ShaderSource { |
| 102 | vertex: include_str!("shaders/blinn/vertex.glsl"), |
| 103 | fragment: include_str!("shaders/blinn/fragment.glsl"), |
| 104 | geometry: Some(include_str!("shaders/blinn/geometry.glsl")), |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | pub const fn attributes() -> [gfx::VertexAttribute; 7] { |
| 109 | [ |
| 110 | gfx::VertexAttribute::new("position", gfx::VertexFormat::Float3), |
| 111 | gfx::VertexAttribute::new("color", gfx::VertexFormat::Float4), |
| 112 | gfx::VertexAttribute::new("normal", gfx::VertexFormat::Float3), |
| 113 | gfx::VertexAttribute::new("uv", gfx::VertexFormat::Float2), |
| 114 | gfx::VertexAttribute::new("opacity", gfx::VertexFormat::Float1), |
| 115 | gfx::VertexAttribute::new("polygon", gfx::VertexFormat::Int1), |
| 116 | gfx::VertexAttribute::new("selected", gfx::VertexFormat::Float1), |
| 117 | ] |
| 118 | } |
| 119 | |
| 120 | pub const fn description() -> gfx::ShaderDescriptor<'static> { |
| 121 | gfx::ShaderDescriptor { |
| 122 | textures: &["diffuseSampler", "specularSampler"], |
| 123 | uniforms: gfx::UniformBlockLayout { |
| 124 | uniforms: &[ |
| 125 | gfx::UniformDescriptor { |
| 126 | name: "model", |
| 127 | kind: gfx::UniformKind::Mat4, |
| 128 | arity: 1, |
| 129 | }, |
| 130 | gfx::UniformDescriptor { |
| 131 | name: "view", |
| 132 | kind: gfx::UniformKind::Mat4, |
| 133 | arity: 1, |
| 134 | }, |
| 135 | gfx::UniformDescriptor { |
| 136 | name: "proj", |
| 137 | kind: gfx::UniformKind::Mat4, |
| 138 | arity: 1, |
| 139 | }, |
| 140 | gfx::UniformDescriptor { |
| 141 | name: "light", |
| 142 | kind: gfx::UniformKind::Float3, |
| 143 | arity: 1, |
| 144 | }, |
| 145 | gfx::UniformDescriptor { |
| 146 | name: "windowSize", |
| 147 | kind: gfx::UniformKind::Float2, |
| 148 | arity: 1, |
| 149 | }, |
| 150 | gfx::UniformDescriptor { |
| 151 | name: "enableTonemap", |
| 152 | kind: gfx::UniformKind::UInt1, |
| 153 | arity: 1, |
| 154 | }, |
| 155 | gfx::UniformDescriptor { |
| 156 | name: "renderMode", |
| 157 | kind: gfx::UniformKind::UInt1, |
| 158 | arity: 1, |
| 159 | }, |
| 160 | gfx::UniformDescriptor { |
| 161 | name: "interactionMode", |
| 162 | kind: gfx::UniformKind::UInt1, |
| 163 | arity: 1, |
| 164 | }, |
| 165 | gfx::UniformDescriptor { |
| 166 | name: "objectId", |
| 167 | kind: gfx::UniformKind::UInt1, |
| 168 | arity: 1, |
| 169 | }, |
| 170 | gfx::UniformDescriptor { |
| 171 | name: "vertexHovered", |
| 172 | kind: gfx::UniformKind::Int1, |
| 173 | arity: 1, |
| 174 | }, |
| 175 | ], |
| 176 | }, |
| 177 | } |
| 178 | } |
| 179 | } |