Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Dynamic Textures Under 256x256

I am creating my own lighting engine of sorts and I am at the point where I am building the textures. I've run into an issue with the textures getting corrupted if the resolution of the texture is lower than 256x256.

It looks like this:

alt text

This is supposed to be all black.

Here's the code where I create the actual texture. This part seems to work fine, and gives me a solid white texture. I call setPixelRegion() at the end, which is supposed to turn the image black:

    lightmapBuffer = new uint8[resX * resY * 4];
     lightmap = UTexture2D::CreateTransient(resX, resY);
     lightmap->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
     lightmap->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
     lightmap->Filter = TextureFilter::TF_Nearest;
     updateTextureRegion = new FUpdateTextureRegion2D(0, 0, 0, 0, resX, resY);
     setPixelRegion(0, 0, resX, resY, 0);

Here's the setPixelRegion code, which should be setting each pixel of the texture to have an RGBA value of (0, 0, 0, 255):

 void ULightableComponent::setPixelRegion(int x, int y, int w, int h, uint8 b)
     uint8 valb = b;
     for (int row = y; row < h; row++)
         for (int col = x; col < w; col++)
             int i = (row * w) + col;
             lightmapBuffer[(4*i)+0] = valb;
             lightmapBuffer[(4*i)+1] = valb;
             lightmapBuffer[(4*i)+2] = valb;
             lightmapBuffer[(4*i)+3] = 255;
     FUpdateTextureRegion2D* updateRegion = new FUpdateTextureRegion2D(x, y, x, y, w, h);
     lightmap->UpdateTextureRegions(0, 1, updateRegion, 1024, 4, lightmapBuffer);

This code works totally fine if the image is at least 256x256, but anything less than that and it gets all garbled like the picture.

Here it is with a 256x256 resolution (this is with a light applied, so it's not just an all black image. The first one is supposed to be all black, but is garbled):

alt text

What am I missing?

One thing I've noticed is the top half of the image seems to work most of the time, but the bottom half is all messed up. It's like all of the data is shifted up to the top. It's still not working properly in the top, but it looks more correct than the bottom.

Product Version: UE 4.17
more ▼

asked Apr 26 '19 at 11:00 AM in C++ Programming

avatar image

107 16 24 28

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question