Add more advanced math nodes (#1383)

Added nodes for the following operations:

* Floor
* Ceil
* Round
* Absolute Value
* Logarithm
* Natural Logarithm
* sin
* cos
* tan
This commit is contained in:
isiko 2023-08-14 15:43:17 +02:00 committed by GitHub
parent 2412a3def6
commit 7558088727
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 176 additions and 0 deletions

View file

@ -83,6 +83,80 @@ where
first.pow(second)
}
// Floor
pub struct FloorNode;
#[node_macro::node_fn(FloorNode)]
fn floor(input: f32) -> f32 {
input.floor()
}
// Ceil
pub struct CeilNode;
#[node_macro::node_fn(CeilNode)]
fn ceil(input: f32) -> f32 {
input.ceil()
}
// Round
pub struct RoundNode;
#[node_macro::node_fn(RoundNode)]
fn round(input: f32) -> f32 {
input.round()
}
// Absolute Value
pub struct AbsoluteNode;
#[node_macro::node_fn(AbsoluteNode)]
fn abs(input: f32) -> f32 {
input.abs()
}
// Log
pub struct LogParameterNode<Second> {
second: Second,
}
#[node_macro::node_fn(LogParameterNode)]
fn ln<U: num_traits::float::Float>(first: U, second: U) -> U {
first.log(second)
}
// Natural Log
pub struct NaturalLogNode;
#[node_macro::node_fn(NaturalLogNode)]
fn ln(input: f32) -> f32 {
input.ln()
}
// Sine
pub struct SineNode;
#[node_macro::node_fn(SineNode)]
fn ln(input: f32) -> f32 {
input.sin()
}
// Cos
pub struct CosineNode;
#[node_macro::node_fn(CosineNode)]
fn ln(input: f32) -> f32 {
input.cos()
}
// Tan
pub struct TangentNode;
#[node_macro::node_fn(TangentNode)]
fn ln(input: f32) -> f32 {
input.tan()
}
// Minimum
pub struct MinParameterNode<Second> {
second: Second,

View file

@ -227,6 +227,15 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
register_node!(graphene_core::ops::ExponentParameterNode<_>, input: f32, params: [f32]),
register_node!(graphene_core::ops::ExponentParameterNode<_>, input: &f32, params: [f32]),
register_node!(graphene_core::ops::ExponentParameterNode<_>, input: f32, params: [&f32]),
register_node!(graphene_core::ops::FloorNode, input: f32, params: []),
register_node!(graphene_core::ops::CeilNode, input: f32, params: []),
register_node!(graphene_core::ops::RoundNode, input: f32, params: []),
register_node!(graphene_core::ops::AbsoluteNode, input: f32, params: []),
register_node!(graphene_core::ops::LogParameterNode<_>, input: f32, params: [f32]),
register_node!(graphene_core::ops::NaturalLogNode, input: f32, params: []),
register_node!(graphene_core::ops::SineNode, input: f32, params: []),
register_node!(graphene_core::ops::CosineNode, input: f32, params: []),
register_node!(graphene_core::ops::TangentNode, input: f32, params: []),
register_node!(graphene_core::ops::MaxParameterNode<_>, input: u32, params: [u32]),
register_node!(graphene_core::ops::MaxParameterNode<_>, input: f32, params: [f32]),
register_node!(graphene_core::ops::MinParameterNode<_>, input: u32, params: [u32]),