Skip to content

Commit

Permalink
Add initial code for Baikal::UberV2Material. Add diffuse and reflecti…
Browse files Browse the repository at this point in the history
…on inputs
  • Loading branch information
DenisBirukov committed Jan 25, 2018
1 parent 412e6a4 commit 9e0bdad
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 17 deletions.
96 changes: 96 additions & 0 deletions Baikal/SceneGraph/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ namespace Baikal

struct VolumeMaterialConcrete : public VolumeMaterial {
};

struct UberV2MaterialConcrete : public UberV2Material {
};
}

SingleBxdf::Ptr SingleBxdf::Create(BxdfType type) {
Expand All @@ -308,4 +311,97 @@ namespace Baikal
VolumeMaterial::Ptr VolumeMaterial::Create() {
return std::make_shared<VolumeMaterialConcrete>();
}

UberV2Material::Ptr UberV2Material::Create() {
return std::make_shared<UberV2MaterialConcrete>();
}

UberV2Material::UberV2Material()
{
using namespace RadeonRays;
//Diffuse
RegisterInput("uberv2.diffuse.color", "base diffuse albedo", { InputType::kFloat4, InputType::kTexture, InputType::kMaterial });
SetInputValue("uberv2.diffuse.color", float4(1.0f, 1.0f, 1.0f, 1.0f));
RegisterInput("uberv2.diffuse.weight", "albedo multiplier", { InputType::kFloat4, InputType::kTexture, InputType::kMaterial });
SetInputValue("uberv2.diffuse.weight", float4(1.0f, 1.0f, 1.0f, 1.0f));

//Reflection
RegisterInput("uberv2.reflection.color", "base reflection albedo", { InputType::kFloat4, InputType::kTexture, InputType::kMaterial });
SetInputValue("uberv2.reflection.color", float4(1.0f, 1.0f, 1.0f));
RegisterInput("uberv2.reflection.weight", "albedo multiplier", { InputType::kFloat4, InputType::kTexture, InputType::kMaterial });
SetInputValue("uberv2.reflection.weight", float4(0.0f, 0.0f, 0.0f));
RegisterInput("uberv2.reflection.roughness", "reflection roughness", { InputType::kFloat4, InputType::kTexture, InputType::kMaterial });
SetInputValue("uberv2.reflection.roughness", float4(0.5f, 0.5f, 0.5f, 0.5f));
RegisterInput("uberv2.reflection.anisotropy", "level of anisotropy", { InputType::kFloat4, InputType::kTexture, InputType::kMaterial });
SetInputValue("uberv2.reflection.anisotropy", float4(0.0f, 0.0f, 0.0f, 0.0f));
RegisterInput("uberv2.reflection.anisotropy_rotation", "orientation of anisotropic component", { InputType::kFloat4, InputType::kTexture, InputType::kMaterial });
SetInputValue("uberv2.reflection.anisotropy_rotation", float4(0.0f, 0.0f, 0.0f, 0.0f));
RegisterInput("uberv2.reflection.mode", "orientation of anisotropic component", {InputType::kUint});
SetInputValue("uberv2.reflection.mode", 0);
RegisterInput("uberv2.reflection.ior", "index of refraction", { InputType::kFloat4, InputType::kTexture, InputType::kMaterial });
SetInputValue("uberv2.reflection.ior", float4(1.5f, 1.5f, 1.5f, 1.5f));
RegisterInput("uberv2.reflection.metalness", "metalness of the material", { InputType::kFloat4, InputType::kTexture, InputType::kMaterial });
SetInputValue("uberv2.reflection.metalness", float4(1.0f, 1.0f, 1.0f, 1.0f));

//Refraction
/* RegisterInput("uberv2.refraction.color", "uberv2.refraction.color", );
SetInputValue("uberv2.refraction.color", );
RegisterInput("uberv2.refraction.weight", "uberv2.refraction.weight", );
SetInputValue("uberv2.refraction.weight", );
RegisterInput("uberv2.refraction.roughness", "uberv2.refraction.roughness", );
SetInputValue("uberv2.refraction.roughness", );
RegisterInput("uberv2.refraction.ior", "uberv2.refraction.ior", );
SetInputValue("uberv2.refraction.ior", );
RegisterInput("uberv2.refraction.ior_mode", "uberv2.refraction.ior_mode", );
SetInputValue("uberv2.refraction.ior_mode", );
RegisterInput("uberv2.refraction.thin_surface", "uberv2.refraction.thin_surface", );
SetInputValue("uberv2.refraction.thin_surface", );
RegisterInput("uberv2.coating.color", "uberv2.coating.color", );
SetInputValue("uberv2.coating.color", );
RegisterInput("uberv2.coating.weight", "uberv2.coating.weight", );
SetInputValue("uberv2.coating.weight", );
RegisterInput("uberv2.coating.mode", "uberv2.coating.mode", );
SetInputValue("uberv2.coating.mode", );
RegisterInput("uberv2.coating.ior", "uberv2.coating.ior", );
SetInputValue("uberv2.coating.ior", );
RegisterInput("uberv2.coating.metalness", "uberv2.coating.metalness", );
SetInputValue("uberv2.coating.metalness", );
RegisterInput("uberv2.emission.color", "uberv2.emission.color", );
SetInputValue("uberv2.emission.color", );
RegisterInput("uberv2.emission.weight", "uberv2.emission.weight", );
SetInputValue("uberv2.emission.weight", );
RegisterInput("uberv2.emission.mode", "uberv2.emission.mode", );
SetInputValue("uberv2.emission.mode", );
RegisterInput("uberv2.transparency", "uberv2.transparency", );
SetInputValue("uberv2.transparency", );
RegisterInput("uberv2.normal", "uberv2.normal", );
SetInputValue("uberv2.normal", );
RegisterInput("uberv2.bump", "uberv2.bump", );
SetInputValue("uberv2.bump", );
RegisterInput("uberv2.displacement", "uberv2.displacement", );
SetInputValue("uberv2.displacement", );
RegisterInput("uberv2.sss.absorption_color", "uberv2.sss.absorption_color", );
SetInputValue("uberv2.sss.absorption_color", );
RegisterInput("uberv2.sss.scatter_color", "uberv2.sss.scatter_color", );
SetInputValue("uberv2.sss.scatter_color", );
RegisterInput("uberv2.sss.absorption_distance", "uberv2.sss.absorption_distance", );
SetInputValue("uberv2.sss.absorption_distance", );
RegisterInput("uberv2.sss.scatter_distance", "uberv2.sss.scatter_distance", );
SetInputValue("uberv2.sss.scatter_distance", );
RegisterInput("uberv2.sss.scatter_direction", "uberv2.sss.scatter_direction", );
SetInputValue("uberv2.sss.scatter_direction", );
RegisterInput("uberv2.sss.weight", "uberv2.sss.weight", );
SetInputValue("uberv2.sss.weight", );
RegisterInput("uberv2.sss.subsurface_color", "uberv2.sss.subsurface_color", );
SetInputValue("uberv2.sss.subsurface_color", );
RegisterInput("uberv2.sss.multiscatter", "uberv2.sss.multiscatter", );
SetInputValue("uberv2.sss.multiscatter", );
SetInputValue("absorption", RadeonRays::float4(.0f, .0f, .0f, .0f));*/
}

bool UberV2Material::HasEmission() const
{
return (GetInputValue("uberv2.emission.weight").float_value.sqnorm() != 0);
}
}
14 changes: 14 additions & 0 deletions Baikal/SceneGraph/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,18 @@ namespace Baikal
VolumeMaterial();
};

class UberV2Material : public Material
{
public:

using Ptr = std::shared_ptr<UberV2Material>;
static Ptr Create();

// Check if material has emissive components
bool HasEmission() const override;

protected:
UberV2Material();
};

}
73 changes: 58 additions & 15 deletions Rpr/WrapObject/Materials/MaterialObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,66 @@ THE SOFTWARE.
#include "MultiBxdfMaterialObject.h"
#include "UnsupportedMaterialObject.h"
#include "ArithmeticMaterialObject.h"
#include "UberMaterialObject.h"

using namespace RadeonRays;
using namespace Baikal;

namespace
{
//contains pairs <rpr input name, baikal input name> of input names
const std::map<std::string, std::string> kInputNamesDictionary = { { "color" , "albedo" },
{ "normal" , "normal" },
{ "roughness" , "roughness" },
{ "roughness_x" , "roughness" },
{ "weight" , "weight" },
{ "ior" , "ior" },
{ "color0", "base_material" },
{ "color1", "top_material" },
{ "data", "data" },
{ "sigmas", "sigmas" },
{ "sigmaa", "sigmaa" },
{ "rotation", "rotation" },
{ "anisotropic", "anisotropic" },
{ "g", "g" },
{ "multiscatter", "multiscatter" }, };
const std::map<std::string, std::string> kInputNamesDictionary = {
{ "color" , "albedo" },
{ "normal" , "normal" },
{ "roughness" , "roughness" },
{ "roughness_x" , "roughness" },
{ "weight" , "weight" },
{ "ior" , "ior" },
{ "color0", "base_material" },
{ "color1", "top_material" },
{ "data", "data" },
{ "sigmas", "sigmas" },
{ "sigmaa", "sigmaa" },
{ "rotation", "rotation" },
{ "anisotropic", "anisotropic" },
{ "g", "g" },
{ "multiscatter", "multiscatter" },
{ "uberv2.diffuse.color", "uberv2.diffuse.color" },
{ "uberv2.diffuse.weight", "uberv2.diffuse.weight" },
{ "uberv2.reflection.color", "uberv2.reflection.color" },
{ "uberv2.reflection.weight", "uberv2.reflection.weight" },
{ "uberv2.reflection.roughness", "uberv2.reflection.roughness" },
{ "uberv2.reflection.anisotropy", "uberv2.reflection.anisotropy" },
{ "uberv2.reflection.anisotropy", "uberv2.reflection.anisotropy" },
{ "uberv2.reflection.mode", "uberv2.reflection.mode" },
{ "uberv2.reflection.ior", "uberv2.reflection.ior" },
{ "uberv2.reflection.metalness", "uberv2.reflection.metalness" },
{ "uberv2.refraction.color", "uberv2.refraction.color" },
{ "uberv2.refraction.weight", "uberv2.refraction.weight" },
{ "uberv2.refraction.roughness", "uberv2.refraction.roughness" },
{ "uberv2.refraction.ior", "uberv2.refraction.ior" },
{ "uberv2.refraction.ior", "uberv2.refraction.ior" },
{ "uberv2.refraction.thin", "uberv2.refraction.thin" },
{ "uberv2.coating.color", "uberv2.coating.color" },
{ "uberv2.coating.weight", "uberv2.coating.weight" },
{ "uberv2.coating.mode", "uberv2.coating.mode" },
{ "uberv2.coating.ior", "uberv2.coating.ior" },
{ "uberv2.coating.metalness", "uberv2.coating.metalness" },
{ "uberv2.emission.color", "uberv2.emission.color" },
{ "uberv2.emission.weight", "uberv2.emission.weight" },
{ "uberv2.emission.mode", "uberv2.emission.mode" },
{ "uberv2.transparency", "uberv2.transparency" },
{ "uberv2.normal", "uberv2.normal" },
{ "uberv2.bump", "uberv2.bump" },
{ "uberv2.displacement", "uberv2.displacement" },
{ "uberv2.sss.absorption", "uberv2.sss.absorption" },
{ "uberv2.sss.scatter", "uberv2.sss.scatter" },
{ "uberv2.sss.absorption", "uberv2.sss.absorption" },
{ "uberv2.sss.scatter", "uberv2.sss.scatter" },
{ "uberv2.sss.scatter", "uberv2.sss.scatter" },
{ "uberv2.sss.weight", "uberv2.sss.weight" },
{ "uberv2.sss.subsurface", "uberv2.sss.subsurface" },
{ "uberv2.sss.multiscatter", "uberv2.sss.multiscatter" }};

std::map<uint32_t, std::string> kMaterialNodeInputStrings = {
{ RPR_MATERIAL_INPUT_COLOR, "color" },
Expand Down Expand Up @@ -194,6 +232,11 @@ MaterialObject* MaterialObject::CreateMaterial(rpr_material_node_type in_type)
{
return new UnsupportedMaterialObject(type);
}

case MaterialObject::kUberV2:
{
return new UberMaterialObject();
}
default:
throw Exception(RPR_ERROR_INVALID_PARAMETER_TYPE, "MaterialObject: unrecognized material type");
}
Expand Down
2 changes: 1 addition & 1 deletion Rpr/WrapObject/Materials/MaterialObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MaterialObject
kStandard = RPR_MATERIAL_NODE_STANDARD,
kPassthrough = RPR_MATERIAL_NODE_PASSTHROUGH,
kOrennayar = RPR_MATERIAL_NODE_ORENNAYAR,
kUberV2
kUberV2 = 0x100
};

//initialize methods
Expand Down
40 changes: 40 additions & 0 deletions Rpr/WrapObject/Materials/UberMaterialObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "UberMaterialObject.h"

#include "TextureMaterialObject.h"

using namespace RadeonRays;
using namespace Baikal;

UberMaterialObject::UberMaterialObject() :
MaterialObject(kUberV2)
{
m_mat = UberV2Material::Create();
}

void UberMaterialObject::SetInputF(const std::string & input_name, const RadeonRays::float4 & val)
{
m_mat->SetInputValue(input_name, val);
}

Baikal::Material::Ptr UberMaterialObject::GetMaterial()
{
return m_mat;
}

void UberMaterialObject::SetInputMaterial(const std::string & input_name, MaterialObject * input)
{
m_mat->SetInputValue(input_name, input->GetMaterial());
}

void UberMaterialObject::SetInputTexture(const std::string & input_name, TextureMaterialObject * input)
{
try
{
m_mat->SetInputValue(input_name, input->GetTexture());
}
catch (...)
{
//Ignore
return;
}
}
43 changes: 43 additions & 0 deletions Rpr/WrapObject/Materials/UberMaterialObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**********************************************************************
Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
********************************************************************/
#pragma once

#include "MaterialObject.h"

class UberMaterialObject : public MaterialObject
{
public:
UberMaterialObject();

void SetInputF(const std::string& input_name, const RadeonRays::float4& val) override;

Baikal::Material::Ptr GetMaterial() override;

protected:
void SetInputMaterial(const std::string& input_name, MaterialObject* input) override;
void SetInputTexture(const std::string& input_name, TextureMaterialObject* input) override;

private:
Baikal::Material::Ptr m_mat; //ubermaterial material

};

2 changes: 1 addition & 1 deletion RprSupport/RprSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ rpr_int rprxCreateMaterial(rprx_context context, rprx_material_type type, rprx_m
if (!context || type != RPRX_MATERIAL_UBER)
return RPR_ERROR_INVALID_PARAMETER;

return rprMaterialSystemCreateNode((rpr_material_system)(context), type, (rpr_material_node*)out_material);
return rprMaterialSystemCreateNode((rpr_material_system)(context), MaterialObject::kUberV2, (rpr_material_node*)out_material);
}

rpr_int rprxMaterialDelete(rprx_context context, rprx_material material)
Expand Down

0 comments on commit 9e0bdad

Please sign in to comment.