Skip to content

Commit

Permalink
➕ feat: add demoWater
Browse files Browse the repository at this point in the history
  • Loading branch information
deepkolos committed Jul 23, 2023
1 parent ea1468f commit 929009f
Show file tree
Hide file tree
Showing 9 changed files with 2,997 additions and 35 deletions.
2,851 changes: 2,851 additions & 0 deletions example/demo/demoCartoonWater/CartoonWater.json

Large diffs are not rendered by default.

Binary file added example/demo/demoCartoonWater/flowmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions example/demo/demoCartoonWater/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import cartoonWater from './CartoonWater.json';
import imgFlowmap from './flowmap.png';
import imgNoise from './noise.png';

const replaceImg = <T>(json: T): T => {
let jsonStr = JSON.stringify(json);
jsonStr = jsonStr.replace(/40bdd9aa-3430-4678-9549-877e9f125c44--764eb/g, imgFlowmap);
jsonStr = jsonStr.replace(/ded3a365-f6f7-4ff1-85d1-05c554ca7f05--764eb/g, imgNoise);
return JSON.parse(jsonStr) as T;
};

const demoCartoonWater = replaceImg(cartoonWater);

export default demoCartoonWater;
Binary file added example/demo/demoCartoonWater/noise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
153 changes: 123 additions & 30 deletions example/dev/devGeometry.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
{
"id": 5,
"data": {
"baseColorValue": [0, 0.8, 1],
"baseColorValue": [
0,
0.8,
1
],
"baseColorValueType": "vec3",
"expanded": true
},
Expand All @@ -37,12 +41,18 @@
},
"outputs": {},
"blocks": [],
"position": [0, 0],
"position": [
0,
0
],
"name": "BaseColorBlock",
"contextId": 1
}
],
"position": [550, 0],
"position": [
550,
0
],
"name": "Fragment"
},
"2": {
Expand Down Expand Up @@ -70,7 +80,11 @@
{
"id": 3,
"data": {
"positionValue": [0, 0, 0],
"positionValue": [
0,
0,
0
],
"positionValueType": "vec3",
"expanded": true
},
Expand All @@ -81,14 +95,21 @@
},
"outputs": {},
"blocks": [],
"position": [0, 0],
"position": [
0,
0
],
"name": "PositionBlock",
"contextId": 2
},
{
"id": 4,
"data": {
"normalValue": [0, 0, 0],
"normalValue": [
0,
0,
0
],
"normalValueType": "vec3",
"expanded": true
},
Expand All @@ -99,18 +120,27 @@
},
"outputs": {},
"blocks": [],
"position": [0, 0],
"position": [
0,
0
],
"name": "NormalBlock",
"contextId": 2
}
],
"position": [550, -300],
"position": [
550,
-300
],
"name": "Vertex"
},
"6": {
"id": 6,
"data": {
"outValue": [0, 0],
"outValue": [
0,
0
],
"outValueType": "vec2",
"channelValue": "UV0",
"exposed": true,
Expand All @@ -126,13 +156,20 @@
}
},
"blocks": [],
"position": [-242.28228024910547, -229.69810622360754],
"position": [
-242.28228024910547,
-229.69810622360754
],
"name": "UV"
},
"11": {
"id": 11,
"data": {
"outValue": [0, 0, 0],
"outValue": [
0,
0,
0
],
"outValueType": "vec3",
"spaceValue": "world",
"exposed": true,
Expand All @@ -148,15 +185,22 @@
}
},
"blocks": [],
"position": [34.79242576474714, -226.2983500884126],
"position": [
34.79242576474714,
-226.2983500884126
],
"name": "Normal"
},
"21": {
"id": 21,
"data": {
"outValue": [0, 0, 0],
"outValue": [
0,
0,
0
],
"outValueType": "vec3",
"spaceValue": "world",
"spaceValue": "object",
"exposed": true,
"expanded": true,
"preview": true,
Expand All @@ -170,13 +214,20 @@
}
},
"blocks": [],
"position": [274.96952951667595, 168.82148903444332],
"position": [
274.96952951667595,
168.82148903444332
],
"name": "Position"
},
"34": {
"id": 34,
"data": {
"outValue": [0, 0, 0],
"outValue": [
0,
0,
0
],
"outValueType": "vec3",
"spaceValue": "world",
"exposed": true,
Expand All @@ -192,15 +243,22 @@
}
},
"blocks": [],
"position": [-246.10611979166669, 142.48704020182294],
"position": [
-246.10611979166669,
142.48704020182294
],
"name": "ViewVector"
},
"195": {
"id": 195,
"data": {
"outValue": [0, 0, 0],
"outValue": [
0,
0,
0
],
"outValueType": "vec3",
"spaceValue": "world",
"spaceValue": "view",
"exposed": true,
"expanded": true,
"previewType": "3d",
Expand All @@ -214,13 +272,21 @@
}
},
"blocks": [],
"position": [18.256482118813096, 166.88480439174964],
"position": [
18.256482118813096,
166.88480439174964
],
"name": "ViewDirection"
},
"216": {
"id": 216,
"data": {
"outValue": [0, 0, 0, 0],
"outValue": [
0,
0,
0,
0
],
"outValueType": "vec4",
"modeValue": "default",
"modeValueType": "string",
Expand All @@ -236,13 +302,21 @@
}
},
"blocks": [],
"position": [-266.9480504432696, 533.5870688934422],
"position": [
-266.9480504432696,
533.5870688934422
],
"name": "ScreenPosition"
},
"241": {
"id": 241,
"data": {
"outValue": [0, 0, 0, 0],
"outValue": [
0,
0,
0,
0
],
"outValueType": "vec4",
"modeValue": "raw",
"modeValueType": "string",
Expand All @@ -258,13 +332,21 @@
}
},
"blocks": [],
"position": [22.626931842831322, 542.3341032037259],
"position": [
22.626931842831322,
542.3341032037259
],
"name": "ScreenPosition"
},
"270": {
"id": 270,
"data": {
"outValue": [0, 0, 0, 0],
"outValue": [
0,
0,
0,
0
],
"outValueType": "vec4",
"modeValue": "center",
"modeValueType": "string",
Expand All @@ -280,13 +362,21 @@
}
},
"blocks": [],
"position": [280.63588313476316, 545.3161223483148],
"position": [
280.63588313476316,
545.3161223483148
],
"name": "ScreenPosition"
},
"303": {
"id": 303,
"data": {
"outValue": [0, 0, 0, 0],
"outValue": [
0,
0,
0,
0
],
"outValueType": "vec4",
"modeValue": "tiled",
"modeValueType": "string",
Expand All @@ -302,7 +392,10 @@
}
},
"blocks": [],
"position": [553.7981795976377, 545.9295556617591],
"position": [
553.7981795976377,
545.9295556617591
],
"name": "ScreenPosition"
}
},
Expand All @@ -312,7 +405,7 @@
"showInspector": true
},
"type": "ShaderGraph",
"version": "",
"version": "0.0.0",
"setting": {
"template": "unlit",
"precision": "single",
Expand All @@ -327,4 +420,4 @@
"clearCoat": false
},
"parameters": []
}
}
2 changes: 2 additions & 0 deletions example/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import demoConstantBiasScaleSubGraph from './demo/demoConstantBiasScaleSubGraph.
import demoFlowMapSubGraph from './demo/demoFlowMapSubGraph.json';
import demoFlowMap from './demo/demoFlowMap.json';
import demoImageFlip from './demo/demoImageFlip.json';
import demoCartoonWater from './demo/demoCartoonWater';

export const Presets = {
devCompile,
Expand Down Expand Up @@ -64,4 +65,5 @@ export const Presets = {
demoFlowMapSubGraph,
demoFlowMap,
demoImageFlip,
demoCartoonWater,
};
4 changes: 2 additions & 2 deletions src/components/artistic/normal/NormalBlendRC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export class NormalBlendRC extends RC {
} else {
const codeFn = (varName: string) => /* wgsl */ `
fn ${varName}(A: vec3f, B: vec3f) -> vec3f {
vec3 t = A.xyz + vec3f(0.0, 0.0, 1.0);
vec3 u = B.xyz * vec3f(-1.0, -1.0, 1.0);
let t = A.xyz + vec3f(0.0, 0.0, 1.0);
let u = B.xyz * vec3f(-1.0, -1.0, 1.0);
return (t / t.z) * dot(t, u) - u;
}`;
const fnVar = compiler.setContext('defines', node, mode, codeFn);
Expand Down
4 changes: 3 additions & 1 deletion src/components/input/geometry/PositionRC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class PositionRC extends RC {
const node = { name: PositionRC.Name, data: {} } as any;
const suffix = SpaceSuffixMap[space];
const key = 'position' + suffix;
const vertVar = key;
let vertVar = key;

if (space !== 'object') {
let code = '';
Expand All @@ -61,6 +61,8 @@ export class PositionRC extends RC {
code = `let ${vertVar} = vec3<f32>(0);`; // TODO
}
compiler.setContext('vertShared', node, key, { varName: vertVar, code });
} else {
vertVar = '*' + vertVar;
}

const varyingVar = compiler.setContext(
Expand Down
4 changes: 2 additions & 2 deletions src/components/input/geometry/ViewVectorRC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export class ViewVectorRC extends RC {
vertVar = compiler.setContext('vertShared', node, key, codeFn);
fragVar = compiler.setContext('fragShared', node, key, codeFn);
} else if (space === 'view') {
const codeFn = (varName: string) => `vec3 ${varName} = -${positionVar};`;
const codeFn = (varName: string) => `let ${varName} = -${positionVar};`;
vertVar = compiler.setContext('vertShared', node, key, codeFn);
fragVar = compiler.setContext('fragShared', node, key, codeFn);
} else {
// TODO
const codeFn = (varName: string) => `vec3 ${varName} = vec3<f32>(0);`;
const codeFn = (varName: string) => `let ${varName} = vec3<f32>(0);`;
vertVar = compiler.setContext('vertShared', node, key, codeFn);
fragVar = compiler.setContext('fragShared', node, key, codeFn);
}
Expand Down

0 comments on commit 929009f

Please sign in to comment.