@onerjs/procedural-textures 8.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/brick/brickProceduralTexture.d.ts +35 -0
- package/brick/brickProceduralTexture.fragment.d.ts +5 -0
- package/brick/brickProceduralTexture.fragment.js +24 -0
- package/brick/brickProceduralTexture.fragment.js.map +1 -0
- package/brick/brickProceduralTexture.js +85 -0
- package/brick/brickProceduralTexture.js.map +1 -0
- package/brick/index.d.ts +1 -0
- package/brick/index.js +2 -0
- package/brick/index.js.map +1 -0
- package/cloud/cloudProceduralTexture.d.ts +35 -0
- package/cloud/cloudProceduralTexture.fragment.d.ts +5 -0
- package/cloud/cloudProceduralTexture.fragment.js +22 -0
- package/cloud/cloudProceduralTexture.fragment.js.map +1 -0
- package/cloud/cloudProceduralTexture.js +85 -0
- package/cloud/cloudProceduralTexture.js.map +1 -0
- package/cloud/index.d.ts +1 -0
- package/cloud/index.js +2 -0
- package/cloud/index.js.map +1 -0
- package/fire/fireProceduralTexture.d.ts +44 -0
- package/fire/fireProceduralTexture.fragment.d.ts +5 -0
- package/fire/fireProceduralTexture.fragment.js +15 -0
- package/fire/fireProceduralTexture.fragment.js.map +1 -0
- package/fire/fireProceduralTexture.js +127 -0
- package/fire/fireProceduralTexture.js.map +1 -0
- package/fire/index.d.ts +1 -0
- package/fire/index.js +2 -0
- package/fire/index.js.map +1 -0
- package/grass/grassProceduralTexture.d.ts +29 -0
- package/grass/grassProceduralTexture.fragment.d.ts +5 -0
- package/grass/grassProceduralTexture.fragment.js +20 -0
- package/grass/grassProceduralTexture.fragment.js.map +1 -0
- package/grass/grassProceduralTexture.js +69 -0
- package/grass/grassProceduralTexture.js.map +1 -0
- package/grass/index.d.ts +1 -0
- package/grass/index.js +2 -0
- package/grass/index.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.js +12 -0
- package/index.js.map +1 -0
- package/legacy/legacy-brick.d.ts +1 -0
- package/legacy/legacy-brick.js +14 -0
- package/legacy/legacy-brick.js.map +1 -0
- package/legacy/legacy-cloud.d.ts +1 -0
- package/legacy/legacy-cloud.js +14 -0
- package/legacy/legacy-cloud.js.map +1 -0
- package/legacy/legacy-fire.d.ts +1 -0
- package/legacy/legacy-fire.js +14 -0
- package/legacy/legacy-fire.js.map +1 -0
- package/legacy/legacy-grass.d.ts +1 -0
- package/legacy/legacy-grass.js +14 -0
- package/legacy/legacy-grass.js.map +1 -0
- package/legacy/legacy-marble.d.ts +1 -0
- package/legacy/legacy-marble.js +14 -0
- package/legacy/legacy-marble.js.map +1 -0
- package/legacy/legacy-normalMap.d.ts +1 -0
- package/legacy/legacy-normalMap.js +14 -0
- package/legacy/legacy-normalMap.js.map +1 -0
- package/legacy/legacy-perlinNoise.d.ts +1 -0
- package/legacy/legacy-perlinNoise.js +14 -0
- package/legacy/legacy-perlinNoise.js.map +1 -0
- package/legacy/legacy-road.d.ts +1 -0
- package/legacy/legacy-road.js +14 -0
- package/legacy/legacy-road.js.map +1 -0
- package/legacy/legacy-starfield.d.ts +1 -0
- package/legacy/legacy-starfield.js +14 -0
- package/legacy/legacy-starfield.js.map +1 -0
- package/legacy/legacy-wood.d.ts +1 -0
- package/legacy/legacy-wood.js +14 -0
- package/legacy/legacy-wood.js.map +1 -0
- package/legacy/legacy.d.ts +1 -0
- package/legacy/legacy.js +17 -0
- package/legacy/legacy.js.map +1 -0
- package/license.md +71 -0
- package/marble/index.d.ts +1 -0
- package/marble/index.js +2 -0
- package/marble/index.js.map +1 -0
- package/marble/marbleProceduralTexture.d.ts +35 -0
- package/marble/marbleProceduralTexture.fragment.d.ts +5 -0
- package/marble/marbleProceduralTexture.fragment.js +28 -0
- package/marble/marbleProceduralTexture.fragment.js.map +1 -0
- package/marble/marbleProceduralTexture.js +85 -0
- package/marble/marbleProceduralTexture.js.map +1 -0
- package/normalMap/index.d.ts +1 -0
- package/normalMap/index.js +2 -0
- package/normalMap/index.js.map +1 -0
- package/normalMap/normalMapProceduralTexture.d.ts +28 -0
- package/normalMap/normalMapProceduralTexture.fragment.d.ts +5 -0
- package/normalMap/normalMapProceduralTexture.fragment.js +15 -0
- package/normalMap/normalMapProceduralTexture.fragment.js.map +1 -0
- package/normalMap/normalMapProceduralTexture.js +62 -0
- package/normalMap/normalMapProceduralTexture.js.map +1 -0
- package/package.json +47 -0
- package/perlinNoise/index.d.ts +1 -0
- package/perlinNoise/index.js +2 -0
- package/perlinNoise/index.js.map +1 -0
- package/perlinNoise/perlinNoiseProceduralTexture.d.ts +28 -0
- package/perlinNoise/perlinNoiseProceduralTexture.fragment.d.ts +5 -0
- package/perlinNoise/perlinNoiseProceduralTexture.fragment.js +59 -0
- package/perlinNoise/perlinNoiseProceduralTexture.fragment.js.map +1 -0
- package/perlinNoise/perlinNoiseProceduralTexture.js +66 -0
- package/perlinNoise/perlinNoiseProceduralTexture.js.map +1 -0
- package/readme.md +34 -0
- package/road/index.d.ts +1 -0
- package/road/index.js +2 -0
- package/road/index.js.map +1 -0
- package/road/roadProceduralTexture.d.ts +26 -0
- package/road/roadProceduralTexture.fragment.d.ts +5 -0
- package/road/roadProceduralTexture.fragment.js +21 -0
- package/road/roadProceduralTexture.fragment.js.map +1 -0
- package/road/roadProceduralTexture.js +49 -0
- package/road/roadProceduralTexture.js.map +1 -0
- package/starfield/index.d.ts +1 -0
- package/starfield/index.js +2 -0
- package/starfield/index.js.map +1 -0
- package/starfield/starfieldProceduralTexture.d.ts +55 -0
- package/starfield/starfieldProceduralTexture.fragment.d.ts +5 -0
- package/starfield/starfieldProceduralTexture.fragment.js +26 -0
- package/starfield/starfieldProceduralTexture.fragment.js.map +1 -0
- package/starfield/starfieldProceduralTexture.js +168 -0
- package/starfield/starfieldProceduralTexture.js.map +1 -0
- package/wood/index.d.ts +1 -0
- package/wood/index.js +2 -0
- package/wood/index.js.map +1 -0
- package/wood/woodProceduralTexture.d.ts +29 -0
- package/wood/woodProceduralTexture.fragment.d.ts +5 -0
- package/wood/woodProceduralTexture.fragment.js +20 -0
- package/wood/woodProceduralTexture.fragment.js.map +1 -0
- package/wood/woodProceduralTexture.js +61 -0
- package/wood/woodProceduralTexture.js.map +1 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Do not edit.
|
|
2
|
+
import { ShaderStore } from "@onerjs/core/Engines/shaderStore.js";
|
|
3
|
+
const name = "marbleProceduralTexturePixelShader";
|
|
4
|
+
const shader = `precision highp float;varying vec2 vPosition;varying vec2 vUV;uniform float numberOfTilesHeight;uniform float numberOfTilesWidth;uniform float amplitude;uniform vec3 marbleColor;uniform vec3 jointColor;const vec3 tileSize=vec3(1.1,1.0,1.1);const vec3 tilePct=vec3(0.98,1.0,0.98);float rand(vec2 n) {return fract(cos(dot(n,vec2(12.9898,4.1414)))*43758.5453);}
|
|
5
|
+
float noise(vec2 n) {const vec2 d=vec2(0.0,1.0);vec2 b=floor(n),f=smoothstep(vec2(0.0),vec2(1.0),fract(n));return mix(mix(rand(b),rand(b+d.yx),f.x),mix(rand(b+d.xy),rand(b+d.yy),f.x),f.y);}
|
|
6
|
+
float turbulence(vec2 P)
|
|
7
|
+
{float val=0.0;float freq=1.0;for (int i=0; i<4; i++)
|
|
8
|
+
{val+=abs(noise(P*freq)/freq);freq*=2.07;}
|
|
9
|
+
return val;}
|
|
10
|
+
float roundF(float number){return sign(number)*floor(abs(number)+0.5);}
|
|
11
|
+
vec3 marble_color(float x)
|
|
12
|
+
{vec3 col;x=0.5*(x+1.);x=sqrt(x);
|
|
13
|
+
x=sqrt(x);x=sqrt(x);col=vec3(.2+.75*x);
|
|
14
|
+
col.b*=0.95;
|
|
15
|
+
return col;}
|
|
16
|
+
void main()
|
|
17
|
+
{float brickW=1.0/numberOfTilesWidth;float brickH=1.0/numberOfTilesHeight;float jointWPercentage=0.01;float jointHPercentage=0.01;vec3 color=marbleColor;float yi=vUV.y/brickH;float nyi=roundF(yi);float xi=vUV.x/brickW;if (mod(floor(yi),2.0)==0.0){xi=xi-0.5;}
|
|
18
|
+
float nxi=roundF(xi);vec2 brickvUV=vec2((xi-floor(xi))/brickH,(yi-floor(yi))/brickW);if (yi<nyi+jointHPercentage && yi>nyi-jointHPercentage){color=mix(jointColor,vec3(0.37,0.25,0.25),(yi-nyi)/jointHPercentage+0.2);}
|
|
19
|
+
else if (xi<nxi+jointWPercentage && xi>nxi-jointWPercentage){color=mix(jointColor,vec3(0.44,0.44,0.44),(xi-nxi)/jointWPercentage+0.2);}
|
|
20
|
+
else {float t=6.28*brickvUV.x/(tileSize.x+noise(vec2(vUV)*6.0));t+=amplitude*turbulence(brickvUV.xy);t=sin(t);color=marble_color(t);}
|
|
21
|
+
gl_FragColor=vec4(color,0.0);}`;
|
|
22
|
+
// Sideeffect
|
|
23
|
+
if (!ShaderStore.ShadersStore[name]) {
|
|
24
|
+
ShaderStore.ShadersStore[name] = shader;
|
|
25
|
+
}
|
|
26
|
+
/** @internal */
|
|
27
|
+
export const marbleProceduralTexturePixelShader = { name, shader };
|
|
28
|
+
//# sourceMappingURL=marbleProceduralTexture.fragment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marbleProceduralTexture.fragment.js","sourceRoot":"","sources":["../../../../dev/proceduralTextures/src/marble/marbleProceduralTexture.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,4CAAiC;AAEvD,MAAM,IAAI,GAAG,oCAAoC,CAAC;AAClD,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;+BAiBgB,CAAC;AAChC,aAAa;AACb,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;IAClC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAC5C,CAAC;AACD,gBAAgB;AAChB,MAAM,CAAC,MAAM,kCAAkC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\n\nconst name = \"marbleProceduralTexturePixelShader\";\nconst shader = `precision highp float;varying vec2 vPosition;varying vec2 vUV;uniform float numberOfTilesHeight;uniform float numberOfTilesWidth;uniform float amplitude;uniform vec3 marbleColor;uniform vec3 jointColor;const vec3 tileSize=vec3(1.1,1.0,1.1);const vec3 tilePct=vec3(0.98,1.0,0.98);float rand(vec2 n) {return fract(cos(dot(n,vec2(12.9898,4.1414)))*43758.5453);}\nfloat noise(vec2 n) {const vec2 d=vec2(0.0,1.0);vec2 b=floor(n),f=smoothstep(vec2(0.0),vec2(1.0),fract(n));return mix(mix(rand(b),rand(b+d.yx),f.x),mix(rand(b+d.xy),rand(b+d.yy),f.x),f.y);}\nfloat turbulence(vec2 P)\n{float val=0.0;float freq=1.0;for (int i=0; i<4; i++)\n{val+=abs(noise(P*freq)/freq);freq*=2.07;}\nreturn val;}\nfloat roundF(float number){return sign(number)*floor(abs(number)+0.5);}\nvec3 marble_color(float x)\n{vec3 col;x=0.5*(x+1.);x=sqrt(x); \nx=sqrt(x);x=sqrt(x);col=vec3(.2+.75*x); \ncol.b*=0.95; \nreturn col;}\nvoid main()\n{float brickW=1.0/numberOfTilesWidth;float brickH=1.0/numberOfTilesHeight;float jointWPercentage=0.01;float jointHPercentage=0.01;vec3 color=marbleColor;float yi=vUV.y/brickH;float nyi=roundF(yi);float xi=vUV.x/brickW;if (mod(floor(yi),2.0)==0.0){xi=xi-0.5;}\nfloat nxi=roundF(xi);vec2 brickvUV=vec2((xi-floor(xi))/brickH,(yi-floor(yi))/brickW);if (yi<nyi+jointHPercentage && yi>nyi-jointHPercentage){color=mix(jointColor,vec3(0.37,0.25,0.25),(yi-nyi)/jointHPercentage+0.2);}\nelse if (xi<nxi+jointWPercentage && xi>nxi-jointWPercentage){color=mix(jointColor,vec3(0.44,0.44,0.44),(xi-nxi)/jointWPercentage+0.2);}\nelse {float t=6.28*brickvUV.x/(tileSize.x+noise(vec2(vUV)*6.0));t+=amplitude*turbulence(brickvUV.xy);t=sin(t);color=marble_color(t);}\ngl_FragColor=vec4(color,0.0);}`;\n// Sideeffect\nif (!ShaderStore.ShadersStore[name]) {\n ShaderStore.ShadersStore[name] = shader;\n}\n/** @internal */\nexport const marbleProceduralTexturePixelShader = { name, shader };\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { __decorate } from "@onerjs/core/tslib.es6.js";
|
|
2
|
+
import { serialize } from "@onerjs/core/Misc/decorators.js";
|
|
3
|
+
import { SerializationHelper } from "@onerjs/core/Misc/decorators.serialization.js";
|
|
4
|
+
import { Color3 } from "@onerjs/core/Maths/math.color.js";
|
|
5
|
+
import { ProceduralTexture } from "@onerjs/core/Materials/Textures/Procedurals/proceduralTexture.js";
|
|
6
|
+
import { RegisterClass } from "@onerjs/core/Misc/typeStore.js";
|
|
7
|
+
import "./marbleProceduralTexture.fragment.js";
|
|
8
|
+
export class MarbleProceduralTexture extends ProceduralTexture {
|
|
9
|
+
constructor(name, size, scene = null, fallbackTexture, generateMipMaps) {
|
|
10
|
+
super(name, size, "marbleProceduralTexture", scene, fallbackTexture, generateMipMaps);
|
|
11
|
+
this._numberOfTilesHeight = 3;
|
|
12
|
+
this._numberOfTilesWidth = 3;
|
|
13
|
+
this._amplitude = 9.0;
|
|
14
|
+
this._jointColor = new Color3(0.72, 0.72, 0.72);
|
|
15
|
+
this.updateShaderUniforms();
|
|
16
|
+
}
|
|
17
|
+
updateShaderUniforms() {
|
|
18
|
+
this.setFloat("numberOfTilesHeight", this._numberOfTilesHeight);
|
|
19
|
+
this.setFloat("numberOfTilesWidth", this._numberOfTilesWidth);
|
|
20
|
+
this.setFloat("amplitude", this._amplitude);
|
|
21
|
+
this.setColor3("jointColor", this._jointColor);
|
|
22
|
+
}
|
|
23
|
+
get numberOfTilesHeight() {
|
|
24
|
+
return this._numberOfTilesHeight;
|
|
25
|
+
}
|
|
26
|
+
set numberOfTilesHeight(value) {
|
|
27
|
+
this._numberOfTilesHeight = value;
|
|
28
|
+
this.updateShaderUniforms();
|
|
29
|
+
}
|
|
30
|
+
get amplitude() {
|
|
31
|
+
return this._amplitude;
|
|
32
|
+
}
|
|
33
|
+
set amplitude(value) {
|
|
34
|
+
this._amplitude = value;
|
|
35
|
+
this.updateShaderUniforms();
|
|
36
|
+
}
|
|
37
|
+
get numberOfTilesWidth() {
|
|
38
|
+
return this._numberOfTilesWidth;
|
|
39
|
+
}
|
|
40
|
+
set numberOfTilesWidth(value) {
|
|
41
|
+
this._numberOfTilesWidth = value;
|
|
42
|
+
this.updateShaderUniforms();
|
|
43
|
+
}
|
|
44
|
+
get jointColor() {
|
|
45
|
+
return this._jointColor;
|
|
46
|
+
}
|
|
47
|
+
set jointColor(value) {
|
|
48
|
+
this._jointColor = value;
|
|
49
|
+
this.updateShaderUniforms();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Serializes this marble procedural texture
|
|
53
|
+
* @returns a serialized marble procedural texture object
|
|
54
|
+
*/
|
|
55
|
+
serialize() {
|
|
56
|
+
const serializationObject = SerializationHelper.Serialize(this, super.serialize());
|
|
57
|
+
serializationObject.customType = "BABYLON.MarbleProceduralTexture";
|
|
58
|
+
return serializationObject;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a Marble Procedural Texture from parsed marble procedural texture data
|
|
62
|
+
* @param parsedTexture defines parsed texture data
|
|
63
|
+
* @param scene defines the current scene
|
|
64
|
+
* @param rootUrl defines the root URL containing marble procedural texture information
|
|
65
|
+
* @returns a parsed Marble Procedural Texture
|
|
66
|
+
*/
|
|
67
|
+
static Parse(parsedTexture, scene, rootUrl) {
|
|
68
|
+
const texture = SerializationHelper.Parse(() => new MarbleProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
|
|
69
|
+
return texture;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
__decorate([
|
|
73
|
+
serialize()
|
|
74
|
+
], MarbleProceduralTexture.prototype, "numberOfTilesHeight", null);
|
|
75
|
+
__decorate([
|
|
76
|
+
serialize()
|
|
77
|
+
], MarbleProceduralTexture.prototype, "amplitude", null);
|
|
78
|
+
__decorate([
|
|
79
|
+
serialize()
|
|
80
|
+
], MarbleProceduralTexture.prototype, "numberOfTilesWidth", null);
|
|
81
|
+
__decorate([
|
|
82
|
+
serialize()
|
|
83
|
+
], MarbleProceduralTexture.prototype, "jointColor", null);
|
|
84
|
+
RegisterClass("BABYLON.MarbleProceduralTexture", MarbleProceduralTexture);
|
|
85
|
+
//# sourceMappingURL=marbleProceduralTexture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marbleProceduralTexture.js","sourceRoot":"","sources":["../../../../dev/proceduralTextures/src/marble/marbleProceduralTexture.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,wCAA6B;AACjD,OAAO,EAAE,mBAAmB,EAAE,sDAA2C;AACzE,OAAO,EAAE,MAAM,EAAE,yCAA8B;AAE/C,OAAO,EAAE,iBAAiB,EAAE,yEAA8D;AAE1F,OAAO,EAAE,aAAa,EAAE,uCAA4B;AAGpD,OAAO,oCAAoC,CAAC;AAE5C,MAAM,OAAO,uBAAwB,SAAQ,iBAAiB;IAM1D,YAAY,IAAY,EAAE,IAAY,EAAE,QAAyB,IAAI,EAAE,eAAyB,EAAE,eAAyB;QACvH,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,yBAAyB,EAAE,KAAK,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;QANlF,yBAAoB,GAAW,CAAC,CAAC;QACjC,wBAAmB,GAAW,CAAC,CAAC;QAChC,eAAU,GAAW,GAAG,CAAC;QACzB,gBAAW,GAAG,IAAI,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAI/C,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAEM,oBAAoB;QACvB,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAChE,IAAI,CAAC,QAAQ,CAAC,oBAAoB,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC9D,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;IAGD,IAAW,mBAAmB;QAC1B,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACrC,CAAC;IAED,IAAW,mBAAmB,CAAC,KAAa;QACxC,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;QAClC,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAGD,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED,IAAW,SAAS,CAAC,KAAa;QAC9B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAGD,IAAW,kBAAkB;QACzB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IACpC,CAAC;IAED,IAAW,kBAAkB,CAAC,KAAa;QACvC,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC;QACjC,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAGD,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED,IAAW,UAAU,CAAC,KAAa;QAC/B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAED;;;OAGG;IACa,SAAS;QACrB,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;QACnF,mBAAmB,CAAC,UAAU,GAAG,iCAAiC,CAAC;QAEnE,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAU,KAAK,CAAC,aAAkB,EAAE,KAAY,EAAE,OAAe;QAC1E,MAAM,OAAO,GAAG,mBAAmB,CAAC,KAAK,CACrC,GAAG,EAAE,CAAC,IAAI,uBAAuB,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,CAAC,gBAAgB,CAAC,EAC5H,aAAa,EACb,KAAK,EACL,OAAO,CACV,CAAC;QAEF,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAnEG;IADC,SAAS,EAAE;kEAGX;AAQD;IADC,SAAS,EAAE;wDAGX;AAQD;IADC,SAAS,EAAE;iEAGX;AAQD;IADC,SAAS,EAAE;yDAGX;AAqCL,aAAa,CAAC,iCAAiC,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["import { serialize } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { ProceduralTexture } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nimport \"./marbleProceduralTexture.fragment\";\r\n\r\nexport class MarbleProceduralTexture extends ProceduralTexture {\r\n private _numberOfTilesHeight: number = 3;\r\n private _numberOfTilesWidth: number = 3;\r\n private _amplitude: number = 9.0;\r\n private _jointColor = new Color3(0.72, 0.72, 0.72);\r\n\r\n constructor(name: string, size: number, scene: Nullable<Scene> = null, fallbackTexture?: Texture, generateMipMaps?: boolean) {\r\n super(name, size, \"marbleProceduralTexture\", scene, fallbackTexture, generateMipMaps);\r\n this.updateShaderUniforms();\r\n }\r\n\r\n public updateShaderUniforms() {\r\n this.setFloat(\"numberOfTilesHeight\", this._numberOfTilesHeight);\r\n this.setFloat(\"numberOfTilesWidth\", this._numberOfTilesWidth);\r\n this.setFloat(\"amplitude\", this._amplitude);\r\n this.setColor3(\"jointColor\", this._jointColor);\r\n }\r\n\r\n @serialize()\r\n public get numberOfTilesHeight(): number {\r\n return this._numberOfTilesHeight;\r\n }\r\n\r\n public set numberOfTilesHeight(value: number) {\r\n this._numberOfTilesHeight = value;\r\n this.updateShaderUniforms();\r\n }\r\n\r\n @serialize()\r\n public get amplitude(): number {\r\n return this._amplitude;\r\n }\r\n\r\n public set amplitude(value: number) {\r\n this._amplitude = value;\r\n this.updateShaderUniforms();\r\n }\r\n\r\n @serialize()\r\n public get numberOfTilesWidth(): number {\r\n return this._numberOfTilesWidth;\r\n }\r\n\r\n public set numberOfTilesWidth(value: number) {\r\n this._numberOfTilesWidth = value;\r\n this.updateShaderUniforms();\r\n }\r\n\r\n @serialize()\r\n public get jointColor(): Color3 {\r\n return this._jointColor;\r\n }\r\n\r\n public set jointColor(value: Color3) {\r\n this._jointColor = value;\r\n this.updateShaderUniforms();\r\n }\r\n\r\n /**\r\n * Serializes this marble procedural texture\r\n * @returns a serialized marble procedural texture object\r\n */\r\n public override serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this, super.serialize());\r\n serializationObject.customType = \"BABYLON.MarbleProceduralTexture\";\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a Marble Procedural Texture from parsed marble procedural texture data\r\n * @param parsedTexture defines parsed texture data\r\n * @param scene defines the current scene\r\n * @param rootUrl defines the root URL containing marble procedural texture information\r\n * @returns a parsed Marble Procedural Texture\r\n */\r\n public static override Parse(parsedTexture: any, scene: Scene, rootUrl: string): MarbleProceduralTexture {\r\n const texture = SerializationHelper.Parse(\r\n () => new MarbleProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps),\r\n parsedTexture,\r\n scene,\r\n rootUrl\r\n );\r\n\r\n return texture;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.MarbleProceduralTexture\", MarbleProceduralTexture);\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./normalMapProceduralTexture.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/proceduralTextures/src/normalMap/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC","sourcesContent":["export * from \"./normalMapProceduralTexture\";\r\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Texture } from "@onerjs/core/Materials/Textures/texture.js";
|
|
2
|
+
import { ProceduralTexture } from "@onerjs/core/Materials/Textures/Procedurals/proceduralTexture.js";
|
|
3
|
+
import type { Scene } from "@onerjs/core/scene.js";
|
|
4
|
+
import type { Nullable } from "@onerjs/core/types.js";
|
|
5
|
+
import "./normalMapProceduralTexture.fragment.js";
|
|
6
|
+
export declare class NormalMapProceduralTexture extends ProceduralTexture {
|
|
7
|
+
private _baseTexture;
|
|
8
|
+
constructor(name: string, size: number, scene?: Nullable<Scene>, fallbackTexture?: Texture, generateMipMaps?: boolean);
|
|
9
|
+
updateShaderUniforms(): void;
|
|
10
|
+
render(useCameraPostProcess?: boolean): void;
|
|
11
|
+
resize(size: any, generateMipMaps: any): void;
|
|
12
|
+
isReady(): boolean;
|
|
13
|
+
get baseTexture(): Texture;
|
|
14
|
+
set baseTexture(texture: Texture);
|
|
15
|
+
/**
|
|
16
|
+
* Serializes this normal map procedural texture
|
|
17
|
+
* @returns a serialized normal map procedural texture object
|
|
18
|
+
*/
|
|
19
|
+
serialize(): any;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a Normal Map Procedural Texture from parsed normal map procedural texture data
|
|
22
|
+
* @param parsedTexture defines parsed texture data
|
|
23
|
+
* @param scene defines the current scene
|
|
24
|
+
* @param rootUrl defines the root URL containing normal map procedural texture information
|
|
25
|
+
* @returns a parsed Normal Map Procedural Texture
|
|
26
|
+
*/
|
|
27
|
+
static Parse(parsedTexture: any, scene: Scene, rootUrl: string): NormalMapProceduralTexture;
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Do not edit.
|
|
2
|
+
import { ShaderStore } from "@onerjs/core/Engines/shaderStore.js";
|
|
3
|
+
const name = "normalMapProceduralTexturePixelShader";
|
|
4
|
+
const shader = `precision highp float;uniform sampler2D baseSampler;uniform float size;varying vec2 vUV;const vec3 LUMA_COEFFICIENT=vec3(0.2126,0.7152,0.0722);float lumaAtCoord(vec2 coord)
|
|
5
|
+
{vec3 pixel=texture2D(baseSampler,coord).rgb;float luma=dot(pixel,LUMA_COEFFICIENT);return luma;}
|
|
6
|
+
void main()
|
|
7
|
+
{float lumaU0=lumaAtCoord(vUV+vec2(-1.0, 0.0)/size);float lumaU1=lumaAtCoord(vUV+vec2( 1.0, 0.0)/size);float lumaV0=lumaAtCoord(vUV+vec2( 0.0,-1.0)/size);float lumaV1=lumaAtCoord(vUV+vec2( 0.0, 1.0)/size);vec2 slope=(vec2(lumaU0-lumaU1,lumaV0-lumaV1)+1.0)*0.5;gl_FragColor=vec4(slope,1.0,1.0);}
|
|
8
|
+
`;
|
|
9
|
+
// Sideeffect
|
|
10
|
+
if (!ShaderStore.ShadersStore[name]) {
|
|
11
|
+
ShaderStore.ShadersStore[name] = shader;
|
|
12
|
+
}
|
|
13
|
+
/** @internal */
|
|
14
|
+
export const normalMapProceduralTexturePixelShader = { name, shader };
|
|
15
|
+
//# sourceMappingURL=normalMapProceduralTexture.fragment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalMapProceduralTexture.fragment.js","sourceRoot":"","sources":["../../../../dev/proceduralTextures/src/normalMap/normalMapProceduralTexture.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,4CAAiC;AAEvD,MAAM,IAAI,GAAG,uCAAuC,CAAC;AACrD,MAAM,MAAM,GAAG;;;;CAId,CAAC;AACF,aAAa;AACb,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;IAClC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAC5C,CAAC;AACD,gBAAgB;AAChB,MAAM,CAAC,MAAM,qCAAqC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\n\nconst name = \"normalMapProceduralTexturePixelShader\";\nconst shader = `precision highp float;uniform sampler2D baseSampler;uniform float size;varying vec2 vUV;const vec3 LUMA_COEFFICIENT=vec3(0.2126,0.7152,0.0722);float lumaAtCoord(vec2 coord)\n{vec3 pixel=texture2D(baseSampler,coord).rgb;float luma=dot(pixel,LUMA_COEFFICIENT);return luma;}\nvoid main()\n{float lumaU0=lumaAtCoord(vUV+vec2(-1.0, 0.0)/size);float lumaU1=lumaAtCoord(vUV+vec2( 1.0, 0.0)/size);float lumaV0=lumaAtCoord(vUV+vec2( 0.0,-1.0)/size);float lumaV1=lumaAtCoord(vUV+vec2( 0.0, 1.0)/size);vec2 slope=(vec2(lumaU0-lumaU1,lumaV0-lumaV1)+1.0)*0.5;gl_FragColor=vec4(slope,1.0,1.0);}\n`;\n// Sideeffect\nif (!ShaderStore.ShadersStore[name]) {\n ShaderStore.ShadersStore[name] = shader;\n}\n/** @internal */\nexport const normalMapProceduralTexturePixelShader = { name, shader };\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { __decorate } from "@onerjs/core/tslib.es6.js";
|
|
2
|
+
import { serializeAsTexture } from "@onerjs/core/Misc/decorators.js";
|
|
3
|
+
import { SerializationHelper } from "@onerjs/core/Misc/decorators.serialization.js";
|
|
4
|
+
import { ProceduralTexture } from "@onerjs/core/Materials/Textures/Procedurals/proceduralTexture.js";
|
|
5
|
+
import { RegisterClass } from "@onerjs/core/Misc/typeStore.js";
|
|
6
|
+
import "./normalMapProceduralTexture.fragment.js";
|
|
7
|
+
export class NormalMapProceduralTexture extends ProceduralTexture {
|
|
8
|
+
constructor(name, size, scene = null, fallbackTexture, generateMipMaps) {
|
|
9
|
+
super(name, size, "normalMapProceduralTexture", scene, fallbackTexture, generateMipMaps);
|
|
10
|
+
this.updateShaderUniforms();
|
|
11
|
+
}
|
|
12
|
+
updateShaderUniforms() {
|
|
13
|
+
this.setTexture("baseSampler", this._baseTexture);
|
|
14
|
+
this.setFloat("size", this.getRenderSize());
|
|
15
|
+
}
|
|
16
|
+
render(useCameraPostProcess) {
|
|
17
|
+
super.render(useCameraPostProcess);
|
|
18
|
+
}
|
|
19
|
+
resize(size, generateMipMaps) {
|
|
20
|
+
super.resize(size, generateMipMaps);
|
|
21
|
+
// We need to update the "size" uniform
|
|
22
|
+
this.updateShaderUniforms();
|
|
23
|
+
}
|
|
24
|
+
isReady() {
|
|
25
|
+
if (!this._baseTexture || !this._baseTexture.isReady()) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return super.isReady();
|
|
29
|
+
}
|
|
30
|
+
get baseTexture() {
|
|
31
|
+
return this._baseTexture;
|
|
32
|
+
}
|
|
33
|
+
set baseTexture(texture) {
|
|
34
|
+
this._baseTexture = texture;
|
|
35
|
+
this.updateShaderUniforms();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Serializes this normal map procedural texture
|
|
39
|
+
* @returns a serialized normal map procedural texture object
|
|
40
|
+
*/
|
|
41
|
+
serialize() {
|
|
42
|
+
const serializationObject = SerializationHelper.Serialize(this, super.serialize());
|
|
43
|
+
serializationObject.customType = "BABYLON.NormalMapProceduralTexture";
|
|
44
|
+
return serializationObject;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a Normal Map Procedural Texture from parsed normal map procedural texture data
|
|
48
|
+
* @param parsedTexture defines parsed texture data
|
|
49
|
+
* @param scene defines the current scene
|
|
50
|
+
* @param rootUrl defines the root URL containing normal map procedural texture information
|
|
51
|
+
* @returns a parsed Normal Map Procedural Texture
|
|
52
|
+
*/
|
|
53
|
+
static Parse(parsedTexture, scene, rootUrl) {
|
|
54
|
+
const texture = SerializationHelper.Parse(() => new NormalMapProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
|
|
55
|
+
return texture;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
__decorate([
|
|
59
|
+
serializeAsTexture()
|
|
60
|
+
], NormalMapProceduralTexture.prototype, "baseTexture", null);
|
|
61
|
+
RegisterClass("BABYLON.NormalMapProceduralTexture", NormalMapProceduralTexture);
|
|
62
|
+
//# sourceMappingURL=normalMapProceduralTexture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalMapProceduralTexture.js","sourceRoot":"","sources":["../../../../dev/proceduralTextures/src/normalMap/normalMapProceduralTexture.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,wCAA6B;AAC1D,OAAO,EAAE,mBAAmB,EAAE,sDAA2C;AAEzE,OAAO,EAAE,iBAAiB,EAAE,yEAA8D;AAE1F,OAAO,EAAE,aAAa,EAAE,uCAA4B;AAEpD,OAAO,uCAAuC,CAAC;AAE/C,MAAM,OAAO,0BAA2B,SAAQ,iBAAiB;IAG7D,YAAY,IAAY,EAAE,IAAY,EAAE,QAAyB,IAAI,EAAE,eAAyB,EAAE,eAAyB;QACvH,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,4BAA4B,EAAE,KAAK,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;QACzF,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAEM,oBAAoB;QACvB,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAY,CAAC,CAAC;IAC1D,CAAC;IAEe,MAAM,CAAC,oBAA8B;QACjD,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACvC,CAAC;IAEe,MAAM,CAAC,IAAS,EAAE,eAAoB;QAClD,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAEpC,uCAAuC;QACvC,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAEe,OAAO;QACnB,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC;YACrD,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAGD,IAAW,WAAW;QAClB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED,IAAW,WAAW,CAAC,OAAgB;QACnC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;QAC5B,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAED;;;OAGG;IACa,SAAS;QACrB,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;QACnF,mBAAmB,CAAC,UAAU,GAAG,oCAAoC,CAAC;QAEtE,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAU,KAAK,CAAC,aAAkB,EAAE,KAAY,EAAE,OAAe;QAC1E,MAAM,OAAO,GAAG,mBAAmB,CAAC,KAAK,CACrC,GAAG,EAAE,CAAC,IAAI,0BAA0B,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,CAAC,gBAAgB,CAAC,EAC/H,aAAa,EACb,KAAK,EACL,OAAO,CACV,CAAC;QAEF,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AArCG;IADC,kBAAkB,EAAE;6DAGpB;AAqCL,aAAa,CAAC,oCAAoC,EAAE,0BAA0B,CAAC,CAAC","sourcesContent":["import { serializeAsTexture } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { ProceduralTexture } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport type { Nullable } from \"core/types\";\r\nimport \"./normalMapProceduralTexture.fragment\";\r\n\r\nexport class NormalMapProceduralTexture extends ProceduralTexture {\r\n private _baseTexture: Texture;\r\n\r\n constructor(name: string, size: number, scene: Nullable<Scene> = null, fallbackTexture?: Texture, generateMipMaps?: boolean) {\r\n super(name, size, \"normalMapProceduralTexture\", scene, fallbackTexture, generateMipMaps);\r\n this.updateShaderUniforms();\r\n }\r\n\r\n public updateShaderUniforms() {\r\n this.setTexture(\"baseSampler\", this._baseTexture);\r\n this.setFloat(\"size\", this.getRenderSize() as number);\r\n }\r\n\r\n public override render(useCameraPostProcess?: boolean) {\r\n super.render(useCameraPostProcess);\r\n }\r\n\r\n public override resize(size: any, generateMipMaps: any): void {\r\n super.resize(size, generateMipMaps);\r\n\r\n // We need to update the \"size\" uniform\r\n this.updateShaderUniforms();\r\n }\r\n\r\n public override isReady(): boolean {\r\n if (!this._baseTexture || !this._baseTexture.isReady()) {\r\n return false;\r\n }\r\n\r\n return super.isReady();\r\n }\r\n\r\n @serializeAsTexture()\r\n public get baseTexture(): Texture {\r\n return this._baseTexture;\r\n }\r\n\r\n public set baseTexture(texture: Texture) {\r\n this._baseTexture = texture;\r\n this.updateShaderUniforms();\r\n }\r\n\r\n /**\r\n * Serializes this normal map procedural texture\r\n * @returns a serialized normal map procedural texture object\r\n */\r\n public override serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this, super.serialize());\r\n serializationObject.customType = \"BABYLON.NormalMapProceduralTexture\";\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a Normal Map Procedural Texture from parsed normal map procedural texture data\r\n * @param parsedTexture defines parsed texture data\r\n * @param scene defines the current scene\r\n * @param rootUrl defines the root URL containing normal map procedural texture information\r\n * @returns a parsed Normal Map Procedural Texture\r\n */\r\n public static override Parse(parsedTexture: any, scene: Scene, rootUrl: string): NormalMapProceduralTexture {\r\n const texture = SerializationHelper.Parse(\r\n () => new NormalMapProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps),\r\n parsedTexture,\r\n scene,\r\n rootUrl\r\n );\r\n\r\n return texture;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.NormalMapProceduralTexture\", NormalMapProceduralTexture);\r\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onerjs/procedural-textures",
|
|
3
|
+
"version": "8.25.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"module": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"**/*.js",
|
|
9
|
+
"**/*.d.ts",
|
|
10
|
+
"**/*.map",
|
|
11
|
+
"readme.md",
|
|
12
|
+
"license.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "npm run clean && npm run compile",
|
|
16
|
+
"clean": "rimraf dist && rimraf *.tsbuildinfo -g && rimraf \"./**/*.!(md|json|build.json|lts.json)\" -g",
|
|
17
|
+
"compile": "tsc -b tsconfig.build.json && tsc -b tsconfig.lts.json",
|
|
18
|
+
"postcompile": "build-tools -c add-js-to-es6"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@onerjs/core": "^8.25.0",
|
|
22
|
+
"@dev/build-tools": "^1.0.0",
|
|
23
|
+
"@lts/procedural-textures": "^1.0.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@onerjs/core": "^8.0.0"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"3D",
|
|
30
|
+
"javascript",
|
|
31
|
+
"html5",
|
|
32
|
+
"webgl",
|
|
33
|
+
"babylon.js"
|
|
34
|
+
],
|
|
35
|
+
"license": "Apache-2.0",
|
|
36
|
+
"esnext": "index.js",
|
|
37
|
+
"type": "module",
|
|
38
|
+
"sideEffects": true,
|
|
39
|
+
"homepage": "https://www.babylonjs.com",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/BabylonJS/Babylon.js.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/BabylonJS/Babylon.js/issues"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./perlinNoiseProceduralTexture.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/proceduralTextures/src/perlinNoise/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC","sourcesContent":["export * from \"./perlinNoiseProceduralTexture\";\r\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Texture } from "@onerjs/core/Materials/Textures/texture.js";
|
|
2
|
+
import { ProceduralTexture } from "@onerjs/core/Materials/Textures/Procedurals/proceduralTexture.js";
|
|
3
|
+
import type { Scene } from "@onerjs/core/scene.js";
|
|
4
|
+
import type { Nullable } from "@onerjs/core/types.js";
|
|
5
|
+
import "./perlinNoiseProceduralTexture.fragment.js";
|
|
6
|
+
export declare class PerlinNoiseProceduralTexture extends ProceduralTexture {
|
|
7
|
+
time: number;
|
|
8
|
+
timeScale: number;
|
|
9
|
+
translationSpeed: number;
|
|
10
|
+
private _currentTranslation;
|
|
11
|
+
constructor(name: string, size: number, scene?: Nullable<Scene>, fallbackTexture?: Texture, generateMipMaps?: boolean);
|
|
12
|
+
updateShaderUniforms(): void;
|
|
13
|
+
render(useCameraPostProcess?: boolean): void;
|
|
14
|
+
resize(size: any, generateMipMaps: any): void;
|
|
15
|
+
/**
|
|
16
|
+
* Serializes this perlin noise procedural texture
|
|
17
|
+
* @returns a serialized perlin noise procedural texture object
|
|
18
|
+
*/
|
|
19
|
+
serialize(): any;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a Perlin Noise Procedural Texture from parsed perlin noise procedural texture data
|
|
22
|
+
* @param parsedTexture defines parsed texture data
|
|
23
|
+
* @param scene defines the current scene
|
|
24
|
+
* @param rootUrl defines the root URL containing perlin noise procedural texture information
|
|
25
|
+
* @returns a parsed Perlin Noise Procedural Texture
|
|
26
|
+
*/
|
|
27
|
+
static Parse(parsedTexture: any, scene: Scene, rootUrl: string): PerlinNoiseProceduralTexture;
|
|
28
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Do not edit.
|
|
2
|
+
import { ShaderStore } from "@onerjs/core/Engines/shaderStore.js";
|
|
3
|
+
const name = "perlinNoiseProceduralTexturePixelShader";
|
|
4
|
+
const shader = `precision highp float;uniform float size;uniform float time;uniform float translationSpeed;varying vec2 vUV;float r(float n)
|
|
5
|
+
{return fract(cos(n*89.42)*343.42);}
|
|
6
|
+
vec2 r(vec2 n)
|
|
7
|
+
{return vec2(r(n.x*23.62-300.0+n.y*34.35),r(n.x*45.13+256.0+n.y*38.89)); }
|
|
8
|
+
float worley(vec2 n,float s)
|
|
9
|
+
{float dis=1.0;for(int x=-1; x<=1; x++)
|
|
10
|
+
{for(int y=-1; y<=1; y++)
|
|
11
|
+
{vec2 p=floor(n/s)+vec2(x,y);float d=length(r(p)+vec2(x,y)-fract(n/s));if (dis>d)
|
|
12
|
+
dis=d;}}
|
|
13
|
+
return 1.0-dis;}
|
|
14
|
+
vec3 hash33(vec3 p3)
|
|
15
|
+
{p3=fract(p3*vec3(0.1031,0.11369,0.13787));p3+=dot(p3,p3.yxz+19.19);return -1.0+2.0*fract(vec3((p3.x+p3.y)*p3.z,(p3.x+p3.z)*p3.y,(p3.y+p3.z)*p3.x));}
|
|
16
|
+
float perlinNoise(vec3 p)
|
|
17
|
+
{vec3 pi=floor(p);vec3 pf=p-pi;vec3 w=pf*pf*(3.0-2.0*pf);return mix(
|
|
18
|
+
mix(
|
|
19
|
+
mix(
|
|
20
|
+
dot(pf-vec3(0,0,0),hash33(pi+vec3(0,0,0))),
|
|
21
|
+
dot(pf-vec3(1,0,0),hash33(pi+vec3(1,0,0))),
|
|
22
|
+
w.x
|
|
23
|
+
),
|
|
24
|
+
mix(
|
|
25
|
+
dot(pf-vec3(0,0,1),hash33(pi+vec3(0,0,1))),
|
|
26
|
+
dot(pf-vec3(1,0,1),hash33(pi+vec3(1,0,1))),
|
|
27
|
+
w.x
|
|
28
|
+
),
|
|
29
|
+
w.z
|
|
30
|
+
),
|
|
31
|
+
mix(
|
|
32
|
+
mix(
|
|
33
|
+
dot(pf-vec3(0,1,0),hash33(pi+vec3(0,1,0))),
|
|
34
|
+
dot(pf-vec3(1,1,0),hash33(pi+vec3(1,1,0))),
|
|
35
|
+
w.x
|
|
36
|
+
),
|
|
37
|
+
mix(
|
|
38
|
+
dot(pf-vec3(0,1,1),hash33(pi+vec3(0,1,1))),
|
|
39
|
+
dot(pf-vec3(1,1,1),hash33(pi+vec3(1,1,1))),
|
|
40
|
+
w.x
|
|
41
|
+
),
|
|
42
|
+
w.z
|
|
43
|
+
),
|
|
44
|
+
w.y
|
|
45
|
+
);}
|
|
46
|
+
#define CUSTOM_FRAGMENT_DEFINITIONS
|
|
47
|
+
void main(void)
|
|
48
|
+
{vec2 uv=gl_FragCoord.xy+translationSpeed;float dis=(
|
|
49
|
+
1.0+perlinNoise(vec3(uv/vec2(size,size),time*0.05)*8.0))
|
|
50
|
+
* (1.0+(worley(uv,32.0)+ 0.5*worley(2.0*uv,32.0)+0.25*worley(4.0*uv,32.0))
|
|
51
|
+
);gl_FragColor=vec4(vec3(dis/4.0),1.0);}
|
|
52
|
+
`;
|
|
53
|
+
// Sideeffect
|
|
54
|
+
if (!ShaderStore.ShadersStore[name]) {
|
|
55
|
+
ShaderStore.ShadersStore[name] = shader;
|
|
56
|
+
}
|
|
57
|
+
/** @internal */
|
|
58
|
+
export const perlinNoiseProceduralTexturePixelShader = { name, shader };
|
|
59
|
+
//# sourceMappingURL=perlinNoiseProceduralTexture.fragment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perlinNoiseProceduralTexture.fragment.js","sourceRoot":"","sources":["../../../../dev/proceduralTextures/src/perlinNoise/perlinNoiseProceduralTexture.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,4CAAiC;AAEvD,MAAM,IAAI,GAAG,yCAAyC,CAAC;AACvD,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDd,CAAC;AACF,aAAa;AACb,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;IAClC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAC5C,CAAC;AACD,gBAAgB;AAChB,MAAM,CAAC,MAAM,uCAAuC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\n\nconst name = \"perlinNoiseProceduralTexturePixelShader\";\nconst shader = `precision highp float;uniform float size;uniform float time;uniform float translationSpeed;varying vec2 vUV;float r(float n)\n{return fract(cos(n*89.42)*343.42);}\nvec2 r(vec2 n)\n{return vec2(r(n.x*23.62-300.0+n.y*34.35),r(n.x*45.13+256.0+n.y*38.89)); }\nfloat worley(vec2 n,float s)\n{float dis=1.0;for(int x=-1; x<=1; x++)\n{for(int y=-1; y<=1; y++)\n{vec2 p=floor(n/s)+vec2(x,y);float d=length(r(p)+vec2(x,y)-fract(n/s));if (dis>d)\ndis=d;}}\nreturn 1.0-dis;}\nvec3 hash33(vec3 p3)\n{p3=fract(p3*vec3(0.1031,0.11369,0.13787));p3+=dot(p3,p3.yxz+19.19);return -1.0+2.0*fract(vec3((p3.x+p3.y)*p3.z,(p3.x+p3.z)*p3.y,(p3.y+p3.z)*p3.x));}\nfloat perlinNoise(vec3 p)\n{vec3 pi=floor(p);vec3 pf=p-pi;vec3 w=pf*pf*(3.0-2.0*pf);return mix(\nmix(\nmix(\ndot(pf-vec3(0,0,0),hash33(pi+vec3(0,0,0))),\ndot(pf-vec3(1,0,0),hash33(pi+vec3(1,0,0))),\nw.x\n),\nmix(\ndot(pf-vec3(0,0,1),hash33(pi+vec3(0,0,1))),\ndot(pf-vec3(1,0,1),hash33(pi+vec3(1,0,1))),\nw.x\n),\nw.z\n),\nmix(\nmix(\ndot(pf-vec3(0,1,0),hash33(pi+vec3(0,1,0))),\ndot(pf-vec3(1,1,0),hash33(pi+vec3(1,1,0))),\nw.x\n),\nmix(\ndot(pf-vec3(0,1,1),hash33(pi+vec3(0,1,1))),\ndot(pf-vec3(1,1,1),hash33(pi+vec3(1,1,1))),\nw.x\n),\nw.z\n),\nw.y\n);}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{vec2 uv=gl_FragCoord.xy+translationSpeed;float dis=(\n1.0+perlinNoise(vec3(uv/vec2(size,size),time*0.05)*8.0))\n* (1.0+(worley(uv,32.0)+ 0.5*worley(2.0*uv,32.0)+0.25*worley(4.0*uv,32.0))\n);gl_FragColor=vec4(vec3(dis/4.0),1.0);}\n`;\n// Sideeffect\nif (!ShaderStore.ShadersStore[name]) {\n ShaderStore.ShadersStore[name] = shader;\n}\n/** @internal */\nexport const perlinNoiseProceduralTexturePixelShader = { name, shader };\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { __decorate } from "@onerjs/core/tslib.es6.js";
|
|
2
|
+
import { serialize } from "@onerjs/core/Misc/decorators.js";
|
|
3
|
+
import { SerializationHelper } from "@onerjs/core/Misc/decorators.serialization.js";
|
|
4
|
+
import { ProceduralTexture } from "@onerjs/core/Materials/Textures/Procedurals/proceduralTexture.js";
|
|
5
|
+
import { RegisterClass } from "@onerjs/core/Misc/typeStore.js";
|
|
6
|
+
import "./perlinNoiseProceduralTexture.fragment.js";
|
|
7
|
+
export class PerlinNoiseProceduralTexture extends ProceduralTexture {
|
|
8
|
+
constructor(name, size, scene = null, fallbackTexture, generateMipMaps) {
|
|
9
|
+
super(name, size, "perlinNoiseProceduralTexture", scene, fallbackTexture, generateMipMaps);
|
|
10
|
+
this.time = 0.0;
|
|
11
|
+
this.timeScale = 1.0;
|
|
12
|
+
this.translationSpeed = 1.0;
|
|
13
|
+
this._currentTranslation = 0;
|
|
14
|
+
this.updateShaderUniforms();
|
|
15
|
+
}
|
|
16
|
+
updateShaderUniforms() {
|
|
17
|
+
this.setFloat("size", this.getRenderSize());
|
|
18
|
+
const scene = this.getScene();
|
|
19
|
+
if (!scene) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const deltaTime = scene.getEngine().getDeltaTime();
|
|
23
|
+
this.time += deltaTime;
|
|
24
|
+
this.setFloat("time", (this.time * this.timeScale) / 1000);
|
|
25
|
+
this._currentTranslation += (deltaTime * this.translationSpeed) / 1000.0;
|
|
26
|
+
this.setFloat("translationSpeed", this._currentTranslation);
|
|
27
|
+
}
|
|
28
|
+
render(useCameraPostProcess) {
|
|
29
|
+
this.updateShaderUniforms();
|
|
30
|
+
super.render(useCameraPostProcess);
|
|
31
|
+
}
|
|
32
|
+
resize(size, generateMipMaps) {
|
|
33
|
+
super.resize(size, generateMipMaps);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Serializes this perlin noise procedural texture
|
|
37
|
+
* @returns a serialized perlin noise procedural texture object
|
|
38
|
+
*/
|
|
39
|
+
serialize() {
|
|
40
|
+
const serializationObject = SerializationHelper.Serialize(this, super.serialize());
|
|
41
|
+
serializationObject.customType = "BABYLON.PerlinNoiseProceduralTexture";
|
|
42
|
+
return serializationObject;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates a Perlin Noise Procedural Texture from parsed perlin noise procedural texture data
|
|
46
|
+
* @param parsedTexture defines parsed texture data
|
|
47
|
+
* @param scene defines the current scene
|
|
48
|
+
* @param rootUrl defines the root URL containing perlin noise procedural texture information
|
|
49
|
+
* @returns a parsed Perlin Noise Procedural Texture
|
|
50
|
+
*/
|
|
51
|
+
static Parse(parsedTexture, scene, rootUrl) {
|
|
52
|
+
const texture = SerializationHelper.Parse(() => new PerlinNoiseProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps), parsedTexture, scene, rootUrl);
|
|
53
|
+
return texture;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
__decorate([
|
|
57
|
+
serialize()
|
|
58
|
+
], PerlinNoiseProceduralTexture.prototype, "time", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
serialize()
|
|
61
|
+
], PerlinNoiseProceduralTexture.prototype, "timeScale", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
serialize()
|
|
64
|
+
], PerlinNoiseProceduralTexture.prototype, "translationSpeed", void 0);
|
|
65
|
+
RegisterClass("BABYLON.PerlinNoiseProceduralTexture", PerlinNoiseProceduralTexture);
|
|
66
|
+
//# sourceMappingURL=perlinNoiseProceduralTexture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perlinNoiseProceduralTexture.js","sourceRoot":"","sources":["../../../../dev/proceduralTextures/src/perlinNoise/perlinNoiseProceduralTexture.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,wCAA6B;AACjD,OAAO,EAAE,mBAAmB,EAAE,sDAA2C;AAEzE,OAAO,EAAE,iBAAiB,EAAE,yEAA8D;AAE1F,OAAO,EAAE,aAAa,EAAE,uCAA4B;AAEpD,OAAO,yCAAyC,CAAC;AAEjD,MAAM,OAAO,4BAA6B,SAAQ,iBAAiB;IAY/D,YAAY,IAAY,EAAE,IAAY,EAAE,QAAyB,IAAI,EAAE,eAAyB,EAAE,eAAyB;QACvH,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,8BAA8B,EAAE,KAAK,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;QAXxF,SAAI,GAAW,GAAG,CAAC;QAGnB,cAAS,GAAW,GAAG,CAAC;QAGxB,qBAAgB,GAAW,GAAG,CAAC;QAE9B,wBAAmB,GAAW,CAAC,CAAC;QAIpC,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAChC,CAAC;IAEM,oBAAoB;QACvB,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAY,CAAC,CAAC;QAEtD,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAE9B,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,OAAO;QACX,CAAC;QACD,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC,YAAY,EAAE,CAAC;QAEnD,IAAI,CAAC,IAAI,IAAI,SAAS,CAAC;QACvB,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;QAE3D,IAAI,CAAC,mBAAmB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAC;QACzE,IAAI,CAAC,QAAQ,CAAC,kBAAkB,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAChE,CAAC;IAEe,MAAM,CAAC,oBAA8B;QACjD,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACvC,CAAC;IAEe,MAAM,CAAC,IAAS,EAAE,eAAoB;QAClD,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACa,SAAS;QACrB,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;QACnF,mBAAmB,CAAC,UAAU,GAAG,sCAAsC,CAAC;QAExE,OAAO,mBAAmB,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAU,KAAK,CAAC,aAAkB,EAAE,KAAY,EAAE,OAAe;QAC1E,MAAM,OAAO,GAAG,mBAAmB,CAAC,KAAK,CACrC,GAAG,EAAE,CAAC,IAAI,4BAA4B,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,CAAC,gBAAgB,CAAC,EACjI,aAAa,EACb,KAAK,EACL,OAAO,CACV,CAAC;QAEF,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AArEU;IADN,SAAS,EAAE;0DACc;AAGnB;IADN,SAAS,EAAE;+DACmB;AAGxB;IADN,SAAS,EAAE;sEAC0B;AAiE1C,aAAa,CAAC,sCAAsC,EAAE,4BAA4B,CAAC,CAAC","sourcesContent":["import { serialize } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport type { Texture } from \"core/Materials/Textures/texture\";\r\nimport { ProceduralTexture } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\r\nimport type { Scene } from \"core/scene\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport type { Nullable } from \"core/types\";\r\nimport \"./perlinNoiseProceduralTexture.fragment\";\r\n\r\nexport class PerlinNoiseProceduralTexture extends ProceduralTexture {\r\n @serialize()\r\n public time: number = 0.0;\r\n\r\n @serialize()\r\n public timeScale: number = 1.0;\r\n\r\n @serialize()\r\n public translationSpeed: number = 1.0;\r\n\r\n private _currentTranslation: number = 0;\r\n\r\n constructor(name: string, size: number, scene: Nullable<Scene> = null, fallbackTexture?: Texture, generateMipMaps?: boolean) {\r\n super(name, size, \"perlinNoiseProceduralTexture\", scene, fallbackTexture, generateMipMaps);\r\n this.updateShaderUniforms();\r\n }\r\n\r\n public updateShaderUniforms() {\r\n this.setFloat(\"size\", this.getRenderSize() as number);\r\n\r\n const scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n const deltaTime = scene.getEngine().getDeltaTime();\r\n\r\n this.time += deltaTime;\r\n this.setFloat(\"time\", (this.time * this.timeScale) / 1000);\r\n\r\n this._currentTranslation += (deltaTime * this.translationSpeed) / 1000.0;\r\n this.setFloat(\"translationSpeed\", this._currentTranslation);\r\n }\r\n\r\n public override render(useCameraPostProcess?: boolean) {\r\n this.updateShaderUniforms();\r\n super.render(useCameraPostProcess);\r\n }\r\n\r\n public override resize(size: any, generateMipMaps: any): void {\r\n super.resize(size, generateMipMaps);\r\n }\r\n\r\n /**\r\n * Serializes this perlin noise procedural texture\r\n * @returns a serialized perlin noise procedural texture object\r\n */\r\n public override serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this, super.serialize());\r\n serializationObject.customType = \"BABYLON.PerlinNoiseProceduralTexture\";\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a Perlin Noise Procedural Texture from parsed perlin noise procedural texture data\r\n * @param parsedTexture defines parsed texture data\r\n * @param scene defines the current scene\r\n * @param rootUrl defines the root URL containing perlin noise procedural texture information\r\n * @returns a parsed Perlin Noise Procedural Texture\r\n */\r\n public static override Parse(parsedTexture: any, scene: Scene, rootUrl: string): PerlinNoiseProceduralTexture {\r\n const texture = SerializationHelper.Parse(\r\n () => new PerlinNoiseProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps),\r\n parsedTexture,\r\n scene,\r\n rootUrl\r\n );\r\n\r\n return texture;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.PerlinNoiseProceduralTexture\", PerlinNoiseProceduralTexture);\r\n"]}
|
package/readme.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Babylon.js Procedural Textures Library
|
|
2
|
+
=====================
|
|
3
|
+
|
|
4
|
+
For usage documentation please visit https://doc.babylonjs.com/extensions and choose "procedural textures library".
|
|
5
|
+
|
|
6
|
+
# Installation instructions
|
|
7
|
+
|
|
8
|
+
To install using npm :
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm install --save @babylonjs/core @babylonjs/procedural-textures
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
# How to use
|
|
15
|
+
|
|
16
|
+
Afterwards it can be imported to your project using:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';
|
|
20
|
+
import { FireProceduralTexture } from '@babylonjs/procedural-textures/fireProceduralTexture';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
And used as usual:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
// Some awesome code
|
|
27
|
+
var fireMaterial = new StandardMaterial("fontainSculptur2", scene);
|
|
28
|
+
var fireTexture = new FireProceduralTexture("fire", 256, scene);
|
|
29
|
+
fireMaterial.diffuseTexture = fireTexture;
|
|
30
|
+
fireMaterial.opacityTexture = fireTexture;
|
|
31
|
+
// Some more awesome code
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For more information you can have a look at our [ES6 dedicated documentation](https://doc.babylonjs.com/features/es6_support).
|
package/road/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./roadProceduralTexture.js";
|
package/road/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/proceduralTextures/src/road/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC","sourcesContent":["export * from \"./roadProceduralTexture\";\r\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Color3 } from "@onerjs/core/Maths/math.color.js";
|
|
2
|
+
import type { Texture } from "@onerjs/core/Materials/Textures/texture.js";
|
|
3
|
+
import { ProceduralTexture } from "@onerjs/core/Materials/Textures/Procedurals/proceduralTexture.js";
|
|
4
|
+
import type { Scene } from "@onerjs/core/scene.js";
|
|
5
|
+
import type { Nullable } from "@onerjs/core/types.js";
|
|
6
|
+
import "./roadProceduralTexture.fragment.js";
|
|
7
|
+
export declare class RoadProceduralTexture extends ProceduralTexture {
|
|
8
|
+
private _roadColor;
|
|
9
|
+
constructor(name: string, size: number, scene?: Nullable<Scene>, fallbackTexture?: Texture, generateMipMaps?: boolean);
|
|
10
|
+
updateShaderUniforms(): void;
|
|
11
|
+
get roadColor(): Color3;
|
|
12
|
+
set roadColor(value: Color3);
|
|
13
|
+
/**
|
|
14
|
+
* Serializes this road procedural texture
|
|
15
|
+
* @returns a serialized road procedural texture object
|
|
16
|
+
*/
|
|
17
|
+
serialize(): any;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a Road Procedural Texture from parsed road procedural texture data
|
|
20
|
+
* @param parsedTexture defines parsed texture data
|
|
21
|
+
* @param scene defines the current scene
|
|
22
|
+
* @param rootUrl defines the root URL containing road procedural texture information
|
|
23
|
+
* @returns a parsed Road Procedural Texture
|
|
24
|
+
*/
|
|
25
|
+
static Parse(parsedTexture: any, scene: Scene, rootUrl: string): RoadProceduralTexture;
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Do not edit.
|
|
2
|
+
import { ShaderStore } from "@onerjs/core/Engines/shaderStore.js";
|
|
3
|
+
const name = "roadProceduralTexturePixelShader";
|
|
4
|
+
const shader = `precision highp float;varying vec2 vUV;
|
|
5
|
+
uniform vec3 roadColor;float rand(vec2 n) {return fract(cos(dot(n,vec2(12.9898,4.1414)))*43758.5453);}
|
|
6
|
+
float noise(vec2 n) {const vec2 d=vec2(0.0,1.0);vec2 b=floor(n),f=smoothstep(vec2(0.0),vec2(1.0),fract(n));return mix(mix(rand(b),rand(b+d.yx),f.x),mix(rand(b+d.xy),rand(b+d.yy),f.x),f.y);}
|
|
7
|
+
float fbm(vec2 n) {float total=0.0,amplitude=1.0;for (int i=0; i<4; i++) {total+=noise(n)*amplitude;n+=n;amplitude*=0.5;}
|
|
8
|
+
return total;}
|
|
9
|
+
#define CUSTOM_FRAGMENT_DEFINITIONS
|
|
10
|
+
void main(void) {
|
|
11
|
+
#define CUSTOM_FRAGMENT_MAIN_BEGIN
|
|
12
|
+
float ratioy=mod(gl_FragCoord.y*100.0 ,fbm(vUV*2.0));vec3 color=roadColor*ratioy;gl_FragColor=vec4(color,1.0);
|
|
13
|
+
#define CUSTOM_FRAGMENT_MAIN_END
|
|
14
|
+
}`;
|
|
15
|
+
// Sideeffect
|
|
16
|
+
if (!ShaderStore.ShadersStore[name]) {
|
|
17
|
+
ShaderStore.ShadersStore[name] = shader;
|
|
18
|
+
}
|
|
19
|
+
/** @internal */
|
|
20
|
+
export const roadProceduralTexturePixelShader = { name, shader };
|
|
21
|
+
//# sourceMappingURL=roadProceduralTexture.fragment.js.map
|