# How to create \*large\* textures?

**URL:** <https://forums.unrealengine.com/t/how-to-create-large-textures/1180240>\
**Category:** Programming & Scripting\
**Tags:** rhi, unreal-engine, Rendering, CPP, question\
**Created:** [May 27, 2023, 11:50am UTC](https://forums.unrealengine.com/t/how-to-create-large-textures/1180240 "2023-05-27T11:50:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aejjee](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/aejjee/32/1204088_2.png) [@Aejjee](https://forums.unrealengine.com/u/Aejjee)\
**Post date:** [May 27, 2023, 11:50am UTC](https://forums.unrealengine.com/t/how-to-create-large-textures/1180240/1 "2023-05-27T11:50:32Z")

</div>

I am trying to pass textures on the order of magnitude of 11 million floats long, however, I am getting this error when I try to create the textures:

 ![Screenshot 2023-05-27 054055](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/2/3/42398ff2cb4e975f0bb10b451cc77994843f41d6.png)

Apparently I can’t create textures larger than 128x128? That’s quite small for a game engine I think. Theoretically, a texture 4096x4096 should be more than enough to achieve this task.

I’m creating the textures like so:

```auto
UTexture2D* AMSPWindow::CreateTextureFrom32BitFloat(TArray<float> data, int width, int height) {
	UTexture2D* texture;
	texture = UTexture2D::CreateTransient(width, height, PF_R32_FLOAT);
	if (!texture) {
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "Failed to create MSP data texture.");
		return nullptr;
	}
	texture->NeverStream = true;
	texture->SRGB = 0;
	texture->LODGroup = TextureGroup::TEXTUREGROUP_Pixels2D;
	FTexture2DMipMap& mip = texture->PlatformData->Mips[0];
	void* dataTarget = mip.BulkData.Lock(LOCK_READ_WRITE);
	FMemory::Memcpy(dataTarget, data.GetData(), width * height * 4);
	mip.BulkData.Unlock();
	texture->UpdateResource();
	return texture;
}

```

I found this technique in a reddit forum here: [https://www.reddit.com/r/unrealengine/comments/gxmmmr/pass\_an\_array\_of\_floatsfcolors\_to\_material/](https://www.reddit.com/r/unrealengine/comments/gxmmmr/pass_an_array_of_floatsfcolors_to_material/)

Any ideas as to what’s going wrong here or how I can get around this?

---

<div class="post-metadata">

**Author:** ![Klian](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/klian/32/1207571_2.png) [@Klian](https://forums.unrealengine.com/u/Klian)\
**Post date:** [May 27, 2023, 12:18pm UTC](https://forums.unrealengine.com/t/how-to-create-large-textures/1180240/2 "2023-05-27T12:18:08Z")

</div>

You’re trying to create a texture bigger than 16k res, which I think is the hard limit right now.

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [May 27, 2023, 5:29pm UTC](https://forums.unrealengine.com/t/how-to-create-large-textures/1180240/3 "2023-05-27T17:29:25Z")

</div>

Yes 16384 is the RHI limit - but that should give you 1 billion floats (if RGBA\_32f rather than R32f)

You’ll need to split the data over multiple textures if you’re wanting more than that…

---

<div class="post-metadata">

**Author:** ![Aejjee](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/aejjee/32/1204088_2.png) [@Aejjee](https://forums.unrealengine.com/u/Aejjee)\
**Post date:** [May 27, 2023, 8:53pm UTC](https://forums.unrealengine.com/t/how-to-create-large-textures/1180240/4 "2023-05-27T20:53:09Z")

</div>

But even though I’m only loading floats into the red channel shouldn’t a 4096x4096 texture still have enough? That has 16 million pixels, and if each pixel holds one float in the red channel I feel like there should still be enough pixels to hold the data.

I guess I may be misunderstanding the difference between rhi resolution and texture resolution. Are those not the same?

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [May 27, 2023, 9:10pm UTC](https://forums.unrealengine.com/t/how-to-create-large-textures/1180240/5 "2023-05-27T21:10:14Z")

</div>

Yes that should be fine!

They are the same resolution between texture and RHI - but from the log you showed in the other post it was trying to allocate a texture 32433x32433 - the maxiumum is 16384x16384.

I just tried creating one here at 4096x4096xR32f and one at 16384x16384xR32f and they seem to work ok…

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/4/0/f4035c31099b0b1b5abf9df19a132df7b9aaa97c.png)

---

<div class="post-metadata">

**Author:** ![Aejjee](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/aejjee/32/1204088_2.png) [@Aejjee](https://forums.unrealengine.com/u/Aejjee)\
**Post date:** [May 27, 2023, 11:16pm UTC](https://forums.unrealengine.com/t/how-to-create-large-textures/1180240/6 "2023-05-27T23:16:50Z")

</div>

Okay so I found the problem, it was quite an obvious mistake on my part. The error says that the texture exceeds the maximum allowed _dimension_, not _size_. In my code I was treating the texture like a float array so I had the dimensions of the texture as `(data.Num(), 1)`, and since the data is typically millions of floats long this clearly exceeds the dimension limits.

It’s nice to have the textures structured like this because it makes shader sampling index wise quite simple, but it seems I will just have to pack the data asymmetrically. I tried making the texture `(data.Num() / 1080, 1080)` and the texture was successfully created. Thanks for everyone’s help!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [June 26, 2023, 11:17pm UTC](https://forums.unrealengine.com/t/how-to-create-large-textures/1180240/7 "2023-06-26T23:17:45Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
