Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions atlas/graphics/deferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,8 @@ void Window::deferredRendering(
lightPipeline->bindTextureCubemap(
"skybox", fallbackSkyboxTexture->textureID, boundTextures);
}
lightPipeline->setUniformBool(
"useIBL", scene->skybox != nullptr && scene->skybox->cubemap.id != 0);
boundTextures++;

lightPipeline->setUniform1f(
Expand Down
237 changes: 176 additions & 61 deletions atlas/object/model.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions editor/views/editor/materialEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ void MaterialEditorPanel::showMaterial() {
{"Metallic", "metallicTexture"},
{"Roughness", "roughnessTexture"},
{"Ambient Occlusion", "aoTexture"},
{"PBR Pack", "pbrPackTexture"},
{"Opacity", "opacityTexture"},
{"Displacement", "displacementTexture"}};
for (const auto &[label, key] : materialSlots) {
Expand Down
27 changes: 26 additions & 1 deletion editor/views/editor/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QDebug>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QEventLoop>
#include <QFile>
#include <QFileInfo>
#include <QHideEvent>
Expand All @@ -33,6 +34,7 @@
#include <QMessageBox>
#include <QMimeData>
#include <QPaintEngine>
#include <QProgressDialog>
#include <QPointer>
#include <QResizeEvent>
#include <QSize>
Expand Down Expand Up @@ -1151,8 +1153,31 @@ bool ViewportPanel::importRuntimeModel(const QString &path) {
{"rotation", QJsonArray{0.0, 0.0, 0.0}},
{"scale", QJsonArray{1.0, 1.0, 1.0}},
{"components", QJsonArray{}}};
QProgressDialog progress(this);
progress.setWindowTitle(tr("Importing Model"));
progress.setLabelText(tr("Preparing %1…").arg(QFileInfo(path).fileName()));
progress.setCancelButton(nullptr);
progress.setRange(0, 100);
progress.setValue(0);
progress.setMinimumDuration(0);
progress.setWindowModality(Qt::WindowModal);
progress.show();
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);

const QString fileName = QFileInfo(path).fileName();
const int id = runtimeContext->pasteObjectDefinition(
QJsonDocument(definition).toJson(QJsonDocument::Compact).toStdString());
QJsonDocument(definition).toJson(QJsonDocument::Compact).toStdString(),
[&progress, &fileName](float value, const std::string &status) {
const int percentage =
std::clamp(static_cast<int>(std::round(value * 100.0f)), 0, 100);
progress.setValue(percentage);
progress.setLabelText(QString::fromStdString(status) +
QObject::tr("\n%1 — %2%")
.arg(fileName)
.arg(percentage));
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
});
progress.setValue(100);
if (id < 0)
return false;
refreshSceneSnapshot();
Expand Down
60 changes: 45 additions & 15 deletions include/atlas/core/default_shaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -1505,25 +1505,40 @@ fragment main0_out main0(main0_in in [[stage_in]], constant UBO& _46 [[buffer(0)
normal = fast::normalize(in.Normal);
}
float3 albedoColor = baseColor.xyz;
int param_pbr_pack = 14;
float4 pbrPackTex = enableTextures(param_pbr_pack, _46, texture1, texture1Smplr, texCoord, texture2, texture2Smplr, texture3, texture3Smplr, texture4, texture4Smplr, texture5, texture5Smplr, texture6, texture6Smplr, texture7, texture7Smplr, texture8, texture8Smplr, texture9, texture9Smplr, texture10, texture10Smplr);
bool hasPbrPack = any(pbrPackTex != float4(-1.0));
float metallicValue = material.metallic;
int param_5 = 9;
float4 metallicTex = enableTextures(param_5, _46, texture1, texture1Smplr, texCoord, texture2, texture2Smplr, texture3, texture3Smplr, texture4, texture4Smplr, texture5, texture5Smplr, texture6, texture6Smplr, texture7, texture7Smplr, texture8, texture8Smplr, texture9, texture9Smplr, texture10, texture10Smplr);
if (any(metallicTex != float4(-1.0)))
if (hasPbrPack)
{
metallicValue *= pbrPackTex.z;
}
else if (any(metallicTex != float4(-1.0)))
{
metallicValue *= metallicTex.x;
}
float roughnessValue = material.roughness;
float roughnessValue = mater)",
R"(ial.roughness;
int param_6 = 10;
float4 roughnessTex = enableTextures(param_6, _46, texture1, texture1Smplr, texCoord, texture2, texture2Smplr, texture3, texture3Smplr, texture4, texture4Smplr, texture5, texture5Smplr, texture6, texture6Smplr, texture7, texture7Smplr, texture8, texture8Smplr, texture9, texture9Smplr, texture10, texture10Smplr);
if (any(roughnessTex != float4(-1.0)))
if (hasPbrPack)
{
roughnessValue *= pbrPackTex.y;
}
else if (any(roughnessTex != float4(-1.0)))
{
roughnessValue *= roughnessTex.x;
}
float aoValue = material.ao)",
R"(;
float aoValue = material.ao;
int param_7 = 11;
float4 aoTex = enableTextures(param_7, _46, texture1, texture1Smplr, texCoord, texture2, texture2Smplr, texture3, texture3Smplr, texture4, texture4Smplr, texture5, texture5Smplr, texture6, texture6Smplr, texture7, texture7Smplr, texture8, texture8Smplr, texture9, texture9Smplr, texture10, texture10Smplr);
if (any(aoTex != float4(-1.0)))
if (hasPbrPack)
{
aoValue *= pbrPackTex.x;
}
else if (any(aoTex != float4(-1.0)))
{
aoValue *= aoTex.x;
}
Expand Down Expand Up @@ -5837,26 +5852,42 @@ fragment main0_out main0(main0_in in [[stage_in]], constant Uniforms& _163 [[buf
discard_fragment();
}
}
int param_pbr_pack = 14;
float4 pbrPackTex = enableTextures(param_pbr_pack, _163, texture1, texture1Smplr, texCoord, texture2, texture2Smplr, texture3, texture3Smplr, texture4, texture4Smplr, texture5, texture5Smplr, texture6, texture6Smplr, texture7, texture7Smplr, texture8, texture8Smplr, texture9, texture9Smplr, texture10, texture10Smplr);
bool hasPbrPack = any(pbrPackTex != float4(-1.0));
float metallic = material.metallic;
int param_4 = 9;
float4 metallicTex = enableTextures(param_4, _163, texture1, texture1Smplr, texCoord, texture2, texture2Smplr, texture3, texture3Smplr, texture4, texture4Smplr, texture5, texture5Smplr, texture6, texture6Smplr, texture7, texture7Smplr, texture8, texture8Smplr, texture9, texture9Smplr, texture10, texture10Smplr);
if (any(metallicTex != float4(-1.0)))
if (hasPbrPack)
{
metallic *= pbrPackTex.z;
}
else if (any(metallicTex != float4(-1.0)))
{
metallic *= metallicTex.x;
}
float roughness = material.roughness;
int param_5 = 10;
float4 roughnessTex = enableTextures(param_5, _163, texture1, texture1Smplr, texCoord, texture2, texture2Smplr, texture3, texture3Smplr, texture4, texture4Smplr, texture5, texture5Smplr, texture6, texture6Smplr, texture7, texture7Smplr, texture8, texture8Smplr, texture9, texture9Smplr, texture10, texture10Smplr);
if (any(roughnessTex != float4(-1.0)))
if (hasPbrPack)
{
roughness *= pbrPackTex.y;
}
else if (any(roughnessTex != float4(-1.0)))
{
roughness *= roughnessTex.x;
}
float ao = material.ao;
int param_6 = 11;
float4 aoTex = enableTextures(param_6, _163, texture1, texture1Smplr, texCoord, texture2, texture2Smplr, texture3, texture3Smplr, texture4, texture4Smplr, texture5, texture5Smplr, texture6, texture6Smplr, texture7, texture7Smplr, texture8, texture8Smplr, texture9, texture9Smplr, texture10, texture10Smplr);
if (any(aoTex != float4(-1.0)))
if (hasPbrPack)
{
ao *= aoTex.x;
ao *= pbrPackTex.x;
}
else if (any(aoTex != float4(-1.0)))
{
ao *= a)",
R"(oTex.x;
}
float3 F0 = float3(0.039999999105930328369140625);
F0 = mix(F0, albedo, float3(metallic));
Expand All @@ -5872,8 +5903,7 @@ fragment main0_out main0(main0_in in [[stage_in]], constant Uniforms& _163 [[buf
{
float4 fragPosLightSpace = (_1905.shadowParams[i_1].lightProjection * _1905.shadowParams[i_1].lightView) * float4(in.FragPos, 1.0);
ShadowParameters _1934;
)",
R"( _1934.lightView = _1905.shadowParams[i_1].lightView;
_1934.lightView = _1905.shadowParams[i_1].lightView;
_1934.lightProjection = _1905.shadowParams[i_1].lightProjection;
_1934.bias0 = _1905.shadowParams[i_1].bias0;
_1934.textureIndex = _1905.shadowParams[i_1].textureIndex;
Expand Down Expand Up @@ -6002,16 +6032,16 @@ R"( _1934.lightView = _1905.shadowParams[i_1].lightView;
}
float facing = _2144;
float cosTheta = cos(radians(_2058.areaLights[i_2].angle));
if ((facing >= cosTheta) && (facing > 0.0))
if ((facing >= cosTh)",
R"(eta) && (facing > 0.0))
{
float range = fast::max(_2058.areaLights[i_2].range, 0.001000000047497451305389404296875);
float attenuation = 1.0 / ((1.0 + (dist / range)) + ((dist * dist) / (range * range)));
float fade = 1.0 - smoothstep(range * 0.89999997615814208984375, range, dist);
float3 radiance = (((float3(_2058.areaLights[i_2].diffuse) * fast::max(_2058.areaLights[i_2].intensity, 0.0)) * attenuation) * facing) * fade;
float3 H = fast::normalize(V + L);
float3 param_42 = N;
float3 pa)",
R"(ram_43 = H;
float3 param_43 = H;
float param_44 = roughness;
float NDF = distributionGGX(param_42, param_43, param_44);
float3 param_45 = N;
Expand Down
11 changes: 10 additions & 1 deletion include/atlas/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "photon/illuminate.h"
#include <algorithm>
#include <any>
#include <functional>
#include <memory>
#include <string>
#include <type_traits>
Expand Down Expand Up @@ -798,6 +799,9 @@ class Model : public GameObject {
* @param resource The resource to load the model from.
*/
void fromResource(const Resource &resource);
void fromResource(
const Resource &resource,
const std::function<void(float, const std::string &)> &progress);

/**
* @brief Gets the objects that make up the model.
Expand Down Expand Up @@ -1043,8 +1047,13 @@ class Model : public GameObject {
private:
std::vector<std::shared_ptr<CoreObject>> objects;
std::string directory;
std::function<void(float, const std::string &)> importProgress;
unsigned int importedMeshCount = 0;
unsigned int totalMeshCount = 0;

void loadModel(const Resource &resource);
void loadModel(
const Resource &resource,
const std::function<void(float, const std::string &)> &progress = {});
void processNode(aiNode *node, const aiScene *scene,
glm::mat4 parentTransform,
std::unordered_map<std::string, Texture> &textureCache);
Expand Down
4 changes: 2 additions & 2 deletions include/atlas/runtime/atlasScripts.h

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions include/atlas/runtime/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <atlas/window.h>
#include <map>
#include <memory>
#include <functional>
#include <string>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -104,6 +105,7 @@ class Context {
json editorEnvironmentData = json::object();
json editorPropertySyncs = json::array();
bool applyingPropertySyncs = false;
std::function<void(float, const std::string &)> modelImportProgress;
std::vector<std::pair<std::string, std::string>> deletedObjectReferences;

ProjectConfig config;
Expand Down Expand Up @@ -149,6 +151,9 @@ class Context {
int createObject(const std::string &type, const std::string &name);
std::string objectDefinitionJson(int id) const;
int pasteObjectDefinition(const std::string &definition);
int pasteObjectDefinition(
const std::string &definition,
const std::function<void(float, const std::string &)> &progress);
bool saveCurrentScene();
bool openSceneFile(const std::string &path);
std::string currentScenePath() const;
Expand Down
3 changes: 2 additions & 1 deletion include/atlas/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ enum class TextureType : int {
Roughness = 10,
AO = 11,
Opacity = 12,
HDR = 13
HDR = 13,
PBRPack = 14
};

/**
Expand Down
24 changes: 18 additions & 6 deletions photon/gi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,26 @@ void photon::GlobalIllumination::updateProbeLayout() {
}
}
baseMaterial.normalTextureIndex = normalTextureIndex;
const int pbrPackTextureIndex = findTextureSlotForType(
object->textures, TextureType::PBRPack, materialTextures,
textureSlots);
baseMaterial.metallicTextureIndex =
findTextureSlotForType(object->textures, TextureType::Metallic,
materialTextures, textureSlots);
pbrPackTextureIndex >= 0
? pbrPackTextureIndex
: findTextureSlotForType(
object->textures, TextureType::Metallic,
materialTextures, textureSlots);
baseMaterial.roughnessTextureIndex =
findTextureSlotForType(object->textures, TextureType::Roughness,
materialTextures, textureSlots);
baseMaterial.aoTextureIndex = findTextureSlotForType(
object->textures, TextureType::AO, materialTextures, textureSlots);
pbrPackTextureIndex >= 0
? pbrPackTextureIndex
: findTextureSlotForType(
object->textures, TextureType::Roughness,
materialTextures, textureSlots);
baseMaterial.aoTextureIndex =
pbrPackTextureIndex >= 0
? pbrPackTextureIndex
: findTextureSlotForType(object->textures, TextureType::AO,
materialTextures, textureSlots);
bool materialBound = false;
int materialID = -1;

Expand Down
23 changes: 17 additions & 6 deletions photon/path_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,26 @@ void photon::PathTracing::buildAccelerationStructure(
}
}
data.normalTextureIndex = normalTextureIndex;
const int pbrPackTextureIndex = findTextureSlotForType(
object->textures, TextureType::PBRPack, materialTextures,
textureSlots);
data.metallicTextureIndex =
findTextureSlotForType(object->textures, TextureType::Metallic,
materialTextures, textureSlots);
pbrPackTextureIndex >= 0
? pbrPackTextureIndex
: findTextureSlotForType(
object->textures, TextureType::Metallic,
materialTextures, textureSlots);
data.roughnessTextureIndex =
findTextureSlotForType(object->textures, TextureType::Roughness,
materialTextures, textureSlots);
pbrPackTextureIndex >= 0
? pbrPackTextureIndex
: findTextureSlotForType(
object->textures, TextureType::Roughness,
materialTextures, textureSlots);
data.aoTextureIndex =
findTextureSlotForType(object->textures, TextureType::AO,
materialTextures, textureSlots);
pbrPackTextureIndex >= 0
? pbrPackTextureIndex
: findTextureSlotForType(object->textures, TextureType::AO,
materialTextures, textureSlots);
data.opacityTextureIndex =
findTextureSlotForType(object->textures, TextureType::Opacity,
materialTextures, textureSlots);
Expand Down
1 change: 1 addition & 0 deletions runtime/atlas.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ declare module "atlas/graphics" {
AO,
Opacity,
HDR,
PBRPack,
}

export class Texture {
Expand Down
20 changes: 19 additions & 1 deletion runtime/lib/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ TextureType parseTextureTypeString(const std::string &value) {
if (token == "ao" || token == "ambientocclusion") {
return TextureType::AO;
}
if (token == "pbrpack" || token == "orm" ||
token == "metallicroughness") {
return TextureType::PBRPack;
}
if (token == "opacity" || token == "alpha") {
return TextureType::Opacity;
}
Expand Down Expand Up @@ -783,6 +787,8 @@ MaterialDefinition loadMaterialDefinition(const json &value,
appendTexture({"roughnessTexture"}, TextureType::Roughness, false);
appendTexture({"aoTexture", "ambientOcclusionTexture"}, TextureType::AO,
false);
appendTexture({"pbrPackTexture", "ormTexture", "metallicRoughnessTexture"},
TextureType::PBRPack, false);
appendTexture({"opacityTexture", "alphaTexture"}, TextureType::Opacity,
false);

Expand Down Expand Up @@ -3847,7 +3853,9 @@ createRenderable(Context &context, const json &objectData,

auto object = std::make_shared<Model>();
object->fromResource(createRuntimeResource(
baseDir, source, ResourceType::Model, "runtime-model"));
baseDir, source, ResourceType::Model,
"runtime-model"),
context.modelImportProgress);

registerGameObject(context, *object, objectData, normalizedType,
generatedIndex);
Expand Down Expand Up @@ -5639,6 +5647,16 @@ int Context::pasteObjectDefinition(const std::string &definition) {
}
}

int Context::pasteObjectDefinition(
const std::string &definition,
const std::function<void(float, const std::string &)> &progress) {
auto previousProgress = std::move(modelImportProgress);
modelImportProgress = progress;
const int result = pasteObjectDefinition(definition);
modelImportProgress = std::move(previousProgress);
return result;
}

bool Context::saveCurrentScene() {
if (currentSceneFile.empty()) {
return false;
Expand Down
4 changes: 4 additions & 0 deletions runtime/lib/scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ TextureType toNativeTextureType(int type) {
return TextureType::Opacity;
case 13:
return TextureType::HDR;
case 14:
return TextureType::PBRPack;
case 0:
default:
return TextureType::Color;
Expand Down Expand Up @@ -352,6 +354,8 @@ int toScriptTextureType(TextureType type) {
return 12;
case TextureType::HDR:
return 13;
case TextureType::PBRPack:
return 14;
case TextureType::Color:
default:
return 0;
Expand Down
Loading
Loading