From fcff5e8ec73da15d511f09e905357d2a13b92040 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sat, 11 May 2019 18:33:42 +0200 Subject: [PATCH] Triplanar sample --- Sources/arm/MaterialBuilder.hx | 16 +++++++++++++++- Sources/arm/ui/UITrait.hx | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Sources/arm/MaterialBuilder.hx b/Sources/arm/MaterialBuilder.hx index 39d0531b..a3eb12fd 100644 --- a/Sources/arm/MaterialBuilder.hx +++ b/Sources/arm/MaterialBuilder.hx @@ -233,7 +233,7 @@ class MaterialBuilder { } } // TexCoords - project - else { + else if (UITrait.inst.brushPaint == 1) { frag.add_uniform('float brushScale', '_brushScale'); frag.write_attrib('vec2 uvsp = sp.xy;'); @@ -266,6 +266,18 @@ class MaterialBuilder { frag.write('texCoord = vec2(texCoord.x * ${Math.cos(a)} - texCoord.y * ${Math.sin(a)}, texCoord.x * ${Math.sin(a)} + texCoord.y * ${Math.cos(a)});'); } } + else { // Triplanar + frag.wposition = true; + frag.n = true; + frag.add_uniform('float brushScale', '_brushScale'); + frag.write_attrib('vec3 triWeight = wnormal * wnormal;'); // n * n + frag.write_attrib('float triMax = max(triWeight.x, max(triWeight.y, triWeight.z));'); + frag.write_attrib('triWeight = max(triWeight - triMax * 0.75, 0.0);'); + frag.write_attrib('vec3 texCoordBlend = triWeight * (1.0 / (triWeight.x + triWeight.y + triWeight.z));'); + frag.write_attrib('vec2 texCoord0 = fract(wposition.yz * brushScale);'); + frag.write_attrib('vec2 texCoord1 = fract(wposition.xz * brushScale);'); + frag.write_attrib('vec2 texCoord2 = fract(wposition.xy * brushScale);'); + } if (UITrait.inst.selectedTool == ToolClone || UITrait.inst.selectedTool == ToolBlur) { @@ -355,7 +367,9 @@ class MaterialBuilder { Cycles.parse_subsurface = UITrait.inst.selectedMaterial.paintSubs; Cycles.parse_height = UITrait.inst.selectedMaterial.paintHeight; Cycles.parse_height_as_channel = true; + Cycles.triplanar = UITrait.inst.brushPaint == 2; var sout = Cycles.parse(UINodes.inst.canvas, con_paint, vert, frag, null, null, null, matcon); + Cycles.triplanar = false; Cycles.parse_emission = false; Cycles.parse_subsurface = false; Cycles.parse_height_as_channel = false; diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index 36ccc9ea..fbe2c36c 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -1179,7 +1179,7 @@ class UITrait extends iron.Trait { if (selectedTool == ToolBrush || selectedTool == ToolFill) { var paintHandle = Id.handle(); - brushPaint = ui.combo(paintHandle, ["UV Map", "Project"], "TexCoord"); + brushPaint = ui.combo(paintHandle, ["UV Map", "Project", "Triplanar"], "TexCoord"); if (paintHandle.changed) { MaterialParser.parsePaintMaterial(); }