|
@@ -1,6 +1,48 @@
|
|
|
import * as THREE from "three";
|
|
|
+import { TriangleBlurShader } from "three/addons/shaders/TriangleBlurShader.js";
|
|
|
import TouchEdge from "./TouchEdge";
|
|
|
|
|
|
+function makeTriangleBlurShader(iterations = 10) {
|
|
|
+ // Remove texture, because texture is a reserved word in WebGL 2
|
|
|
+ const { texture, ...uniforms } = TriangleBlurShader.uniforms;
|
|
|
+
|
|
|
+ const TriangleBlurShader2 = {
|
|
|
+ ...TriangleBlurShader,
|
|
|
+
|
|
|
+ name: "TriangleBlurShader2",
|
|
|
+
|
|
|
+ uniforms: {
|
|
|
+ ...uniforms,
|
|
|
+
|
|
|
+ // Replace texture with blurTexture for WebGL 2
|
|
|
+ blurTexture: { value: null },
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ // Replace texture with blurTexture for WebGL 2
|
|
|
+ TriangleBlurShader2.fragmentShader =
|
|
|
+ TriangleBlurShader2.fragmentShader.replace(
|
|
|
+ "uniform sampler2D texture;",
|
|
|
+ "uniform sampler2D blurTexture;"
|
|
|
+ );
|
|
|
+ TriangleBlurShader2.fragmentShader =
|
|
|
+ TriangleBlurShader2.fragmentShader.replace(
|
|
|
+ "texture2D( texture",
|
|
|
+ "texture2D( blurTexture"
|
|
|
+ );
|
|
|
+
|
|
|
+ // Make iterations configurable.
|
|
|
+ TriangleBlurShader2.fragmentShader =
|
|
|
+ TriangleBlurShader2.fragmentShader.replace(
|
|
|
+ "#define ITERATIONS 10.0",
|
|
|
+ "#define ITERATIONS " + iterations + ".0"
|
|
|
+ );
|
|
|
+
|
|
|
+ console.log("shader:", TriangleBlurShader2.fragmentShader);
|
|
|
+
|
|
|
+ return TriangleBlurShader2;
|
|
|
+}
|
|
|
+
|
|
|
export default class ImgLabel extends THREE.Mesh {
|
|
|
constructor(texture, matLine, isHorizontal = true) {
|
|
|
let width, height, p;
|
|
@@ -31,6 +73,17 @@ export default class ImgLabel extends THREE.Mesh {
|
|
|
// transparent: true,
|
|
|
// });
|
|
|
|
|
|
+ // const shader = makeTriangleBlurShader(12);
|
|
|
+
|
|
|
+ // const blurMaterial = new THREE.ShaderMaterial({
|
|
|
+ // vertexShader: shader.vertexShader,
|
|
|
+ // fragmentShader: shader.fragmentShader,
|
|
|
+ // uniforms: THREE.UniformsUtils.clone(shader.uniforms),
|
|
|
+ // });
|
|
|
+ // // console.log("blurMaterial", blurMaterial.uniforms);
|
|
|
+ // blurMaterial.uniforms.blurTexture.value = texture;
|
|
|
+ // blurMaterial.uniforms.delta.value = new THREE.Vector2(0.5, 0.9);
|
|
|
+
|
|
|
const bg = new THREE.MeshBasicMaterial({
|
|
|
color: 0xf2f2f2,
|
|
|
transparent: false,
|
|
@@ -39,8 +92,8 @@ export default class ImgLabel extends THREE.Mesh {
|
|
|
super(g, bg);
|
|
|
|
|
|
let imgRatio = texture.image.width / texture.image.height;
|
|
|
-
|
|
|
- const imageG = new THREE.PlaneGeometry(width, width / imgRatio);
|
|
|
+ const imgHeight = width / imgRatio >= 2 ? 2 : width / imgRatio;
|
|
|
+ const imageG = new THREE.PlaneGeometry(width, imgHeight);
|
|
|
|
|
|
imageG.rotateX(-Math.PI / 2);
|
|
|
|