Sending 1D depthbuffer to a shader

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ogge
Prole
Posts: 4
Joined: Sat Jan 15, 2022 9:52 pm

Sending 1D depthbuffer to a shader

Post 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?
Nelvin
Party member
Posts: 124
Joined: Mon Sep 12, 2016 7:52 am
Location: Germany

Re: Sending 1D depthbuffer to a shader

Post 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.
ogge
Prole
Posts: 4
Joined: Sat Jan 15, 2022 9:52 pm

Re: Sending 1D depthbuffer to a shader

Post 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?
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Sending 1D depthbuffer to a shader

Post 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
ogge
Prole
Posts: 4
Joined: Sat Jan 15, 2022 9:52 pm

Re: Sending 1D depthbuffer to a shader

Post 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!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests