├── LICENSE ├── README.md ├── index.glsl └── package.json /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Jonas Folletête 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # glsl-triplanar-mapping 2 | 📐 GLSL Triplanar texture mapping. glslify format. 3 | 4 | Inspired by this [article](https://gamedevelopment.tutsplus.com/articles/use-tri-planar-texture-mapping-for-better-terrain--gamedev-13821). 5 | 6 | ## NPM Installation 7 | 8 | ```sh 9 | npm install glsl-triplanar-mapping 10 | ``` 11 | 12 | ## Usage 13 | 14 | ```glsl 15 | #pragma glslify: triplanarMapping = require(glsl-triplanar-mapping) 16 | 17 | void main() { 18 | vec3 color = triplanarMapping(texture, normal, position); 19 | gl_FragColor = vec4(color, 1.0); 20 | } 21 | ``` 22 | 23 | ## License 24 | [MIT license](https://github.com/JonasFolletete/glsl-triplanar-mapping/blob/master/LICENSE) -------------------------------------------------------------------------------- /index.glsl: -------------------------------------------------------------------------------- 1 | vec3 blendNormal(vec3 normal){ 2 | vec3 blending = abs(normal); 3 | blending = normalize(max(blending, 0.00001)); 4 | blending /= vec3(blending.x + blending.y + blending.z); 5 | return blending; 6 | } 7 | 8 | vec3 triplanarMapping (sampler2D texture, vec3 normal, vec3 position) { 9 | vec3 normalBlend = blendNormal(normal); 10 | vec3 xColor = texture2D(texture, position.yz).rgb; 11 | vec3 yColor = texture2D(texture, position.xz).rgb; 12 | vec3 zColor = texture2D(texture, position.xy).rgb; 13 | 14 | return (xColor * normalBlend.x + yColor * normalBlend.y + zColor * normalBlend.z); 15 | } 16 | 17 | #pragma glslify: export(triplanarMapping) 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "glsl-triplanar-mapping", 3 | "version": "1.0.1", 4 | "description": "📐 GLSL Triplanar texture mapping. glslify format.", 5 | "main": "index.glsl", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/JonasFolletete/glsl-triplanar-mapping.git" 9 | }, 10 | "keywords": [ 11 | "glsl", 12 | "triplanar", 13 | "triplanar-mapping", 14 | "mapping", 15 | "three.js", 16 | "webgl", 17 | "glslify" 18 | ], 19 | "author": "Jonas Folletête", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/JonasFolletete/glsl-triplanar-mapping/issues" 23 | } 24 | } 25 | --------------------------------------------------------------------------------