Read F_RGBA Pixels from a uncompressed Texture2D in a custom node (HLSL)

I have data I need to send to a custom node. I need the custom node because my data is dynamic and I need to loop through it.

I wrote the data in a Texture2D and set the Compression to UI (none) and disable the mip gen.

The data is written properly into the buffer of the texture (verified multiple times) but my issue is how to access it properly from the HLSL.

Fill the buffer :

UTexture2D* UWavesBPFunctions::AddWavesToTextureObjects(const TArray<FWaveStruct>& waves)
{
	const SIZE_T copySize = sizeof(FWaveStruct) - sizeof(FWaveStruct::LastWave);
	UTexture2D* waveTex = UTexture2D::CreateTransient(copySize*waves.Num()/sizeof(float), 1, PF_FloatRGBA, FName("WaveDataTex"));
	FTexture2DMipMap& mipPart1 = waveTex->PlatformData->Mips[0];
	waveTex->CompressionSettings = TextureCompressionSettings::TC_EditorIcon;
	waveTex->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
	waveTex->LODGroup = TextureGroup::TEXTUREGROUP_Pixels2D;
	waveTex->SRGB = 0;
	waveTex->DeferCompression = 1;
	uint8* dataPart1 = static_cast<uint8*>(mipPart1.BulkData.Lock(LOCK_READ_WRITE));
	for (TArray<FWaveStruct>::TConstIterator wavesIter(waves); wavesIter; ++wavesIter)
	{
		const uint8* srcPtr = static_cast<const uint8*>(static_cast<const void*>(&(*(wavesIter))));

		FMemory::Memcpy(dataPart1, srcPtr+sizeof(FWaveStruct::LastWave), copySize);
		
		dataPart1+=copySize;
	}
	mipPart1.BulkData.Unlock();
	waveTex->UpdateResource();
	
	return waveTex;
}

HLSL I tried both of those :

    amplitude = WavesData.mips[0][pos];

    amplitude = Texture2DSampleLevel(WavesData, WavesDataSampler,  float2(0 ,0),0);

The code above is just trying to get the first float in the buffer and nothing else that’s why the UV is just 0,0.

Since it is almost impossible to debug code in a custom node (I added an additional output and check if the value is the correct one with a “if” but I can’t know what its actual value is).

What am I doing wrong ? How to access the “unchanged” data in the texture to use it as a buffer ?

1 Like

ever figure this out? I’m doing the version your last example for a fake lighting system via render target, but it just renders black for me