Question

I am attempting to create a tile engine using a pixel shader and two textures. One texture will hold the tileset and one the map.

Is it possible to read the texture data as actual (unsampled) data so I can pull indexes from the map?

What is the best way to read that pixel data?

I have tried just text2D but that leaves something to be desired (I am a bit new to pixel shaders to be honest).

Basically, I need a way to read the actual data from a specific pixel in my map texture and use that as an integer index into the tile texture. Assume I have managed to create and pass the appropriate textures to the shader.

Any thoughts?

(using monogame for metro so dx level 9_1)

Was it helpful?

Solution

If you use tex2D and pass in (x + 0.5) / width and (y + 0.5) / height, you should get the exact pixel value at (x, y). More information here: Texture memory-tex2D basics

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top