Skip to content

Commit

Permalink
[lab] Fix path-traced mode
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Sep 14, 2023
1 parent b14d20c commit 809ad88
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
8 changes: 8 additions & 0 deletions base/Sources/arm/App.hx
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,14 @@ class App {

// Default camera controls
Context.raw.cameraControls = Config.raw.camera_controls;

#if is_lab
arm.App.notifyOnNextFrame(function() {
arm.App.notifyOnNextFrame(function() {
@:privateAccess TabMeshes.setDefaultMesh(".Sphere");
});
});
#end
}
else if (Context.raw.frame == 3) {
Context.raw.ddirty = 3;
Expand Down
4 changes: 4 additions & 0 deletions base/Sources/arm/Enums.hx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ package arm;
var ViewMetallic = 5;
var ViewOpacity = 6;
var ViewHeight = 7;
#if (is_paint || is_sculpt)
var ViewEmission = 8;
var ViewSubsurface = 9;
var ViewTexCoord = 10;
Expand All @@ -63,6 +64,9 @@ package arm;
var ViewObjectID = 13;
var ViewMask = 14;
var ViewPathTrace = 15;
#else
var ViewPathTrace = 8;
#end
}

@:enum abstract ChannelType(Int) from Int to Int {
Expand Down
8 changes: 8 additions & 0 deletions base/Sources/arm/render/RenderPathBase.hx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ class RenderPathBase {

#if (kha_direct3d12 || kha_vulkan || kha_metal)
if (Context.raw.viewportMode == ViewPathTrace) {
#if is_paint
var useLiveLayer = Context.raw.tool == ToolMaterial;
#else
var useLiveLayer = false;
#end
RenderPathRaytrace.draw(useLiveLayer);
return;
}
Expand Down Expand Up @@ -271,7 +275,11 @@ class RenderPathBase {
drawGbuffer();

#if (kha_direct3d12 || kha_vulkan || kha_metal)
#if is_paint
var useLiveLayer = Context.raw.tool == ToolMaterial;
#else
var useLiveLayer = false;
#end
Context.raw.viewportMode == ViewPathTrace ? RenderPathRaytrace.draw(useLiveLayer) : drawCommands();
#else
drawCommands();
Expand Down
3 changes: 2 additions & 1 deletion base/Sources/arm/render/RenderPathRaytrace.hx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class RenderPathRaytrace {
var md = mo.data;
var geom = md.geom;
var mo_scale = mo.transform.scale.x; // Uniform scale only
vb_scale = mo.parent.transform.scale.x * md.scalePos * mo_scale;
vb_scale = md.scalePos * mo_scale;
if (mo.parent != null) vb_scale *= mo.parent.transform.scale.x;
vb = geom.vertexBuffer;
ib = geom.indexBuffers[0];
}
Expand Down
33 changes: 31 additions & 2 deletions base/Sources/arm/ui/TabMeshes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package arm.ui;

import zui.Zui;
import zui.Id;
import iron.data.MeshData;
import iron.object.MeshObject;
import arm.util.MeshUtil;

Expand Down Expand Up @@ -150,11 +151,39 @@ class TabMeshes {

#if is_lab
static function setDefaultMesh(name: String) {
var mo: MeshObject = cast iron.Scene.active.getChild(name);
var mo: MeshObject = null;
if (name == ".Plane" || name == ".Sphere") {
var mesh: Dynamic = name == ".Plane" ? new arm.geom.Plane(1, 1, 2048, 2048) : new arm.geom.Sphere(0.9, 2048, 1024, false, 3.0);
var raw = {
name: "Tessellated",
vertex_arrays: [
{ values: mesh.posa, attrib: "pos", data: "short4norm" },
{ values: mesh.nora, attrib: "nor", data: "short2norm" },
{ values: mesh.texa, attrib: "tex", data: "short2norm" }
],
index_arrays: [
{ values: mesh.inda, material: 0 }
],
scale_pos: mesh.scalePos,
scale_tex: mesh.scaleTex
};
var md = new MeshData(raw, function(md: MeshData) {});
mo = new MeshObject(md, Context.raw.paintObject.materials);
iron.Scene.active.meshes.remove(mo);
mo.name = "Tessellated";
}
else {
mo = cast iron.Scene.active.getChild(name);
}

mo.visible = true;
iron.Scene.active.meshes = [mo];
Context.raw.ddirty = 2;
Context.raw.paintObject = mo;
Project.paintObjects[0] = mo;
if (UIHeader.inst.worktab.position == Space3D) {
iron.Scene.active.meshes = [mo];
}

#if (kha_direct3d12 || kha_vulkan || kha_metal)
arm.render.RenderPathRaytrace.ready = false;
#end
Expand Down
3 changes: 3 additions & 0 deletions base/Sources/arm/ui/UIMenubar.hx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ class UIMenubar {
m.translate(0, 0, 1.5);
Scene.active.camera.transform.setMatrix(m);
}
#if (kha_direct3d12 || kha_vulkan || kha_metal)
arm.render.RenderPathRaytrace.ready = false;
#end
}
#end
}
Expand Down

0 comments on commit 809ad88

Please sign in to comment.