Project format bpp

This commit is contained in:
luboslenco
2019-07-10 07:59:58 +02:00
parent 693cf8291e
commit 4bb8ebca7f
6 changed files with 35 additions and 24 deletions
+5 -3
View File
@@ -113,7 +113,8 @@ class Project {
if (UITrait.inst.projectType > 0) {
var mesh:Dynamic = UITrait.inst.projectType == 1 ?
new iron.format.proc.Sphere(1, 512, 256) :
// new iron.format.proc.Sphere(1, 512, 256) :
new iron.format.proc.Plane(1, 1, 512, 512) :
new iron.format.proc.Plane(1, 1, 512, 512);
var raw = {
name: "Tesselated",
@@ -131,7 +132,7 @@ class Project {
var md = new MeshData(raw, function(md:MeshData) {});
Data.cachedMeshes.set("SceneTesselated", md);
if (UITrait.inst.projectType == 2) {
if (UITrait.inst.projectType == 1 || UITrait.inst.projectType == 2) {
ViewportUtil.setView(0, 0, 1, 0, 0, 0); // Top
ViewportUtil.orbit(0, Math.PI / 6); // Orbit down
}
@@ -201,7 +202,8 @@ typedef TProjectFormat = {
}
typedef TLayerData = {
public var res:Int;
public var res:Int; // Width pixels
public var bpp:Int; // Bits per pixel
public var texpaint:haxe.io.Bytes;
public var texpaint_nor:haxe.io.Bytes;
public var texpaint_pack:haxe.io.Bytes;
+4
View File
@@ -55,10 +55,14 @@ class ExportArm {
}
}
var bitsPos = UITrait.inst.bitsHandle.position;
var bpp = bitsPos == 0 ? 8 : bitsPos == 1 ? 16 : 32;
var ld:Array<TLayerData> = [];
for (l in Project.layers) {
ld.push({
res: l.texpaint.width,
bpp: bpp,
texpaint: Lz4.encode(l.texpaint.getPixels()),
texpaint_nor: Lz4.encode(l.texpaint_nor.getPixels()),
texpaint_pack: Lz4.encode(l.texpaint_pack.getPixels()),
+17 -7
View File
@@ -4,6 +4,8 @@ import haxe.io.Bytes;
import kha.Window;
import kha.Blob;
import kha.Image;
import kha.graphics4.TextureFormat;
import kha.graphics4.DepthStencilFormat;
import iron.data.MaterialData;
import iron.data.MeshData;
import iron.data.Data;
@@ -143,7 +145,13 @@ class ImportArm {
Context.paintObject.skip_context = "paint";
Context.mergedObject.visible = true;
UITrait.inst.resHandle.position = Config.getTextureResPos(project.layer_datas[0].res);
var l0 = project.layer_datas[0];
UITrait.inst.resHandle.position = Config.getTextureResPos(l0.res);
if (l0.bpp == null) l0.bpp = 8; // TODO: deprecated
var bitsPos = l0.bpp == 8 ? 0 : l0.bpp == 16 ? 1 : 2;
UITrait.inst.bitsHandle.position = bitsPos;
var bytesPerPixel = Std.int(l0.bpp / 8);
var format = l0.bpp == 8 ? TextureFormat.RGBA32 : l0.bpp == 16 ? TextureFormat.RGBA64 : TextureFormat.RGBA128;
if (Project.layers[0].texpaint.width != Config.getTextureRes()) {
for (l in Project.layers) l.resizeAndSetBits();
@@ -152,14 +160,16 @@ class ImportArm {
rts.get("texpaint_blend0").image.unload();
rts.get("texpaint_blend0").raw.width = Config.getTextureRes();
rts.get("texpaint_blend0").raw.height = Config.getTextureRes();
rts.get("texpaint_blend0").image = Image.createRenderTarget(Config.getTextureRes(), Config.getTextureRes(), kha.graphics4.TextureFormat.L8, kha.graphics4.DepthStencilFormat.NoDepthAndStencil);
rts.get("texpaint_blend0").image = Image.createRenderTarget(Config.getTextureRes(), Config.getTextureRes(), TextureFormat.L8, DepthStencilFormat.NoDepthAndStencil);
rts.get("texpaint_blend1").image.unload();
rts.get("texpaint_blend1").raw.width = Config.getTextureRes();
rts.get("texpaint_blend1").raw.height = Config.getTextureRes();
rts.get("texpaint_blend1").image = Image.createRenderTarget(Config.getTextureRes(), Config.getTextureRes(), kha.graphics4.TextureFormat.L8, kha.graphics4.DepthStencilFormat.NoDepthAndStencil);
rts.get("texpaint_blend1").image = Image.createRenderTarget(Config.getTextureRes(), Config.getTextureRes(), TextureFormat.L8, DepthStencilFormat.NoDepthAndStencil);
Context.brushBlendDirty = true;
}
// for (l in Project.layers) l.unload();
Project.layers = [];
for (i in 0...project.layer_datas.length) {
@@ -168,19 +178,19 @@ class ImportArm {
Project.layers.push(l);
// TODO: create render target from bytes
var texpaint = Image.fromBytes(Lz4.decode(ld.texpaint, ld.res * ld.res * 4), ld.res, ld.res);
var texpaint = Image.fromBytes(Lz4.decode(ld.texpaint, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format);
l.texpaint.g2.begin(false);
l.texpaint.g2.drawImage(texpaint, 0, 0);
l.texpaint.g2.end();
// texpaint.unload();
var texpaint_nor = Image.fromBytes(Lz4.decode(ld.texpaint_nor, ld.res * ld.res * 4), ld.res, ld.res);
var texpaint_nor = Image.fromBytes(Lz4.decode(ld.texpaint_nor, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format);
l.texpaint_nor.g2.begin(false);
l.texpaint_nor.g2.drawImage(texpaint_nor, 0, 0);
l.texpaint_nor.g2.end();
// texpaint_nor.unload();
var texpaint_pack = Image.fromBytes(Lz4.decode(ld.texpaint_pack, ld.res * ld.res * 4), ld.res, ld.res);
var texpaint_pack = Image.fromBytes(Lz4.decode(ld.texpaint_pack, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format);
l.texpaint_pack.g2.begin(false);
l.texpaint_pack.g2.drawImage(texpaint_pack, 0, 0);
l.texpaint_pack.g2.end();
@@ -188,7 +198,7 @@ class ImportArm {
if (ld.texpaint_mask != null) {
l.createMask(0, false);
var texpaint_mask = Image.fromBytes(Lz4.decode(ld.texpaint_mask, ld.res * ld.res), ld.res, ld.res, kha.graphics4.TextureFormat.L8);
var texpaint_mask = Image.fromBytes(Lz4.decode(ld.texpaint_mask, ld.res * ld.res), ld.res, ld.res, TextureFormat.L8);
l.texpaint_mask.g2.begin(false);
l.texpaint_mask.g2.drawImage(texpaint_mask, 0, 0);
l.texpaint_mask.g2.end();
+5 -10
View File
@@ -995,16 +995,11 @@ class MaterialBuilder {
// Height
if (heightUsed) {
frag.write('vec4 vech;');
frag.write('vech.x = textureOffsetShared(texpaint_pack, texCoord, ivec2(-1, 0)).a;');
frag.write('vech.y = textureOffsetShared(texpaint_pack, texCoord, ivec2(1, 0)).a;');
frag.write('vech.z = textureOffsetShared(texpaint_pack, texCoord, ivec2(0, -1)).a;');
frag.write('vech.w = textureOffsetShared(texpaint_pack, texCoord, ivec2(0, 1)).a;');
// Displace normal strength
frag.write('vech *= 15 * 7; float h1 = vech.x - vech.y; float h2 = vech.z - vech.w;');
frag.write('vec3 va = normalize(vec3(2.0, 0.0, h1));');
frag.write('vec3 vb = normalize(vec3(0.0, 2.0, h2));');
frag.write('vec3 vc = normalize(vec3(h1, h2, 2.0));');
frag.write('float bump_res_x = dFdx(pack.a) * 32.0;');
frag.write('float bump_res_y = dFdy(pack.a) * 32.0;');
frag.write('vec3 va = normalize(vec3(1.0, 0.0, bump_res_x));');
frag.write('vec3 vb = normalize(vec3(0.0, 1.0, bump_res_y));');
frag.write('vec3 vc = normalize(vec3(bump_res_x, bump_res_y, 1.0));');
frag.write('n = normalize(mul(n, mat3(va, vb, vc)));');
}
//
+3 -3
View File
@@ -1241,14 +1241,14 @@ class NodesMaterial {
{
name: "blend_type",
type: "ENUM",
data: ["Mix", "Add", "Multiply", "Subtract", "Screen", "Divide", "Difference", "Darken", "Lighten", "Soft Light"],
data: ["Mix", "Add", "Multiply", "Subtract", "Screen", "Divide", "Difference", "Darken", "Lighten", "Overlay", "Dodge", "Burn", "Hue", "Saturation", "Value", "Color", "Soft Light", "Linear Light"],
default_value: 0,
output: 0
},
{
name: "use_clamp",
type: "BOOL",
default_value: "false",
default_value: false,
output: 0
}
]
@@ -1673,7 +1673,7 @@ class NodesMaterial {
{
name: "use_clamp",
type: "BOOL",
default_value: "false",
default_value: false,
output: 0
}
]
+1 -1
View File
@@ -463,7 +463,7 @@ class UINodes {
}
public function acceptDrag(assetIndex:Int) {
var n = NodesMaterial.createImageTexture();
var n = canvasType == 0 ? NodesMaterial.createImageTexture() : NodesBrush.createImageTexture();
n.buttons[0].default_value = assetIndex;
nodes.nodesSelected = [n];
}