67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
"use strict";
|
|
|
|
const ElevatorMaterialGame = (function(){
|
|
|
|
const ElevatorMaterialGame = function(hollow_bond){
|
|
|
|
let cabin_mat = null;
|
|
let light_mat = null;
|
|
|
|
this.get_cabin_material = () => {
|
|
if(cabin_mat) return cabin_mat;
|
|
|
|
const def = (hollow_bond.theme && hollow_bond.theme.elevator_cabin) ? hollow_bond.theme.elevator_cabin : {
|
|
vertex: `
|
|
varying vec3 vNormal;
|
|
void main(){
|
|
vNormal = normalize(normalMatrix * normal);
|
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
}
|
|
`,
|
|
fragment: `
|
|
varying vec3 vNormal;
|
|
void main(){
|
|
gl_FragColor = vec4(vec3(0.35) + abs(vNormal.y) * 0.1, 1.0);
|
|
}
|
|
`
|
|
};
|
|
|
|
cabin_mat = new THREE.ShaderMaterial({
|
|
vertexShader: def.vertex,
|
|
fragmentShader: def.fragment,
|
|
side: THREE.DoubleSide
|
|
});
|
|
|
|
return cabin_mat;
|
|
};
|
|
|
|
this.get_light_material = () => {
|
|
if(light_mat) return light_mat;
|
|
|
|
const def = (hollow_bond.theme && hollow_bond.theme.elevator_light) ? hollow_bond.theme.elevator_light : {
|
|
vertex: `
|
|
void main(){ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }
|
|
`,
|
|
fragment: `
|
|
void main(){ gl_FragColor = vec4(0.95, 0.92, 0.82, 1.0); }
|
|
`
|
|
};
|
|
|
|
light_mat = new THREE.ShaderMaterial({
|
|
vertexShader: def.vertex,
|
|
fragmentShader: def.fragment,
|
|
side: THREE.DoubleSide
|
|
});
|
|
|
|
return light_mat;
|
|
};
|
|
|
|
this.reset = () => {
|
|
if(cabin_mat){ cabin_mat.dispose(); cabin_mat = null; }
|
|
if(light_mat){ light_mat.dispose(); light_mat = null; }
|
|
};
|
|
|
|
};
|
|
|
|
return ElevatorMaterialGame;
|
|
})(); |