Jump to content

Basic PBR setup


Josh
 Share

Recommended Posts

In Leadwerks there was one skybox to set. In Ultra there are up to three different environment maps you can use, but most of the time you will just use two textures in three places.

This tool can be used to turn an HDR file into a specular and diffuse environment map. I plan to provide a large collection of free skyboxes from free sources ready-to-use once I have this finalized. You can load the outputted KTX2 textures with the appropriate plugin, or you can convert them to DDS and load them without any plugin. I am including one ready-to-use environment map in the default template. BC6H is the best compression format for these images.

Set the world environment maps with the command below. ENVIRONMENTMAP_BACKGROUND is the skybox. SPECULAR is the specular reflections that appear on objects. DIFFUSE is the diffuse PBR lighting.

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    auto world = CreateWorld();

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create a camera
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 0, -2);

    auto specmap = LoadTexture("Materials/Environment/Storm/specular.dds");
    auto diffmap = LoadTexture("Materials/Environment/Storm/diffuse.dds");

    world->SetEnvironmentMap(specmap, ENVIRONMENTMAP_BACKGROUND);
    world->SetEnvironmentMap(specmap, ENVIRONMENTMAP_SPECULAR);
    world->SetEnvironmentMap(diffmap, ENVIRONMENTMAP_DIFFUSE);

    auto mtl = CreateMaterial();
    mtl->SetRoughness(0.25);
    mtl->SetMetalness(0.5);

    auto ball = CreateSphere(world);
    ball->SetMaterial(mtl);

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        camera->UpdateControls(window);
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

Note there are no lighting created, the material is just reflecting the sky, which is quite bright:

Untitled.thumb.jpg.44d43de8775c9b63ffcaae2785a9032b.jpg

It looks good, but would seem very unnatural if the sphere was inside a building. Voxel ray tracing solves that problem by inserting geometry into the reflection before the skybox is sampled.

  • Like 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...