|
186 | 186 | 'adv / soft-body': 'soft-body', |
187 | 187 | 'adv / wave': 'wave', |
188 | 188 | 'adv / triangle-blur': 'triangle-blur', |
| 189 | + 'adv / triplanar-mapping': 'triplanar-mapping', |
189 | 190 | 'adv / render-to-texture': 'rtt', |
190 | 191 | 'adv / temporal-blur': 'temporal-blur', |
191 | 192 | 'adv / conditional': 'conditional', |
|
2385 | 2386 |
|
2386 | 2387 | break; |
2387 | 2388 |
|
| 2389 | + case 'triplanar-mapping': |
| 2390 | + |
| 2391 | + // MATERIAL |
| 2392 | + |
| 2393 | + mtl = new THREE.PhongNodeMaterial(); |
| 2394 | + |
| 2395 | + var scale = new THREE.FloatNode( .02 ); |
| 2396 | + |
| 2397 | + var triplanarMapping = new THREE.FunctionNode( [ |
| 2398 | + // Reference: https://github.com/keijiro/StandardTriplanar |
| 2399 | + "vec4 triplanar_mapping( sampler2D texture, vec3 normal, vec3 position, float scale ) {", |
| 2400 | + |
| 2401 | + // Blending factor of triplanar mapping |
| 2402 | + " vec3 bf = normalize( abs( normal ) );", |
| 2403 | + " bf /= dot( bf, vec3( 1.0 ) );", |
| 2404 | + |
| 2405 | + // Triplanar mapping |
| 2406 | + " vec2 tx = position.yz * scale;", |
| 2407 | + " vec2 ty = position.zx * scale;", |
| 2408 | + " vec2 tz = position.xy * scale;", |
| 2409 | + |
| 2410 | + // Base color |
| 2411 | + " vec4 cx = texture2D(texture, tx) * bf.x;", |
| 2412 | + " vec4 cy = texture2D(texture, ty) * bf.y;", |
| 2413 | + " vec4 cz = texture2D(texture, tz) * bf.z;", |
| 2414 | + |
| 2415 | + " return cx + cy + cz;", |
| 2416 | + |
| 2417 | + "}" |
| 2418 | + ].join( "\n" ) ); |
| 2419 | + |
| 2420 | + var triplanarMappingTexture = new THREE.FunctionCallNode( triplanarMapping, { |
| 2421 | + texture: new THREE.TextureNode( getTexture( "brick" ) ), |
| 2422 | + normal: new THREE.NormalNode( THREE.NormalNode.WORLD ), |
| 2423 | + position: new THREE.PositionNode( THREE.PositionNode.WORLD ), |
| 2424 | + scale: scale, |
| 2425 | + } ); |
| 2426 | + |
| 2427 | + mtl.color = triplanarMappingTexture; |
| 2428 | + |
| 2429 | + // GUI |
| 2430 | + |
| 2431 | + addGui( 'scale', scale.value, function ( val ) { |
| 2432 | + |
| 2433 | + scale.value = val; |
| 2434 | + |
| 2435 | + }, false, 0.001, .1 ); |
| 2436 | + |
| 2437 | + break; |
| 2438 | + |
2388 | 2439 | case 'firefly': |
2389 | 2440 |
|
2390 | 2441 | // MATERIAL |
|
0 commit comments