Normal map blending for layers

This commit is contained in:
luboslenco
2021-01-29 15:15:12 +01:00
parent 229adac99f
commit b443977c74
9 changed files with 37 additions and 7 deletions
+7
View File
@@ -29,6 +29,13 @@ void main() {
vec4 col1 = textureLod(tex1, texCoord, 0);
FragColor = vec4(mix(cola, col1, str));
}
else if (blending == -2) { // Merging _nor with normal blending
vec4 col1 = textureLod(tex1, texCoord, 0);
// Whiteout blend
vec3 n1 = cola.rgb * vec3(2.0, 2.0, 2.0) - vec3(1.0, 1.0, 1.0);
vec3 n2 = mix(vec3(0.5, 0.5, 1.0), col1.rgb, str) * vec3(2.0, 2.0, 2.0) - vec3(1.0, 1.0, 1.0);
FragColor = vec4(normalize(vec3(n1.xy + n2.xy, n1.z * n2.z)) * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5), max(col0.a, cola.a));
}
else if (blending == 0) { // Mix
FragColor = vec4(mix(cola.rgb, col0.rgb, str), max(col0.a, cola.a));
}
+1 -1
View File
@@ -402,7 +402,7 @@ class Layers {
l0.texpaint_nor.g4.setTexture(texmask, mask);
l0.texpaint_nor.g4.setTexture(texa, imga);
l0.texpaint_nor.g4.setFloat(opac, l1.maskOpacity);
l0.texpaint_nor.g4.setInt(blending, -1);
l0.texpaint_nor.g4.setInt(blending, l1.paintNorBlend ? -2 : -1);
l0.texpaint_nor.g4.setVertexBuffer(iron.data.ConstData.screenAlignedVB);
l0.texpaint_nor.g4.setIndexBuffer(iron.data.ConstData.screenAlignedIB);
l0.texpaint_nor.g4.drawIndexedVertices();
+1
View File
@@ -46,6 +46,7 @@ typedef TLayerData = {
public var paint_rough: Bool;
public var paint_met: Bool;
public var paint_nor: Bool;
public var paint_nor_blend: Bool;
public var paint_height: Bool;
public var paint_emis: Bool;
public var paint_subs: Bool;
+1
View File
@@ -41,6 +41,7 @@ class LayerSlot {
public var paintRough = true;
public var paintMet = true;
public var paintNor = true;
public var paintNorBlend = true;
public var paintHeight = true;
public var paintEmis = true;
public var paintSubs = true;
+1
View File
@@ -81,6 +81,7 @@ class ExportArm {
paint_rough: l.paintRough,
paint_met: l.paintMet,
paint_nor: l.paintNor,
paint_nor_blend: l.paintNorBlend,
paint_height: l.paintHeight,
paint_emis: l.paintEmis,
paint_subs: l.paintSubs
+1 -1
View File
@@ -208,7 +208,7 @@ class ExportTexture {
Layers.expb.g4.setTexture(Layers.texmask, hasMask ? l1.texpaint_mask : empty);
Layers.expb.g4.setTexture(Layers.texa, Layers.imga);
Layers.expb.g4.setFloat(Layers.opac, l1.maskOpacity);
Layers.expb.g4.setInt(Layers.blending, -1);
Layers.expb.g4.setInt(Layers.blending, l1.paintNorBlend ? -2 : -1);
Layers.expb.g4.setVertexBuffer(iron.data.ConstData.screenAlignedVB);
Layers.expb.g4.setIndexBuffer(iron.data.ConstData.screenAlignedIB);
Layers.expb.g4.drawIndexedVertices();
+1
View File
@@ -255,6 +255,7 @@ class ImportArm {
l.paintRough = ld.paint_rough;
l.paintMet = ld.paint_met;
l.paintNor = ld.paint_nor;
l.paintNorBlend = ld.paint_nor_blend != null ? ld.paint_nor_blend : true; // TODO: deprecated
l.paintHeight = ld.paint_height;
l.paintEmis = ld.paint_emis;
l.paintSubs = ld.paint_subs;
+11 -1
View File
@@ -209,7 +209,17 @@ class MakeMesh {
}
if (l.paintNor) {
frag.write('ntex = mix(ntex, texpaint_nor_sample.rgb, texpaint_opac);');
if (l.paintNorBlend) {
// Whiteout blend
frag.write('{');
frag.write('vec3 n1 = ntex * vec3(2.0, 2.0, 2.0) - vec3(1.0, 1.0, 1.0);');
frag.write('vec3 n2 = mix(vec3(0.5, 0.5, 1.0), texpaint_nor_sample.rgb, texpaint_opac) * vec3(2.0, 2.0, 2.0) - vec3(1.0, 1.0, 1.0);');
frag.write('ntex = normalize(vec3(n1.xy + n2.xy, n1.z * n2.z)) * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5);');
frag.write('}');
}
else {
frag.write('ntex = mix(ntex, texpaint_nor_sample.rgb, texpaint_opac);');
}
}
}
+13 -4
View File
@@ -367,7 +367,7 @@ class TabLayers {
if (contextMenu) {
var add = l.fill_layer != null ? 1 : 0;
var menuElements = l.getChildren() != null ? 6 : (19 + add);
var menuElements = l.getChildren() != null ? 6 : (20 + add);
UIMenu.draw(function(ui: Zui) {
ui.text(l.name, Right, ui.t.HIGHLIGHT_COL);
@@ -458,14 +458,19 @@ class TabLayers {
}
children[0].parent = null;
children[0].name = l.name;
if (children[0].fill_layer != null) children[0].toPaintLayer();
l.delete();
}
iron.App.notifyOnInit(_init);
}
if (l.getChildren() == null && ui.button(tr("Merge Down"), Left)) {
Context.setLayer(l);
iron.App.notifyOnInit(History.mergeLayers);
iron.App.notifyOnInit(Layers.mergeDown);
function _init() {
Context.setLayer(l);
History.mergeLayers();
Layers.mergeDown();
if (Context.layer.fill_layer != null) Context.layer.toPaintLayer();
}
iron.App.notifyOnInit(_init);
}
if (ui.button(tr("Duplicate"), Left)) {
function _init() {
@@ -514,6 +519,7 @@ class TabLayers {
var baseHandle = Id.handle().nest(l.id);
var opacHandle = Id.handle().nest(l.id);
var norHandle = Id.handle().nest(l.id);
var norBlendHandle = Id.handle().nest(l.id);
var occHandle = Id.handle().nest(l.id);
var roughHandle = Id.handle().nest(l.id);
var metHandle = Id.handle().nest(l.id);
@@ -523,6 +529,7 @@ class TabLayers {
baseHandle.selected = l.paintBase;
opacHandle.selected = l.paintOpac;
norHandle.selected = l.paintNor;
norBlendHandle.selected = l.paintNorBlend;
occHandle.selected = l.paintOcc;
roughHandle.selected = l.paintRough;
metHandle.selected = l.paintMet;
@@ -532,6 +539,7 @@ class TabLayers {
l.paintBase = ui.check(baseHandle, tr("Base Color"));
l.paintOpac = ui.check(opacHandle, tr("Opacity"));
l.paintNor = ui.check(norHandle, tr("Normal"));
l.paintNorBlend = ui.check(norBlendHandle, tr("Normal Blending"));
l.paintOcc = ui.check(occHandle, tr("Occlusion"));
l.paintRough = ui.check(roughHandle, tr("Roughness"));
l.paintMet = ui.check(metHandle, tr("Metallic"));
@@ -541,6 +549,7 @@ class TabLayers {
if (baseHandle.changed ||
opacHandle.changed ||
norHandle.changed ||
norBlendHandle.changed ||
occHandle.changed ||
roughHandle.changed ||
metHandle.changed ||