rl-loadout-lib
Version:
Load Rocket League assets into three.js
156 lines (152 loc) • 5.53 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const three_1 = require("three");
const color_1 = require("./include/color");
class ExtendedMeshStandardMaterial extends three_1.ShaderMaterial {
constructor() {
super({
uniforms: three_1.UniformsUtils.merge([
three_1.UniformsLib.common,
three_1.UniformsLib.envmap,
three_1.UniformsLib.aomap,
three_1.UniformsLib.lightmap,
three_1.UniformsLib.emissivemap,
three_1.UniformsLib.bumpmap,
three_1.UniformsLib.normalmap,
three_1.UniformsLib.displacementmap,
three_1.UniformsLib.roughnessmap,
three_1.UniformsLib.metalnessmap,
three_1.UniformsLib.fog,
three_1.UniformsLib.lights,
{
emissive: { value: new three_1.Color(0x000000) },
roughness: { value: 0.5 },
metalness: { value: 0 },
envMapIntensity: { value: 1 },
}
]),
});
this.lights = true;
this.normalMapType = three_1.TangentSpaceNormalMap;
this.fragmentShader = ExtendedMeshStandardMaterial.createFragmentShader('', '');
this.vertexShader = three_1.ShaderLib.standard.vertexShader;
}
get map() {
return this.uniforms.map.value;
}
set map(map) {
this.uniforms.map.value = map;
}
get normalMap() {
return this.uniforms.normalMap.value;
}
set normalMap(normalMap) {
this.uniforms.normalMap.value = normalMap;
}
get envMap() {
return this.uniforms.envMap.value;
}
set envMap(envMap) {
this.uniforms.envMap.value = envMap;
}
static createFragmentShader(uniforms, diffuseShader) {
// language=GLSL
return `
uniform vec3 diffuse;
uniform vec3 emissive;
uniform float roughness;
uniform float metalness;
uniform float opacity;
uniform float transparency;
uniform float reflectivity;
uniform float clearcoat;
uniform float clearcoatRoughness;
uniform vec3 sheen;
varying vec3 vViewPosition;
varying vec3 vNormal;
varying vec3 vTangent;
varying vec3 vBitangent;
` + color_1.COLOR_INCLUDE + `
` + uniforms + `
void main() {
vec4 diffuseColor = vec4(diffuse, opacity);
ReflectedLight reflectedLight = ReflectedLight(vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0));
vec3 totalEmissiveRadiance = emissive;
` + diffuseShader + `
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
diffuseColor.a *= saturate(1. - transparency + linearToRelativeLuminance(reflectedLight.directSpecular + reflectedLight.indirectSpecular));
gl_FragColor = vec4(outgoingLight, diffuseColor.a);
}
`;
}
}
exports.ExtendedMeshStandardMaterial = ExtendedMeshStandardMaterial;
//# sourceMappingURL=extended-mesh-standard-material.js.map