Skip to content

Commit

Permalink
Add support for rendering entities with a simple RGBA value.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaeroxe committed Dec 24, 2018
1 parent eb0d92e commit 6158c39
Show file tree
Hide file tree
Showing 23 changed files with 255 additions and 64 deletions.
16 changes: 16 additions & 0 deletions amethyst_renderer/src/color.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
//! Color value types.
use amethyst_core::specs::{Component, DenseVecStorage};

use gfx::shade::{Formatted, ToUniform};
use gfx_core::shade::{BaseType, ContainerType, UniformValue};
use glsl_layout::{vec3, vec4};

/// An RGBA color value.
///
/// ## As a Component
/// If you attach this as a component to an entity then passes should multiply any rendered pixels
/// in the component with this color. Please note alpha multiplication will only produce
/// transparency if the rendering pass would normally be capable of rendering that entity
/// transparently.
///
/// ## More than a Component
/// This structure has more uses than just as a component, and you'll find it in other places
/// throughout the `amethyst_renderer` API.
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct Rgba(pub f32, pub f32, pub f32, pub f32);

Expand Down Expand Up @@ -59,6 +71,10 @@ impl Default for Rgba {
}
}

impl Component for Rgba {
type Storage = DenseVecStorage<Self>;
}

impl From<[f32; 3]> for Rgba {
fn from(arr: [f32; 3]) -> Rgba {
Rgba(arr[0], arr[1], arr[2], 1.0)
Expand Down
9 changes: 8 additions & 1 deletion amethyst_renderer/src/pass/debug_lines/interleaved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
},
types::{Encoder, Factory},
vertex::{Color, Normal, Position, Query},
Rgba,
};

use super::*;
Expand Down Expand Up @@ -145,7 +146,13 @@ where
return;
}

set_vertex_args(effect, encoder, camera, &GlobalTransform(na::one()));
set_vertex_args(
effect,
encoder,
camera,
&GlobalTransform(na::one()),
Rgba::WHITE,
);

effect.draw(mesh.slice(), encoder);
effect.clear();
Expand Down
27 changes: 23 additions & 4 deletions amethyst_renderer/src/pass/flat/interleaved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::{
types::{Encoder, Factory},
vertex::{Position, Query, TexCoord},
visibility::Visibility,
Rgba,
};

use super::*;
Expand Down Expand Up @@ -84,6 +85,7 @@ where
ReadStorage<'a, MeshHandle>,
ReadStorage<'a, Material>,
ReadStorage<'a, GlobalTransform>,
ReadStorage<'a, Rgba>,
);
}

Expand Down Expand Up @@ -126,14 +128,22 @@ where
mesh,
material,
global,
rgba,
): <Self as PassData<'a>>::Data,
) {
let camera = get_camera(active, &camera, &global);

match visibility {
None => {
for (mesh, material, global, _, _) in
(&mesh, &material, &global, !&hidden, !&hidden_prop).join()
for (mesh, material, global, rgba, _, _) in (
&mesh,
&material,
&global,
rgba.maybe(),
!&hidden,
!&hidden_prop,
)
.join()
{
draw_mesh(
encoder,
Expand All @@ -144,6 +154,7 @@ where
&tex_storage,
Some(material),
&material_defaults,
rgba,
camera,
Some(global),
&[V::QUERIED_ATTRIBUTES],
Expand All @@ -152,8 +163,14 @@ where
}
}
Some(ref visibility) => {
for (mesh, material, global, _) in
(&mesh, &material, &global, &visibility.visible_unordered).join()
for (mesh, material, global, rgba, _) in (
&mesh,
&material,
&global,
rgba.maybe(),
&visibility.visible_unordered,
)
.join()
{
draw_mesh(
encoder,
Expand All @@ -164,6 +181,7 @@ where
&tex_storage,
Some(material),
&material_defaults,
rgba,
camera,
Some(global),
&[V::QUERIED_ATTRIBUTES],
Expand All @@ -182,6 +200,7 @@ where
&tex_storage,
material.get(*entity),
&material_defaults,
rgba.get(*entity),
camera,
global.get(*entity),
&[V::QUERIED_ATTRIBUTES],
Expand Down
12 changes: 10 additions & 2 deletions amethyst_renderer/src/pass/flat/separate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::{
types::{Encoder, Factory},
vertex::{Attributes, Position, Separate, TexCoord, VertexFormat},
visibility::Visibility,
Rgba,
};

use super::*;
Expand Down Expand Up @@ -94,6 +95,7 @@ impl<'a> PassData<'a> for DrawFlatSeparate {
ReadStorage<'a, Material>,
ReadStorage<'a, GlobalTransform>,
ReadStorage<'a, JointTransforms>,
ReadStorage<'a, Rgba>,
);
}

Expand Down Expand Up @@ -150,17 +152,19 @@ impl Pass for DrawFlatSeparate {
material,
global,
joints,
rgba,
): <Self as PassData<'a>>::Data,
) {
let camera = get_camera(active, &camera, &global);

match visibility {
None => {
for (joint, mesh, material, global, _, _) in (
for (joint, mesh, material, global, rgba, _, _) in (
joints.maybe(),
&mesh,
&material,
&global,
rgba.maybe(),
!&hidden,
!&hidden_prop,
)
Expand All @@ -175,6 +179,7 @@ impl Pass for DrawFlatSeparate {
&tex_storage,
Some(material),
&material_defaults,
rgba,
camera,
Some(global),
&ATTRIBUTES,
Expand All @@ -183,11 +188,12 @@ impl Pass for DrawFlatSeparate {
}
}
Some(ref visibility) => {
for (joint, mesh, material, global, _) in (
for (joint, mesh, material, global, rgba, _) in (
joints.maybe(),
&mesh,
&material,
&global,
rgba.maybe(),
&visibility.visible_unordered,
)
.join()
Expand All @@ -201,6 +207,7 @@ impl Pass for DrawFlatSeparate {
&tex_storage,
Some(material),
&material_defaults,
rgba,
camera,
Some(global),
&ATTRIBUTES,
Expand All @@ -219,6 +226,7 @@ impl Pass for DrawFlatSeparate {
&tex_storage,
material.get(*entity),
&material_defaults,
rgba.get(*entity),
camera,
global.get(*entity),
&ATTRIBUTES,
Expand Down
Loading

0 comments on commit 6158c39

Please sign in to comment.