Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
avvy
web-app-avvy-shaderlib
Commits
df127c17
Commit
df127c17
authored
3 years ago
by
Vlad Gaydukov
Browse files
Options
Download
Plain Diff
Merge branch '
AL-7339
-media' into 'master'
Al 7339 media See merge request avvy/web-app-avvy-shaderlib!11
parents
ff42d123
fa580b07
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
assets/build/mediablock_alpha.png
+0
-0
assets/build/mediablock_alpha.png
build/avvy-shaderlib.js
+128
-37
build/avvy-shaderlib.js
public/js/avvy-shader-editor.js
+255
-116
public/js/avvy-shader-editor.js
src/editor/mocks/MockMedia.js
+14
-0
src/editor/mocks/MockMedia.js
src/editor/modules/MockController.js
+2
-0
src/editor/modules/MockController.js
src/editor/settings.js
+6
-3
src/editor/settings.js
src/library/ShaderLib.js
+2
-0
src/library/ShaderLib.js
src/library/glsl/fs/media.fs.glsl
+22
-0
src/library/glsl/fs/media.fs.glsl
src/library/glsl/fs/media_pars.fs.glsl
+42
-0
src/library/glsl/fs/media_pars.fs.glsl
src/library/glsl/vs/media.vs.glsl
+2
-0
src/library/glsl/vs/media.vs.glsl
src/library/glsl/vs/media_pars.vs.glsl
+4
-0
src/library/glsl/vs/media_pars.vs.glsl
src/library/materials/Media.js
+78
-0
src/library/materials/Media.js
with
555 additions
and
156 deletions
+555
-156
assets/build/mediablock_alpha.png
0 → 100755
View file @
df127c17
17.9 KB
This diff is collapsed.
Click to expand it.
build/avvy-shaderlib.js
View file @
df127c17
...
...
@@ -134,7 +134,9 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */
var
__WEBPACK_IMPORTED_MODULE_5__materials_Water__
=
__webpack_require__
(
19
);
/* harmony import */
var
__WEBPACK_IMPORTED_MODULE_6__materials_Simple__
=
__webpack_require__
(
24
);
/* harmony import */
var
__WEBPACK_IMPORTED_MODULE_7__materials_PBR__
=
__webpack_require__
(
27
);
/* harmony import */
var
__WEBPACK_IMPORTED_MODULE_8__materials_Colormap__
=
__webpack_require__
(
32
);
/* harmony import */
var
__WEBPACK_IMPORTED_MODULE_8__materials_Colormap__
=
__webpack_require__
(
28
);
/* harmony import */
var
__WEBPACK_IMPORTED_MODULE_9__materials_Media__
=
__webpack_require__
(
33
);
...
...
@@ -157,6 +159,7 @@ function ShaderLib() {
'
flower
'
:
__WEBPACK_IMPORTED_MODULE_0__materials_Flower__
[
"
a
"
/* Flower */
],
'
PBR
'
:
__WEBPACK_IMPORTED_MODULE_7__materials_PBR__
[
"
a
"
/* PBR */
],
'
colormap
'
:
__WEBPACK_IMPORTED_MODULE_8__materials_Colormap__
[
"
a
"
/* ColorMap */
],
'
media
'
:
__WEBPACK_IMPORTED_MODULE_9__materials_Media__
[
"
a
"
/* Media */
],
};
this
.
matObjects
=
{};
...
...
@@ -768,17 +771,19 @@ PBR.prototype.init = function () {
this
.
material
.
userData
.
args
=
this
.
args
;
this
.
material
.
userData
.
effect
=
'
PBR
'
;
/*
this.material.onBeforeCompile = function (shader) {
shader
.
vertexShader
=
__webpack_require__
(
28
)
+
shader
.
vertexShader
;
shader.vertexShader =
require('../glsl/vs/post_outline_pars.vs.glsl'
) + shader.vertexShader;
shader.vertexShader = shader.vertexShader.replace('#include <begin_vertex>',
__webpack_require__
(
29
));
require('../glsl/vs/post_outline.vs.glsl'
));
shader
.
fragmentShader
=
__webpack_require__
(
30
)
+
shader
.
fragmentShader
;
shader.fragmentShader =
require('../glsl/fs/post_outline_pars.fs.glsl'
) + shader.fragmentShader;
shader.fragmentShader = shader.fragmentShader.replace('#include <dithering_fragment>',
__webpack_require__
(
31
));
require('../glsl/fs/post_outline.fs.glsl'
));
};
*/
return
this
;
...
...
@@ -789,30 +794,6 @@ PBR.prototype.init = function () {
/***/
}),
/* 28 */
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
varying vec2 _vUv;
\n
varying vec3 _vPosition;
\n
varying vec3 _vNormal;
\n\n
varying vec3 fNormal;
\n
varying vec3 fPosition;
\n
varying vec2 fUv;
\n
"
/***/
}),
/* 29 */
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
vec3 transformed = vec3( position );
\n
_vPosition = transformed;
\n
_vUv = uv;
\n
_vNormal = normal;
\n\n
fNormal = normalize(normalMatrix * normal);
\n
vec4 pos = modelViewMatrix * vec4(position, 1.0);
\n
fPosition = pos.xyz;
\n
fUv = uv;
"
/***/
}),
/* 30 */
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
varying vec2 _vUv;
\n
varying vec3 _vPosition;
\n
varying vec3 _vNormal;
\n\n
varying vec3 fNormal;
\n
varying vec3 fPosition;
\n
varying vec2 fUv;
\n\n\n
/*float calcFactor(vec2 uv, float threshold, float gap) {
\n
return clamp(smoothstep(threshold - gap, threshold + gap, uv.x) + smoothstep(threshold - gap, threshold + gap, uv.y), 0., 1.);
\n
}*/
\n\n
float border(vec2 uv, float uLineWidth, vec2 gap) {
\n
vec2 xy0 = smoothstep(vec2(uLineWidth) - gap, vec2(uLineWidth) + gap, uv);
\n
vec2 xy1 = smoothstep(vec2(1. - uLineWidth) - gap, vec2(1. - uLineWidth) + gap, uv);
\n
vec2 xy = xy0 - xy1;
\n
return clamp(xy.x * xy.y, 0., 1.);
\n
}
\n
"
/***/
}),
/* 31 */
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
/* dithering_fragment */
\n\n
#ifdef DITHERING
\n
gl_FragColor.rgb = dithering( gl_FragColor.rgb );
\n
#endif
\n\n\n
/* custom */
\n\n
/*
\n
float fn = 0.07;
\n
if (_vUv.x < fn || _vUv.x > 1.0-fn || _vUv.y < fn|| _vUv.y > 1.0-fn ) {
\n
gl_FragColor = vec4(1.0,1,0,1.0);
\n
}
\n
*/
\n\n
/*
\n
vec3 uLineColor = vec3(1.0,1.0,1.0);
\n
vec3 uBgColor = gl_FragColor.rgb;
\n
float uLineWidth = 0.01;
\n\n
float threshold = 1. - uLineWidth;
\n
float gap = uLineWidth + .05;
\n
float factor = calcFactor(_vUv, threshold, gap);
\n
gl_FragColor = mix(vec4(uLineColor, 1.), vec4(uBgColor, 1.), 1. - factor);*/
\n\n\n
vec3 uLineColor = vec3(1.0,1.0,1.0);
\n
vec3 uBgColor = gl_FragColor.rgb;
\n
float uLineWidth = 0.01;
\n\n
vec2 fw = vec2(uLineWidth + 0.005);
\n
vec2 coords = _vUv.xy;
\n\n
float br = border(coords, uLineWidth, fw);
\n
gl_FragColor = vec4(mix(uLineColor, uBgColor, br), 1.);
\n
"
/***/
}),
/* 32 */
/***/
(
function
(
module
,
__webpack_exports__
,
__webpack_require__
)
{
"
use strict
"
;
...
...
@@ -849,15 +830,15 @@ ColorMap.prototype.prepare = function () {
this
.
material
.
onBeforeCompile
=
function
(
shader
)
{
shader
.
uniforms
.
uColor
=
this
.
userData
.
uniforms
.
uColor
;
shader
.
fragmentShader
=
__webpack_require__
(
33
)
+
shader
.
fragmentShader
;
shader
.
fragmentShader
=
__webpack_require__
(
29
)
+
shader
.
fragmentShader
;
shader
.
fragmentShader
=
shader
.
fragmentShader
.
replace
(
'
#include <map_fragment>
'
,
__webpack_require__
(
3
4
));
__webpack_require__
(
3
0
));
shader
.
vertexShader
=
__webpack_require__
(
3
5
)
+
shader
.
vertexShader
;
shader
.
vertexShader
=
__webpack_require__
(
3
1
)
+
shader
.
vertexShader
;
shader
.
vertexShader
=
shader
.
vertexShader
.
replace
(
'
#include <begin_vertex>
'
,
__webpack_require__
(
3
6
));
__webpack_require__
(
3
2
));
};
}
return
this
;
...
...
@@ -867,29 +848,139 @@ ColorMap.prototype.prepare = function () {
/***/
}),
/*
33
*/
/*
29
*/
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
uniform vec3 uColor;
\n
varying vec3 vWorldPosition;
\n\n
vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
\n
vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
\n
vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); }
\n\n\n
float snoise(vec2 v) {
\n\n
const vec4 C = vec4(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439);
\n\n
vec2 i = floor(v + dot(v, C.yy));
\n
vec2 x0 = v - i + dot(i, C.xx);
\n\n
vec2 i1 = vec2(0.0);
\n
i1 = (x0.x > x0.y)? vec2(1.0, 0.0):vec2(0.0, 1.0);
\n
vec2 x1 = x0.xy + C.xx - i1;
\n
vec2 x2 = x0.xy + C.zz;
\n\n
i = mod289(i);
\n
vec3 p = permute(
\n
permute( i.y + vec3(0.0, i1.y, 1.0))
\n
+ i.x + vec3(0.0, i1.x, 1.0 ));
\n\n
vec3 m = max(0.5 - vec3(
\n
dot(x0,x0),
\n
dot(x1,x1),
\n
dot(x2,x2)
\n
), 0.0);
\n\n
m = m*m ;
\n
m = m*m ;
\n\n
vec3 x = 2.0 * fract(p * C.www) - 1.0;
\n
vec3 h = abs(x) - 0.5;
\n
vec3 ox = floor(x + 0.5);
\n
vec3 a0 = x - ox;
\n\n
m *= 1.79284291400159 - 0.85373472095314 * (a0*a0+h*h);
\n\n
vec3 g = vec3(0.0);
\n
g.x = a0.x * x0.x + h.x * x0.y;
\n
g.yz = a0.yz * vec2(x1.x,x2.x) + h.yz * vec2(x1.y,x2.y);
\n
return 130.0 * dot(m, g);
\n
}
\n
"
/***/
}),
/* 3
4
*/
/* 3
0
*/
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
#ifdef USE_MAP
\n
vec4 texelColor = texture2D( map, vUv );
\n
texelColor = mapTexelToLinear( texelColor );
\n
diffuseColor *= texelColor;
\n\n
vec2 pos = vec2(vWorldPosition.xz*0.25);
\n
vec3 color = vec3(0.0);
\n\n
pos *= 0.2;
\n\n
color = vec3(snoise(pos)*.5+.5);
\n
vec4 col = vec4(uColor.xyz, 0.2) * vec4(vec3(color), 0.8);
\n
diffuseColor = mix (diffuseColor, col, col.w);
\n\n\n
#endif
"
/***/
}),
/* 3
5
*/
/* 3
1
*/
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
varying vec3 vWorldPosition;
\n
"
/***/
}),
/* 3
6
*/
/* 3
2
*/
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
vec3 transformed = vec3( position );
\n\n
//vec4 _Position = vec4( position, 1.0 );
\n\n
/*#ifdef USE_INSTANCING
\n
_Position = instanceMatrix * _Position;
\n
#endif
\n\n
vec4 worldPosition4 = projectionMatrix * _Position;
\n
vWorldPosition = vec3(worldPosition4);*/
\n\n
vec4 slWorldPosition = vec4( transformed, 1.0 );
\n\n
#ifdef USE_INSTANCING
\n
slWorldPosition = instanceMatrix * slWorldPosition;
\n
#endif
\n\n
slWorldPosition = modelMatrix * slWorldPosition;
\n\n
vWorldPosition = vec3(slWorldPosition);
"
/***/
}),
/* 33 */
/***/
(
function
(
module
,
__webpack_exports__
,
__webpack_require__
)
{
"
use strict
"
;
/* harmony export (binding) */
__webpack_require__
.
d
(
__webpack_exports__
,
"
a
"
,
function
()
{
return
Media
;
});
/* harmony import */
var
__WEBPACK_IMPORTED_MODULE_0__core_BaseMaterial__
=
__webpack_require__
(
0
);
function
Media
(
args
)
{
__WEBPACK_IMPORTED_MODULE_0__core_BaseMaterial__
[
"
a
"
/* BaseMaterial */
].
call
(
this
);
this
.
args
=
args
;
let
xSize
=
this
.
args
.
mesh
.
geometry
.
boundingBox
.
max
.
x
-
this
.
args
.
mesh
.
geometry
.
boundingBox
.
min
.
x
;
let
ySize
=
this
.
args
.
mesh
.
geometry
.
boundingBox
.
max
.
y
-
this
.
args
.
mesh
.
geometry
.
boundingBox
.
min
.
y
;
if
(
xSize
>
ySize
)
{
xSize
=
xSize
/
ySize
;
ySize
=
1
;
}
else
{
ySize
=
ySize
/
xSize
;
xSize
=
1
;
}
this
.
uniforms
=
{
uTime
:
{
value
:
0
},
uFactorX
:
{
value
:
xSize
},
uFactorY
:
{
value
:
ySize
},
uScale
:
{
value
:
1
},
outlineSampler
:
{
type
:
'
t
'
,
value
:
new
THREE
.
TextureLoader
().
load
(
'
/static/img/mediablock_alpha.png
'
)},
};
this
.
material
=
null
;
this
.
prepare
();
}
Media
.
prototype
=
Object
.
create
(
__WEBPACK_IMPORTED_MODULE_0__core_BaseMaterial__
[
"
a
"
/* BaseMaterial */
].
prototype
);
Media
.
prototype
.
constructor
=
Media
;
Media
.
prototype
.
prepare
=
function
()
{
this
.
material
=
this
.
copy
(
this
.
args
.
mesh
.
material
);
this
.
material
.
emissiveMap
=
this
.
material
.
map
;
this
.
material
.
map
=
null
;
this
.
material
.
transparent
=
true
;
this
.
material
.
depthWrite
=
false
;
this
.
material
.
depthTest
=
true
;
this
.
material
.
renderOrder
=
-
1
;
this
.
material
.
side
=
THREE
.
FrontSide
;
this
.
material
.
userData
.
effect
=
'
Media
'
;
this
.
material
.
userData
.
args
=
this
.
args
;
this
.
material
.
userData
.
uniforms
=
this
.
uniforms
;
this
.
material
.
onBeforeCompile
=
function
(
shader
)
{
shader
.
uniforms
.
uTime
=
this
.
userData
.
uniforms
.
uTime
;
shader
.
uniforms
.
uFactorX
=
this
.
userData
.
uniforms
.
uFactorX
;
shader
.
uniforms
.
uFactorY
=
this
.
userData
.
uniforms
.
uFactorY
;
shader
.
uniforms
.
uScale
=
this
.
userData
.
uniforms
.
uScale
;
shader
.
uniforms
.
outlineSampler
=
this
.
userData
.
uniforms
.
outlineSampler
;
shader
.
fragmentShader
=
__webpack_require__
(
34
)
+
'
\n
'
+
shader
.
fragmentShader
;
shader
.
fragmentShader
=
shader
.
fragmentShader
.
replace
(
'
#include <dithering_fragment>
'
,
//dithering_fragment map_fragment
__webpack_require__
(
35
));
shader
.
vertexShader
=
__webpack_require__
(
36
)
+
'
\n
'
+
shader
.
vertexShader
;
shader
.
vertexShader
=
shader
.
vertexShader
.
replace
(
'
#include <begin_vertex>
'
,
__webpack_require__
(
37
));
};
return
this
;
};
Media
.
prototype
.
update
=
function
(
dt
)
{
this
.
uniforms
.
uTime
.
value
+=
dt
;
};
/***/
}),
/* 34 */
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
varying vec2 _vUV;
\n
varying vec4 _vTexCoords;
\n
varying vec3 _vNormal;
\n
varying vec4 _vWorldPosition;
\n\n
uniform float uTime;
\n
uniform float uFactorX;
\n
uniform float uFactorY;
\n
uniform float uScale;
\n
uniform sampler2D outlineSampler;
\n\n
vec2 _voronoi_RandomVector_float (vec2 UV, float offset)
\n
{
\n
mat2 m = mat2(15.27, 47.63, 99.41, 89.98);
\n
UV = fract(sin(UV * m));
\n
return vec2(sin(UV.y*+offset)*0.5+0.5, cos(UV.x*offset)*0.5+0.5);
\n
}
\n\n
void _voronoi_float(vec2 UV, float AngleOffset, float CellDensity, out float Out, out float Cells)
\n
{
\n
vec2 g = floor(UV * CellDensity);
\n
vec2 f = fract(UV * CellDensity);
\n
float t = 8.0;
\n
vec3 res = vec3(8.0, 0.0, 0.0);
\n\n
for(int y=-1; y<=1; y++)
\n
{
\n
for(int x=-1; x<=1; x++)
\n
{
\n
vec2 lattice = vec2(x,y);
\n
vec2 offset = _voronoi_RandomVector_float(lattice + g, AngleOffset);
\n
float d = distance(lattice + offset, f);
\n\n
if(d < res.x)
\n
{
\n
res = vec3(d, offset.x, offset.y);
\n
Out = res.x;
\n
Cells = res.y;
\n
}
\n
}
\n
}
\n
}
"
/***/
}),
/* 35 */
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
float offset = uTime * 1.0;
\n\n
float cells;
\n
float cells2;
\n\n
vec2 uv2 = _vUV * uScale;
\n
uv2.x = uv2.x*uFactorX;
\n
uv2.y = uv2.y*uFactorY;
\n\n
_voronoi_float(uv2, offset, 4.0, cells, cells2);
\n\n
cells = cells * 1.2;
\n
vec4 tex = texture2D( outlineSampler, _vUV);
\n
tex = tex * -1.1;
\n\n
vec4 col = (vec4(cells) - tex) * vec4(0.7, 0.86, 0.94, 0.18);// * diffuseColor;
\n\n
vec4 emissiveColor2 = texture2D( emissiveMap, vUv );
\n
emissiveColor2.rgb = emissiveMapTexelToLinear( emissiveColor2 ).rgb;
\n
totalEmissiveRadiance *= emissiveColor2.rgb;
\n\n
gl_FragColor = mix (col, emissiveColor2, emissiveColor2.w);
\n
"
/***/
}),
/* 36 */
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
varying vec2 _vUV;
\n
varying vec4 _vTexCoords;
\n
varying vec3 _vNormal;
\n
varying vec4 _vWorldPosition;
\n
"
/***/
}),
/* 37 */
/***/
(
function
(
module
,
exports
)
{
module
.
exports
=
"
vec3 transformed = vec3( position );
\n
_vUV = uv;
\n
"
/***/
})
/******/
]);
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
public/js/avvy-shader-editor.js
View file @
df127c17
This diff is collapsed.
Click to expand it.
src/editor/mocks/MockMedia.js
0 → 100644
View file @
df127c17
import
{
EventDispatcher
}
from
"
avvyland-editor/src/core/EventDispatcher
"
;
function
MockMedia
()
{
}
MockMedia
.
prototype
.
constructor
=
MockMedia
;
MockMedia
.
prototype
.
getMock
=
function
()
{
return
{};
};
export
{
MockMedia
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/editor/modules/MockController.js
View file @
df127c17
...
...
@@ -8,6 +8,7 @@ import {MockOutline} from "../mocks/MockOutline";
import
{
MockFlower
}
from
"
../mocks/MockFlower
"
;
import
{
MockPBR
}
from
"
../mocks/MockPBR
"
;
import
{
MockColorMap
}
from
"
../mocks/MockColorMap
"
;
import
{
MockMedia
}
from
"
../mocks/MockMedia
"
;
function
MockController
()
{
...
...
@@ -21,6 +22,7 @@ function MockController() {
'
PBR
'
:
new
MockPBR
(),
'
flower
'
:
new
MockFlower
(),
'
colormap
'
:
new
MockColorMap
(),
'
media
'
:
new
MockMedia
(),
};
const
_this
=
this
;
...
...
This diff is collapsed.
Click to expand it.
src/editor/settings.js
View file @
df127c17
...
...
@@ -8,10 +8,13 @@ export const BLOCK_ID = [
"
1693498425197436682
"
,
"
1693498425197436682
"
,
"
5075465772448925158
"
,
"
36973535368859058
"
,
"
17617086485307841930
"
,
"
7754572731808253331
"
,
"
15212218644260260682
"
,
"
17717244977373136322
"
,
];
export
const
ACTIVE_BLOCK
=
BLOCK_ID
[
6
];
export
const
ACTIVE_SHADER
=
'
PBR
'
;
export
const
ACTIVE_BLOCK
=
BLOCK_ID
[
8
];
export
const
ACTIVE_SHADER
=
'
media
'
;
This diff is collapsed.
Click to expand it.
src/library/ShaderLib.js
View file @
df127c17
...
...
@@ -7,6 +7,7 @@ import {Water} from "./materials/Water";
import
{
Simple
}
from
"
./materials/Simple
"
;
import
{
PBR
}
from
"
./materials/PBR
"
;
import
{
ColorMap
}
from
"
./materials/Colormap
"
;
import
{
Media
}
from
"
./materials/Media
"
;
function
ShaderLib
()
{
...
...
@@ -20,6 +21,7 @@ function ShaderLib() {
'
flower
'
:
Flower
,
'
PBR
'
:
PBR
,
'
colormap
'
:
ColorMap
,
'
media
'
:
Media
,
};
this
.
matObjects
=
{};
...
...
This diff is collapsed.
Click to expand it.
src/library/glsl/fs/media.fs.glsl
0 → 100644
View file @
df127c17
float
offset
=
uTime
*
1
.
0
;
float
cells
;
float
cells2
;
vec2
uv2
=
_vUV
*
uScale
;
uv2
.
x
=
uv2
.
x
*
uFactorX
;
uv2
.
y
=
uv2
.
y
*
uFactorY
;
_voronoi_float
(
uv2
,
offset
,
4
.
0
,
cells
,
cells2
);
cells
=
cells
*
1
.
2
;
vec4
tex
=
texture2D
(
outlineSampler
,
_vUV
);
tex
=
tex
*
-
1
.
1
;
vec4
col
=
(
vec4
(
cells
)
-
tex
)
*
vec4
(
0
.
7
,
0
.
86
,
0
.
94
,
0
.
18
);
// * diffuseColor;
vec4
emissiveColor2
=
texture2D
(
emissiveMap
,
vUv
);
emissiveColor2
.
rgb
=
emissiveMapTexelToLinear
(
emissiveColor2
).
rgb
;
totalEmissiveRadiance
*=
emissiveColor2
.
rgb
;
gl_FragColor
=
mix
(
col
,
emissiveColor2
,
emissiveColor2
.
w
);
This diff is collapsed.
Click to expand it.
src/library/glsl/fs/media_pars.fs.glsl
0 → 100644
View file @
df127c17
varying
vec2
_vUV
;
varying
vec4
_vTexCoords
;
varying
vec3
_vNormal
;
varying
vec4
_vWorldPosition
;
uniform
float
uTime
;
uniform
float
uFactorX
;
uniform
float
uFactorY
;
uniform
float
uScale
;
uniform
sampler2D
outlineSampler
;
vec2
_voronoi_RandomVector_float
(
vec2
UV
,
float
offset
)
{
mat2
m
=
mat2
(
15
.
27
,
47
.
63
,
99
.
41
,
89
.
98
);
UV
=
fract
(
sin
(
UV
*
m
));
return
vec2
(
sin
(
UV
.
y
*+
offset
)
*
0
.
5
+
0
.
5
,
cos
(
UV
.
x
*
offset
)
*
0
.
5
+
0
.
5
);
}
void
_voronoi_float
(
vec2
UV
,
float
AngleOffset
,
float
CellDensity
,
out
float
Out
,
out
float
Cells
)
{
vec2
g
=
floor
(
UV
*
CellDensity
);
vec2
f
=
fract
(
UV
*
CellDensity
);
float
t
=
8
.
0
;
vec3
res
=
vec3
(
8
.
0
,
0
.
0
,
0
.
0
);
for
(
int
y
=-
1
;
y
<=
1
;
y
++
)
{
for
(
int
x
=-
1
;
x
<=
1
;
x
++
)
{
vec2
lattice
=
vec2
(
x
,
y
);
vec2
offset
=
_voronoi_RandomVector_float
(
lattice
+
g
,
AngleOffset
);
float
d
=
distance
(
lattice
+
offset
,
f
);
if
(
d
<
res
.
x
)
{
res
=
vec3
(
d
,
offset
.
x
,
offset
.
y
);
Out
=
res
.
x
;
Cells
=
res
.
y
;
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/library/glsl/vs/media.vs.glsl
0 → 100644
View file @
df127c17
vec3
transformed
=
vec3
(
position
);
_vUV
=
uv
;
This diff is collapsed.
Click to expand it.
src/library/glsl/vs/media_pars.vs.glsl
0 → 100644
View file @
df127c17
varying
vec2
_vUV
;
varying
vec4
_vTexCoords
;
varying
vec3
_vNormal
;
varying
vec4
_vWorldPosition
;
This diff is collapsed.
Click to expand it.
src/library/materials/Media.js
0 → 100644
View file @
df127c17
import
{
BaseMaterial
}
from
"
../core/BaseMaterial
"
;
function
Media
(
args
)
{
BaseMaterial
.
call
(
this
);
this
.
args
=
args
;
let
xSize
=
this
.
args
.
mesh
.
geometry
.
boundingBox
.
max
.
x
-
this
.
args
.
mesh
.
geometry
.
boundingBox
.
min
.
x
;
let
ySize
=
this
.
args
.
mesh
.
geometry
.
boundingBox
.
max
.
y
-
this
.
args
.
mesh
.
geometry
.
boundingBox
.
min
.
y
;
if
(
xSize
>
ySize
)
{
xSize
=
xSize
/
ySize
;
ySize
=
1
;
}
else
{
ySize
=
ySize
/
xSize
;
xSize
=
1
;
}
this
.
uniforms
=
{
uTime
:
{
value
:
0
},
uFactorX
:
{
value
:
xSize
},
uFactorY
:
{
value
:
ySize
},
uScale
:
{
value
:
1
},
outlineSampler
:
{
type
:
'
t
'
,
value
:
new
THREE
.
TextureLoader
().
load
(
'
/static/img/mediablock_alpha.png
'
)},
};
this
.
material
=
null
;
this
.
prepare
();
}
Media
.
prototype
=
Object
.
create
(
BaseMaterial
.
prototype
);
Media
.
prototype
.
constructor
=
Media
;
Media
.
prototype
.
prepare
=
function
()
{
this
.
material
=
this
.
copy
(
this
.
args
.
mesh
.
material
);
this
.
material
.
emissiveMap
=
this
.
material
.
map
;
this
.
material
.
map
=
null
;
this
.
material
.
transparent
=
true
;
this
.
material
.
depthWrite
=
false
;
this
.
material
.
depthTest
=
true
;
this
.
material
.
renderOrder
=
-
1
;
this
.
material
.
side
=
THREE
.
FrontSide
;
this
.
material
.
userData
.
effect
=
'
Media
'
;
this
.
material
.
userData
.
args
=
this
.
args
;
this
.
material
.
userData
.
uniforms
=
this
.
uniforms
;
this
.
material
.
onBeforeCompile
=
function
(
shader
)
{
shader
.
uniforms
.
uTime
=
this
.
userData
.
uniforms
.
uTime
;
shader
.
uniforms
.
uFactorX
=
this
.
userData
.
uniforms
.
uFactorX
;
shader
.
uniforms
.
uFactorY
=
this
.
userData
.
uniforms
.
uFactorY
;
shader
.
uniforms
.
uScale
=
this
.
userData
.
uniforms
.
uScale
;
shader
.
uniforms
.
outlineSampler
=
this
.
userData
.
uniforms
.
outlineSampler
;
shader
.
fragmentShader
=
require
(
'
../glsl/fs/media_pars.fs.glsl
'
)
+
'
\n
'
+
shader
.
fragmentShader
;
shader
.
fragmentShader
=
shader
.
fragmentShader
.
replace
(
'
#include <dithering_fragment>
'
,
//dithering_fragment map_fragment
require
(
'
../glsl/fs/media.fs.glsl
'
));
shader
.
vertexShader
=
require
(
'
../glsl/vs/media_pars.vs.glsl
'
)
+
'
\n
'
+
shader
.
vertexShader
;
shader
.
vertexShader
=
shader
.
vertexShader
.
replace
(
'
#include <begin_vertex>
'
,
require
(
'
../glsl/vs/media.vs.glsl
'
));
};
return
this
;
};
Media
.
prototype
.
update
=
function
(
dt
)
{
this
.
uniforms
.
uTime
.
value
+=
dt
;
};
export
{
Media
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help