Skip to content

Commit

Permalink
added layout2x2 node
Browse files Browse the repository at this point in the history
  • Loading branch information
lonegamedev committed Apr 14, 2023
1 parent 4bc0245 commit 336be03
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/lib/library/lgd/layout2x2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Color } from "@/lib/designer/color";
import { GpuDesignerNode } from "@/lib/designer/gpudesignernode";

export class Layout2x2 extends GpuDesignerNode {
public init() {
this.title = "Layout2x2";

this.addInput("image0");
this.addInput("image1");
this.addInput("image2");
this.addInput("image3");

this.addColorProperty("bg", "Background Color", new Color());

const source = `
vec4 process(vec2 uv)
{
vec2 cellSize = vec2(0.5, 0.5);
vec2 cell = floor(uv / cellSize);
vec2 subUv = (uv - cell * cellSize) / cellSize;
vec4 tex0 = texture(image0, subUv);
vec4 tex1 = texture(image1, subUv);
vec4 tex2 = texture(image2, subUv);
vec4 tex3 = texture(image3, subUv);
if(image0_connected) {
if(cell.x < 1.0 && cell.y > 0.0) {
return tex0;
}
}
if(image1_connected) {
if(cell.x > 0.0 && cell.y > 0.0) {
return tex1;
}
}
if(image2_connected) {
if(cell.x < 1.0 && cell.y < 1.0) {
return tex2;
}
}
if(image3_connected) {
if(cell.x > 0.0 && cell.y < 1.0) {
return tex3;
}
}
return vec4(prop_bg.rgb, 1.0);
}
`;

this.buildShader(source);
}
}
2 changes: 2 additions & 0 deletions src/lib/library/libraryv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import { GradientNoiseFractalSum } from "./v2/gradientnoisefractalsum";
import { SimplexNoiseV2 } from "./v2/simplexnoise";
import { DirectionalWarpNodeV2 } from "./v2/directionalwarpv2";
import { ImageNode } from "./v2/imagenode";
import { Layout2x2 } from "./lgd/layout2x2";

export function createLibrary() {
const lib = new DesignerLibrary();
Expand Down Expand Up @@ -183,6 +184,7 @@ export function createLibrary() {
lib.addNode("image", "Image", ImageNode);
//lib.addNode("simplexnoise", "Simplex Noise", SimplexNoiseV2);
// lib.addNode("betterwarp", "Better Warp", BetterWarpNode);
lib.addNode("layout2x2", "Layout2x2", Layout2x2);

return lib;
}

0 comments on commit 336be03

Please sign in to comment.