1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
//! Material parameters for mesh rendering.
use color;
use color::Color;
use render::BasicPipelineState;
use texture::Texture;
use util;
#[doc(inline)]
pub use self::basic::Basic;
/// Basic material API.
pub mod basic {
use super::*;
/// Parameters for a basic solid mesh material.
///
/// Renders triangle meshes with a solid color or texture.
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
pub struct Basic {
/// Solid color applied in the absence of `map`.
///
/// Default: `WHITE`.
pub color: Color,
/// Texture applied using the mesh texture co-ordinates.
///
/// Default: `None`.
pub map: Option<Texture<[f32; 4]>>,
}
impl Default for Basic {
fn default() -> Self {
Self {
color: color::WHITE,
map: None,
}
}
}
/// Parameters for a basic solid mesh material with a custom pipeline.
///
/// Renders triangle meshes with a custom pipeline with a basic material as
/// its input.
#[derive(Clone, Debug, PartialEq, Hash)]
pub struct Custom {
/// Solid color applied in the absense of `map`.
pub color: Color,
/// Texture applied using the mesh texture co-ordinates.
pub map: Option<Texture<[f32; 4]>>,
/// The custom pipeline state object to be applied to the mesh.
pub pipeline: BasicPipelineState,
}
impl Eq for Custom {}
}
/// Parameters for a Lamberian diffusion reflection model.
///
/// Renders triangle meshes with the Gouraud illumination model.
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
pub struct Lambert {
/// Solid color applied in the absense of `map`.
///
/// Default: `WHITE`.
pub color: Color,
/// Specifies whether lighting should be constant over faces.
///
/// Default: `false` (lighting is interpolated across faces).
pub flat: bool,
}
impl Default for Lambert {
fn default() -> Self {
Self {
color: color::WHITE,
flat: false,
}
}
}
/// Parameters for a line material.
///
/// Renders line strip meshes with a solid color and unit width.
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
pub struct Line {
/// Solid line color.
///
/// Default: `0xFFFFFF` (white).
pub color: Color,
}
impl Default for Line {
fn default() -> Self {
Self {
color: color::WHITE,
}
}
}
/// Parameters for a PBR (physically based rendering) lighting model.
///
/// Renders triangle meshes with a PBR (physically-based rendering)
/// illumination model
#[derive(Derivative)]
#[derivative(Clone, Debug, PartialEq, Hash, Eq)]
pub struct Pbr {
/// Solid base color applied in the absense of `base_color_map`.
///
/// Default: `WHITE`.
pub base_color_factor: Color,
/// Base color alpha factor applied in the absense of `base_color_map`.
///
/// Default: `1.0` (opaque).
#[derivative(Hash(hash_with = "util::hash_f32"))]
pub base_color_alpha: f32,
/// Metallic factor in the range [0.0, 1.0].
///
/// Default: `1.0`.
#[derivative(Hash(hash_with = "util::hash_f32"))]
pub metallic_factor: f32,
/// Roughness factor in the range [0.0, 1.0].
///
/// * A value of 1.0 means the material is completely rough.
/// * A value of 0.0 means the material is completely smooth.
///
/// Default: `1.0`.
#[derivative(Hash(hash_with = "util::hash_f32"))]
pub roughness_factor: f32,
/// Scalar multiplier in the range [0.0, 1.0] that controls the amount of
/// occlusion applied in the presense of `occlusion_map`.
///
/// Default: `1.0`.
#[derivative(Hash(hash_with = "util::hash_f32"))]
pub occlusion_strength: f32,
/// Solid emissive color applied in the absense of `emissive_map`.
///
/// Default: `BLACK`.
pub emissive_factor: Color,
/// Scalar multiplier applied to each normal vector of the `normal_map`.
///
/// This value is ignored in the absense of `normal_map`.
///
/// Default: `1.0`.
#[derivative(Hash(hash_with = "util::hash_f32"))]
pub normal_scale: f32,
/// Base color texture.
///
/// Default: `None`.
pub base_color_map: Option<Texture<[f32; 4]>>,
/// Normal texture.
///
/// Default: `None`.
pub normal_map: Option<Texture<[f32; 4]>>,
/// Emissive texture.
///
/// Default: `None`.
pub emissive_map: Option<Texture<[f32; 4]>>,
/// Metallic-roughness texture.
///
/// Default: `None`.
pub metallic_roughness_map: Option<Texture<[f32; 4]>>,
/// Occlusion texture.
///
/// Default: `None`.
pub occlusion_map: Option<Texture<[f32; 4]>>,
}
impl Default for Pbr {
fn default() -> Self {
Self {
base_color_factor: color::WHITE,
base_color_alpha: 1.0,
metallic_factor: 1.0,
roughness_factor: 1.0,
occlusion_strength: 1.0,
emissive_factor: color::BLACK,
normal_scale: 1.0,
base_color_map: None,
normal_map: None,
emissive_map: None,
metallic_roughness_map: None,
occlusion_map: None,
}
}
}
/// Parameters for a Phong reflection model.
///
/// Renders triangle meshes with the Phong illumination model.
#[derive(Derivative)]
#[derivative(Clone, Debug, PartialEq, Hash, Eq)]
pub struct Phong {
/// Solid color applied in the absense of `map`.
///
/// Default: `WHITE`.
pub color: Color,
/// Determines the sharpness of specular highlights.
///
/// Higher values result in sharper highlights to produce a glossy effect.
///
/// Default: `30.0`.
#[derivative(Hash(hash_with = "util::hash_f32"))]
pub glossiness: f32,
}
impl Default for Phong {
fn default() -> Self {
Self {
color: color::WHITE,
glossiness: 30.0,
}
}
}
/// Texture for a 2D sprite.
///
/// Renders [`Sprite`] objects with the given texture.
///
/// [`Sprite`]: ../sprite/struct.Sprite.html
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
pub struct Sprite {
/// The texture the apply to the sprite.
pub map: Texture<[f32; 4]>,
}
/// Parameters for mesh wireframe rasterization.
///
/// Renders the edges of a triangle mesh with a solid color.
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
pub struct Wireframe {
/// Solid color applied to each wireframe edge.
///
/// Default: `WHITE`.
pub color: Color,
}
/// Specifies the appearance of a [`Mesh`](struct.Mesh.html).
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub enum Material {
/// Renders triangle meshes with a solid color or texture.
Basic(Basic),
/// Renders triangle meshes with a custom pipeline with a basic material as
/// its input.
CustomBasic(basic::Custom),
/// Renders line strip meshes with a solid color and unit width.
Line(Line),
/// Renders triangle meshes with the Gouraud illumination model.
Lambert(Lambert),
/// Renders triangle meshes with the Phong illumination model.
Phong(Phong),
/// Renders triangle meshes with a PBR (physically-based rendering)
/// illumination model
Pbr(Pbr),
/// Renders [`Sprite`] objects with the given texture.
///
/// [`Sprite`]: ../sprite/struct.Sprite.html
Sprite(Sprite),
/// Renders the edges of a triangle mesh with a solid color.
Wireframe(Wireframe),
}
impl From<Basic> for Material {
fn from(params: Basic) -> Self {
Material::Basic(params)
}
}
impl From<basic::Custom> for Material {
fn from(params: basic::Custom) -> Self {
Material::CustomBasic(params)
}
}
impl From<Lambert> for Material {
fn from(params: Lambert) -> Self {
Material::Lambert(params)
}
}
impl From<Line> for Material {
fn from(params: Line) -> Self {
Material::Line(params)
}
}
impl From<Phong> for Material {
fn from(params: Phong) -> Self {
Material::Phong(params)
}
}
impl From<Pbr> for Material {
fn from(params: Pbr) -> Self {
Material::Pbr(params)
}
}
impl From<Sprite> for Material {
fn from(params: Sprite) -> Self {
Material::Sprite(params)
}
}
impl From<Wireframe> for Material {
fn from(params: Wireframe) -> Self {
Material::Wireframe(params)
}
}