Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BRAYNS-662 Add engine endpoints v3 #1291

Merged
merged 40 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0847d05
Added info to remove default values.
Adrien4193 Sep 12, 2024
469c650
C++ side cleanup.
Adrien4193 Sep 26, 2024
7ab80a6
formatting.
Adrien4193 Sep 26, 2024
9afdb7d
Use array for boxes.
Adrien4193 Sep 26, 2024
8cda95a
Python side + tests.
Adrien4193 Oct 4, 2024
97f2887
Minor changes.
Adrien4193 Oct 4, 2024
ca708e6
Simplified tasks.
Adrien4193 Oct 4, 2024
66e50fe
Rewrite task system.
Adrien4193 Nov 1, 2024
055d632
Changed data model.
Adrien4193 Nov 4, 2024
881ad34
Checkpoint geometry objects.
Adrien4193 Nov 15, 2024
984e716
Checkpoint all curves.
Adrien4193 Nov 15, 2024
0dce15a
All geometry objects.
Adrien4193 Nov 18, 2024
fa5e04d
Geometry endpoints.
Adrien4193 Nov 18, 2024
74502e6
Python side geometry.
Adrien4193 Nov 18, 2024
c149c10
Quad mesh tested.
Adrien4193 Nov 18, 2024
d1740b3
All geometries tested.
Adrien4193 Nov 19, 2024
53ab48d
Texture endpoints.
Adrien4193 Nov 21, 2024
9ef5a54
Use different types for binary and text data.
Adrien4193 Nov 21, 2024
bed0c3f
Fixed bug.
Adrien4193 Nov 21, 2024
ab799fd
Python textures.
Adrien4193 Nov 21, 2024
ce0816e
Material checkpoint.
Adrien4193 Nov 22, 2024
2fde4c3
All material objects.
Adrien4193 Nov 22, 2024
f1b43cc
Materials tested.
Adrien4193 Nov 26, 2024
6949c25
Light endpoints implemented.
Adrien4193 Nov 27, 2024
16dc4a7
Lights tested.
Adrien4193 Nov 28, 2024
c3eb060
Fixed material texture ownership.
Adrien4193 Nov 29, 2024
ab3c676
Task endpoints.
Adrien4193 Dec 2, 2024
5ebac46
Renderer objects.
Adrien4193 Dec 3, 2024
4c75ced
Renderer endpoints.
Adrien4193 Dec 3, 2024
a0bae75
Renderer python.
Adrien4193 Dec 3, 2024
7c70853
Renderer tested.
Adrien4193 Dec 3, 2024
4645085
Material validation in renderer.
Adrien4193 Dec 3, 2024
a906faf
Scene objects.
Adrien4193 Dec 4, 2024
01ae791
Add scene endpoints.
Adrien4193 Dec 4, 2024
8a499c9
Scene python API.
Adrien4193 Dec 4, 2024
718ef99
Scene objects tested.
Adrien4193 Dec 9, 2024
5bfb22a
Updated task system.
Adrien4193 Dec 9, 2024
3712d82
Rendering tested.
Adrien4193 Dec 10, 2024
51386fe
Fix tests + format.
Adrien4193 Dec 10, 2024
c3a2982
Fix release build error.
Adrien4193 Dec 10, 2024
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
Prev Previous commit
Next Next commit
All material objects.
  • Loading branch information
Adrien4193 committed Nov 22, 2024
commit 2fde4c3b44ca4d7cc993c793cdd702c3c691e3ba
125 changes: 110 additions & 15 deletions src/brayns/core/objects/MaterialObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

#include "MaterialObjects.h"

#include "common/Objects.h"

namespace
{
using namespace brayns;
Expand Down Expand Up @@ -79,60 +77,157 @@ MaterialField<T> storeAndGet(ObjectManager &objects, std::vector<Stored<UserText
return std::visit([&](const auto &value) { return storeAndGet(objects, textures, value); }, params);
}

AoMaterialSettings storeTexturesAndGetSettings(ObjectManager &objects, std::vector<Stored<UserTexture>> &textures, const AoMaterialParams &params)
AoMaterialSettings parseSettings(ObjectManager &objects, std::vector<Stored<UserTexture>> &textures, const AoMaterialParams &params)
{
return {
.diffuse = storeAndGet(objects, textures, params.diffuse),
.opacity = storeAndGet(objects, textures, params.opacity),
};
}

ScivisMaterialSettings parseSettings(ObjectManager &objects, std::vector<Stored<UserTexture>> &textures, const ScivisMaterialParams &params)
{
return {
.diffuse = storeAndGet(objects, textures, params.diffuse),
.opacity = storeAndGet(objects, textures, params.opacity),
.specular = storeAndGet(objects, textures, params.specular),
.shininess = storeAndGet(objects, textures, params.shininess),
.transparencyFilter = params.transparencyFilter,
};
}

namespace brayns
PrincipledMaterialSettings parseSettings(ObjectManager &objects, std::vector<Stored<UserTexture>> &textures, const PrincipledMaterialParams &params)
{
CreateObjectResult createAoMaterial(ObjectManager &objects, Device &device, CreateAoMaterialParams params)
return {
.baseColor = storeAndGet(objects, textures, params.baseColor),
.edgeColor = storeAndGet(objects, textures, params.edgeColor),
.metallic = storeAndGet(objects, textures, params.metallic),
.diffuse = storeAndGet(objects, textures, params.diffuse),
.specular = storeAndGet(objects, textures, params.specular),
.ior = storeAndGet(objects, textures, params.ior),
.transmission = storeAndGet(objects, textures, params.transmission),
.transmissionColor = storeAndGet(objects, textures, params.transmissionColor),
.transmissionDepth = storeAndGet(objects, textures, params.transmissionDepth),
.roughness = storeAndGet(objects, textures, params.roughness),
.anisotropy = storeAndGet(objects, textures, params.anisotropy),
.rotation = storeAndGet(objects, textures, params.rotation),
.normal = storeAndGet(objects, textures, params.normal),
.baseNormal = storeAndGet(objects, textures, params.baseNormal),
.thin = params.thin,
.thickness = storeAndGet(objects, textures, params.thickness),
.backlight = storeAndGet(objects, textures, params.backlight),
.coat = storeAndGet(objects, textures, params.coat),
.coatIor = storeAndGet(objects, textures, params.coatIor),
.coatColor = storeAndGet(objects, textures, params.coatColor),
.coatThickness = storeAndGet(objects, textures, params.coatThickness),
.coatRoughness = storeAndGet(objects, textures, params.coatRoughness),
.coatNormal = storeAndGet(objects, textures, params.coatNormal),
.sheen = storeAndGet(objects, textures, params.sheen),
.sheenColor = storeAndGet(objects, textures, params.sheenColor),
.sheenTint = storeAndGet(objects, textures, params.sheenTint),
.sheenRoughness = storeAndGet(objects, textures, params.sheenRoughness),
.opacity = storeAndGet(objects, textures, params.opacity),
.emissiveColor = storeAndGet(objects, textures, params.emissiveColor),
};
}

template<typename T>
CreateObjectResult createMaterialAs(ObjectManager &objects, Device &device, const auto &params, auto create, std::string name)
{
auto &[base, derived] = params;
const auto &[base, derived] = params;

auto textures = std::vector<Stored<UserTexture>>();

auto settings = storeTexturesAndGetSettings(objects, textures, derived);
auto settings = parseSettings(objects, textures, derived);

auto material = createAoMaterial(device, settings);
auto material = create(device, settings);

auto ptr = toShared(UserAoMaterial{std::move(derived), std::move(material), std::move(textures)});
auto ptr = toShared(T{derived, std::move(material), std::move(textures)});

auto object = UserMaterial{
.value = ptr,
.get = [=] { return ptr->value; },
};

auto stored = objects.add(std::move(object), {"AoMaterial"}, std::move(base));
auto stored = objects.add(std::move(object), {std::move(name)}, std::move(base));

return getResult(stored);
}

GetAoMaterialResult getAoMaterial(ObjectManager &objects, const GetObjectParams &params)
template<typename T>
auto getMaterialAs(ObjectManager &objects, const GetObjectParams &params)
{
auto stored = objects.getAsStored<UserMaterial>(params.id);
auto &material = *castAsShared<UserAoMaterial>(stored.get().value, stored);
auto &material = *castAsShared<T>(stored.get().value, stored);
return getResult(material.settings);
}

void updateAoMaterial(ObjectManager &objects, Device &device, const UpdateAoMaterialParams &params)
template<typename T>
void updateMaterialAs(ObjectManager &objects, Device &device, const auto &params)
{
auto stored = objects.getAsStored<UserMaterial>(params.id);
auto &material = *castAsShared<UserAoMaterial>(stored.get().value, stored);
auto &material = *castAsShared<T>(stored.get().value, stored);

auto updated = getUpdatedParams(params, material.settings);

auto textures = std::vector<Stored<UserTexture>>();

auto settings = storeTexturesAndGetSettings(objects, textures, updated);
auto settings = parseSettings(objects, textures, updated);

material.value.update(settings);
device.throwIfError();

material.settings = std::move(updated);
}
}

namespace brayns
{
CreateObjectResult createAoMaterial(ObjectManager &objects, Device &device, const CreateAoMaterialParams &params)
{
auto create = [](auto &device, const auto &settings) { return createAoMaterial(device, settings); };
return createMaterialAs<UserAoMaterial>(objects, device, params, create, "AoMaterial");
}

GetAoMaterialResult getAoMaterial(ObjectManager &objects, const GetObjectParams &params)
{
return getMaterialAs<UserAoMaterial>(objects, params);
}

void updateAoMaterial(ObjectManager &objects, Device &device, const UpdateAoMaterialParams &params)
{
updateMaterialAs<UserAoMaterial>(objects, device, params);
}

CreateObjectResult createScivisMaterial(ObjectManager &objects, Device &device, const CreateScivisMaterialParams &params)
{
auto create = [](auto &device, const auto &settings) { return createScivisMaterial(device, settings); };
return createMaterialAs<UserScivisMaterial>(objects, device, params, create, "ScivisMaterial");
}

GetScivisMaterialResult getScivisMaterial(ObjectManager &objects, const GetObjectParams &params)
{
return getMaterialAs<UserScivisMaterial>(objects, params);
}

void updateScivisMaterial(ObjectManager &objects, Device &device, const UpdateScivisMaterialParams &params)
{
updateMaterialAs<UserScivisMaterial>(objects, device, params);
}

CreateObjectResult createPrincipledMaterial(ObjectManager &objects, Device &device, const CreatePrincipledMaterialParams &params)
{
auto create = [](auto &device, const auto &settings) { return createPrincipledMaterial(device, settings); };
return createMaterialAs<UserPrincipledMaterial>(objects, device, params, create, "PrincipledMaterial");
}

GetPrincipledMaterialResult getPrincipledMaterial(ObjectManager &objects, const GetObjectParams &params)
{
return getMaterialAs<UserPrincipledMaterial>(objects, params);
}

void updatePrincipledMaterial(ObjectManager &objects, Device &device, const UpdatePrincipledMaterialParams &params)
{
updateMaterialAs<UserPrincipledMaterial>(objects, device, params);
}
}
145 changes: 144 additions & 1 deletion src/brayns/core/objects/MaterialObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,150 @@ using GetAoMaterialResult = GetResultOf<AoMaterialParams>;
using UpdateAoMaterialParams = UpdateParamsOf<AoMaterialParams>;
using UserAoMaterial = UserMaterialOf<AoMaterialParams, AoMaterial>;

CreateObjectResult createAoMaterial(ObjectManager &objects, Device &device, CreateAoMaterialParams params);
CreateObjectResult createAoMaterial(ObjectManager &objects, Device &device, const CreateAoMaterialParams &params);
GetAoMaterialResult getAoMaterial(ObjectManager &objects, const GetObjectParams &params);
void updateAoMaterial(ObjectManager &objects, Device &device, const UpdateAoMaterialParams &params);

struct ScivisMaterialParams
{
MaterialParams<Color3> diffuse;
MaterialParams<float> opacity;
MaterialParams<Color3> specular;
MaterialParams<float> shininess;
Color3 transparencyFilter;
};

template<>
struct JsonObjectReflector<ScivisMaterialParams>
{
static auto reflect()
{
auto builder = JsonBuilder<ScivisMaterialParams>();
builder.field("diffuse", [](auto &object) { return &object.diffuse; }).description("Diffuse color").defaultValue(Color3{0.8F, 0.8F, 0.8F});
builder.field("opacity", [](auto &object) { return &object.opacity; }).description("Opacity").defaultValue(1.0F);
builder.field("specular", [](auto &object) { return &object.specular; }).description("Specular color").defaultValue(Color3{0.0F, 0.0F, 0.0F});
builder.field("shininess", [](auto &object) { return &object.shininess; }).description("Phong exponent").defaultValue(10);
builder.field("transparencyFilter", [](auto &object) { return &object.transparencyFilter; })
.description("Transparency filter")
.defaultValue(Color3{0.0F, 0.0F, 0.0F});
return builder.build();
}
};

using CreateScivisMaterialParams = CreateParamsOf<ScivisMaterialParams>;
using GetScivisMaterialResult = GetResultOf<ScivisMaterialParams>;
using UpdateScivisMaterialParams = UpdateParamsOf<ScivisMaterialParams>;
using UserScivisMaterial = UserMaterialOf<ScivisMaterialParams, ScivisMaterial>;

CreateObjectResult createScivisMaterial(ObjectManager &objects, Device &device, const CreateScivisMaterialParams &params);
GetScivisMaterialResult getScivisMaterial(ObjectManager &objects, const GetObjectParams &params);
void updateScivisMaterial(ObjectManager &objects, Device &device, const UpdateScivisMaterialParams &params);

struct PrincipledMaterialParams
{
MaterialParams<Color3> baseColor;
MaterialParams<Color3> edgeColor;
MaterialParams<float> metallic;
MaterialParams<float> diffuse;
MaterialParams<float> specular;
MaterialParams<float> ior;
MaterialParams<float> transmission;
MaterialParams<Color3> transmissionColor;
MaterialParams<float> transmissionDepth;
MaterialParams<float> roughness;
MaterialParams<float> anisotropy;
MaterialParams<float> rotation;
MaterialParams<float> normal;
MaterialParams<float> baseNormal;
bool thin;
MaterialParams<float> thickness;
MaterialParams<float> backlight;
MaterialParams<float> coat;
MaterialParams<float> coatIor;
MaterialParams<Color3> coatColor;
MaterialParams<float> coatThickness;
MaterialParams<float> coatRoughness;
MaterialParams<float> coatNormal;
MaterialParams<float> sheen;
MaterialParams<Color3> sheenColor;
MaterialParams<float> sheenTint;
MaterialParams<float> sheenRoughness;
MaterialParams<float> opacity;
MaterialParams<Color3> emissiveColor;
};

template<>
struct JsonObjectReflector<PrincipledMaterialParams>
{
static auto reflect()
{
auto builder = JsonBuilder<PrincipledMaterialParams>();
builder.field("baseColor", [](auto &object) { return &object.baseColor; })
.description("Base color, linear RGB")
.defaultValue(Color3{0.8F, 0.8F, 0.8F});
builder.field("edgeColor", [](auto &object) { return &object.edgeColor; })
.description("Edge color, linear RGB, metallic only")
.defaultValue(Color3{1.0F, 1.0F, 1.0F});
builder.field("metallic", [](auto &object) { return &object.metallic; })
.description("Mix between dielectric and metallic (1 = full metal)")
.defaultValue(0.0F);
builder.field("diffuse", [](auto &object) { return &object.diffuse; }).description("Diffuse reflection weight").defaultValue(1.0F);
builder.field("specular", [](auto &object) { return &object.specular; }).description("Specular reflection weight").defaultValue(1.0F);
builder.field("ior", [](auto &object) { return &object.ior; }).description("Index of refraction").defaultValue(1.0F);
builder.field("transmission", [](auto &object) { return &object.transmission; })
.description("Specular transmission weight")
.defaultValue(0.0F);
builder.field("transmissionColor", [](auto &object) { return &object.transmissionColor; })
.description("Attenuated color due to transmission")
.defaultValue(Color3{1.0F, 1.0F, 1.0F});
builder.field("transmissionDepth", [](auto &object) { return &object.transmissionDepth; })
.description("Distance at which color attenuation is transmissionColor")
.defaultValue(1.0F);
builder.field("roughness", [](auto &object) { return &object.roughness; })
.description("Diffuse and specular roughness (0 = smooth)")
.defaultValue(0.0F);
builder.field("anisotropy", [](auto &object) { return &object.anisotropy; }).description("Specular anisotropy").defaultValue(0.0F);
builder.field("rotation", [](auto &object) { return &object.rotation; })
.description("Rotation of anisotropy direction (1 = full circle)")
.defaultValue(0.0F);
builder.field("normal", [](auto &object) { return &object.normal; }).description("Normal map").defaultValue(1.0F);
builder.field("baseNormal", [](auto &object) { return &object.baseNormal; }).description("Overrides default normal").defaultValue(1.0F);
builder.field("thin", [](auto &object) { return &object.thin; })
.description("")
.description("Wether the material is thin or solid")
.defaultValue(false);
builder.field("thickness", [](auto &object) { return &object.thickness; }).description("Thickness of thin material").defaultValue(1.0F);
builder.field("backlight", [](auto &object) { return &object.backlight; })
.description("Diffuse transmission of thin material, 0 = reflection, 1 = 50/50, 2 = transmission")
.defaultValue(0.0F);
builder.field("coat", [](auto &object) { return &object.coat; }).description("Coat layer weight").defaultValue(0.0F);
builder.field("coatIor", [](auto &object) { return &object.coatIor; }).description("Coat layer IOR").defaultValue(1.5F);
builder.field("coatColor", [](auto &object) { return &object.coatColor; })
.description("Coat layer color")
.defaultValue(Color3{1.0F, 1.0F, 1.0F});
builder.field("coatThickness", [](auto &object) { return &object.coatThickness; }).description("Coat layer thickness").defaultValue(1.0F);
builder.field("coatRoughness", [](auto &object) { return &object.coatRoughness; }).description("Coat layer roughness").defaultValue(0.0F);
builder.field("coatNormal", [](auto &object) { return &object.coatNormal; }).description("Coat layer normal map").defaultValue(1.0F);
builder.field("sheen", [](auto &object) { return &object.sheen; }).description("Sheen layer weight").defaultValue(0.0F);
builder.field("sheenColor", [](auto &object) { return &object.sheenColor; })
.description("Sheen layer color")
.defaultValue(Color3{1.0F, 1.0F, 1.0F});
builder.field("sheenTint", [](auto &object) { return &object.sheenTint; }).description("Sheen layer color").defaultValue(0.0F);
builder.field("sheenRoughness", [](auto &object) { return &object.sheenRoughness; }).description("Sheen layer roughness").defaultValue(0.2F);
builder.field("opacity", [](auto &object) { return &object.opacity; }).description("Cut-out opacity").defaultValue(1.0F);
builder.field("emissiveColor", [](auto &object) { return &object.emissiveColor; })
.description("Color and intensity of light emission")
.defaultValue(Color3{0.0F, 0.0F, 0.0F});
return builder.build();
}
};

using CreatePrincipledMaterialParams = CreateParamsOf<PrincipledMaterialParams>;
using GetPrincipledMaterialResult = GetResultOf<PrincipledMaterialParams>;
using UpdatePrincipledMaterialParams = UpdateParamsOf<PrincipledMaterialParams>;
using UserPrincipledMaterial = UserMaterialOf<PrincipledMaterialParams, PrincipledMaterial>;

CreateObjectResult createPrincipledMaterial(ObjectManager &objects, Device &device, const CreatePrincipledMaterialParams &params);
GetPrincipledMaterialResult getPrincipledMaterial(ObjectManager &objects, const GetObjectParams &params);
void updatePrincipledMaterial(ObjectManager &objects, Device &device, const UpdatePrincipledMaterialParams &params);
}