UNPKG

rl-loadout-lib

Version:

Load Rocket League assets into three.js

132 lines (123 loc) 4.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const three_1 = require("three"); const extended_mesh_standard_material_1 = require("./extended-mesh-standard-material"); const UNIFORMS = ` uniform sampler2D rgbaMap; uniform sampler2D decalMap; uniform vec3 primaryColor; uniform vec3 accentColor; uniform vec3 paintColor; uniform vec3 bodyPaintColor; uniform int bodyPainted; uniform int painted; uniform int isBlank; `; const DIFFUSE_SHADER = ` // Get color from base map vec4 texelColor = texture2D(map, vUv); vec4 rgbaMapColor = texture2D(rgbaMap, vUv); vec4 decalMapColor = texture2D(decalMap, vUv); if (bodyPainted == 1) { texelColor.rgb = blendNormal(texelColor.rgb, bodyPaintColor.rgb, 1.0 - rgbaMapColor.r); } // primary color float primaryMask = rgbaMapColor.r; if (isBlank == 0) { primaryMask = decalMapColor.r; } if (primaryMask > 0.58823529411) { // red 150 texelColor.rgb = blendNormal(texelColor.rgb, primaryColor.rgb, primaryMask); } if (isBlank == 0) { // accent color if (primaryMask > 0.58823529411) { texelColor.rgb = blendNormal(texelColor.rgb, accentColor.rgb, decalMapColor.a); } // decal paint if (painted == 1) { texelColor.rgb = blendNormal(texelColor.rgb, paintColor.rgb, decalMapColor.g); } } // accent color on body texelColor.rgb = blendNormal(texelColor.rgb, accentColor.rgb, rgbaMapColor.g); texelColor = mapTexelToLinear(texelColor); diffuseColor *= texelColor; `; class StaticDecalMaterial extends extended_mesh_standard_material_1.ExtendedMeshStandardMaterial { constructor() { super(); this.lights = true; this.fragmentShader = extended_mesh_standard_material_1.ExtendedMeshStandardMaterial.createFragmentShader(UNIFORMS, DIFFUSE_SHADER); this.uniforms.rgbaMap = { value: null }; this.uniforms.decalMap = { value: null }; this.uniforms.primaryColor = { value: new three_1.Color() }; this.uniforms.accentColor = { value: new three_1.Color() }; this.uniforms.paintColor = { value: new three_1.Color() }; this.uniforms.bodyPaintColor = { value: new three_1.Color() }; this.uniforms.painted = { value: 0 }; this.uniforms.isBlank = { value: 0 }; this.uniforms.bodyPainted = { value: 0 }; } get rgbaMap() { return this.uniforms.rgbaMap.value; } set rgbaMap(rgbaMap) { this.uniforms.rgbaMap.value = rgbaMap; } get decalMap() { return this.uniforms.decalMap.value; } set decalMap(decalMap) { this.uniforms.decalMap.value = decalMap; this.uniforms.isBlank.value = decalMap != undefined ? 0 : 1; } get primaryColor() { return this.uniforms.primaryColor.value; } set primaryColor(primaryColor) { if (primaryColor != undefined) { this.uniforms.primaryColor.value.copy(primaryColor); } else { this.uniforms.primaryColor.value.setRGB(0, 0, 0); } } get accentColor() { return this.uniforms.accentColor.value; } set accentColor(accentColor) { if (accentColor != undefined) { this.uniforms.accentColor.value.copy(accentColor); } else { this.uniforms.accentColor.value.setRGB(0, 0, 0); } } get paintColor() { return this.uniforms.paintColor.value; } set paintColor(paintColor) { if (paintColor != undefined) { this.uniforms.accentColor.value.copy(paintColor); this.uniforms.painted.value = 1; } else { this.uniforms.painted.value = 0.0; } } get bodyPaintColor() { return this.uniforms.bodyPaintColor.value; } set bodyPaintColor(bodyPaintColor) { if (bodyPaintColor != undefined) { this.uniforms.bodyPaintColor.value.copy(bodyPaintColor); this.uniforms.bodyPainted.value = 1; } else { this.uniforms.bodyPainted.value = 0; } } } exports.StaticDecalMaterial = StaticDecalMaterial; //# sourceMappingURL=static-decal-material.js.map