Skip to content

Commit

Permalink
[ShaderGraph] Added random nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
TothBenoit committed Dec 18, 2024
1 parent 2732456 commit bd45972
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
17 changes: 17 additions & 0 deletions hrt/shgraph/nodes/Random.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package hrt.shgraph.nodes;

using hxsl.Ast;

@name("Random")
@description("Gives a random number from a vec2 seed")
@width(80)
@group("Math")
class Random extends ShaderNodeHxsl {
static var SRC = {
@sginput(0.0) var seed : Vec2;
@sgoutput var output : Float;
function fragment() {
output = fract(sin(dot(seed, vec2(12.9898,78.233)))*43758.5453123);
}
};
}
18 changes: 18 additions & 0 deletions hrt/shgraph/nodes/Random2D.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package hrt.shgraph.nodes;

using hxsl.Ast;

@name("Random2D")
@description("Gives a random vec2 from a vec2 seed")
@width(80)
@group("Math")
class Random2D extends ShaderNodeHxsl {
static var SRC = {
@sginput(0.0) var seed : Vec2;
@sgoutput var output : Vec2;
function fragment() {
output = vec2(fract(sin(dot(seed, vec2(12.9898,78.233)))*43758.5453123),
fract(sin(dot(seed, vec2(1572.9898,132.237)))*157468.33458));
}
};
}
19 changes: 19 additions & 0 deletions hrt/shgraph/nodes/Random3D.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package hrt.shgraph.nodes;

using hxsl.Ast;

@name("Random3D")
@description("Gives a random vec3 from a vec2 seed")
@width(80)
@group("Math")
class Random3D extends ShaderNodeHxsl {
static var SRC = {
@sginput(0.0) var seed : Vec2;
@sgoutput var output : Vec3;
function fragment() {
output = vec3(fract(sin(dot(seed, vec2(12.9898,78.233)))*43758.5453123),
fract(sin(dot(seed, vec2(1572.9898,132.237)))*157468.33458),
fract(sin(dot(seed, vec2(14.5757,59.147)))*4756.281));
}
};
}

0 comments on commit bd45972

Please sign in to comment.