Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional optimisation #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 48 additions & 9 deletions src/lib/library/v1/blend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ export class BlendNode extends GpuDesignerNode {
"Min",
"Switch",
"Overlay",
"Screen"
"Screen",
// News blend mode
"Exclusion",
"Hard light",
"Soft light",
"Color dodge",
"Color burn",
"Linear burn"
]);
this.addFloatProperty("opacity", "Opacity", 1.0, 0.0, 1.0, 0.01);

Expand All @@ -41,37 +48,69 @@ export class BlendNode extends GpuDesignerNode {
if (prop_type==0){ // multiply
col.rgb = colA.rgb * colB.rgb;
}
if (prop_type==1) // add
else if (prop_type==1) // add
col.rgb = colA.rgb + colB.rgb;
if (prop_type==2) // subtract
else if (prop_type==2) // subtract
col.rgb = colB.rgb - colA.rgb;
if (prop_type==3) // divide
else if (prop_type==3) // divide
col.rgb = colB.rgb / colA.rgb;
// if (prop_type==4) {// add sub
// if (colA.r > 0.5) col.r = colB.r + colA.r; else col.r = colB.r - colA.r;
// if (colA.g > 0.5) col.g = colB.g + colA.g; else col.g = colB.g - colA.g;
// if (colA.b > 0.5) col.b = colB.b + colA.b; else col.b = colB.b - colA.b;
// }
if (prop_type==4) { // max
else if (prop_type==4) { // max
col.rgb = max(colA.rgb, colB.rgb);
}
if (prop_type==5) { // min
else if (prop_type==5) { // min
col.rgb = min(colA.rgb, colB.rgb);
}
if (prop_type==6) { // switch
else if (prop_type==6) { // switch
col.rgb = colA.rgb;
}
if (prop_type==7) { // overlay
else if (prop_type==7) { // overlay
if (colB.r < 0.5) col.r = colB.r * colA.r; else col.r = screen(colB.r, colA.r);
if (colB.g < 0.5) col.g = colB.g * colA.g; else col.g = screen(colB.g, colA.g);
if (colB.b < 0.5) col.b = colB.b * colA.b; else col.b = screen(colB.b, colA.b);
}
if (prop_type==8) { // screen
else if (prop_type==8) { // screen
col.r = screen(colA.r, colB.r);
col.g = screen(colA.g, colB.g);
col.b = screen(colA.b, colB.b);
}

else if (prop_type==9){ // exclusion
col.rgb = colB.rgb + colA.rgb - 2.0 * colB.rgb * colA.rgb;
}
// a = colB; b = colA
else if (prop_type==10){ // Hard light
if(colB.r < 0.5) col.r = (2.0 * colB.r * colA.r); else col.r = (1.0 - 2.0 * (1.0 - colB.r) * (1.0 - colA.r));
if(colB.g < 0.5) col.g = (2.0 * colB.g * colA.g); else col.g = (1.0 - 2.0 * (1.0 - colB.g) * (1.0 - colA.g));
if(colB.b < 0.5) col.b = (2.0 * colB.b * colA.b); else col.b = (1.0 - 2.0 * (1.0 - colB.b) * (1.0 - colA.b));
//if b < 0.5 ? (2.0 * a * b) : (1.0 - 2.0 * (1.0 - a) * (1.0 - b))
}

else if (prop_type==11){ // Soft light
if(colB.r < 0.5) col.r = 2.0 * colB.r * colA.r + colB.r * colB.r * (1.0 - 2.0 * colA.r); else col.r = sqrt(colB.r) * (2.0 * colA.r - 1.0) + (2.0 * colB.r) * (1.0 - colA.r);
if(colB.g < 0.5) col.g = 2.0 * colB.g * colA.g + colB.g * colB.g * (1.0 - 2.0 * colA.g); else col.g = sqrt(colB.g) * (2.0 * colA.g - 1.0) + (2.0 * colB.g) * (1.0 - colA.g);
if(colB.b < 0.5) col.b = 2.0 * colB.b * colA.b + colB.b * colB.b * (1.0 - 2.0 * colA.b); else col.b = sqrt(colB.b) * (2.0 * colA.b - 1.0) + (2.0 * colB.b) * (1.0 - colA.b);
//b < 0.5 ? (2.0 * a * b + a * a * (1.0 - 2.0 * b)) : (sqrt(a) * (2.0 * b - 1.0) + (2.0 * a) * (1.0 - b))
}

else if (prop_type==12){ // Color dodge
col.rgb = colB.rgb / (1.0 - colA.rgb);
}

else if (prop_type==13){ // Color burn
col.rgb = 1.0 - (1.0 - colB.rgb) / colA.rgb;
}

else if (prop_type==14){ // Linear burn
col.rgb = colB.rgb + colA.rgb - 1.0;
}



// apply opacity
col.rgb = mix(colB.rgb, col.rgb, vec3(finalOpacity));

Expand Down
6 changes: 3 additions & 3 deletions src/lib/library/v1/mirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ export class MirrorNode extends GpuDesignerNode {
uv.x = prop_offset - (uv.x - prop_offset);

// right to left
if (prop_mode == 1)
else if (prop_mode == 1)
if (uv.x < prop_offset)
uv.x = prop_offset + (prop_offset - uv.x);

// bottom to top
if (prop_mode == 2)
else if (prop_mode == 2)
if (uv.y < prop_offset)
uv.y = prop_offset + (prop_offset - uv.y);

// top to bottom
if (prop_mode == 3)
else if (prop_mode == 3)
if (uv.y > prop_offset)
uv.y = prop_offset - (uv.y - prop_offset);

Expand Down
8 changes: 4 additions & 4 deletions src/lib/library/v2/extractchannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export class ExtractChannel extends GpuDesignerNode {
float getChannel(vec4 inputData, int mode)
{
if (mode == 0) return inputData.r;
if (mode == 1) return inputData.g;
if (mode == 2) return inputData.b;
if (mode == 3) return inputData.a;
if (mode == 4) {
else if (mode == 1) return inputData.g;
else if (mode == 2) return inputData.b;
else if (mode == 3) return inputData.a;
else if (mode == 4) {
return (inputData.r + inputData.g + inputData.b) * 0.3333333;
}

Expand Down