Bake height
This commit is contained in:
@@ -65,24 +65,31 @@ class MakeBake {
|
|||||||
frag.write('vec3 res = normalize(mul(n0, invTBN)) * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5);');
|
frag.write('vec3 res = normalize(mul(n0, invTBN)) * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5);');
|
||||||
frag.write('fragColor[0] = vec4(res, 1.0);');
|
frag.write('fragColor[0] = vec4(res, 1.0);');
|
||||||
}
|
}
|
||||||
else if (UITrait.inst.bakeType == 3) { // Normal (World)
|
else if (UITrait.inst.bakeType == 3) { // Normal (Object)
|
||||||
frag.n = true;
|
frag.n = true;
|
||||||
frag.write('fragColor[0] = vec4(n * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5), 1.0);');
|
frag.write('fragColor[0] = vec4(n * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5), 1.0);');
|
||||||
if (UITrait.inst.bakeUpAxis == 1) { // Y up
|
if (UITrait.inst.bakeUpAxis == 1) { // Y up
|
||||||
frag.write('fragColor[0].rgb = vec3(fragColor[0].r, fragColor[0].b, 1.0 - fragColor[0].g);');
|
frag.write('fragColor[0].rgb = vec3(fragColor[0].r, fragColor[0].b, 1.0 - fragColor[0].g);');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (UITrait.inst.bakeType == 4) { // Position
|
else if (UITrait.inst.bakeType == 4) { // Height
|
||||||
|
frag.wposition = true;
|
||||||
|
frag.add_uniform('sampler2D texpaint_undo', '_texpaint_undo'); // Baked high-poly positions
|
||||||
|
frag.write('vec3 wpos0 = textureLod(texpaint_undo, texCoord, 0.0).rgb * vec3(2.0, 2.0, 2.0) - vec3(1.0, 1.0, 1.0);');
|
||||||
|
frag.write('float res = distance(wpos0, wposition) * 10.0;');
|
||||||
|
frag.write('fragColor[0] = vec4(res, res, res, 1.0);');
|
||||||
|
}
|
||||||
|
else if (UITrait.inst.bakeType == 5) { // Position
|
||||||
frag.wposition = true;
|
frag.wposition = true;
|
||||||
frag.write('fragColor[0] = vec4(wposition * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5), 1.0);');
|
frag.write('fragColor[0] = vec4(wposition * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5), 1.0);');
|
||||||
if (UITrait.inst.bakeUpAxis == 1) { // Y up
|
if (UITrait.inst.bakeUpAxis == 1) { // Y up
|
||||||
frag.write('fragColor[0].rgb = vec3(fragColor[0].r, fragColor[0].b, 1.0 - fragColor[0].g);');
|
frag.write('fragColor[0].rgb = vec3(fragColor[0].r, fragColor[0].b, 1.0 - fragColor[0].g);');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (UITrait.inst.bakeType == 5) { // TexCoord
|
else if (UITrait.inst.bakeType == 6) { // TexCoord
|
||||||
frag.write('fragColor[0] = vec4(texCoord.xy, 0.0, 1.0);');
|
frag.write('fragColor[0] = vec4(texCoord.xy, 0.0, 1.0);');
|
||||||
}
|
}
|
||||||
else if (UITrait.inst.bakeType == 6) { // Material ID
|
else if (UITrait.inst.bakeType == 7) { // Material ID
|
||||||
frag.add_uniform('sampler2D texpaint_nor_undo', '_texpaint_nor_undo');
|
frag.add_uniform('sampler2D texpaint_nor_undo', '_texpaint_nor_undo');
|
||||||
frag.write('float sample_matid = textureLod(texpaint_nor_undo, texCoord, 0.0).a + 1.0 / 255.0;');
|
frag.write('float sample_matid = textureLod(texpaint_nor_undo, texCoord, 0.0).a + 1.0 / 255.0;');
|
||||||
frag.write('float matid_r = fract(sin(dot(vec2(sample_matid, sample_matid * 20.0), vec2(12.9898, 78.233))) * 43758.5453);');
|
frag.write('float matid_r = fract(sin(dot(vec2(sample_matid, sample_matid * 20.0), vec2(12.9898, 78.233))) * 43758.5453);');
|
||||||
@@ -90,7 +97,7 @@ class MakeBake {
|
|||||||
frag.write('float matid_b = fract(sin(dot(vec2(sample_matid, sample_matid * 40.0), vec2(12.9898, 78.233))) * 43758.5453);');
|
frag.write('float matid_b = fract(sin(dot(vec2(sample_matid, sample_matid * 40.0), vec2(12.9898, 78.233))) * 43758.5453);');
|
||||||
frag.write('fragColor[0] = vec4(matid_r, matid_g, matid_b, 1.0);');
|
frag.write('fragColor[0] = vec4(matid_r, matid_g, matid_b, 1.0);');
|
||||||
}
|
}
|
||||||
else if (UITrait.inst.bakeType == 7) { // Object ID
|
else if (UITrait.inst.bakeType == 8) { // Object ID
|
||||||
frag.add_uniform('float objectId', '_objectId');
|
frag.add_uniform('float objectId', '_objectId');
|
||||||
frag.write('float obid = objectId + 1.0 / 255.0;');
|
frag.write('float obid = objectId + 1.0 / 255.0;');
|
||||||
frag.write('float id_r = fract(sin(dot(vec2(obid, obid * 20.0), vec2(12.9898, 78.233))) * 43758.5453);');
|
frag.write('float id_r = fract(sin(dot(vec2(obid, obid * 20.0), vec2(12.9898, 78.233))) * 43758.5453);');
|
||||||
|
|||||||
@@ -389,8 +389,11 @@ class RenderPathPaint {
|
|||||||
|
|
||||||
if (Context.tool == ToolBake) {
|
if (Context.tool == ToolBake) {
|
||||||
if (Context.pdirty > 0) dilated = false;
|
if (Context.pdirty > 0) dilated = false;
|
||||||
if (UITrait.inst.bakeType == 2) { // Normal (Tangent)
|
var isNormal = UITrait.inst.bakeType == 2;
|
||||||
UITrait.inst.bakeType = 3; // Bake high poly world normals
|
var isHeight = UITrait.inst.bakeType == 4;
|
||||||
|
if (isNormal || isHeight) { // Normal (Tangent), Height
|
||||||
|
var _bakeType = UITrait.inst.bakeType;
|
||||||
|
UITrait.inst.bakeType = isNormal ? 3 : 5; // Bake high poly world normals / position
|
||||||
MaterialParser.parsePaintMaterial();
|
MaterialParser.parsePaintMaterial();
|
||||||
var _paintObject = Context.paintObject;
|
var _paintObject = Context.paintObject;
|
||||||
var highPoly = Project.paintObjects[UITrait.inst.bakeHighPoly];
|
var highPoly = Project.paintObjects[UITrait.inst.bakeHighPoly];
|
||||||
@@ -402,12 +405,12 @@ class RenderPathPaint {
|
|||||||
UITrait.inst.sub--;
|
UITrait.inst.sub--;
|
||||||
if (pushUndoLast) History.paint();
|
if (pushUndoLast) History.paint();
|
||||||
|
|
||||||
UITrait.inst.bakeType = 2;
|
UITrait.inst.bakeType = _bakeType;
|
||||||
MaterialParser.parsePaintMaterial();
|
MaterialParser.parsePaintMaterial();
|
||||||
Context.selectPaintObject(_paintObject);
|
Context.selectPaintObject(_paintObject);
|
||||||
RenderPathPaint.commandsPaint();
|
RenderPathPaint.commandsPaint();
|
||||||
}
|
}
|
||||||
else if (UITrait.inst.bakeType == 7) { // Object ID
|
else if (UITrait.inst.bakeType == 8) { // Object ID
|
||||||
var _layerFilter = UITrait.inst.layerFilter;
|
var _layerFilter = UITrait.inst.layerFilter;
|
||||||
var _paintObject = Context.paintObject;
|
var _paintObject = Context.paintObject;
|
||||||
var isMerged = Context.mergedObject != null;
|
var isMerged = Context.mergedObject != null;
|
||||||
@@ -426,9 +429,9 @@ class RenderPathPaint {
|
|||||||
}
|
}
|
||||||
#if kha_direct3d12
|
#if kha_direct3d12
|
||||||
else if (UITrait.inst.bakeType == 0 || // AO (DXR)
|
else if (UITrait.inst.bakeType == 0 || // AO (DXR)
|
||||||
UITrait.inst.bakeType == 8 || // Lightmap (DXR)
|
UITrait.inst.bakeType == 9 || // Lightmap (DXR)
|
||||||
UITrait.inst.bakeType == 9 || // Bent Normal (DXR)
|
UITrait.inst.bakeType == 10 || // Bent Normal (DXR)
|
||||||
UITrait.inst.bakeType == 10) { // Thickness (DXR)
|
UITrait.inst.bakeType == 11) { // Thickness (DXR)
|
||||||
RenderPathRaytrace.commandsBake();
|
RenderPathRaytrace.commandsBake();
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
|
|||||||
@@ -316,10 +316,10 @@ class RenderPathRaytrace {
|
|||||||
|
|
||||||
static function getBakeShaderName():String {
|
static function getBakeShaderName():String {
|
||||||
return
|
return
|
||||||
UITrait.inst.bakeType == 0 ? "raytrace_bake_ao.cso" :
|
UITrait.inst.bakeType == 0 ? "raytrace_bake_ao.cso" :
|
||||||
UITrait.inst.bakeType == 8 ? "raytrace_bake_light.cso" :
|
UITrait.inst.bakeType == 9 ? "raytrace_bake_light.cso" :
|
||||||
UITrait.inst.bakeType == 9 ? "raytrace_bake_bent.cso" :
|
UITrait.inst.bakeType == 10 ? "raytrace_bake_bent.cso" :
|
||||||
"raytrace_bake_thick.cso";
|
"raytrace_bake_thick.cso";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function draw() {
|
public static function draw() {
|
||||||
|
|||||||
@@ -676,7 +676,6 @@ class UITrait {
|
|||||||
if (onBrush != null) onBrush(0);
|
if (onBrush != null) onBrush(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (brushTime > 0) { // Brush released
|
else if (brushTime > 0) { // Brush released
|
||||||
brushTime = 0;
|
brushTime = 0;
|
||||||
@@ -986,15 +985,14 @@ class UITrait {
|
|||||||
else if (Context.tool == ToolBake) {
|
else if (Context.tool == ToolBake) {
|
||||||
ui.changed = false;
|
ui.changed = false;
|
||||||
var bakeHandle = Id.handle({position: bakeType});
|
var bakeHandle = Id.handle({position: bakeType});
|
||||||
var ao = #if kha_direct3d12 "AO (DXR)" #else "AO" #end;
|
var bakes = ["AO", "Curvature", "Normal", "Normal (Object)", "Height", "Position", "TexCoord", "Material ID", "Object ID"];
|
||||||
var bakes = [ao, "Curvature", "Normal (Tang)", "Normal (World)", "Position", "TexCoord", "Material ID", "Object ID"];
|
|
||||||
#if kha_direct3d12
|
#if kha_direct3d12
|
||||||
bakes.push("Lightmap (DXR)");
|
bakes.push("Lightmap");
|
||||||
bakes.push("BentNormal (DXR)");
|
bakes.push("Bent Normal");
|
||||||
bakes.push("Thickness (DXR)");
|
bakes.push("Thickness");
|
||||||
#end
|
#end
|
||||||
bakeType = ui.combo(bakeHandle, bakes, "Bake");
|
bakeType = ui.combo(bakeHandle, bakes, "Bake");
|
||||||
if (bakeType == 3 || bakeType == 4 || bakeType == 9) {
|
if (bakeType == 3 || bakeType == 5 || bakeType == 10) {
|
||||||
var bakeUpAxisHandle = Id.handle({position: bakeUpAxis});
|
var bakeUpAxisHandle = Id.handle({position: bakeUpAxis});
|
||||||
bakeUpAxis = ui.combo(bakeUpAxisHandle, ["Z", "Y"], "Up Axis");
|
bakeUpAxis = ui.combo(bakeUpAxisHandle, ["Z", "Y"], "Up Axis");
|
||||||
}
|
}
|
||||||
@@ -1011,7 +1009,7 @@ class UITrait {
|
|||||||
bakeAoOffset = ui.slider(offsetHandle, "Offset", 0.0, 2.0, true);
|
bakeAoOffset = ui.slider(offsetHandle, "Offset", 0.0, 2.0, true);
|
||||||
}
|
}
|
||||||
#if kha_direct3d12
|
#if kha_direct3d12
|
||||||
if (bakeType == 0 || bakeType == 8 || bakeType == 9 || bakeType == 10) { // ao, bent, lightmap, thick
|
if (bakeType == 0 || bakeType == 9 || bakeType == 10 || bakeType == 11) { // ao, bent, lightmap, thick
|
||||||
ui.text("Rays/pix: " + arm.render.RenderPathRaytrace.raysPix);
|
ui.text("Rays/pix: " + arm.render.RenderPathRaytrace.raysPix);
|
||||||
ui.text("Rays/sec: " + arm.render.RenderPathRaytrace.raysSec);
|
ui.text("Rays/sec: " + arm.render.RenderPathRaytrace.raysSec);
|
||||||
}
|
}
|
||||||
@@ -1026,7 +1024,7 @@ class UITrait {
|
|||||||
var smoothHandle = Id.handle({value: bakeCurvSmooth});
|
var smoothHandle = Id.handle({value: bakeCurvSmooth});
|
||||||
bakeCurvSmooth = Std.int(ui.slider(smoothHandle, "Smooth", 0, 5, false, 1));
|
bakeCurvSmooth = Std.int(ui.slider(smoothHandle, "Smooth", 0, 5, false, 1));
|
||||||
}
|
}
|
||||||
if (bakeType == 2) { // Normal (Tang)
|
if (bakeType == 2 || bakeType == 4) { // Normal (Tang), Height
|
||||||
var ar = [for (p in Project.paintObjects) p.name];
|
var ar = [for (p in Project.paintObjects) p.name];
|
||||||
var polyHandle = Id.handle({position: bakeHighPoly});
|
var polyHandle = Id.handle({position: bakeHighPoly});
|
||||||
bakeHighPoly = ui.combo(polyHandle, ar, "High Poly");
|
bakeHighPoly = ui.combo(polyHandle, ar, "High Poly");
|
||||||
@@ -1157,9 +1155,9 @@ class UITrait {
|
|||||||
ui._y += 2;
|
ui._y += 2;
|
||||||
|
|
||||||
var modeHandle = Id.handle({position: 0});
|
var modeHandle = Id.handle({position: 0});
|
||||||
var modes = ["Render", "Base Color", "Normal Map", "Occlusion", "Roughness", "Metallic", "TexCoord", "Normal", "MaterialID", "Mask"];
|
var modes = ["Render", "Base Color", "Normal", "Occlusion", "Roughness", "Metallic", "TexCoord", "Normal (Object)", "Material ID", "Mask"];
|
||||||
#if kha_direct3d12
|
#if kha_direct3d12
|
||||||
modes.push("Path-Trace (DXR)");
|
modes.push("Path-Trace");
|
||||||
#end
|
#end
|
||||||
UITrait.inst.viewportMode = ui.combo(modeHandle, modes, "Mode");
|
UITrait.inst.viewportMode = ui.combo(modeHandle, modes, "Mode");
|
||||||
if (modeHandle.changed) {
|
if (modeHandle.changed) {
|
||||||
|
|||||||
Reference in New Issue
Block a user