Page 1 of 1

Sending 1D depthbuffer to a shader

Posted: Sat Jan 15, 2022 11:22 pm
by ogge
Hello, is there a way for me to send a 1D depth-buffer to a shader.

I'm trying to store a value(distance) for every x-coordinate on the screen. And I would like to send it to my shader.
I've tried to send an array to the shader, but that won't let me send over 1019 values to a shader. Plus I heard that It was very slow.

So how can I do this?

Re: Sending 1D depthbuffer to a shader

Posted: Sun Jan 16, 2022 8:38 am
by Nelvin
You could use a texture, store your distances in it's pixels and then sample the value using your x-coordinate in your shader.

Re: Sending 1D depthbuffer to a shader

Posted: Sun Jan 16, 2022 9:42 am
by ogge
Nelvin wrote: Sun Jan 16, 2022 8:38 am You could use a texture, store your distances in it's pixels and then sample the value using your x-coordinate in your shader.
but won't that limit me to store a maximum of 255*4 different values per pixel?

Re: Sending 1D depthbuffer to a shader

Posted: Sun Jan 16, 2022 10:51 am
by grump
Make an ImageData of format r32f (or whatever fits best) with the approriate width and a height of 1 pixel. Make an Image from the ImageData, that's your texture, and send it to the shader. Use Image:replacePixels to update the texture. Use ImageData:mapPixel to update the pixels, avoid ImageData:setPixel.

https://love2d.org/wiki/PixelFormat
https://love2d.org/wiki/ImageData:mapPixel
https://love2d.org/wiki/(Image):replacePixels

Re: Sending 1D depthbuffer to a shader

Posted: Sun Jan 16, 2022 3:53 pm
by ogge
grump wrote: Sun Jan 16, 2022 10:51 am Make an ImageData of format r32f (or whatever fits best) with the approriate width and a height of 1 pixel. Make an Image from the ImageData, that's your texture, and send it to the shader. Use Image:replacePixels to update the texture. Use ImageData:mapPixel to update the pixels, avoid ImageData:setPixel.

https://love2d.org/wiki/PixelFormat
https://love2d.org/wiki/ImageData:mapPixel
https://love2d.org/wiki/(Image):replacePixels
thank you!