Jump to content

Odd Results with TEXTURE_R16


SpiderPig
 Share

Go to solution Solved by Josh,

Recommended Posts

Got some weird results with this.  It's using the default shaders for the material so I understand that the result is supposed to be red as there's only data in the red channel of the image.  However only a few small areas appear to have a gradient between red and black pixels and the rest is just solid black or solid red.  Unsure if an appropriate shader needs to be made to sample this or if the texture is not being created correctly.

Saved result of the pixmap shown is Visual Studio:

VS_Image.jpg.ce6271888c2b0b547525ab11e25dd224.jpg

Result with bluegrid.dds:

BlueGrid_Works.thumb.jpg.c29c7cd486b35d0392c733c1ceaaff70.jpg

Result with R16 texture:

Result.thumb.jpg.7903d7a926a13bd60e6fc092749d2d73.jpg

The texture is spread across a grid, so each pixel should be a metre apart and there should be interpolation between each pixel shouldn't there?  I'm seeing some pixels that worked and others that have rounded edges where I think they should be blending.

#include "UltraEngine.h"

using namespace UltraEngine;

Vec3 mousepos = Vec3(0.0f);
float move_adjustment = 0.1f;
float move_speed = 1.0f;
float lookspeed = 0.1f;
float looksmoothing = 0.5f;

int main(int argc, const char* argv[])
{
    auto displays = GetDisplays();
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    auto world = CreateWorld();
    auto framebuffer = CreateFramebuffer(window);

    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetFov(70);
    camera->SetPosition(0, 10, 0);

    auto light = CreateDirectionalLight(world);
    light->SetRotation(35, 35, 0);

    auto box = CreateBox(world);
    box->SetPosition(10.0f, 2049.0f, 10.0f);

    int size = 256;
    unsigned short* buffer = new unsigned short[size * size];
    for (int y = 0; y < size; y++) {
        for (int x = 0; x < size; x++) {
            buffer[(y * size) + x] = (unsigned short)Random(USHRT_MAX);
        }
    }

    auto data = CreateBuffer(size * size * 2);
    data->Poke(0, (const char*)buffer, size * size * 2);

    auto map = CreatePixmap(size, size, TEXTURE_R16, data);
    map->Save("Test.dds");

    vector<shared_ptr<Pixmap>> mipchain;
    mipchain.push_back(map);
    auto texture = CreateTexture(TEXTURE_2D, size, size, map->format, mipchain);
    auto mat = CreateMaterial();
    mat->SetTexture(texture, TEXTURE_DIFFUSE);
    //mat->SetTexture(LoadTexture("Materials\\Developer\\bluegrid.dds"), TEXTURE_DIFFUSE);//Works

    delete[] buffer;

    auto custom_model = CreateModel(world);
    auto mesh = custom_model->AddMesh();

    int index = 0;
    for (int z = 0; z < size; z++) {
        for (int x = 0; x < size; x++) {
            mesh->AddVertex(x, 0.0f, z, 0.0f, 1.0f, 0.0f, (float)x / (float)size, (float)z / (float)size);

            if (x != 0 && x != size - 1 && z != 0 && z != size - 1) {
                mesh->AddPrimitive(index, index - size - 1, index - 1);
                mesh->AddPrimitive(index, index - size, index - size - 1);
            }
            index++;
        }
    }
    custom_model->UpdateBounds();
    custom_model->SetMaterial(mat);


    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        if (window->KeyHit(KEY_F2) == true) { camera->SetWireframe(!camera->GetWireframe()); }

        auto _displaySize = window->GetSize();
        float cx = Round((float)_displaySize.x / 2.0f);
        float cy = Round((float)_displaySize.y / 2.0f);

        auto mpos = Vec3(window->GetMousePosition().x, window->GetMousePosition().y, window->GetMousePosition().z);
        window->SetMousePosition(cx, cy);
        mpos = mpos * looksmoothing + mousepos * (1 - looksmoothing);
        auto dx = (mpos.x - cx) * lookspeed;
        auto dy = (mpos.y - cy) * lookspeed;


        auto camrot = camera->GetRotation();
        camrot.x += dy;
        camrot.y += dx;
        camera->SetRotation(camrot);
        mousepos = mpos;

        auto speed = 0.1f;
        if (window->KeyDown(KEY_SHIFT) == true) { speed = speed * 10.0f; }
        if (window->KeyDown(KEY_W) == true) { camera->Move(0, 0, speed); }
        else if (window->KeyDown(KEY_S) == true) { camera->Move(0, 0, -speed); }
        if (window->KeyDown(KEY_A) == true) { camera->Move(-speed, 0, 0); }
        else if (window->KeyDown(KEY_D) == true) { camera->Move(speed, 0, 0); }
        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

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...