Page 1 of 1

How to make the same shader as Love2d default one

Posted: Thu Apr 13, 2023 3:46 pm
by Sasha264
Good day! :awesome:

I've noticed that when the default shader is set up using

Code: Select all

love.graphics.setShader()
it's possible to draw both a simple Image love.graphics.newImage and an ArrayImage love.graphics.newArrayImage without any additional code changes.

However, I'm struggling to create the same behavior with my custom shader. I have no problem creating a shader that works with either ArrayImage or a simple Image, but not with both. By "both," I mean not simultaneously, but with one (random) of them at a time, like in my example:

Code: Select all

-- This works just fine
love.graphics.setShader()
love.graphics.draw(image, 100, 100)
love.graphics.draw(arrayImage, 300, 100)

-- But this gives an error!
-- love.graphics.setShader(shader)
-- love.graphics.draw(image, 100, 100)
-- love.graphics.draw(arrayImage, 300, 100)
Is it even possible?

Here's the full code attached to illustrate my problem:
main.lua
(1.25 KiB) Downloaded 75 times

Re: How to make the same shader as Love2d default one

Posted: Thu Apr 13, 2023 3:55 pm
by Sasha264
Small comment, why do I even need that:
It happened that in some of my code, I have a collection of one-layered ArrayImage-s, and I was hoping that I could draw them with all of my shaders that are designed to work with simple images. Unfortunately, I had no luck. I even tried using love.graphics.drawLayer, but it still requires an ArrayImage as the image type inside the pixel shader. And I don't want to maintain two versions of all my shaders — one for simple Images and one for one-layered ArrayImage-s.

Re: How to make the same shader as Love2d default one

Posted: Thu Apr 13, 2023 6:30 pm
by zorg
Unless i misremember, löve's default behavior is to check whether the image is an array image or not, then load the appropriate "default" shader to handle it... so it's still two shaders.

Re: How to make the same shader as Love2d default one

Posted: Sun Apr 16, 2023 10:13 am
by Sasha264
@zorg, well... that make sense. Thank you)

Re: How to make the same shader as Love2d default one

Posted: Sun Apr 16, 2023 1:30 pm
by slime
Yep, there are a small number of different default shaders love uses internally depending on what's being drawn: https://github.com/love2d/love/blob/78e ... r.lua#L449

Re: How to make the same shader as Love2d default one

Posted: Sat Apr 29, 2023 10:05 pm
by Sasha264
slime wrote: Sun Apr 16, 2023 1:30 pm Yep, there are a small number of different default shaders love uses internally depending on what's being drawn: https://github.com/love2d/love/blob/78e ... r.lua#L449
Thank you! That's good to know :)