@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
59 lines (58 loc) • 1.52 kB
JavaScript
;
import VERTEX from "./GroundProjectedSkybox.vert.glsl";
import FRAGMENT from "./GroundProjectedSkybox.frag.glsl";
import {
Mesh,
IcosahedronGeometry,
ShaderMaterial,
DoubleSide
} from "three";
function _geometry() {
return new IcosahedronGeometry(1, 16);
}
function _material() {
const uniforms = {
map: { value: null },
height: { value: 15 },
radius: { value: 100 }
};
const material = new ShaderMaterial({
uniforms,
fragmentShader: "",
vertexShader: VERTEX,
side: DoubleSide
});
return material;
}
export class GroundProjectedSkybox extends Mesh {
constructor(geometry, material) {
super(_geometry(), _material());
this.geometry = new IcosahedronGeometry(1, 16);
}
setTexture(texture) {
const isCubeMap = texture.isCubeTexture;
const defines = [isCubeMap ? "#define ENVMAP_TYPE_CUBE" : ""];
const fragmentShader = defines.join("\n") + FRAGMENT;
this.material.fragmentShader = fragmentShader;
this.material.needsUpdate = true;
this.material.uniforms.map.value = texture;
}
set radius(radius) {
this.material.uniforms.radius.value = radius;
}
get radius() {
return this.material.uniforms.radius.value;
}
set height(height) {
this.material.uniforms.height.value = height;
}
get height() {
return this.material.uniforms.height.value;
}
copy(source, recursive) {
super.copy(source, recursive);
this.radius = source.radius;
this.height = source.height;
return this;
}
}