0

I'm trying to achieve rendering of cell-based terrain (one like in old games like Transport Tycoon) with strong cell borders. To optimize performance I pass a texture with an actual game map in which I try to encode a cell type for a custom shader, so the shader could lookup the type for every cell and determine which textures to apply to a particular cell while rendering the terrain mesh.

It would be convenient to pass that map in an integer type so I could mask particular bits with bitwise operators and basically pass a lot of data in just one byte. Passing floats leads to losing precision and I can't be sure I have the same integer after converting to a float and back to int.

Is there any way to pass an array (2d array or even texture is better) of Integer type to a shader or there's a reason they don't have SetIntegerArray in API like lack of compatibility with mobile GPU or something?

Pavel Vorobyov
  • 773
  • 6
  • 10

1 Answers1

0

Integer are not recommended to use because:

Depending on the platform, integer types might not be supported by the GPU. For example, Direct3D 9 and OpenGL ES 2.0 GPUs only operate on floating point data, and simple-looking integer expressions (involving bit or logical operations) might be emulated using fairly complicated floating point math instructions. https://docs.unity3d.com/Manual/SL-DataTypesAndPrecision.html

So you must use floating point types. Use Material.SetFloatArray() or Material.SetVectorArray() for assigning.

Sergiy Klimkov
  • 530
  • 7
  • 15