Physically Based Rendering is a set of rendering techniques which simulate how light and surface materials interact in the natural world. The goal is to create images which are more realistic than traditional shading approaches.
HPS
This is a very simple HPS sample to create a shell using Physically Based Rendering (or PBR).
...
This should result in a scene similar to:
...
PBR Materials Without Textures
It’s also possible to specify PBR materials without using textures or maps. Consider the following sample code;
HPS
Code Block |
---|
void TestSimplePBRCHPSView::OnUserCode4() { typedeffloat structsphereRadius { float r= 0.8; float sphereOffset = 2.0; float factorOffset = 0.2; int factorCount = 7; float normalFactor = 0.0; float metalFactor = 0.0; float roughFactor = 0.0; float occlusionFactor = 0.0; float alphaFactor = 0.0; HPS::Point position(0,0,0); char segmentName[64]; RGBAColor cyan(0, 1, 1, 1); SegmentKey testKey = GetCanvas().GetFrontView().GetAttachedModel().GetSegmentKey().Subsegment("test"); testKey.InsertDistantLight(Vector(-0.4174f, -0.2564f, 0.8951f)); sprintf(segmentName, "sphere baseline"); SegmentKey baselineSphereKey = testKey.Subsegment(segmentName); baselineSphereKey.InsertSphere(position, sphereRadius); baselineSphereKey.GetMaterialMappingControl().SetFaceColor(HPS::RGBAColor(0, 1, 1)); SegmentKey spheresKey = testKey.Subsegment("spheres"); for (int i = 0; i < factorCount; ++i) { for (int j = 0; j < factorCount; ++j) { sprintf(segmentName, "sphere %d %d", i, j); position.x += sphereOffset; metalFactor = i * factorOffset; roughFactor = j * factorOffset; SegmentKey aSphereKey = spheresKey.Subsegment(segmentName); aSphereKey.InsertSphere(position, sphereRadius); HPS::PBRMaterialKit pbrMaterialKit; pbrMaterialKit. SetBaseColorFactor(cyan). SetNormalFactor(normalFactor). SetMetalnessFactor(metalFactor). SetRoughnessFactor(roughFactor). SetOcclusionFactor(occlusionFactor). SetAlphaFactor(alphaFactor); aSphereKey.SetPBRMaterial(pbrMaterialKit); } position.x = 0; position.y += sphereOffset; } } |
3DF
Code Block |
---|
void TestSimplePBR()
{
typedef struct { float r, g, b, a; } RGBA;
float sphereRadius = 0.8;
float sphereOffset = 2.0;
float factorOffset = 0.2;
int factorCount = 7;
float normalFactor = 0.0;
float metalFactor = 0.0;
float roughFactor = 0.0;
float occlusionFactor = 0.0;
float alphaFactor = 0.0;
HPoint position;
char segmentName[64];
RGBA cyan;
cyan.r = 0;
cyan.g = 1;
cyan.b = 1;
cyan.a = 1;
HC_Open_Segment("test"); {
sprintf(segmentName, "sphere baseline");
position.Set(0, 0, 0);
HC_Open_Segment(segmentName); {
HC_Insert_Sphere(&position, sphereRadius, nullptr, nullptr);
HC_Set_Color("faces = (r=0.0 g=1 b=1)");
} HC_Close_Segment();
HC_Open_Segment("spheres"); {
for (int i = 0; i < factorCount; ++i)
{
for (int j = 0; j < factorCount; ++j)
{
sprintf(segmentName, "sphere %d %d", i, j);
position.x += sphereOffset;
metalFactor = i * factorOffset;
roughFactor = j * factorOffset;
HC_Open_Segment(segmentName); {
HC_Insert_Sphere(&position, sphereRadius, nullptr, nullptr);
HC_Set_PBR_Material(nullptr, nullptr, nullptr, nullptr, 0, nullptr, 0, nullptr, 0, &cyan, normalFactor, metalFactor, roughFactor, occlusionFactor, alphaFactor, nullptr);
} HC_Close_Segment();
}
position.x = 0;
position.y += sphereOffset;
}
} HC_Close_Segment();
} HC_Close_Segment();
} |
Rendering Result
This code produces a scene as follows where the rough factor changes from 0.0 to 1.0 moving from left to right and the metal factor change from 0.0 to 1.0 moving from the bottom to the top;
...