Skip to content

Commit

Permalink
Shape padding
Browse files Browse the repository at this point in the history
  • Loading branch information
makscee committed Mar 31, 2024
1 parent 3cba7f7 commit 9355693
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion assets/shaders/sdf_shape.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const GLOW = 0.1;
const AA = 0.01;
@fragment
fn fragment(in: MeshVertexOutput) -> @location(0) vec4<f32> {
let size = material.data[10].xy;
let padding = material.data[1].z;
let size = material.data[10].xy + vec2(padding);
let alpha = material.data[10].z;
let thickness = material.data[10].w * 0.03;

Expand Down
11 changes: 10 additions & 1 deletion src/components/representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub enum RepresentationMaterial {
fbm: Option<RepFbm>,
#[serde(default = "f32_one_e")]
alpha: Expression,
#[serde(default = "f32_zero_e")]
padding: Expression,
},
Text {
#[serde(default = "f32_one_e")]
Expand Down Expand Up @@ -317,6 +319,7 @@ impl RepresentationMaterial {
shape_type,
fill,
alpha,
padding,
fbm,
} => {
let handle = world.get::<Handle<ShapeMaterial>>(entity).unwrap().clone();
Expand All @@ -326,6 +329,8 @@ impl RepresentationMaterial {
.remove(&handle)
{
let mut refresh_mesh = false;
let padding = padding.get_float(context, world).unwrap_or_default();
material.data[1].z = padding;
match shape {
RepShape::Circle { radius } => {
let radius = radius.get_float(context, world).unwrap_or(1.0);
Expand Down Expand Up @@ -419,7 +424,9 @@ impl RepresentationMaterial {
.unwrap()
.get_mut(&mesh.0)
{
*mesh = shape.shader_shape().mesh(material.data[10].xy());
*mesh = shape
.shader_shape()
.mesh(material.data[10].xy() + vec2(padding, padding));
}
}
let _ = world
Expand Down Expand Up @@ -564,6 +571,7 @@ impl RepresentationMaterial {
shape_type,
fill,
alpha,
padding,
fbm,
} => {
ui.horizontal(|ui| {
Expand Down Expand Up @@ -616,6 +624,7 @@ impl RepresentationMaterial {
};
}
});
show_tree("padding:", padding, context, ui, world);
show_tree("alpha:", alpha, context, ui, world);
match shape {
RepShape::Circle { radius } => {
Expand Down

0 comments on commit 9355693

Please sign in to comment.